diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index d49586ceaeb82..34bfcaef89e76 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -250,11 +250,9 @@ function BrowserGlue() { BrowserGlue.prototype = { _saveSession: false, - _isPlacesInitObserver: false, - _isPlacesLockedObserver: false, - _isPlacesShutdownObserver: false, _isPlacesDatabaseLocked: false, _migrationImportsDefaultBookmarks: false, + _disposed: false, _setPrefToSaveSession: function BG__setPrefToSaveSession(aForce) { if (!this._saveSession && !aForce) @@ -292,6 +290,10 @@ BrowserGlue.prototype = { // nsIObserver implementation observe: function BG_observe(subject, topic, data) { + //observers have implcititly disposed + if (this._disposed) + return; + switch (topic) { case "notifications-open-settings": this._openPreferences("content"); @@ -347,25 +349,11 @@ BrowserGlue.prototype = { case "places-init-complete": if (!this._migrationImportsDefaultBookmarks) this._initPlaces(false); - - Services.obs.removeObserver(this, "places-init-complete"); - this._isPlacesInitObserver = false; - // no longer needed, since history was initialized completely. - Services.obs.removeObserver(this, "places-database-locked"); - this._isPlacesLockedObserver = false; break; case "places-database-locked": this._isPlacesDatabaseLocked = true; - // Stop observing, so further attempts to load history service - // will not show the prompt. - Services.obs.removeObserver(this, "places-database-locked"); - this._isPlacesLockedObserver = false; break; case "places-shutdown": - if (this._isPlacesShutdownObserver) { - Services.obs.removeObserver(this, "places-shutdown"); - this._isPlacesShutdownObserver = false; - } // places-shutdown is fired when the profile is about to disappear. this._onPlacesShutdown(); break; @@ -374,8 +362,6 @@ BrowserGlue.prototype = { break; case "distribution-customization-complete": Services.obs.removeObserver(this, "distribution-customization-complete"); - // Customization has finished, we don't need the customizer anymore. - delete this._distributionCustomizer; break; case "browser-glue-test": // used by tests if (data == "post-update-notification") { @@ -419,7 +405,15 @@ BrowserGlue.prototype = { // Any component depending on Places should be finalized in // _onPlacesShutdown. Any component that doesn't need to act after // the UI has gone should be finalized in _onQuitApplicationGranted. - this._dispose(); + if (this._bookmarksBackupIdleTime) { + this._idleService.removeIdleObserver(this, this._bookmarksBackupIdleTime); + delete this._bookmarksBackupIdleTime; + } + +#ifdef NIGHTLY_BUILD + Services.prefs.removeObserver(POLARIS_ENABLED, this); +#endif + this._disposed = true; break; case "keyword-search": // This notification is broadcast by the docshell when it "fixes up" a @@ -581,39 +575,40 @@ BrowserGlue.prototype = { // initialization (called on application startup) _init: function BG__init() { let os = Services.obs; - os.addObserver(this, "notifications-open-settings", false); - os.addObserver(this, "prefservice:after-app-defaults", false); - os.addObserver(this, "final-ui-startup", false); - os.addObserver(this, "browser-delayed-startup-finished", false); - os.addObserver(this, "sessionstore-windows-restored", false); - os.addObserver(this, "browser:purge-session-history", false); - os.addObserver(this, "quit-application-requested", false); - os.addObserver(this, "quit-application-granted", false); + [ "notifications-open-settings" + ,"prefservice:after-app-defaults" + ,"final-ui-startup" + ,"browser-delayed-startup-finished" + ,"sessionstore-windows-restored" + ,"browser:purge-session-history" + ,"quit-application-requested" + ,"quit-application-granted" #ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS - os.addObserver(this, "browser-lastwindow-close-requested", false); - os.addObserver(this, "browser-lastwindow-close-granted", false); + ,"browser-lastwindow-close-requested" + ,"browser-lastwindow-close-granted" #endif - os.addObserver(this, "weave:service:ready", false); - os.addObserver(this, "weave:engine:clients:display-uri", false); - os.addObserver(this, "session-save", false); - os.addObserver(this, "places-init-complete", false); - this._isPlacesInitObserver = true; - os.addObserver(this, "places-database-locked", false); - this._isPlacesLockedObserver = true; - os.addObserver(this, "distribution-customization-complete", false); - os.addObserver(this, "places-shutdown", false); - this._isPlacesShutdownObserver = true; - os.addObserver(this, "handle-xul-text-link", false); - os.addObserver(this, "profile-before-change", false); + ,"weave:service:ready" + ,"weave:engine:clients:display-uri" + ,"session-save" + ,"places-init-complete" + ,"places-database-locked" + ,"distribution-customization-complete" + ,"places-shutdown" + ,"handle-xul-text-link" + ,"profile-before-change" #ifdef MOZ_SERVICES_HEALTHREPORT - os.addObserver(this, "keyword-search", false); + ,"keyword-search" #endif - os.addObserver(this, "browser-search-engine-modified", false); - os.addObserver(this, "browser-search-service", false); - os.addObserver(this, "restart-in-safe-mode", false); - os.addObserver(this, "flash-plugin-hang", false); - os.addObserver(this, "xpi-signature-changed", false); - os.addObserver(this, "autocomplete-did-enter-text", false); + ,"browser-search-engine-modified" + ,"browser-search-service" + ,"restart-in-safe-mode" + ,"flash-plugin-hang" + ,"xpi-signature-changed" + ,"autocomplete-did-enter-text" + ].forEach(topic => { + os.addObserver(this, topic, true); + }) + ExtensionManagement.registerScript("chrome://browser/content/ext-utils.js"); ExtensionManagement.registerScript("chrome://browser/content/ext-browserAction.js"); @@ -635,52 +630,6 @@ BrowserGlue.prototype = { this._firstWindowReady = new Promise(resolve => this._firstWindowLoaded = resolve); }, - // cleanup (called on application shutdown) - _dispose: function BG__dispose() { - let os = Services.obs; - os.removeObserver(this, "notifications-open-settings"); - os.removeObserver(this, "prefservice:after-app-defaults"); - os.removeObserver(this, "final-ui-startup"); - os.removeObserver(this, "sessionstore-windows-restored"); - os.removeObserver(this, "browser:purge-session-history"); - os.removeObserver(this, "quit-application-requested"); - os.removeObserver(this, "quit-application-granted"); - os.removeObserver(this, "restart-in-safe-mode"); -#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS - os.removeObserver(this, "browser-lastwindow-close-requested"); - os.removeObserver(this, "browser-lastwindow-close-granted"); -#endif - os.removeObserver(this, "weave:service:ready"); - os.removeObserver(this, "weave:engine:clients:display-uri"); - os.removeObserver(this, "session-save"); - if (this._bookmarksBackupIdleTime) { - this._idleService.removeIdleObserver(this, this._bookmarksBackupIdleTime); - delete this._bookmarksBackupIdleTime; - } - if (this._isPlacesInitObserver) - os.removeObserver(this, "places-init-complete"); - if (this._isPlacesLockedObserver) - os.removeObserver(this, "places-database-locked"); - if (this._isPlacesShutdownObserver) - os.removeObserver(this, "places-shutdown"); - os.removeObserver(this, "handle-xul-text-link"); - os.removeObserver(this, "profile-before-change"); -#ifdef MOZ_SERVICES_HEALTHREPORT - os.removeObserver(this, "keyword-search"); -#endif - os.removeObserver(this, "browser-search-engine-modified"); - try { - os.removeObserver(this, "browser-search-service"); - // may have already been removed by the observer - } catch (ex) {} -#ifdef NIGHTLY_BUILD - Services.prefs.removeObserver(POLARIS_ENABLED, this); -#endif - os.removeObserver(this, "flash-plugin-hang"); - os.removeObserver(this, "xpi-signature-changed"); - os.removeObserver(this, "autocomplete-did-enter-text"); - }, - _onAppDefaults: function BG__onAppDefaults() { // apply distribution customizations (prefs) // other customizations are applied in _finalUIStartup()