@@ -7,13 +7,12 @@ const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
7
7
Cu . import ( "resource://gre/modules/XPCOMUtils.jsm" ) ;
8
8
Cu . importGlobalProperties ( [ "fetch" ] ) ;
9
9
10
- XPCOMUtils . defineLazyModuleGetter ( this , "Preferences" ,
11
- "resource://gre/modules/Preferences.jsm" ) ;
12
10
XPCOMUtils . defineLazyModuleGetter ( this , "Services" ,
13
11
"resource://gre/modules/Services.jsm" ) ;
14
12
15
13
const ACTIVITY_STREAM_ENABLED_PREF = "browser.newtabpage.activity-stream.enabled" ;
16
14
const BROWSER_READY_NOTIFICATION = "sessionstore-windows-restored" ;
15
+ const PREF_CHANGED_TOPIC = "nsPref:changed" ;
17
16
const REASON_SHUTDOWN_ON_PREF_CHANGE = "PREF_OFF" ;
18
17
const REASON_STARTUP_ON_PREF_CHANGE = "PREF_ON" ;
19
18
const RESOURCE_BASE = "resource://activity-stream" ;
@@ -86,10 +85,9 @@ function uninit(reason) {
86
85
/**
87
86
* onPrefChanged - handler for changes to ACTIVITY_STREAM_ENABLED_PREF
88
87
*
89
- * @param {bool } isEnabled Determines whether Activity Stream is enabled
90
88
*/
91
- function onPrefChanged ( isEnabled ) {
92
- if ( isEnabled ) {
89
+ function onPrefChanged ( ) {
90
+ if ( Services . prefs . getBoolPref ( ACTIVITY_STREAM_ENABLED_PREF , false ) ) {
93
91
init ( REASON_STARTUP_ON_PREF_CHANGE ) ;
94
92
} else {
95
93
uninit ( REASON_SHUTDOWN_ON_PREF_CHANGE ) ;
@@ -103,10 +101,10 @@ function onBrowserReady() {
103
101
waitingForBrowserReady = false ;
104
102
105
103
// 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
107
105
108
106
// 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 ) ) {
110
108
init ( startupReason ) ;
111
109
}
112
110
}
@@ -121,6 +119,11 @@ function observe(subject, topic, data) {
121
119
// Avoid running synchronously during this event that's used for timing
122
120
Services . tm . dispatchToMainThread ( ( ) => onBrowserReady ( ) ) ;
123
121
break ;
122
+ case PREF_CHANGED_TOPIC :
123
+ if ( data === ACTIVITY_STREAM_ENABLED_PREF ) {
124
+ onPrefChanged ( ) ;
125
+ }
126
+ break ;
124
127
}
125
128
}
126
129
@@ -154,7 +157,7 @@ this.shutdown = function shutdown(data, reason) {
154
157
Services . obs . removeObserver ( observe , BROWSER_READY_NOTIFICATION ) ;
155
158
} else {
156
159
// 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 ) ;
158
161
}
159
162
160
163
// Unload any add-on modules that might might have been imported
0 commit comments