Bug 1375485 - Expose classifyPermissions on ExtensionData. r?aswan
MozReview-Commit-ID: HrqRIeYQuUl
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -130,39 +130,16 @@ function validateThemeManifest(manifestP
for (let propName of manifestProperties) {
if (propName != "theme" && !allowedThemeProperties.includes(propName)) {
invalidProps.push(propName);
}
}
return invalidProps;
}
-/**
- * Classify an individual permission from a webextension manifest
- * as a host/origin permission, an api permission, or a regular permission.
- *
- * @param {string} perm The permission string to classify
- *
- * @returns {object}
- * An object with exactly one of the following properties:
- * "origin" to indicate this is a host/origin permission.
- * "api" to indicate this is an api permission
- * (as used for webextensions experiments).
- * "permission" to indicate this is a regular permission.
- */
-function classifyPermission(perm) {
- let match = /^(\w+)(?:\.(\w+)(?:\.\w+)*)?$/.exec(perm);
- if (!match) {
- return {origin: perm};
- } else if (match[1] == "experiments" && match[2]) {
- return {api: match[2]};
- }
- return {permission: perm};
-}
-
const LOGGER_ID_BASE = "addons.webextension.";
const UUID_MAP_PREF = "extensions.webextensions.uuids";
const LEAVE_STORAGE_PREF = "extensions.webextensions.keepStorageOnUninstall";
const LEAVE_UUID_PREF = "extensions.webextensions.keepUuidOnUninstall";
const COMMENT_REGEXP = new RegExp(String.raw`
^
(
@@ -453,16 +430,39 @@ this.ExtensionData = class {
resolve(JSON.parse(text));
} catch (e) {
reject(e);
}
});
});
}
+ /**
+ * Classify an individual permission from a webextension manifest
+ * as a host/origin permission, an api permission, or a regular permission.
+ *
+ * @param {string} perm The permission string to classify
+ *
+ * @returns {object}
+ * An object with exactly one of the following properties:
+ * "origin" to indicate this is a host/origin permission.
+ * "api" to indicate this is an api permission
+ * (as used for webextensions experiments).
+ * "permission" to indicate this is a regular permission.
+ */
+ classifyPermission(perm) {
+ let match = /^(\w+)(?:\.(\w+)(?:\.\w+)*)?$/.exec(perm);
+ if (!match) {
+ return {origin: perm};
+ } else if (match[1] == "experiments" && match[2]) {
+ return {api: match[2]};
+ }
+ return {permission: perm};
+ }
+
// 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.
get userPermissions() {
if (this.type !== "extension") {
return null;
@@ -582,17 +582,17 @@ this.ExtensionData = class {
if (perm === "geckoProfiler") {
const acceptedExtensions = Services.prefs.getStringPref("extensions.geckoProfiler.acceptedExtensionIds", "");
if (!acceptedExtensions.split(",").includes(id)) {
this.manifestError("Only whitelisted extensions are allowed to access the geckoProfiler.");
continue;
}
}
- let type = classifyPermission(perm);
+ let type = this.classifyPermission(perm);
if (type.origin) {
let matcher = new MatchPattern(perm, {ignorePath: true});
perm = matcher.pattern;
originPermissions.add(perm);
} else if (type.api) {
apiNames.add(type.api);
}
@@ -1597,17 +1597,17 @@ this.Extension = class extends Extension
}
get name() {
return this.manifest.name;
}
get optionalOrigins() {
if (this._optionalOrigins == null) {
- let origins = this.manifest.optional_permissions.filter(perm => classifyPermission(perm).origin);
+ let origins = this.manifest.optional_permissions.filter(perm => this.classifyPermission(perm).origin);
this._optionalOrigins = new MatchPatternSet(origins, {ignorePath: true});
}
return this._optionalOrigins;
}
};
this.Langpack = class extends ExtensionData {
constructor(addonData, startupReason) {