Bug 1197420 Part 2 Extension cleanups for optional permissions r=kmag
☠☠ backed out by 0fa8a7ec4b42 ☠ ☠
authorAndrew Swan <aswan@mozilla.com>
Thu, 23 Mar 2017 21:45:25 -0700
changeset 397711 440bab1415095b4574672125d1786ad13766fad2
parent 397710 3e690bbe8b5a74e1eb952843445d0d145ac751ca
child 397712 46e135035f1049d81fabfc8c5c74c1b2d46f26b3
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1197420
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
browser/base/content/test/webextensions/browser_extension_sideloading.js
browser/modules/ExtensionsUI.jsm
toolkit/components/extensions/Extension.jsm
toolkit/mozapps/extensions/AddonManager.jsm
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js
--- a/browser/base/content/test/webextensions/browser_extension_sideloading.js
+++ b/browser/base/content/test/webextensions/browser_extension_sideloading.js
@@ -90,56 +90,56 @@ add_task(function* () {
   const ID1 = "addon1@tests.mozilla.org";
   let mock1 = new MockAddon({
     id: ID1,
     name: "Test 1",
     userDisabled: true,
     seen: false,
     userPermissions: {
       permissions: ["history"],
-      hosts: ["https://*/*"],
+      origins: ["https://*/*"],
     },
     iconURL: ICON_URL,
   });
 
   const ID2 = "addon2@tests.mozilla.org";
   let mock2 = new MockAddon({
     id: ID2,
     name: "Test 2",
     userDisabled: true,
     seen: false,
     userPermissions: {
       permissions: [],
-      hosts: [],
+      origins: [],
     },
   });
 
   const ID3 = "addon3@tests.mozilla.org";
   let mock3 = new MockAddon({
     id: ID3,
     name: "Test 3",
     isWebExtension: true,
     userDisabled: true,
     seen: false,
     userPermissions: {
       permissions: [],
-      hosts: ["<all_urls>"],
+      origins: ["<all_urls>"],
     }
   });
 
   const ID4 = "addon4@tests.mozilla.org";
   let mock4 = new MockAddon({
     id: ID4,
     name: "Test 4",
     isWebExtension: true,
     userDisabled: true,
     seen: false,
     userPermissions: {
       permissions: [],
-      hosts: ["<all_urls>"],
+      origins: ["<all_urls>"],
     }
   });
 
   let provider = new MockProvider(mock1, mock2, mock3, mock4);
   AddonManagerPrivate.registerProvider(provider, [{
     id: "extension",
     name: "Extensions",
     uiPriority: 4000,
--- a/browser/modules/ExtensionsUI.jsm
+++ b/browser/modules/ExtensionsUI.jsm
@@ -215,21 +215,21 @@ this.ExtensionsUI = {
   },
 
   // Create a set of formatted strings for a permission prompt
   _buildStrings(info) {
     let result = {};
 
     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 == "<all_urls>") {
         allUrls = true;
         break;
       }
       let match = /^[htps*]+:\/\/([^/]+)\//.exec(permission);
       if (!match) {
         throw new Error("Unparseable host permission");
       }
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -370,43 +370,43 @@ this.ExtensionData = class {
     });
   }
 
   // This method should return a structured representation of any
   // capabilities this extension has access to, as derived from the
   // 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;
   }
 
   // Compute the difference between two sets of permissions, suitable
   // for presenting to the user.
   static comparePermissions(oldPermissions, newPermissions) {
     // See bug 1331769: should we do something more complicated to
     // compare host permissions?
     // e.g., if we go from <all_urls> to a specific host or from
     // 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)),
     };
   }
 
   parseManifest() {
     return Promise.all([
       this.readJSON("manifest.json"),
       Management.lazyInit(),
--- a/toolkit/mozapps/extensions/AddonManager.jsm
+++ b/toolkit/mozapps/extensions/AddonManager.jsm
@@ -1343,17 +1343,17 @@ var AddonManagerInternal = {
       return Promise.resolve();
     }
 
     let newPerms = info.addon.userPermissions;
 
     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();
     }
 
     return new Promise((resolve, reject) => {
       let subject = {wrappedJSObject: {
         addon: info.addon,
         permissions: difference,
         resolve, reject
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -720,17 +720,17 @@ function attachUpdateHandler(install) {
       return Promise.resolve();
     }
 
     let newPerms = info.addon.userPermissions;
 
     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();
     }
 
     return new Promise((resolve, reject) => {
       let subject = {
         wrappedJSObject: {
           target: getBrowserElement(),
           info: {
@@ -1286,17 +1286,17 @@ var gViewController = {
           return false;
         let addonType = AddonManager.addonTypes[aAddon.type];
         return (!(addonType.flags & AddonManager.TYPE_SUPPORTS_ASK_TO_ACTIVATE) &&
                 hasPermission(aAddon, "enable"));
       },
       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(),
                 info: {
                   type: "sideload",
                   addon: aAddon,
                   icon: aAddon.iconURL,
                   permissions: perms,
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -1017,17 +1017,17 @@ var loadManifestFromWebManifest = Task.a
     else
       addon.optionsBrowserStyle = manifest.options_ui.browser_style;
   }
 
   // WebExtensions don't use iconURLs
   addon.iconURL = null;
   addon.icon64URL = null;
   addon.icons = manifest.icons || {};
-  addon.userPermissions = extension.userPermissions();
+  addon.userPermissions = extension.userPermissions;
 
   addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DEFAULT;
 
   function getLocale(aLocale) {
     // Use the raw manifest, here, since we need values with their
     // localization placeholders still in place.
     let rawManifest = extension.rawManifest;
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js
@@ -515,17 +515,17 @@ add_task(function* test_permissions_prom
 
   yield promiseCompleteInstall(install);
 
   notEqual(perminfo, undefined, "Permission handler was invoked");
   equal(perminfo.existingAddon, null, "Permission info does not include an existing addon");
   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/*", "<all_urls>"], "Host permissions are correct");
+  deepEqual(perms.origins, ["https://*.example.com/*", "<all_urls>"], "Host permissions are correct");
   deepEqual(perms.apis, ["test"], "Experiments permissions are correct");
 
   let addon = yield promiseAddonByID(perminfo.addon.id);
   notEqual(addon, null, "Extension was installed");
 
   addon.uninstall();
   yield OS.File.remove(xpi.path);
 });