Bug 1349509 - Reload devtools when installing the addon. r=jryans
MozReview-Commit-ID: 4FXwRHvKWJo
--- 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() {}