Skip to content

Commit bbd5126

Browse files
author
Micah Lee
committed
Mostly working code to show a notificationBox only when upgrading from
an earlier HTTPS Everywhere version that doesn't have a prefs_version. https://trac.torproject.org/projects/tor/ticket/8776
1 parent 8e3cdb4 commit bbd5126

3 files changed

Lines changed: 39 additions & 23 deletions

File tree

‎src/chrome/content/toolbar_button.js‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
window.addEventListener("load", https_everywhere_load, true);
2+
gBrowser.addEventListener("load", migratePreferences, true);
23

34
const CI = Components.interfaces;
45
const CC = Components.classes;
@@ -75,7 +76,6 @@ httpsEverywhere.toolbarButton = {
7576

7677
gBrowser.addEventListener('load', tb.handleShowHint, true);
7778
}
78-
7979
},
8080

8181
/**
@@ -152,8 +152,7 @@ httpsEverywhere.toolbarButton = {
152152

153153
toolbarbutton.setAttribute('rulesetsApplied', counter);
154154
HTTPSEverywhere.log(INFO, 'Setting icon counter to: ' + counter);
155-
}
156-
155+
}
157156
};
158157

159158

@@ -265,3 +264,37 @@ function open_in_tab(url) {
265264
// hook event for showing hint
266265
HTTPSEverywhere.log(DBUG, 'Adding listener for toolbarButton init.');
267266
window.addEventListener("load", httpsEverywhere.toolbarButton.init, false);
267+
268+
function migratePreferences() {
269+
gBrowser.removeEventListener("load", migratePreferences, true);
270+
271+
let prefs_version = HTTPSEverywhere.prefs.getIntPref("prefs_version");
272+
273+
// first migration loses saved prefs
274+
if(prefs_version == 0) {
275+
try {
276+
// upgrades will have old rules as preferences, such as the EFF rule
277+
let upgrade = false;
278+
let childList = HTTPSEverywhere.prefs.getChildList("", {});
279+
for(let i=0; i<childList.length; i++) {
280+
if(childList[i] == 'EFF') upgrade = true;
281+
}
282+
283+
if(upgrade) {
284+
let nBox = gBrowser.getNotificationBox();
285+
let strings = document.getElementById('HttpsEverywhereStrings');
286+
let msg = strings.getString('https-everywhere.migration.notification0');
287+
nBox.appendNotification(
288+
msg,
289+
'https-everywhere-migration0',
290+
'chrome://https-everywhere/skin/https-everywhere-24.png',
291+
nBox.PRIORITY_WARNING_MEDIUM
292+
);
293+
}
294+
} catch(e) {
295+
HTTPSEverywhere.log(WARN, "Migration from prefs_version 0 error: "+e);
296+
}
297+
298+
HTTPSEverywhere.prefs.setIntPref("prefs_version", prefs_version+1);
299+
}
300+
}

‎src/chrome/locale/en/https-everywhere.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ https-everywhere.menu.enableDisable = Enable / Disable Rules
44
https-everywhere.menu.noRules = (No Rules for This Page)
55
https-everywhere.menu.unknownRules = (Rules for This Page Unknown)
66
https-everywhere.toolbar.hint = HTTPS Everywhere is now active. You can toggle it on a site-by-site basis by clicking the icon in the address bar.
7-
https-everywhere.migration.notification0 = In order to improve your browsing experience with HTTPS Everywhere, we've changed how we store rules. Your existing enabled/disabled rules have been reset to their default values.
7+
https-everywhere.migration.notification0 = In order to implement a crucial fix, this update resets your HTTPS Everywhere rules for specific websites to their default values.

‎src/components/https-everywhere.js‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,7 @@ function HTTPSEverywhere() {
199199
this.obsService.addObserver(this, "profile-after-change", false);
200200
this.obsService.addObserver(this, "sessionstore-windows-restored", false);
201201
}
202-
203-
// preference migrations
204-
/*var prefs_version = this.prefs.getIntPref("prefs_version");
205-
if(prefs_version == 0) {
206-
var nBox = gBrowser.getNotificationBox();
207-
var strings = document.getElementById('HttpsEverywhereStrings');
208-
var msg = strings.getString('https-everywhere.migration.notification0');
209-
nBox.appendNotification(
210-
msg,
211-
'https-everywhere-migration0',
212-
'chrome://https-everywhere/skin/https-everywhere-24.png',
213-
nBox.PRIORITY_WARNING_MEDIUM
214-
);
215-
216-
this.prefs.setIntPref("prefs_version", prefs_version+1);
217-
}*/
218-
202+
219203
return;
220204
}
221205

@@ -487,8 +471,6 @@ HTTPSEverywhere.prototype = {
487471
}
488472
}
489473
}
490-
} else if (topic == "app-startup") {
491-
this.log(DBUG,"Got app-startup");
492474
} else if (topic == "profile-before-change") {
493475
this.log(INFO, "Got profile-before-change");
494476
var catman = Components.classes["@mozilla.org/categorymanager;1"]
@@ -519,6 +501,7 @@ HTTPSEverywhere.prototype = {
519501
SERVICE_CTRID, false, true);
520502
}
521503
} else if (topic == "sessionstore-windows-restored") {
504+
this.log(DBUG,"Got sessionstore-windows-restored");
522505
this.maybeShowObservatoryPopup();
523506
}
524507
return;

0 commit comments

Comments
 (0)