From 8cb3adf5612f12ef155f599f1359c827748f6d1f Mon Sep 17 00:00:00 2001 From: David Dahl Date: Fri, 30 Jul 2010 08:30:55 -0300 Subject: [PATCH] Bug 579954 - sometimes gBrowser cannot be accessed, r=gavin --- .../console/hudservice/HUDService.jsm | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/toolkit/components/console/hudservice/HUDService.jsm b/toolkit/components/console/hudservice/HUDService.jsm index 70237145756..b80a748e313 100644 --- a/toolkit/components/console/hudservice/HUDService.jsm +++ b/toolkit/components/console/hudservice/HUDService.jsm @@ -1408,10 +1408,18 @@ HUD_SERVICE.prototype = { 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) { @@ -1420,7 +1428,6 @@ HUD_SERVICE.prototype = return; } - let xulWindow = XPCNativeWrapper.unwrap(xulWindow); let gBrowser = xulWindow.gBrowser;