Skip to content

Commit

Permalink
Bug 1761814 prevent menus onclick property with event pages and mv3 r…
Browse files Browse the repository at this point in the history
…=robwu

Differential Revision: https://phabricator.services.mozilla.com/D142242
  • Loading branch information
mixedpuppy committed Mar 31, 2022
1 parent 7a18c8a commit 215e717
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions browser/components/extensions/child/ext-menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ this.menusInternal = class extends ExtensionAPI {
createProperties.id = ++gNextMenuItemID;
}
let { onclick } = createProperties;
if (onclick && !context.extension.persistentBackground) {
throw new ExtensionError(
`Property "onclick" cannot be used in menus.create, replace with an "onClicked" event listener.`
);
}
delete createProperties.onclick;
context.childManager
.callParentAsyncFunction("menusInternal.create", [createProperties])
Expand All @@ -159,6 +164,11 @@ this.menusInternal = class extends ExtensionAPI {

update(id, updateProperties) {
let { onclick } = updateProperties;
if (onclick && !context.extension.persistentBackground) {
throw new ExtensionError(
`Property "onclick" cannot be used in menus.update, replace with an "onClicked" event listener.`
);
}
delete updateProperties.onclick;
return context.childManager
.callParentAsyncFunction("menusInternal.update", [
Expand Down
2 changes: 2 additions & 0 deletions browser/components/extensions/schemas/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
},
"onclick": {
"type": "function",
"max_manifest_version": 2,
"optional": true,
"description": "A function that will be called back when the menu item is clicked. Event pages cannot use this; instead, they should register a listener for $(ref:contextMenus.onClicked).",
"parameters": [
Expand Down Expand Up @@ -374,6 +375,7 @@
},
"onclick": {
"type": "function",
"max_manifest_version": 2,
"optional": "omit-key-if-missing",
"parameters": [
{
Expand Down

0 comments on commit 215e717

Please sign in to comment.