From 0672fec97cef5565b84c7bbcea46557258da5905 Mon Sep 17 00:00:00 2001 From: Andrew Swan Date: Thu, 23 Mar 2017 21:45:25 -0700 Subject: [PATCH] Bug 1197420 Part 2 Extension cleanups for optional permissions r=kmag - Convert the object used to represent permissions to the format used in the optional permissions UI (property hosts becomes origins) - Turn Extension.userPermissions into a getter MozReview-Commit-ID: Dc44DMfKjG --HG-- extra : rebase_source : e24e1b52edd3ddcd353a6407497ec4076039af03 --- .../webextensions/browser_extension_sideloading.js | 8 ++++---- browser/modules/ExtensionsUI.jsm | 4 ++-- toolkit/components/extensions/Extension.jsm | 10 +++++----- toolkit/mozapps/extensions/AddonManager.jsm | 2 +- toolkit/mozapps/extensions/content/extensions.js | 4 ++-- toolkit/mozapps/extensions/internal/XPIProvider.jsm | 2 +- .../test/xpcshell/test_webextension_install.js | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/browser/base/content/test/webextensions/browser_extension_sideloading.js b/browser/base/content/test/webextensions/browser_extension_sideloading.js index 8e8f917d20c1..a54777c7874d 100644 --- a/browser/base/content/test/webextensions/browser_extension_sideloading.js +++ b/browser/base/content/test/webextensions/browser_extension_sideloading.js @@ -95,7 +95,7 @@ add_task(function* () { seen: false, userPermissions: { permissions: ["history"], - hosts: ["https://*/*"], + origins: ["https://*/*"], }, iconURL: ICON_URL, }); @@ -108,7 +108,7 @@ add_task(function* () { seen: false, userPermissions: { permissions: [], - hosts: [], + origins: [], }, }); @@ -121,7 +121,7 @@ add_task(function* () { seen: false, userPermissions: { permissions: [], - hosts: [""], + origins: [""], } }); @@ -134,7 +134,7 @@ add_task(function* () { seen: false, userPermissions: { permissions: [], - hosts: [""], + origins: [""], } }); diff --git a/browser/modules/ExtensionsUI.jsm b/browser/modules/ExtensionsUI.jsm index c1aed9e124cd..0322679178ad 100644 --- a/browser/modules/ExtensionsUI.jsm +++ b/browser/modules/ExtensionsUI.jsm @@ -220,11 +220,11 @@ this.ExtensionsUI = { let bundle = Services.strings.createBundle(BROWSER_PROPERTIES); - let perms = info.permissions || {hosts: [], permissions: []}; + let perms = info.permissions || {origins: [], permissions: []}; // First classify our host permissions let allUrls = false, wildcards = [], sites = []; - for (let permission of perms.hosts) { + for (let permission of perms.origins) { if (permission == "") { allUrls = true; break; diff --git a/toolkit/components/extensions/Extension.jsm b/toolkit/components/extensions/Extension.jsm index a7ea0b114504..3d4cebe0d137 100644 --- a/toolkit/components/extensions/Extension.jsm +++ b/toolkit/components/extensions/Extension.jsm @@ -375,20 +375,20 @@ this.ExtensionData = class { // manifest. The current implementation just returns the contents // of the permissions attribute, if we add things like url_overrides, // they should also be added here. - userPermissions() { + get userPermissions() { let result = { - hosts: this.whiteListedHosts.pat, + origins: this.whiteListedHosts.pat, apis: [...this.apiNames], }; if (Array.isArray(this.manifest.content_scripts)) { for (let entry of this.manifest.content_scripts) { - result.hosts.push(...entry.matches); + result.origins.push(...entry.matches); } } const EXP_PATTERN = /^experiments\.\w+/; result.permissions = [...this.permissions] - .filter(p => !result.hosts.includes(p) && !EXP_PATTERN.test(p)); + .filter(p => !result.origins.includes(p) && !EXP_PATTERN.test(p)); return result; } @@ -401,7 +401,7 @@ this.ExtensionData = class { // a *.domain.com to specific-host.domain.com that's actually a // drop in permissions but the simple test below will cause a prompt. return { - hosts: newPermissions.hosts.filter(perm => !oldPermissions.hosts.includes(perm)), + origins: newPermissions.origins.filter(perm => !oldPermissions.origins.includes(perm)), permissions: newPermissions.permissions.filter(perm => !oldPermissions.permissions.includes(perm)), }; } diff --git a/toolkit/mozapps/extensions/AddonManager.jsm b/toolkit/mozapps/extensions/AddonManager.jsm index 850685a93d21..153e5521d4bd 100644 --- a/toolkit/mozapps/extensions/AddonManager.jsm +++ b/toolkit/mozapps/extensions/AddonManager.jsm @@ -1348,7 +1348,7 @@ var AddonManagerInternal = { let difference = Extension.comparePermissions(oldPerms, newPerms); // If there are no new permissions, just go ahead with the update - if (difference.hosts.length == 0 && difference.permissions.length == 0) { + if (difference.origins.length == 0 && difference.permissions.length == 0) { return Promise.resolve(); } diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js index 12dc7964a932..b70bfe315962 100644 --- a/toolkit/mozapps/extensions/content/extensions.js +++ b/toolkit/mozapps/extensions/content/extensions.js @@ -725,7 +725,7 @@ function attachUpdateHandler(install) { let difference = Extension.comparePermissions(oldPerms, newPerms); // If there are no new permissions, just proceed - if (difference.hosts.length == 0 && difference.permissions.length == 0) { + if (difference.origins.length == 0 && difference.permissions.length == 0) { return Promise.resolve(); } @@ -1291,7 +1291,7 @@ var gViewController = { doCommand(aAddon) { if (aAddon.isWebExtension && !aAddon.seen && WEBEXT_PERMISSION_PROMPTS) { let perms = aAddon.userPermissions; - if (perms.hosts.length > 0 || perms.permissions.length > 0) { + if (perms.origins.length > 0 || perms.permissions.length > 0) { let subject = { wrappedJSObject: { target: getBrowserElement(), diff --git a/toolkit/mozapps/extensions/internal/XPIProvider.jsm b/toolkit/mozapps/extensions/internal/XPIProvider.jsm index 519bbd3b0d1f..148d08571072 100644 --- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm @@ -1022,7 +1022,7 @@ var loadManifestFromWebManifest = Task.async(function*(aUri) { addon.iconURL = null; addon.icon64URL = null; addon.icons = manifest.icons || {}; - addon.userPermissions = extension.userPermissions(); + addon.userPermissions = extension.userPermissions; addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DEFAULT; diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js b/toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js index e50950a7c140..da0c8a64d98a 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js @@ -520,7 +520,7 @@ add_task(function* test_permissions_prompt() { notEqual(perminfo.addon, null, "Permission info includes the new addon"); let perms = perminfo.addon.userPermissions; deepEqual(perms.permissions, ["tabs", "storage"], "API permissions are correct"); - deepEqual(perms.hosts, ["https://*.example.com/*", ""], "Host permissions are correct"); + deepEqual(perms.origins, ["https://*.example.com/*", ""], "Host permissions are correct"); deepEqual(perms.apis, ["test"], "Experiments permissions are correct"); let addon = yield promiseAddonByID(perminfo.addon.id);