Skip to content
This repository was archived by the owner on Feb 29, 2020. It is now read-only.

Commit f30b605

Browse files
marco-cMardak
authored andcommitted
chore(bootstrap): Backport Preferences -> Services.prefs change from bug 1357517
1 parent 9a32100 commit f30b605

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

system-addon/bootstrap.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
77
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
88
Cu.importGlobalProperties(["fetch"]);
99

10-
XPCOMUtils.defineLazyModuleGetter(this, "Preferences",
11-
"resource://gre/modules/Preferences.jsm");
1210
XPCOMUtils.defineLazyModuleGetter(this, "Services",
1311
"resource://gre/modules/Services.jsm");
1412

1513
const ACTIVITY_STREAM_ENABLED_PREF = "browser.newtabpage.activity-stream.enabled";
1614
const BROWSER_READY_NOTIFICATION = "sessionstore-windows-restored";
15+
const PREF_CHANGED_TOPIC = "nsPref:changed";
1716
const REASON_SHUTDOWN_ON_PREF_CHANGE = "PREF_OFF";
1817
const REASON_STARTUP_ON_PREF_CHANGE = "PREF_ON";
1918
const RESOURCE_BASE = "resource://activity-stream";
@@ -86,10 +85,9 @@ function uninit(reason) {
8685
/**
8786
* onPrefChanged - handler for changes to ACTIVITY_STREAM_ENABLED_PREF
8887
*
89-
* @param {bool} isEnabled Determines whether Activity Stream is enabled
9088
*/
91-
function onPrefChanged(isEnabled) {
92-
if (isEnabled) {
89+
function onPrefChanged() {
90+
if (Services.prefs.getBoolPref(ACTIVITY_STREAM_ENABLED_PREF, false)) {
9391
init(REASON_STARTUP_ON_PREF_CHANGE);
9492
} else {
9593
uninit(REASON_SHUTDOWN_ON_PREF_CHANGE);
@@ -103,10 +101,10 @@ function onBrowserReady() {
103101
waitingForBrowserReady = false;
104102

105103
// Listen for changes to the pref that enables Activity Stream
106-
Preferences.observe(ACTIVITY_STREAM_ENABLED_PREF, onPrefChanged);
104+
Services.prefs.addObserver(ACTIVITY_STREAM_ENABLED_PREF, observe); // eslint-disable-line no-use-before-define
107105

108106
// Only initialize if the pref is true
109-
if (Preferences.get(ACTIVITY_STREAM_ENABLED_PREF)) {
107+
if (Services.prefs.getBoolPref(ACTIVITY_STREAM_ENABLED_PREF, false)) {
110108
init(startupReason);
111109
}
112110
}
@@ -121,6 +119,11 @@ function observe(subject, topic, data) {
121119
// Avoid running synchronously during this event that's used for timing
122120
Services.tm.dispatchToMainThread(() => onBrowserReady());
123121
break;
122+
case PREF_CHANGED_TOPIC:
123+
if (data === ACTIVITY_STREAM_ENABLED_PREF) {
124+
onPrefChanged();
125+
}
126+
break;
124127
}
125128
}
126129

@@ -154,7 +157,7 @@ this.shutdown = function shutdown(data, reason) {
154157
Services.obs.removeObserver(observe, BROWSER_READY_NOTIFICATION);
155158
} else {
156159
// Stop listening to the pref that enables Activity Stream
157-
Preferences.ignore(ACTIVITY_STREAM_ENABLED_PREF, onPrefChanged);
160+
Services.prefs.removeObserver(ACTIVITY_STREAM_ENABLED_PREF, observe);
158161
}
159162

160163
// Unload any add-on modules that might might have been imported

0 commit comments

Comments
 (0)