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
This commit is contained in:
Andrew Swan 2017-03-23 21:45:25 -07:00
Родитель f1085e3c9d
Коммит 0672fec97c
7 изменённых файлов: 16 добавлений и 16 удалений

Просмотреть файл

@ -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: ["<all_urls>"],
origins: ["<all_urls>"],
}
});
@ -134,7 +134,7 @@ add_task(function* () {
seen: false,
userPermissions: {
permissions: [],
hosts: ["<all_urls>"],
origins: ["<all_urls>"],
}
});

Просмотреть файл

@ -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 == "<all_urls>") {
allUrls = true;
break;

Просмотреть файл

@ -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)),
};
}

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -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(),

Просмотреть файл

@ -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;

Просмотреть файл

@ -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/*", "<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);