Bug 1387359 - Add developer toggle to CustomizableUI even if devtools already loaded. r=nchevobbe, a=lizzard
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 04 Aug 2017 11:09:56 +0200
changeset 423564 8a94cd4f9c0740240d1a33d0e310d0a1d36901ab
parent 423563 32c6671592f98604fe929e86f2a1d52a34b52692
child 423565 e08775132fa2aa7df8f0d2f35059651a47cc8e94
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe, lizzard
bugs1387359, 1359855
milestone56.0
Bug 1387359 - Add developer toggle to CustomizableUI even if devtools already loaded. r=nchevobbe, a=lizzard 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
devtools/client/devtools-startup.js
--- a/devtools/client/devtools-startup.js
+++ b/devtools/client/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",