Bug 1412028 - expose executeKey from devtools-startup;r=ochameau
In order to execute the initial user action after going through
the onboarding flow, devtools-startup should expose a method easy
to call from the outside to trigger a devtools "command".
For now this is limited to devtools keyshortcuts.
MozReview-Commit-ID: 4QFAQCUu7IK
--- a/devtools/shim/devtools-startup.js
+++ b/devtools/shim/devtools-startup.js
@@ -439,37 +439,49 @@ DevToolsStartup.prototype = {
},
hookKeyShortcuts(window) {
let doc = window.document;
let keyset = doc.createElement("keyset");
keyset.setAttribute("id", "devtoolsKeyset");
for (let key of KeyShortcuts) {
- let xulKey = this.createKey(doc, key, () => this.onKey(window, key));
+ let keyId = key.toolId || key.id;
+ let xulKey = this.createKey(doc, key, () => this.executeKey(keyId, window));
keyset.appendChild(xulKey);
}
// 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) {
+ /**
+ * Execute the command associated with a DevTools key shortcut, for the provided
+ * window.
+ *
+ * @param {String} keyId
+ * id or toolId for the DevTools key shortcut to execute (see KeyShortcuts).
+ * @param {Window} window
+ * the window where the command should be executed (command will most likely
+ * apply to the selected tab).
+ */
+ executeKey(keyId, window) {
// 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.
let { gDevToolsBrowser } = require("devtools/client/framework/devtools-browser");
+ let key = KeyShortcuts.find(k => keyId === (k.toolId || k.id));
gDevToolsBrowser.onKeyShortcut(window, key, startTime);
}
},
// Create a <xul:key> DOM Element
createKey(doc, { id, toolId, shortcut, modifiers: mod }, oncommand) {
let k = doc.createElement("key");
k.id = "key_" + (id || toolId);