Bug 1387359 - add developer toggle to CustomizableUI even if devtools already loaded;r=nchevobbe
After
Bug 1359855, the developer toggle is added to CustomizableUI via devtools-startup.
It is added after browser-delayed-startup-finished is received. However when starting
devtools with --jsconsole, devtools will be initialized before we receive the event and
the toggle will never be added to the UI.
Introducing a new flag here dedicated to the developer toggle and adding a few comments
to the devtools-startup:hookWindow() method which becomes a bit complex now.
MozReview-Commit-ID: IhPFznt0O83
--- a/devtools/shim/devtools-startup.js
+++ b/devtools/shim/devtools-startup.js
@@ -155,16 +155,21 @@ XPCOMUtils.defineLazyGetter(this, "KeySh
modifiers
},
];
});
function DevToolsStartup() {}
DevToolsStartup.prototype = {
+ /**
+ * Flag that indicates if the developer toggle was already added to customizableUI.
+ */
+ developerToggleCreated: false,
+
handle: function (cmdLine) {
let consoleFlag = cmdLine.handleFlag("jsconsole", false);
let debuggerFlag = cmdLine.handleFlag("jsdebugger", false);
let devtoolsFlag = cmdLine.handleFlag("devtools", false);
if (consoleFlag) {
this.handleConsoleFlag(cmdLine);
}
@@ -201,25 +206,29 @@ DevToolsStartup.prototype = {
/**
* Register listeners to all possible entry points for Developer Tools.
* But instead of implementing the actual actions, defer to DevTools codebase.
* In most cases, it only needs to call this.initDevTools which handles the rest.
* We do that to prevent loading any DevTools module until the user intent to use them.
*/
hookWindow(window) {
+ // Key Shortcuts need to be added on all the created windows.
this.hookKeyShortcuts(window);
- // All the other hooks are only necessary if the tools aren't loaded yet.
- if (this.initialized) {
- return;
+ if (!this.developerToggleCreated) {
+ this.hookDeveloperToggle();
+ this.developerToggleCreated = true;
}
- this.hookWebDeveloperMenu(window);
- this.hookDeveloperToggle(window);
+ // The developer menu hook only needs to be added if devtools have not been
+ // initialized yet.
+ if (!this.initialized) {
+ this.hookWebDeveloperMenu(window);
+ }
},
/**
* Dynamically register a wrench icon in the customization menu.
* You can use this button by right clicking on Firefox toolbar
* and dragging it from the customization panel to the toolbar.
* (i.e. this isn't displayed by default to users!)
*
@@ -228,17 +237,17 @@ DevToolsStartup.prototype = {
* its menu. So we have to register this button for the menu to work.
*
* Also, this menu duplicates its own entries from the "Web Developer"
* menu in the system menu, under "Tools" main menu item. The system
* menu is being hooked by "hookWebDeveloperMenu" which ends up calling
* devtools/client/framework/browser-menu to create the items for real,
* initDevTools, from onViewShowing is also calling browser-menu.
*/
- hookDeveloperToggle(window) {
+ hookDeveloperToggle() {
let id = "developer-button";
let widget = CustomizableUI.getWidget(id);
if (widget && widget.provider == CustomizableUI.PROVIDER_API) {
return;
}
let item = {
id: id,
type: "view",