Bug 1261665 - Do not use devtools module in devtools addon before reloading. r=jryans
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 14 Apr 2016 01:40:44 -0700
changeset 331050 ef461673c13f81ff4bbb162f739227ab75844941
parent 331049 cd9c7f0216c4b19d79e607ca7ff04302c6375add
child 331051 f98aad8ef492eb30e2a7e5f38a522b41a6434e8a
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1261665
milestone48.0a1
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 1261665 - Do not use devtools module in devtools addon before reloading. r=jryans
devtools/bootstrap.js
--- a/devtools/bootstrap.js
+++ b/devtools/bootstrap.js
@@ -69,21 +69,37 @@ let getTopLevelWindow = function (window
                .QueryInterface(Ci.nsIInterfaceRequestor)
                .getInterface(Ci.nsIDOMWindow);
 };
 
 function reload(event) {
   // We automatically reload the toolbox if we are on a browser tab
   // with a toolbox already opened
   let top = getTopLevelWindow(event.view)
-  let isBrowser = top.location.href.includes("/browser.xul") && top.gDevToolsBrowser;
+  let isBrowser = top.location.href.includes("/browser.xul");
   let reloadToolbox = false;
-  if (isBrowser && top.gDevToolsBrowser.hasToolboxOpened) {
-    reloadToolbox = top.gDevToolsBrowser.hasToolboxOpened(top);
+  if (isBrowser && top.gBrowser) {
+    // We do not use any devtools code before the call to Loader.jsm reload as
+    // any attempt to use Loader.jsm to load a module will instanciate a new
+    // Loader.
+    let nbox = top.gBrowser.getNotificationBox();
+    reloadToolbox =
+      top.document.getAnonymousElementByAttribute(nbox, "class",
+        "devtools-toolbox-bottom-iframe") ||
+      top.document.getAnonymousElementByAttribute(nbox, "class",
+        "devtools-toolbox-side-iframe") ||
+      Services.wm.getMostRecentWindow("devtools:toolbox");
   }
+  let browserConsole = Services.wm.getMostRecentWindow("devtools:webconsole");
+  let reopenBrowserConsole = false;
+  if (browserConsole) {
+    browserConsole.close();
+    reopenBrowserConsole = true;
+  }
+
   dump("Reload DevTools.  (reload-toolbox:"+reloadToolbox+")\n");
 
   // Invalidate xul cache in order to see changes made to chrome:// files
   Services.obs.notifyObservers(null, "startupcache-invalidate", null);
 
   // This frame script is going to be executed in all processes: parent and childs
   Services.ppmm.loadProcessScript("data:,new " + function () {
     /* Flush message manager cached frame scripts as well as chrome locales */
@@ -128,25 +144,16 @@ function reload(event) {
           let isJSONView = content.document.baseURI.startsWith("resource://devtools/");
           if (isJSONView) {
             content.location.reload();
           }
         }, false);
       }
     } else if (windowtype === "devtools:webide") {
       window.location.reload();
-    } else if (windowtype === "devtools:webconsole") {
-      // Browser console document can't just be reloaded.
-      // HUDService is going to close it on unload.
-      // Instead we have to manually toggle it.
-      let HUDService = devtools.require("devtools/client/webconsole/hudservice");
-      HUDService.toggleBrowserConsole()
-        .then(() => {
-          HUDService.toggleBrowserConsole();
-        });
     }
   }
 
   if (reloadToolbox) {
     // Reopen the toolbox automatically if we are reloading from toolbox shortcut
     // and are on a browser window.
     // Wait for a second before opening the toolbox to avoid races
     // between the old and the new one.
@@ -154,16 +161,24 @@ function reload(event) {
     setTimeout(() => {
       let { TargetFactory } = devtools.require("devtools/client/framework/target");
       let { gDevTools } = devtools.require("devtools/client/framework/devtools");
       let target = TargetFactory.forTab(top.gBrowser.selectedTab);
       gDevTools.showToolbox(target);
     }, 1000);
   }
 
+  // Browser console document can't just be reloaded.
+  // HUDService is going to close it on unload.
+  // Instead we have to manually toggle it.
+  if (reopenBrowserConsole) {
+    let HUDService = devtools.require("devtools/client/webconsole/hudservice");
+    HUDService.toggleBrowserConsole();
+  }
+
   actionOccurred("reloadAddonReload");
 }
 
 let prefs = {
   // Enable dump as some errors are only printed on the stdout
   "browser.dom.window.dump.enabled": true,
   // Enable the browser toolbox and various chrome-only features
   "devtools.chrome.enabled": true,