Bug 614348 - browser/fuel/test/browser_ApplicationQuitting.js causes ASSERTION: XPConnect is being called on a scope without a 'Components' property r=ian, a=blocking
authorRaymond Lee <raymond@appcoast.com>
Tue, 21 Dec 2010 14:01:10 -0800
changeset 59614 38451849d0eb83627c54b9b02b353fabe2823a27
parent 59613 2ab02651a7730d998d61714401ec57f5620dd7b8
child 59615 5afc616dc96f3cc5d862adc600eca1b9472dd396
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersian, blocking
bugs614348
milestone2.0b9pre
Bug 614348 - browser/fuel/test/browser_ApplicationQuitting.js causes ASSERTION: XPConnect is being called on a scope without a 'Components' property r=ian, a=blocking
browser/base/content/browser-tabview.js
browser/base/content/browser.js
browser/base/content/tabview/ui.js
--- a/browser/base/content/browser-tabview.js
+++ b/browser/base/content/browser-tabview.js
@@ -74,16 +74,22 @@ let TabView = {
           });
       };
       gBrowser.tabContainer.addEventListener(
         "TabShow", this._tabShowEventListener, true);
     }
   },
 
   // ----------
+  uninit: function TabView_uninit() {
+    if (this._window)
+      Services.obs.removeObserver(this, "quit-application-requested");
+  },
+
+  // ----------
   // Creates the frame and calls the callback once it's loaded. 
   // If the frame already exists, calls the callback immediately. 
   _initFrame: function TabView__initFrame(callback) {
     if (this._window) {
       if (typeof callback == "function")
         callback();
     } else {
       // ___ find the deck
@@ -98,33 +104,34 @@ let TabView = {
       if (typeof callback == "function")
         iframe.addEventListener("DOMContentLoaded", callback, false);
 
       iframe.setAttribute("src", "chrome://browser/content/tabview.html");
       this._deck.appendChild(iframe);
       this._window = iframe.contentWindow;
 
       // ___ visibility storage handler
-      let self = this;
-      function observer(subject, topic, data) {
-        if (topic == "quit-application-requested") {
-          let data = (self.isVisible() ? "true" : "false");
-          self._sessionstore.setWindowValue(window, self._visibilityID, data);
-        }
-      }
-      Services.obs.addObserver(observer, "quit-application-requested", false);
+      Services.obs.addObserver(this, "quit-application-requested", false);
 
       if (this._tabShowEventListener) {
         gBrowser.tabContainer.removeEventListener(
           "TabShow", this._tabShowEventListener, true);
       }
     }
   },
 
   // ----------
+  observe: function TabView_observe(subject, topic, data) {
+    if (topic == "quit-application-requested") {
+      let data = (this.isVisible() ? "true" : "false");
+      this._sessionstore.setWindowValue(window, this._visibilityID, data);
+    }
+  },
+
+  // ----------
   getContentWindow: function TabView_getContentWindow() {
     return this._window;
   },
 
   // ----------
   isVisible: function() {
     return (this._deck ? this._deck.selectedIndex == 1 : false);
   },
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1641,16 +1641,17 @@ function BrowserShutdown()
   PlacesStarButton.uninit();
 
   try {
     gPrefService.removeObserver(gHomeButton.prefDomain, gHomeButton);
   } catch (ex) {
     Components.utils.reportError(ex);
   }
 
+  TabView.uninit();
   BrowserOffline.uninit();
   OfflineApps.uninit();
   gPrivateBrowsingUI.uninit();
   IndexedDBPromptHelper.uninit();
   AddonManager.removeAddonListener(AddonsMgrListener);
 
   var enumerator = Services.wm.getEnumerator(null);
   enumerator.getNext();
--- a/browser/base/content/tabview/ui.js
+++ b/browser/base/content/tabview/ui.js
@@ -198,28 +198,30 @@ let UI = {
       else
         this._pageBounds = Items.getPageBounds();
 
       iQ(window).resize(function() {
         self._resize();
       });
 
       // ___ setup observer to save canvas images
-      var observer = {
-        observe : function(subject, topic, data) {
-          if (topic == "quit-application-requested") {
-            if (self.isTabViewVisible())
-              GroupItems.removeHiddenGroups();
+      function quitObserver(subject, topic, data) {
+        if (topic == "quit-application-requested") {
+          if (self.isTabViewVisible())
+            GroupItems.removeHiddenGroups();
 
-            TabItems.saveAll(true);
-            self._save();
-          }
+          TabItems.saveAll(true);
+          self._save();
         }
-      };
-      Services.obs.addObserver(observer, "quit-application-requested", false);
+      }
+      Services.obs.addObserver(
+        quitObserver, "quit-application-requested", false);
+      this._cleanupFunctions.push(function() {
+        Services.obs.removeObserver(quitObserver, "quit-application-requested");
+      });
 
       // ___ Done
       this._frameInitialized = true;
       this._save();
 
       // fire an iframe initialized event so everyone knows tab view is 
       // initialized.
       let event = document.createEvent("Events");
@@ -232,17 +234,16 @@ let UI = {
     }
   },
 
   uninit: function UI_uninit() {
     // call our cleanup functions
     this._cleanupFunctions.forEach(function(func) {
       func();
     });
-
     this._cleanupFunctions = [];
 
     // additional clean up
     TabItems.uninit();
     GroupItems.uninit();
     Storage.uninit();
 
     this._removeTabActionHandlers();