diff --git a/devtools/client/devtools-startup.js b/devtools/client/devtools-startup.js index a01155002242..88c1ce5e73d9 100644 --- a/devtools/client/devtools-startup.js +++ b/devtools/client/devtools-startup.js @@ -184,7 +184,6 @@ DevToolsStartup.prototype = { this.handleDebuggerServerFlag(cmdLine, debuggerServerFlag); } - // Only top level Firefox Windows fire a browser-delayed-startup-finished event let onWindowReady = window => { this.hookWindow(window); @@ -513,15 +512,6 @@ DevToolsStartup.prototype = { } }, - // Used by tests and the toolbox to register the same key shortcuts in toolboxes loaded - // in a window window. - get KeyShortcuts() { - return KeyShortcuts; - }, - get wrappedJSObject() { - return this; - }, - /* eslint-disable max-len */ helpInfo: " --jsconsole Open the Browser Console.\n" + " --jsdebugger Open the Browser Toolbox.\n" + diff --git a/devtools/client/framework/test/browser_toolbox_window_shortcuts.js b/devtools/client/framework/test/browser_toolbox_window_shortcuts.js index 88fe35fea820..dde06dfeaec0 100644 --- a/devtools/client/framework/test/browser_toolbox_window_shortcuts.js +++ b/devtools/client/framework/test/browser_toolbox_window_shortcuts.js @@ -5,33 +5,28 @@ "use strict"; -var Startup = Cc["@mozilla.org/devtools/startup-clh;1"].getService(Ci.nsISupports) - .wrappedJSObject; var {Toolbox} = require("devtools/client/framework/toolbox"); -var toolbox, toolIDs, toolShortcuts = [], idIndex, modifiedPrefs = []; +var toolbox, toolIDs, idIndex, modifiedPrefs = []; function test() { addTab("about:blank").then(function () { toolIDs = []; for (let [id, definition] of gDevTools._tools) { - let shortcut = Startup.KeyShortcuts.filter(s => s.toolId == id)[0]; - if (!shortcut) { - continue; - } - toolIDs.push(id); - toolShortcuts.push(shortcut); + if (definition.key) { + toolIDs.push(id); - // Enable disabled tools - let pref = definition.visibilityswitch, prefValue; - try { - prefValue = Services.prefs.getBoolPref(pref); - } catch (e) { - continue; - } - if (!prefValue) { - modifiedPrefs.push(pref); - Services.prefs.setBoolPref(pref, true); + // Enable disabled tools + let pref = definition.visibilityswitch, prefValue; + try { + prefValue = Services.prefs.getBoolPref(pref); + } catch (e) { + continue; + } + if (!prefValue) { + modifiedPrefs.push(pref); + Services.prefs.setBoolPref(pref, true); + } } } let target = TargetFactory.forTab(gBrowser.selectedTab); @@ -54,9 +49,8 @@ function testShortcuts(aToolbox, aIndex) { toolbox.once("select", selectCB); - let shortcut = toolShortcuts[aIndex]; - let key = shortcut.shortcut; - let toolModifiers = shortcut.modifiers; + let key = gDevTools._tools.get(toolIDs[aIndex]).key; + let toolModifiers = gDevTools._tools.get(toolIDs[aIndex]).modifiers; let modifiers = { accelKey: toolModifiers.includes("accel"), altKey: toolModifiers.includes("alt"), diff --git a/devtools/client/framework/toolbox.js b/devtools/client/framework/toolbox.js index eb0e54a2375d..97e1f336629a 100644 --- a/devtools/client/framework/toolbox.js +++ b/devtools/client/framework/toolbox.js @@ -14,7 +14,7 @@ const HOST_HISTOGRAM = "DEVTOOLS_TOOLBOX_HOST"; const SCREENSIZE_HISTOGRAM = "DEVTOOLS_SCREEN_RESOLUTION_ENUMERATED_PER_USER"; const HTML_NS = "http://www.w3.org/1999/xhtml"; -var {Ci, Cu, Cc} = require("chrome"); +var {Ci, Cu} = require("chrome"); var promise = require("promise"); var defer = require("devtools/shared/defer"); var Services = require("Services"); @@ -27,8 +27,6 @@ var Menu = require("devtools/client/framework/menu"); var MenuItem = require("devtools/client/framework/menu-item"); var { DOMHelpers } = require("resource://devtools/client/shared/DOMHelpers.jsm"); const { KeyCodes } = require("devtools/client/shared/keycodes"); -var Startup = Cc["@mozilla.org/devtools/startup-clh;1"].getService(Ci.nsISupports) - .wrappedJSObject; const { BrowserLoader } = Cu.import("resource://devtools/client/shared/browser-loader.js", {}); @@ -859,25 +857,24 @@ Toolbox.prototype = { let doc = this.win.parent.document; - for (let item of Startup.KeyShortcuts) { - // KeyShortcuts contain tool-specific and global key shortcuts, - // here we only need to copy shortcut specific to each tool. - if (!item.toolId) { + for (let [id, toolDefinition] of gDevTools.getToolDefinitionMap()) { + // Prevent multiple entries for the same tool. + if (!toolDefinition.key || doc.getElementById("key_" + id)) { continue; } - let { toolId, shortcut, modifiers } = item; + let toolId = id; let key = doc.createElement("key"); key.id = "key_" + toolId; - if (shortcut.startsWith("VK_")) { - key.setAttribute("keycode", shortcut); + if (toolDefinition.key.startsWith("VK_")) { + key.setAttribute("keycode", toolDefinition.key); } else { - key.setAttribute("key", shortcut); + key.setAttribute("key", toolDefinition.key); } - key.setAttribute("modifiers", modifiers); + key.setAttribute("modifiers", toolDefinition.modifiers); // needed. See bug 371900 key.setAttribute("oncommand", "void(0);"); key.addEventListener("command", () => {