mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 1280347 - Require a permission for the API r=mixedpuppy
The new permission is added to make it easier to audit the usage of the API. It is an optional permission, in case we ever decide to introduce a permission warning for it. Differential Revision: https://phabricator.services.mozilla.com/D6771 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
a69fd162a2
commit
fd1f17a6e3
@ -15,6 +15,14 @@
|
||||
"contextMenus"
|
||||
]
|
||||
}]
|
||||
}, {
|
||||
"$extend": "OptionalPermission",
|
||||
"choices": [{
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"menus.overrideContext"
|
||||
]
|
||||
}]
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -404,6 +412,7 @@
|
||||
},
|
||||
{
|
||||
"name": "overrideContext",
|
||||
"permissions": ["menus.overrideContext"],
|
||||
"type": "function",
|
||||
"description": "Show the matching menu items from this extension instead of the default menu. This should be called during a 'contextmenu' DOM event handler, and only applies to the menu that opens after this event.",
|
||||
"parameters": [
|
||||
|
@ -57,7 +57,7 @@ add_task(async function overrideContext_in_extension_tab() {
|
||||
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
permissions: ["menus"],
|
||||
permissions: ["menus", "menus.overrideContext"],
|
||||
},
|
||||
files: {
|
||||
"tab.html": `
|
||||
@ -250,7 +250,7 @@ add_task(async function overrideContext_sidebar_edge_cases() {
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
useAddonManager: "temporary", // To automatically show sidebar on load.
|
||||
manifest: {
|
||||
permissions: ["menus"],
|
||||
permissions: ["menus", "menus.overrideContext"],
|
||||
sidebar_action: {
|
||||
default_panel: "sidebar.html",
|
||||
},
|
||||
|
@ -66,7 +66,7 @@ add_task(async function overrideContext_with_context() {
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
applications: {gecko: {id: "@menu-test-extension"}},
|
||||
permissions: ["menus", "tabs", "bookmarks", "<all_urls>"],
|
||||
permissions: ["menus", "menus.overrideContext", "tabs", "bookmarks", "<all_urls>"],
|
||||
},
|
||||
files: {
|
||||
"tab.html": `
|
||||
|
@ -53,6 +53,11 @@ add_task(async function overrideContext_permissions() {
|
||||
// "contextmenu" event. So we use a generator to run tests, and yield
|
||||
// before we call overrideContext after an asynchronous operation.
|
||||
let testGenerator = (async function* () {
|
||||
browser.test.assertEq(undefined, browser.menus.overrideContext,
|
||||
"menus.overrideContext requires the 'menus.overrideContext' permission");
|
||||
await requestPermissions({permissions: ["menus.overrideContext"]});
|
||||
yield;
|
||||
|
||||
// context without required property.
|
||||
browser.test.assertThrows(
|
||||
() => { browser.menus.overrideContext({context: "tab"}); },
|
||||
@ -114,6 +119,10 @@ add_task(async function overrideContext_permissions() {
|
||||
|
||||
// Host permissions were revoked, access should be blocked again.
|
||||
assertNotAllowed(CONTEXT_OPTIONS_TAB, E_PERM_TAB);
|
||||
|
||||
await browser.permissions.remove({permissions: ["menus.overrideContext"]});
|
||||
browser.test.assertEq(undefined, browser.menus.overrideContext,
|
||||
"menus.overrideContext is unavailable after revoking the permission");
|
||||
})();
|
||||
|
||||
// eslint-disable-next-line mozilla/balanced-listeners
|
||||
@ -133,7 +142,7 @@ add_task(async function overrideContext_permissions() {
|
||||
useAddonManager: "temporary", // To automatically show sidebar on load.
|
||||
manifest: {
|
||||
permissions: ["menus"],
|
||||
optional_permissions: ["tabs", "bookmarks", "<all_urls>"],
|
||||
optional_permissions: ["menus.overrideContext", "tabs", "bookmarks", "<all_urls>"],
|
||||
sidebar_action: {
|
||||
default_panel: "sidebar.html",
|
||||
},
|
||||
|
@ -376,6 +376,7 @@ const GRANTED_WITHOUT_USER_PROMPT = [
|
||||
"identity",
|
||||
"idle",
|
||||
"menus",
|
||||
"menus.overrideContext",
|
||||
"mozillaAddons",
|
||||
"search",
|
||||
"storage",
|
||||
|
Loading…
Reference in New Issue
Block a user