summaryrefslogtreecommitdiffstats
path: root/mobile/android/modules/geckoview/GeckoViewWebExtension.sys.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/modules/geckoview/GeckoViewWebExtension.sys.mjs')
-rw-r--r--mobile/android/modules/geckoview/GeckoViewWebExtension.sys.mjs54
1 files changed, 40 insertions, 14 deletions
diff --git a/mobile/android/modules/geckoview/GeckoViewWebExtension.sys.mjs b/mobile/android/modules/geckoview/GeckoViewWebExtension.sys.mjs
index 749f753626..421839264a 100644
--- a/mobile/android/modules/geckoview/GeckoViewWebExtension.sys.mjs
+++ b/mobile/android/modules/geckoview/GeckoViewWebExtension.sys.mjs
@@ -283,6 +283,16 @@ function exportFlags(aPolicy) {
return flags;
}
+function normalizePermissions(perms) {
+ if (perms?.permissions) {
+ perms = { ...perms };
+ perms.permissions = perms.permissions.filter(
+ perm => !perm.startsWith("internal:")
+ );
+ }
+ return perms;
+}
+
async function exportExtension(aAddon, aPermissions, aSourceURI) {
// First, let's make sure the policy is ready if present
let policy = WebExtensionPolicy.getByID(aAddon.id);
@@ -360,22 +370,12 @@ async function exportExtension(aAddon, aPermissions, aSourceURI) {
updateDate = null;
}
- const normalizePermissions = perms => {
- if (perms?.permissions) {
- perms = { ...perms };
- perms.permissions = perms.permissions.filter(
- perm => !perm.startsWith("internal:")
- );
- }
- return perms;
- };
-
const optionalPermissions = aAddon.optionalPermissions?.permissions ?? [];
- const optionalOrigins = aAddon.optionalPermissions?.origins ?? [];
+ const optionalOrigins = aAddon.optionalOriginsNormalized;
const grantedPermissions =
- normalizePermissions(await lazy.ExtensionPermissions.get(id)) ?? [];
- const grantedOptionalPermissions = grantedPermissions?.permissions ?? [];
- const grantedOptionalOrigins = grantedPermissions?.origins ?? [];
+ normalizePermissions(await lazy.ExtensionPermissions.get(id)) ?? {};
+ const grantedOptionalPermissions = grantedPermissions.permissions ?? [];
+ const grantedOptionalOrigins = grantedPermissions.origins ?? [];
return {
webExtensionId: id,
@@ -623,6 +623,32 @@ class AddonManagerListener {
// the GeckoView side when it is actually going to be available.
this.onExtensionReady = this.onExtensionReady.bind(this);
lazy.Management.on("ready", this.onExtensionReady);
+ lazy.Management.on("change-permissions", this.onOptionalPermissionsChanged);
+ }
+
+ async onOptionalPermissionsChanged(type, { extensionId }) {
+ // In xpcshell tests there wil be test extensions that trigger this event while the
+ // AddonManager has not been started at all, on the contrary on a regular browser
+ // instance the AddonManager is expected to be already fully started for an extension
+ // for the extension to be able to reach the "ready" state, and so we just silently
+ // early exit here if the AddonManager is not ready.
+ if (!lazy.AddonManager.isReady) {
+ return;
+ }
+
+ const addon = await lazy.AddonManager.getAddonByID(extensionId);
+ if (!addon) {
+ return;
+ }
+ const extension = await exportExtension(
+ addon,
+ addon.userPermissions,
+ /* aSourceURI */ null
+ );
+ lazy.EventDispatcher.instance.sendRequest({
+ type: "GeckoView:WebExtension:OnOptionalPermissionsChanged",
+ extension,
+ });
}
async onExtensionReady(name, extInstance) {