Bug 1522820 - Disable browser action's "Remove Extension" if the addon can't be uninstalled. r=Felipe a=lizzard
authorOriol Brufau <oriol-bugzilla@hotmail.com>
Wed, 06 Feb 2019 17:18:32 +0000
changeset 512953 bc23b491541e589b832b4605f188c22260f0f957
parent 512952 fc9047475850942b21cec35ed83c6f09666fa512
child 512954 b61d0fdc785b3dd4deafd0e29a3a3116d52cc11f
push id10657
push usercbrindusan@mozilla.com
push dateFri, 08 Feb 2019 23:40:36 +0000
treeherdermozilla-beta@daa824c92e14 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe, lizzard
bugs1522820
milestone66.0
Bug 1522820 - Disable browser action's "Remove Extension" if the addon can't be uninstalled. r=Felipe a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D18493
browser/base/content/browser.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -6316,28 +6316,39 @@ var ToolbarContextMenu = {
     // Toolbar buttons are wrapped in customize mode. Unwrap if necessary.
     let {triggerNode} = popup;
     if (triggerNode && gCustomizeMode.isWrappedToolbarItem(triggerNode)) {
       return triggerNode.firstElementChild;
     }
     return triggerNode;
   },
 
-  updateExtension(popup) {
+  _getExtensionId(popup) {
+    let node = this._getUnwrappedTriggerNode(popup);
+    return node && node.getAttribute("data-extensionid");
+  },
+
+  async updateExtension(popup) {
     let removeExtension = popup.querySelector(".customize-context-removeExtension");
     let manageExtension = popup.querySelector(".customize-context-manageExtension");
     let separator = removeExtension.nextElementSibling;
-    let node = this._getUnwrappedTriggerNode(popup);
-    let isWebExt = node && node.hasAttribute("data-extensionid");
-    removeExtension.hidden = manageExtension.hidden = separator.hidden = !isWebExt;
+    let id = this._getExtensionId(popup);
+    let addon = id && await AddonManager.getAddonByID(id);
+    removeExtension.hidden = manageExtension.hidden = separator.hidden = !addon;
+    if (addon) {
+      removeExtension.disabled = !(addon.permissions & AddonManager.PERM_CAN_UNINSTALL);
+    }
   },
 
   async removeExtensionForContextAction(popup) {
-    let id = this._getUnwrappedTriggerNode(popup).getAttribute("data-extensionid");
-    let addon = await AddonManager.getAddonByID(id);
+    let id = this._getExtensionId(popup);
+    let addon = id && await AddonManager.getAddonByID(id);
+    if (!addon || !(addon.permissions & AddonManager.PERM_CAN_UNINSTALL)) {
+      return;
+    }
     let {name} = addon;
     let brand = document.getElementById("bundle_brand").getString("brandShorterName");
     let {getFormattedString, getString} = gNavigatorBundle;
     let title = getFormattedString("webext.remove.confirmation.title", [name]);
     let message = getFormattedString("webext.remove.confirmation.message", [name, brand]);
     let btnTitle = getString("webext.remove.confirmation.button");
     let {BUTTON_TITLE_IS_STRING: titleString, BUTTON_TITLE_CANCEL: titleCancel,
          BUTTON_POS_0, BUTTON_POS_1, confirmEx} = Services.prompt;
@@ -6345,19 +6356,21 @@ var ToolbarContextMenu = {
     let response = confirmEx(null, title, message, btnFlags, btnTitle, null, null, null,
                              {value: 0});
     if (response == 0) {
       addon.uninstall();
     }
   },
 
   openAboutAddonsForContextAction(popup) {
-    let id = this._getUnwrappedTriggerNode(popup).getAttribute("data-extensionid");
-    let viewID = "addons://detail/" + encodeURIComponent(id);
-    BrowserOpenAddonsMgr(viewID);
+    let id = this._getExtensionId(popup);
+    if (id) {
+      let viewID = "addons://detail/" + encodeURIComponent(id);
+      BrowserOpenAddonsMgr(viewID);
+    }
   },
 };
 
 var gPageStyleMenu = {
   // This maps from a <browser> element (or, more specifically, a
   // browser's permanentKey) to an Object that contains the most recent
   // information about the browser content's stylesheets. That Object
   // is populated via the PageStyle:StyleSheets message from the content