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:
Rob Wu 2018-09-27 08:21:07 +00:00
parent a69fd162a2
commit fd1f17a6e3
5 changed files with 23 additions and 4 deletions

View File

@ -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": [

View File

@ -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",
},

View File

@ -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": `

View File

@ -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",
},

View File

@ -376,6 +376,7 @@ const GRANTED_WITHOUT_USER_PROMPT = [
"identity",
"idle",
"menus",
"menus.overrideContext",
"mozillaAddons",
"search",
"storage",