Bug 614326 - browser_privacypane_*.js cause ASSERTION: XPConnect is being called on a scope without a 'Components' property due to no unregistration of autoStartPrivateBrowsingObserver; r,a=gavin
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 26 Nov 2010 15:24:26 -0500
changeset 58279 30f1fb628aa60a153d085e50fd520d49fbed779c
parent 58278 7ce0cc6b8cc9f52d5d70bbb3f28e81f000eee647
child 58280 b7c49f3a60896527634890cec083db65040fef04
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersgavin
bugs614326
milestone2.0b8pre
Bug 614326 - browser_privacypane_*.js cause ASSERTION: XPConnect is being called on a scope without a 'Components' property due to no unregistration of autoStartPrivateBrowsingObserver; r,a=gavin
browser/components/preferences/privacy.js
--- a/browser/components/preferences/privacy.js
+++ b/browser/components/preferences/privacy.js
@@ -56,16 +56,18 @@ var gPrivacyPane = {
    */
   init: function ()
   {
     this._updateSanitizeSettingsButton();
     this.initializeHistoryMode();
     this.updateHistoryModePane();
     this.updatePrivacyMicroControls();
     this.initAutoStartPrivateBrowsingObserver();
+
+    window.addEventListener("unload", this.removeASPBObserver.bind(this), false);
   },
 
   // HISTORY MODE
 
   /**
    * The list of preferences which affect the initial history mode settings.
    * If the auto start private browsing mode pref is active, the initial
    * history mode would be set to "Don't remember anything".
@@ -240,23 +242,34 @@ var gPrivacyPane = {
    */
   initAutoStartPrivateBrowsingObserver: function PPP_initAutoStartPrivateBrowsingObserver()
   {
     let prefService = document.getElementById("privacyPreferences")
                               .service
                               .QueryInterface(Components.interfaces.nsIPrefBranch2);
     prefService.addObserver("browser.privatebrowsing.autostart",
                             this.autoStartPrivateBrowsingObserver,
-                            true);
+                            false);
+  },
+
+  /**
+   * Install the observer for the auto-start private browsing mode pref.
+   */
+  removeASPBObserver: function PPP_removeASPBObserver()
+  {
+    let prefService = document.getElementById("privacyPreferences")
+                              .service
+                              .QueryInterface(Components.interfaces.nsIPrefBranch2);
+    prefService.removeObserver("browser.privatebrowsing.autostart",
+                               this.autoStartPrivateBrowsingObserver);
   },
 
   autoStartPrivateBrowsingObserver:
   {
-    QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIObserver,
-                                           Components.interfaces.nsISupportsWeakReference]),
+    QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIObserver]),
 
     observe: function PPP_observe(aSubject, aTopic, aData)
     {
       let privateBrowsingService = Components.classes["@mozilla.org/privatebrowsing;1"].
         getService(Components.interfaces.nsIPrivateBrowsingService);
 
       // Toggle the private browsing mode without switching the session
       let prefValue = document.getElementById("browser.privatebrowsing.autostart").value;