author | Shane Caraveo <scaraveo@mozilla.com> |
Tue, 14 Feb 2017 16:24:03 -0800 | |
changeset 343134 | 673306dc657e3d5626f25f1ae720673d5ee84b7f |
parent 343133 | 74e585cee9b7de481d16bdc63fb42c9a32157a55 |
child 343135 | 85641936e47153d49c9c0a58b5efe91b99771cc1 |
push id | 31371 |
push user | cbook@mozilla.com |
push date | Thu, 16 Feb 2017 12:15:11 +0000 |
treeherder | mozilla-central@8c8b54b13be7 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | aswan |
bugs | 1338727 |
milestone | 54.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
|
--- a/browser/components/extensions/.eslintrc.js +++ b/browser/components/extensions/.eslintrc.js @@ -10,12 +10,13 @@ module.exports = { // eslint-disable-li "TabContext": true, "Window": true, "WindowEventManager": true, "browserActionFor": true, "getCookieStoreIdForTab": true, "getDevToolsTargetForContext": true, "makeWidgetId": true, "pageActionFor": true, + "sidebarActionFor": true, "tabTracker": true, "windowTracker": true, }, };
--- a/browser/components/extensions/ext-commands.js +++ b/browser/components/extensions/ext-commands.js @@ -120,26 +120,32 @@ CommandList.prototype = { // We need to have the attribute "oncommand" for the "command" listener to fire, // and it is currently ignored when set to the empty string. keyElement.setAttribute("oncommand", "//"); /* eslint-disable mozilla/balanced-listeners */ // We remove all references to the key elements when the extension is shutdown, // therefore the listeners for these elements will be garbage collected. keyElement.addEventListener("command", (event) => { + let action; if (name == "_execute_page_action") { - let win = event.target.ownerGlobal; - pageActionFor(this.extension).triggerAction(win); + action = pageActionFor(this.extension); } else if (name == "_execute_browser_action") { - let win = event.target.ownerGlobal; - browserActionFor(this.extension).triggerAction(win); + action = browserActionFor(this.extension); + } else if (name == "_execute_sidebar_action") { + action = sidebarActionFor(this.extension); } else { this.extension.tabManager .addActiveTabPermission(); this.emit("command", name); + return; + } + if (action) { + let win = event.target.ownerGlobal; + action.triggerAction(win); } }); /* eslint-enable mozilla/balanced-listeners */ return keyElement; }, /**
--- a/browser/components/extensions/ext-sidebarAction.js +++ b/browser/components/extensions/ext-sidebarAction.js @@ -247,16 +247,29 @@ class SidebarAction { } let broadcaster = document.getElementById(this.id); if (broadcaster) { broadcaster.remove(); } } windowTracker.removeOpenListener(this.windowOpenListener); } + + /** + * Triggers this sidebar action for the given window, with the same effects as + * if it were toggled via menu or toolbarbutton by a user. + * + * @param {ChromeWindow} window + */ + triggerAction(window) { + let {SidebarUI} = window; + if (SidebarUI) { + SidebarUI.toggle(this.id); + } + } } SidebarAction.for = (extension) => { return sidebarActionMap.get(extension); }; global.sidebarActionFor = SidebarAction.for;
--- a/browser/components/extensions/test/browser/browser-common.ini +++ b/browser/components/extensions/test/browser/browser-common.ini @@ -33,16 +33,17 @@ support-files = [browser_ext_browserAction_popup_resize.js] [browser_ext_browserAction_simple.js] [browser_ext_browsingData_formData.js] [browser_ext_browsingData_history.js] [browser_ext_browsingData_pluginData.js] [browser_ext_browsingData_serviceWorkers.js] [browser_ext_commands_execute_browser_action.js] [browser_ext_commands_execute_page_action.js] +[browser_ext_commands_execute_sidebar_action.js] [browser_ext_commands_getAll.js] [browser_ext_commands_onCommand.js] [browser_ext_contentscript_connect.js] [browser_ext_contextMenus.js] [browser_ext_contextMenus_checkboxes.js] [browser_ext_contextMenus_chrome.js] [browser_ext_contextMenus_icons.js] [browser_ext_contextMenus_onclick.js]
new file mode 100644 --- /dev/null +++ b/browser/components/extensions/test/browser/browser_ext_commands_execute_sidebar_action.js @@ -0,0 +1,52 @@ +/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set sts=2 sw=2 et tw=80: */ +"use strict"; + +add_task(function* test_execute_sidebar_action() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + "commands": { + "_execute_sidebar_action": { + "suggested_key": { + "default": "Alt+Shift+J", + }, + }, + }, + "sidebar_action": { + "default_panel": "sidebar.html", + }, + }, + files: { + "sidebar.html": ` + <!DOCTYPE html> + <html> + <head> + <meta charset="utf-8"> + <script src="sidebar.js"></script> + </head> + </html> + `, + + "sidebar.js": function() { + browser.runtime.sendMessage("from-sidebar-action"); + }, + }, + background() { + browser.runtime.onMessage.addListener(msg => { + if (msg == "from-sidebar-action") { + browser.test.notifyPass("execute-sidebar-action-opened"); + } + }); + }, + }); + + yield extension.startup(); + yield SimpleTest.promiseFocus(window); + // Since we didn't set useAddonManager, the sidebar will not be automatically + // opened for this test. + ok(document.getElementById("sidebar-box").hidden, "sidebar box is not visible"); + // Send the key to open the sidebar. + EventUtils.synthesizeKey("j", {altKey: true, shiftKey: true}); + yield extension.awaitFinish("execute-sidebar-action-opened"); + yield extension.unload(); +});