Bug 579954 - sometimes gBrowser cannot be accessed, r=gavin
authorDavid Dahl <ddahl@mozilla.com>
Fri, 30 Jul 2010 08:30:55 -0300
changeset 48414 b45b63b9283ff9c3527db335ed397b28e338e304
parent 48413 8f3643fcb8ff9d8c2c4a8e890c436f7063955ee9
child 48415 7e4b21f34d2ab8d64780c88e1b713dda810b42bc
push id14718
push userrcampbell@mozilla.com
push dateFri, 30 Jul 2010 11:31:33 +0000
treeherderautoland@b45b63b9283f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs579954
milestone2.0b3pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 579954 - sometimes gBrowser cannot be accessed, r=gavin
toolkit/components/console/hudservice/HUDService.jsm
--- a/toolkit/components/console/hudservice/HUDService.jsm
+++ b/toolkit/components/console/hudservice/HUDService.jsm
@@ -1403,29 +1403,36 @@ HUD_SERVICE.prototype =
    *
    * @param nsIDOMWindow aContentWindow
    * @returns void
    */
   windowInitializer: function HS_WindowInitalizer(aContentWindow)
   {
     var xulWindow = aContentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
       .getInterface(Ci.nsIWebNavigation)
-      .QueryInterface(Ci.nsIDocShellTreeItem)
-      .rootTreeItem
-      .QueryInterface(Ci.nsIInterfaceRequestor)
-      .getInterface(Ci.nsIDOMWindow);
+                      .QueryInterface(Ci.nsIDocShell)
+                      .chromeEventHandler.ownerDocument.defaultView;
+
+    let xulWindow = XPCNativeWrapper.unwrap(xulWindow);
+
+    let docElem = xulWindow.document.documentElement;
+    if (!docElem || docElem.getAttribute("windowtype") != "navigator:browser" ||
+        !xulWindow.gBrowser) {
+      // Do not do anything unless we have a browser window.
+      // This may be a view-source window or other type of non-browser window.
+      return;
+    }
 
     if (aContentWindow.document.location.href == "about:blank" &&
         HUDWindowObserver.initialConsoleCreated == false) {
       // TODO: need to make this work with about:blank in the future
       // see bug 568661
       return;
     }
 
-    let xulWindow = XPCNativeWrapper.unwrap(xulWindow);
     let gBrowser = xulWindow.gBrowser;
 
 
     var container = gBrowser.tabContainer;
     container.addEventListener("TabClose", this.onTabClose, false);
 
     if (gBrowser && !HUDWindowObserver.initialConsoleCreated) {
       HUDWindowObserver.initialConsoleCreated = true;