Verified Commit d1579ad1 authored by ma1's avatar ma1
Browse files

fixup! [android] Modify add-on support

Bug 43132: Enable scriptless installation on Android.
parent b0b0ccd9
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -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 });
  }
+25 −0
Original line number Diff line number Diff line
@@ -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
+9 −10
Original line number Diff line number Diff line
@@ -32,10 +32,9 @@ Classes = [
        'esModule': 'resource://gre/modules/amWebAPI.sys.mjs',
        'constructor': 'WebAPI',
    },
]

if buildconfig.substs['MOZ_WIDGET_TOOLKIT'] != 'android':
    Classes += [
    # 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'],
+5 −0
Original line number Diff line number Diff line
@@ -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