[tor-commits] [Git][tpo/applications/tor-browser][tor-browser-128.3.0esr-14.0-1] fixup! [android] Modify add-on support

ma1 (@ma1) git at gitlab.torproject.org
Tue Oct 8 19:49:18 UTC 2024



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/d1579ad16e24c94e6e23baa0e67abae9db4ca183

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/d1579ad16e24c94e6e23baa0e67abae9db4ca183
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tor-commits/attachments/20241008/d8880045/attachment-0001.htm>


More information about the tor-commits mailing list