From 42972328447c302eca456e28f00e635474ecd612 Mon Sep 17 00:00:00 2001 From: Andrew Swan Date: Tue, 23 Aug 2016 19:24:15 -0700 Subject: [PATCH] Bug 1297028 Expose Addon.canUninstall flag to content r=bz,rhelmer MozReview-Commit-ID: Ec6QPj9h9k7 --HG-- extra : rebase_source : 747cb4ce54d5e8d0cc7bc2cc3654471b3b07bfcb --- dom/webidl/AddonManager.webidl | 2 ++ toolkit/mozapps/extensions/AddonManager.jsm | 1 + .../extensions/test/browser/browser_webapi.js | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/dom/webidl/AddonManager.webidl b/dom/webidl/AddonManager.webidl index 33099a5c8f03..79f2fb7a0b8f 100644 --- a/dom/webidl/AddonManager.webidl +++ b/dom/webidl/AddonManager.webidl @@ -24,6 +24,8 @@ interface Addon { readonly attribute boolean isEnabled; // If the add-on is currently active in the browser. readonly attribute boolean isActive; + // If the add-on may be uninstalled + readonly attribute boolean canUninstall; Promise uninstall(); Promise setEnabled(boolean value); diff --git a/toolkit/mozapps/extensions/AddonManager.jsm b/toolkit/mozapps/extensions/AddonManager.jsm index 04259b0f5511..0072d0d89e2b 100644 --- a/toolkit/mozapps/extensions/AddonManager.jsm +++ b/toolkit/mozapps/extensions/AddonManager.jsm @@ -335,6 +335,7 @@ function webAPIForAddon(addon) { // A few properties are computed for a nicer API result.isEnabled = !addon.userDisabled; + result.canUninstall = Boolean(addon.permissions & AddonManager.PERM_CAN_UNINSTALL); return result; } diff --git a/toolkit/mozapps/extensions/test/browser/browser_webapi.js b/toolkit/mozapps/extensions/test/browser/browser_webapi.js index 427fc8ba7906..ca8e41aad04e 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_webapi.js +++ b/toolkit/mozapps/extensions/test/browser/browser_webapi.js @@ -17,7 +17,7 @@ function testWithAPI(task) { let gProvider = new MockProvider(); -gProvider.createAddons([{ +let addons = gProvider.createAddons([{ id: "addon1@tests.mozilla.org", name: "Test add-on 1", version: "2.1", @@ -41,8 +41,18 @@ gProvider.createAddons([{ type: "extension", userDisabled: true, isActive: false, +}, { + id: "addon4@tests.mozilla.org", + name: "Test add-on 4", + version: "1", + description: "Longer description", + type: "extension", + userDisabled: false, + isActive: true, }]); +addons[3].permissions &= ~AddonManager.PERM_CAN_UNINSTALL; + function API_getAddonByID(browser, id) { return ContentTask.spawn(browser, id, function*(id) { let addon = yield content.navigator.mozAddonManager.getAddonByID(id); @@ -67,6 +77,10 @@ add_task(testWithAPI(function*(browser) { case "isEnabled": realVal = !real.userDisabled; break; + + case "canUninstall": + realVal = Boolean(real.permissions & AddonManager.PERM_CAN_UNINSTALL); + break; } // null and undefined don't compare well so stringify them first