Bug 1412029 - pass key shortcut id to aboutdevtools page;r=bgrins draft
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 01 Nov 2017 14:47:31 +0100
changeset 694837 f236777ea914ebad6cc7a0e61be97491b6eb97c2
parent 694288 311b339aff26b861b282015b1e28344de7ed47e6
child 694838 5038fcb6741653b7f66581cd601ba9dea58a847f
child 694842 f2f96e29a8849dec83b03d6daacbf6c6ca7fce2f
push id88270
push userjdescottes@mozilla.com
push dateWed, 08 Nov 2017 11:00:05 +0000
reviewersbgrins
bugs1412029
milestone58.0a1
Bug 1412029 - pass key shortcut id to aboutdevtools page;r=bgrins MozReview-Commit-ID: 4Fmj1p1bgsB
devtools/shim/devtools-startup.js
--- a/devtools/shim/devtools-startup.js
+++ b/devtools/shim/devtools-startup.js
@@ -466,24 +466,25 @@ DevToolsStartup.prototype = {
     // Appending a <key> element is not always enough. The <keyset> needs
     // to be detached and reattached to make sure the <key> is taken into
     // account (see bug 832984).
     let mainKeyset = doc.getElementById("mainKeyset");
     mainKeyset.parentNode.insertBefore(keyset, mainKeyset);
   },
 
   onKey(window, key) {
-    // Record the timing at which this event started in order to compute later in
-    // gDevTools.showToolbox, the complete time it takes to open the toolbox.
-    // i.e. especially take `initDevTools` into account.
-
-    let startTime = window.performance.now();
-    let require = this.initDevTools("KeyShortcut");
-    if (require) {
-      // require might be null if initDevTools was called while DevTools are disabled.
+    if (!Services.prefs.getBoolPref(DEVTOOLS_ENABLED_PREF)) {
+      let id = key.toolId || key.id;
+      this.openInstallPage("KeyShortcut", id);
+    } else {
+      // Record the timing at which this event started in order to compute later in
+      // gDevTools.showToolbox, the complete time it takes to open the toolbox.
+      // i.e. especially take `initDevTools` into account.
+      let startTime = window.performance.now();
+      let require = this.initDevTools("KeyShortcut");
       let { gDevToolsBrowser } = require("devtools/client/framework/devtools-browser");
       gDevToolsBrowser.onKeyShortcut(window, key, startTime);
     }
   },
 
   // Create a <xul:key> DOM Element
   createKey(doc, { id, toolId, shortcut, modifiers: mod }, oncommand) {
     let k = doc.createElement("key");
@@ -529,17 +530,27 @@ DevToolsStartup.prototype = {
     this.initialized = true;
     let { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
     // Ensure loading main devtools module that hooks up into browser UI
     // and initialize all devtools machinery.
     require("devtools/client/framework/devtools-browser");
     return require;
   },
 
-  openInstallPage: function (reason) {
+  /**
+   * Open about:devtools to start the onboarding flow.
+   *
+   * @param {String} reason
+   *        One of "KeyShortcut", "SystemMenu", "HamburgerMenu", "ContextMenu",
+   *        "CommandLine".
+   * @param {String} keyId
+   *        Optional. If the onboarding flow was triggered by a keyboard shortcut, pass
+   *        the shortcut key id (or toolId) to about:devtools.
+   */
+  openInstallPage: function (reason, keyId) {
     let { gBrowser } = Services.wm.getMostRecentWindow("navigator:browser");
 
     // Focus about:devtools tab if there is already one opened in the current window.
     for (let tab of gBrowser.tabs) {
       let browser = tab.linkedBrowser;
       // browser.documentURI might be undefined if the browser tab is still loading.
       let location = browser.documentURI ? browser.documentURI.spec : "";
       if (location.startsWith("about:devtools") &&
@@ -557,16 +568,20 @@ DevToolsStartup.prototype = {
       params.push("reason=" + encodeURIComponent(reason));
     }
 
     let selectedBrowser = gBrowser.selectedBrowser;
     if (selectedBrowser) {
       params.push("tabid=" + selectedBrowser.outerWindowID);
     }
 
+    if (keyId) {
+      params.push("keyid=" + keyId);
+    }
+
     if (params.length > 0) {
       url += "?" + params.join("&");
     }
 
     // Set relatedToCurrent: true to open the tab next to the current one.
     gBrowser.selectedTab = gBrowser.addTab(url, {relatedToCurrent: true});
   },