Bug 1349509 - Reload devtools when installing the addon. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 02 Nov 2016 07:55:00 -0700
changeset 503830 21a2cc5e3e14b73f65e7b7e34ff10c34af4bb151
parent 503826 0df1cc2cd662be10fb8a4a47f908a4ff7fc3012e
child 550513 8a9298a415789394a28fb0671046b1fa687d58df
push id50667
push userbmo:poirot.alex@gmail.com
push dateThu, 23 Mar 2017 15:55:27 +0000
reviewersjryans
bugs1349509
milestone55.0a1
Bug 1349509 - Reload devtools when installing the addon. r=jryans MozReview-Commit-ID: 4FXwRHvKWJo
devtools/bootstrap.js
--- a/devtools/bootstrap.js
+++ b/devtools/bootstrap.js
@@ -137,30 +137,32 @@ let getTopLevelWindow = function (window
                .rootTreeItem
                .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");
   let reloadToolbox = false;
-  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");
+  if (event) {
+    let top = getTopLevelWindow(event.view);
+    let isBrowser = top.location.href.includes("/browser.xul");
+    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;
   }
 
@@ -243,16 +245,17 @@ function reload(event) {
     // 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.
     let {setTimeout} = Cu.import("resource://gre/modules/Timer.jsm", {});
     setTimeout(() => {
       let { TargetFactory } = devtools.require("devtools/client/framework/target");
       let { gDevTools } = devtools.require("devtools/client/framework/devtools");
+      let top = getTopLevelWindow(event.view);
       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.
@@ -281,26 +284,33 @@ function startup(data) {
     let value = prefs[name];
     let userValue = Services.prefs.getBoolPref(name);
     // Only toggle if the pref isn't already set to the right value
     if (userValue != value) {
       Services.prefs.setBoolPref(name, value);
       originalPrefValues[name] = userValue;
     }
   }
+
+  reload();
 }
 function shutdown() {
   listener.stop();
   listener = null;
 
   // Restore preferences that used to be before the addon was installed
   for (let name in originalPrefValues) {
     let userValue = Services.prefs.getBoolPref(name);
     // Only reset the pref if it hasn't changed
     if (userValue == prefs[name]) {
       Services.prefs.setBoolPref(name, originalPrefValues[name]);
     }
   }
 }
 function install() {
-  actionOccurred("reloadAddonInstalled");
+  try {
+    actionOccurred("reloadAddonInstalled");
+  } catch (e) {
+    // When installing on Firefox builds without devtools, telemetry doesn't
+    // work yet and throws.
+  }
 }
 function uninstall() {}