Bug 1370716 - Only try to add _action menus if extension has permission
MozReview-Commit-ID: KpT1RH30NMh
--- a/browser/components/extensions/ext-browserAction.js
+++ b/browser/components/extensions/ext-browserAction.js
@@ -136,17 +136,21 @@ this.browserAction = class extends Exten
onBeforeCreated: document => {
let view = document.createElementNS(XUL_NS, "panelview");
view.id = this.viewId;
view.setAttribute("flex", "1");
view.setAttribute("extension", true);
document.getElementById("PanelUI-multiView").appendChild(view);
- document.addEventListener("popupshowing", this);
+
+ if (this.extension.hasPermission("menus") ||
+ this.extension.hasPermission("contextMenus")) {
+ document.addEventListener("popupshowing", this);
+ }
},
onDestroyed: document => {
document.removeEventListener("popupshowing", this);
let view = document.getElementById(this.viewId);
if (view) {
this.clearPopup();
@@ -331,20 +335,16 @@ this.browserAction = class extends Exten
this.eventQueue = [];
}
this.clearPopup();
}
break;
case "popupshowing":
- if (!global.actionContextMenu) {
- break;
- }
-
const menu = event.target;
const trigger = menu.triggerNode;
const node = window.document.getElementById(this.id);
const contexts = ["toolbar-context-menu", "customizationPanelItemContextMenu"];
if (contexts.includes(menu.id) && node && isAncestorOrSelf(node, trigger)) {
global.actionContextMenu({
extension: this.extension,
--- a/browser/components/extensions/ext-menus.js
+++ b/browser/components/extensions/ext-menus.js
@@ -76,16 +76,20 @@ var gMenuBuilder = {
// Builds a context menu for browserAction and pageAction buttons.
buildActionContextMenu(contextData) {
const {menu} = contextData;
contextData.tab = tabTracker.activeTab;
contextData.pageUrl = contextData.tab.linkedBrowser.currentURI.spec;
const root = gRootItems.get(contextData.extension);
+ if (!root) {
+ return;
+ }
+
const children = this.buildChildren(root, contextData);
const visible = children.slice(0, ACTION_MENU_TOP_LEVEL_LIMIT);
if (visible.length) {
this.xulMenu = menu;
menu.addEventListener("popuphidden", this);
const separator = menu.ownerDocument.createElement("menuseparator");
--- a/browser/components/extensions/ext-pageAction.js
+++ b/browser/components/extensions/ext-pageAction.js
@@ -160,17 +160,21 @@ this.pageAction = class extends Extensio
addButton(window) {
let document = window.document;
let button = document.createElement("image");
button.id = this.id;
button.setAttribute("class", "urlbar-icon");
button.addEventListener("click", this); // eslint-disable-line mozilla/balanced-listeners
- document.addEventListener("popupshowing", this);
+
+ if (this.extension.hasPermission("menus") ||
+ this.extension.hasPermission("contextMenus")) {
+ document.addEventListener("popupshowing", this);
+ }
document.getElementById("urlbar-icons").appendChild(button);
return button;
}
// Returns the page action button for the given window, creating it if
// it doesn't already exist.
@@ -204,20 +208,16 @@ this.pageAction = class extends Extensio
switch (event.type) {
case "click":
if (event.button === 0) {
this.handleClick(window);
}
break;
case "popupshowing":
- if (!global.actionContextMenu) {
- break;
- }
-
const menu = event.target;
const trigger = menu.triggerNode;
if (menu.id === "toolbar-context-menu" && trigger && trigger.id === this.id) {
global.actionContextMenu({
extension: this.extension,
onPageAction: true,
menu: menu,