Bug 1395535 - trigger addon reload from devtools-startup if devtools addon failed to start;r=ochameau
MozReview-Commit-ID: KLK92FkB5te
--- a/devtools/shim/devtools-startup.js
+++ b/devtools/shim/devtools-startup.js
@@ -178,17 +178,27 @@ DevToolsStartup.prototype = {
*/
recorded: false,
/**
* Flag that indicates if the developer toggle was already added to customizableUI.
*/
developerToggleCreated: false,
+ /**
+ * Flag that checks if the DevTools addon has been installed and started.
+ */
+ isDevToolsAvailable: false,
+
handle: function (cmdLine) {
+ // Update isDevToolsAvailable by checking if resource://devtools is registered.
+ this.isDevToolsAvailable = Services.io.getProtocolHandler("resource")
+ .QueryInterface(Ci.nsIResProtocolHandler)
+ .hasSubstitution("devtools");
+
let consoleFlag = cmdLine.handleFlag("jsconsole", false);
let debuggerFlag = cmdLine.handleFlag("jsdebugger", false);
let devtoolsFlag = cmdLine.handleFlag("devtools", false);
if (consoleFlag) {
this.handleConsoleFlag(cmdLine);
}
if (debuggerFlag) {
@@ -382,16 +392,33 @@ DevToolsStartup.prototype = {
// Bug 371900: command event is fired only if "oncommand" attribute is set.
k.setAttribute("oncommand", ";");
k.addEventListener("command", oncommand);
return k;
},
initDevTools: function (reason) {
+ if (!this.isDevToolsAvailable) {
+ // Under very specific circumstances, DevTools addon might only be installed but not
+ // started. In this case we attempt to reload the addon.
+ const { AddonManager } = Components.utils.import("resource://gre/modules/AddonManager.jsm", {});
+ AddonManager.getAddonByID("devtools@mozilla.org", (addon) => {
+ addon.enabled = true;
+ addon.active = true;
+ addon.reload();
+
+ // DevTools should now be ready to be used.
+ this.isDevToolsAvailable = true;
+ });
+
+ throw new Error("Firefox DevTools addon had to be reloaded , please try again." +
+ "Force addon scan via `--setpref extensions.startupScanScopes=15`");
+ }
+
if (reason && !this.recorded) {
// Only save the first call for each firefox run as next call
// won't necessarely start the tool. For example key shortcuts may
// only change the currently selected tool.
try {
Services.telemetry.getHistogramById("DEVTOOLS_ENTRY_POINT")
.add(reason);
} catch (e) {