diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /toolkit/components/extensions/Extension.sys.mjs | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/extensions/Extension.sys.mjs')
-rw-r--r-- | toolkit/components/extensions/Extension.sys.mjs | 93 |
1 files changed, 70 insertions, 23 deletions
diff --git a/toolkit/components/extensions/Extension.sys.mjs b/toolkit/components/extensions/Extension.sys.mjs index 8ab3c30234..56f1320d6c 100644 --- a/toolkit/components/extensions/Extension.sys.mjs +++ b/toolkit/components/extensions/Extension.sys.mjs @@ -161,6 +161,13 @@ XPCOMUtils.defineLazyPreferenceGetter( 30 * 1000 ); +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "installIncludesOrigins", + "extensions.originControls.grantByDefault", + false +); + var { GlobalManager, IconDetails, @@ -509,14 +516,36 @@ var ExtensionAddonObserver = { }, onUninstalled(addon) { + this.clearOnUninstall(addon.id); + }, + + /** + * Clears persistent state from the add-on post install. + * + * @param {string} addonId The ID of the addon that has been uninstalled. + */ + clearOnUninstall(addonId) { + const tasks = []; + function addShutdownBlocker(name, promise) { + lazy.AsyncShutdown.profileChangeTeardown.addBlocker(name, promise); + tasks.push({ name, promise }); + } + function notifyUninstallTaskObservers() { + Management.emit("cleanupAfterUninstall", addonId, tasks); + } + // Cleanup anything that is used by non-extension addon types // since only extensions have uuid's. - lazy.ExtensionPermissions.removeAll(addon.id); + addShutdownBlocker( + `Clear ExtensionPermissions for ${addonId}`, + lazy.ExtensionPermissions.removeAll(addonId) + ); - lazy.QuarantinedDomains.clearUserPref(addon.id); + lazy.QuarantinedDomains.clearUserPref(addonId); - let uuid = UUIDMap.get(addon.id, false); + let uuid = UUIDMap.get(addonId, false); if (!uuid) { + notifyUninstallTaskObservers(); return; } @@ -527,8 +556,8 @@ var ExtensionAddonObserver = { ); // Clear all cached resources (e.g. CSS and images); - lazy.AsyncShutdown.profileChangeTeardown.addBlocker( - `Clear cache for ${addon.id}`, + addShutdownBlocker( + `Clear cache for ${addonId}`, clearCacheForExtensionPrincipal(principal, /* clearAll */ true) ); @@ -549,38 +578,38 @@ var ExtensionAddonObserver = { // down because is being uninstalled) and then cleared from // the persisted serviceworker registration on the next // startup. - lazy.AsyncShutdown.profileChangeTeardown.addBlocker( - `Clear ServiceWorkers for ${addon.id}`, + addShutdownBlocker( + `Clear ServiceWorkers for ${addonId}`, lazy.ServiceWorkerCleanUp.removeFromPrincipal(principal) ); // Clear the persisted dynamic content scripts created with the scripting // API (if any). - lazy.AsyncShutdown.profileChangeTeardown.addBlocker( - `Clear scripting store for ${addon.id}`, - lazy.ExtensionScriptingStore.clearOnUninstall(addon.id) + addShutdownBlocker( + `Clear scripting store for ${addonId}`, + lazy.ExtensionScriptingStore.clearOnUninstall(addonId) ); // Clear the DNR API's rules data persisted on disk (if any). - lazy.AsyncShutdown.profileChangeTeardown.addBlocker( - `Clear declarativeNetRequest store for ${addon.id}`, + addShutdownBlocker( + `Clear declarativeNetRequest store for ${addonId}`, lazy.ExtensionDNRStore.clearOnUninstall(uuid) ); if (!Services.prefs.getBoolPref(LEAVE_STORAGE_PREF, false)) { // Clear browser.storage.local backends. - lazy.AsyncShutdown.profileChangeTeardown.addBlocker( - `Clear Extension Storage ${addon.id} (File Backend)`, - lazy.ExtensionStorage.clear(addon.id, { shouldNotifyListeners: false }) + addShutdownBlocker( + `Clear Extension Storage ${addonId} (File Backend)`, + lazy.ExtensionStorage.clear(addonId, { shouldNotifyListeners: false }) ); // Clear browser.storage.sync rust-based backend. // (storage.sync clearOnUninstall will resolve and log an error on the // browser console in case of unexpected failures). if (!lazy.storageSyncOldKintoBackend) { - lazy.AsyncShutdown.profileChangeTeardown.addBlocker( - `Clear Extension StorageSync ${addon.id}`, - lazy.extensionStorageSync.clearOnUninstall(addon.id) + addShutdownBlocker( + `Clear Extension StorageSync ${addonId}`, + lazy.extensionStorageSync.clearOnUninstall(addonId) ); } @@ -595,7 +624,7 @@ var ExtensionAddonObserver = { }); Services.qms.clearStoragesForPrincipal(storagePrincipal); - lazy.ExtensionStorageIDB.clearMigratedExtensionPref(addon.id); + lazy.ExtensionStorageIDB.clearMigratedExtensionPref(addonId); // If LSNG is not enabled, we need to clear localStorage explicitly using // the old API. @@ -632,8 +661,10 @@ var ExtensionAddonObserver = { if (!Services.prefs.getBoolPref(LEAVE_UUID_PREF, false)) { // Clear the entry in the UUID map - UUIDMap.remove(addon.id); + UUIDMap.remove(addonId); } + + notifyUninstallTaskObservers(); }, onPropertyChanged(addon, properties) { @@ -1172,8 +1203,10 @@ export class ExtensionData { * includes the contents of the "permissions" property as well as other * capabilities that are derived from manifest fields that users should * be informed of (e.g., origins where content scripts are injected). + * + * For MV3 extensions with origin controls, this does not include origins. */ - get manifestPermissions() { + getRequiredPermissions() { if (this.type !== "extension") { return null; } @@ -1217,6 +1250,20 @@ export class ExtensionData { } /** + * Returns additional permissions that extensions is requesting based on its + * manifest. For now, this is host_permissions (and content scripts) in mv3. + */ + getRequestedPermissions() { + if (this.type !== "extension") { + return null; + } + if (this.originControls && lazy.installIncludesOrigins) { + return { permissions: [], origins: this.getManifestOrigins() }; + } + return { permissions: [], origins: [] }; + } + + /** * Returns optional permissions from the manifest, including host permissions * if originControls is true. */ @@ -3705,8 +3752,8 @@ export class Extension extends ExtensionData { if ( this.originControls && - this.manifest.granted_host_permissions && - this.startupReason === "ADDON_INSTALL" + this.startupReason === "ADDON_INSTALL" && + (this.manifest.granted_host_permissions || lazy.installIncludesOrigins) ) { let origins = this.getManifestOrigins(); lazy.ExtensionPermissions.add(this.id, { permissions: [], origins }); |