Bug 1843866 - Add tab parameter to commands.onCommand. r=robwu
Differential Revision: https://phabricator.services.mozilla.com/D206880
This commit is contained in:
@@ -13,8 +13,13 @@ ChromeUtils.defineESModuleGetters(this, {
|
||||
this.commands = class extends ExtensionAPIPersistent {
|
||||
PERSISTENT_EVENTS = {
|
||||
onCommand({ fire }) {
|
||||
const { extension } = this;
|
||||
const { tabManager } = extension;
|
||||
|
||||
let listener = (eventName, commandName) => {
|
||||
fire.async(commandName);
|
||||
let nativeTab = tabTracker.activeTab;
|
||||
tabManager.addActiveTabPermission(nativeTab);
|
||||
fire.async(commandName, tabManager.convert(nativeTab));
|
||||
};
|
||||
this.on("command", listener);
|
||||
return {
|
||||
|
||||
@@ -104,6 +104,12 @@
|
||||
{
|
||||
"name": "command",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "tab",
|
||||
"$ref": "tags.Tab",
|
||||
"optional": true,
|
||||
"description": "Details of the $(ref:tabs.Tab) where the command was activated."
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -226,7 +226,16 @@ add_task(async function test_user_defined_commands() {
|
||||
}
|
||||
|
||||
function background() {
|
||||
browser.commands.onCommand.addListener(commandName => {
|
||||
browser.commands.onCommand.addListener(async (commandName, tab) => {
|
||||
let [expectedTab] = await browser.tabs.query({
|
||||
currentWindow: true,
|
||||
active: true,
|
||||
});
|
||||
browser.test.assertEq(
|
||||
tab.id,
|
||||
expectedTab.id,
|
||||
"Expected onCommand listener to pass the current tab"
|
||||
);
|
||||
browser.test.sendMessage("oncommand", commandName);
|
||||
});
|
||||
browser.test.sendMessage("ready");
|
||||
@@ -408,8 +417,9 @@ add_task(async function test_commands_event_page() {
|
||||
},
|
||||
},
|
||||
background() {
|
||||
browser.commands.onCommand.addListener(name => {
|
||||
browser.commands.onCommand.addListener((name, tab) => {
|
||||
browser.test.assertEq(name, "toggle-feature", "command received");
|
||||
browser.test.assertTrue(!!tab, "tab received");
|
||||
browser.test.sendMessage("onCommand");
|
||||
});
|
||||
browser.test.sendMessage("ready");
|
||||
|
||||
Reference in New Issue
Block a user