ma1 pushed to branch tor-browser-128.3.0esr-14.0-1 at The Tor Project / Applications / Tor Browser
Commits: d1579ad1 by hackademix at 2024-10-08T14:25:29+02:00 fixup! [android] Modify add-on support
Bug 43132: Enable scriptless installation on Android.
- - - - -
4 changed files:
- mobile/shared/modules/geckoview/GeckoViewWebExtension.sys.mjs - toolkit/mozapps/extensions/AddonManager.sys.mjs - toolkit/mozapps/extensions/components.conf - toolkit/mozapps/extensions/internal/XPIInstall.sys.mjs
Changes:
===================================== mobile/shared/modules/geckoview/GeckoViewWebExtension.sys.mjs ===================================== @@ -354,7 +354,9 @@ async function exportExtension(aAddon, aSourceURI) { disabledFlags.push("appVersionDisabled"); } const baseURL = policy ? policy.getURL() : ""; - const privateBrowsingAllowed = policy ? policy.privateBrowsingAllowed : false; + const privateBrowsingAllowed = policy + ? policy.privateBrowsingAllowed + : lazy.PrivateBrowsingUtils.permanentPrivateBrowsing;
let updateDate; try { @@ -509,6 +511,9 @@ class ExtensionInstallListener {
async onInstallEnded(aInstall, aAddon) { debug`onInstallEnded addonId=${aAddon.id}`; + if (lazy.PrivateBrowsingUtils.permanentPrivateBrowsing) { + await GeckoViewWebExtension.setPrivateBrowsingAllowed(aAddon.id, true); + } const extension = await exportExtension(aAddon, aInstall.sourceURI); this.resolve({ extension }); }
===================================== toolkit/mozapps/extensions/AddonManager.sys.mjs ===================================== @@ -83,7 +83,10 @@ const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { AbuseReporter: "resource://gre/modules/AbuseReporter.sys.mjs", AddonRepository: "resource://gre/modules/addons/AddonRepository.sys.mjs", + GeckoViewWebExtension: "resource://gre/modules/GeckoViewWebExtension.sys.mjs", + EventDispatcher: "resource://gre/modules/Messaging.sys.mjs", Extension: "resource://gre/modules/Extension.sys.mjs", + PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", RemoteSettings: "resource://services-settings/remote-settings.sys.mjs", TelemetryTimestamps: "resource://gre/modules/TelemetryTimestamps.sys.mjs", isGatedPermissionType: @@ -2346,6 +2349,24 @@ var AddonManagerInternal = { return promiseInstall; },
+ async installGeckoViewWebExtension(extensionUri) { + const installId = Services.uuid.generateUUID().toString(); + let { extension } = await lazy.GeckoViewWebExtension.installWebExtension( + installId, + extensionUri + ); + if (lazy.PrivateBrowsingUtils.permanentPrivateBrowsing) { + extension = await lazy.GeckoViewWebExtension.setPrivateBrowsingAllowed( + extension.webExtensionId, + true + ); + } + await lazy.EventDispatcher.instance.sendRequest({ + type: "GeckoView:WebExtension:OnInstalled", + extension, + }); + }, + /** * Starts installation of an AddonInstall notifying the registered * web install listener of a blocked or started install. @@ -2518,6 +2539,10 @@ var AddonManagerInternal = { );
if (installAllowed) { + if (AppConstants.platform == "android") { + aInstall.cancel(); + return this.installGeckoViewWebExtension(aInstall.sourceURI); + } startInstall("AMO"); } else if (installPerm === Ci.nsIPermissionManager.DENY_ACTION) { // Block without prompt
===================================== toolkit/mozapps/extensions/components.conf ===================================== @@ -32,14 +32,13 @@ Classes = [ 'esModule': 'resource://gre/modules/amWebAPI.sys.mjs', 'constructor': 'WebAPI', }, + # tor-browser#43132: re-enable XPI handler on Android to allow scriptless extensions installation. + # This reverts https://bugzilla.mozilla.org/show_bug.cgi?id=1610571, which made sense for generic + # GeckoView extensionless embedders and for Firefox, relying on navigator.mozAddonManager. + { + 'cid': '{7beb3ba8-6ec3-41b4-b67c-da89b8518922}', + 'contract_ids': ['@mozilla.org/uriloader/content-handler;1?type=application/x-xpinstall'], + 'esModule': 'resource://gre/modules/amContentHandler.sys.mjs', + 'constructor': 'amContentHandler', + }, ] - -if buildconfig.substs['MOZ_WIDGET_TOOLKIT'] != 'android': - Classes += [ - { - 'cid': '{7beb3ba8-6ec3-41b4-b67c-da89b8518922}', - 'contract_ids': ['@mozilla.org/uriloader/content-handler;1?type=application/x-xpinstall'], - 'esModule': 'resource://gre/modules/amContentHandler.sys.mjs', - 'constructor': 'amContentHandler', - }, - ]
===================================== toolkit/mozapps/extensions/internal/XPIInstall.sys.mjs ===================================== @@ -4475,6 +4475,11 @@ export var XPIInstall = { return false; }
+ // tor-browser#43132: short-circuit permission check on Android scriptless install from AMO + if (AppConstants.platform == "android" && uri.prePath == "https://addons.mozilla.org") { + return true; + } + let requireWhitelist = Services.prefs.getBoolPref( PREF_XPI_WHITELIST_REQUIRED, true
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/d1579ad1...