Bug 1280267 - Open a browser content toolbox matching the current tab process. r=jryans
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 07 Sep 2016 06:48:42 -0700
changeset 357008 a130813c15a4dda55a37fa1ce3feb344339ce32b
parent 357007 5a68cb04da5303c5c1e4b855af851ca5f608f9a3
child 357009 082c1bcd6035e3475412dc26809b18b2c8300817
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1280267
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1280267 - Open a browser content toolbox matching the current tab process. r=jryans MozReview-Commit-ID: EifO2RaNqg0
devtools/client/framework/devtools-browser.js
devtools/client/locales/en-US/toolbox.properties
devtools/client/menus.js
--- a/devtools/client/framework/devtools-browser.js
+++ b/devtools/client/framework/devtools-browser.js
@@ -223,72 +223,77 @@ var gDevToolsBrowser = exports.gDevTools
     let win = Services.wm.getMostRecentWindow("devtools:webide");
     if (win) {
       win.focus();
     } else {
       Services.ww.openWindow(null, "chrome://webide/content/", "webide", "chrome,centerscreen,resizable", null);
     }
   },
 
-  _getContentProcessTarget: function () {
+  _getContentProcessTarget: function (processId) {
     // Create a DebuggerServer in order to connect locally to it
     if (!DebuggerServer.initialized) {
       DebuggerServer.init();
       DebuggerServer.addBrowserActors();
     }
     DebuggerServer.allowChromeProcess = true;
 
     let transport = DebuggerServer.connectPipe();
     let client = new DebuggerClient(transport);
 
     let deferred = defer();
     client.connect().then(() => {
-      client.mainRoot.listProcesses(response => {
-        // Do nothing if there is only one process, the parent process.
-        let contentProcesses = response.processes.filter(p => (!p.parent));
-        if (contentProcesses.length < 1) {
-          let msg = L10N.getStr("toolbox.noContentProcess.message");
-          Services.prompt.alert(null, "", msg);
-          deferred.reject("No content processes available.");
-          return;
-        }
-        // Otherwise, arbitrary connect to the unique content process.
-        client.getProcess(contentProcesses[0].id)
-              .then(response => {
-                let options = {
-                  form: response.form,
-                  client: client,
-                  chrome: true,
-                  isTabActor: false
-                };
-                return TargetFactory.forRemoteTab(options);
-              })
-              .then(target => {
-                // Ensure closing the connection in order to cleanup
-                // the debugger client and also the server created in the
-                // content process
-                target.on("close", () => {
-                  client.close();
-                });
-                deferred.resolve(target);
+      client.getProcess(processId)
+            .then(response => {
+              let options = {
+                form: response.form,
+                client: client,
+                chrome: true,
+                isTabActor: false
+              };
+              return TargetFactory.forRemoteTab(options);
+            })
+            .then(target => {
+              // Ensure closing the connection in order to cleanup
+              // the debugger client and also the server created in the
+              // content process
+              target.on("close", () => {
+                client.close();
               });
-      });
+              deferred.resolve(target);
+            });
     });
 
     return deferred.promise;
   },
 
-   // Used by browser-sets.inc, command
-  openContentProcessToolbox: function () {
-    this._getContentProcessTarget()
-        .then(target => {
-          // Display a new toolbox, in a new window, with debugger by default
-          return gDevTools.showToolbox(target, "jsdebugger",
-                                       Toolbox.HostType.WINDOW);
-        });
+   // Used by menus.js
+  openContentProcessToolbox: function (gBrowser) {
+    let { childCount } = Services.ppmm;
+    // Get the process message manager for the current tab
+    let mm = gBrowser.selectedBrowser.messageManager.processMessageManager;
+    let processId = null;
+    for (let i = 1; i < childCount; i++) {
+      let child = Services.ppmm.getChildAt(i);
+      if (child == mm) {
+        processId = i;
+        break;
+      }
+    }
+    if (processId) {
+      this._getContentProcessTarget(processId)
+          .then(target => {
+            // Display a new toolbox, in a new window, with debugger by default
+            return gDevTools.showToolbox(target, "jsdebugger",
+                                         Toolbox.HostType.WINDOW);
+          });
+    } else {
+      let msg = L10N.getStr("toolbox.noContentProcessForTab.message");
+      Services.prompt.alert(null, "", msg);
+    }
   },
 
   /**
    * Install Developer widget
    */
   installDeveloperWidget: function () {
     let id = "developer-button";
     let widget = CustomizableUI.getWidget(id);
--- a/devtools/client/locales/en-US/toolbox.properties
+++ b/devtools/client/locales/en-US/toolbox.properties
@@ -88,20 +88,20 @@ browserConsoleCmd.commandkey=j
 # This is the tooltip of the pick button in the toolbox toolbar
 pickButton.tooltip=Pick an element from the page
 
 # LOCALIZATION NOTE (sidebar.showAllTabs.tooltip)
 # This is the tooltip shown when hover over the '…' button in the tabbed side
 # bar, when there's no enough space to show all tabs at once
 sidebar.showAllTabs.tooltip=All tabs
 
-# LOCALIZATION NOTE (toolbox.noContentProcess.message)
+# LOCALIZATION NOTE (toolbox.noContentProcessForTab.message)
 # Used as a message in the alert displayed when trying to open a browser
-# content toolbox and there is no content process running
-toolbox.noContentProcess.message=No content process running.
+# content toolbox and there is no content process running for the current tab
+toolbox.noContentProcessForTab.message=No content process for this tab.
 
 # LOCALIZATION NOTE (toolbox.viewCssSourceInStyleEditor.label)
 # Used as a message in either tooltips or contextual menu items to open the
 # corresponding URL as a css file in the Style-Editor tool.
 # DEV NOTE: Mostly used wherever toolbox.viewSourceInStyleEditor is used.
 toolbox.viewCssSourceInStyleEditor.label=Open File in Style-Editor
 
 # LOCALIZATION NOTE (toolbox.viewJsSourceInDebugger.label)
--- a/devtools/client/menus.js
+++ b/devtools/client/menus.js
@@ -107,18 +107,19 @@ exports.menuitems = [
       id: "browserToolbox",
       modifiers: "accel,alt,shift",
       keytext: true
     }
   },
   { id: "menu_browserContentToolbox",
     l10nKey: "browserContentToolboxMenu",
     disabled: true,
-    oncommand() {
-      gDevToolsBrowser.openContentProcessToolbox();
+    oncommand(event) {
+      let window = event.target.ownerDocument.defaultView;
+      gDevToolsBrowser.openContentProcessToolbox(window.gBrowser);
     }
   },
   { id: "menu_browserConsole",
     l10nKey: "browserConsoleCmd",
     oncommand() {
       let HUDService = require("devtools/client/webconsole/hudservice");
       HUDService.openBrowserConsoleOrFocus();
     },