[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser] 56/68: Bug 40091: Load HTTPS Everywhere as a builtin addon in desktop



This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch tor-browser-91.8.0esr-11.5-1
in repository tor-browser.

commit a9fdc83f68bb96f0ed7aa21667c6a4795fc499f3
Author: Alex Catarineu <acat@xxxxxxxxxxxxxx>
AuthorDate: Fri Sep 4 12:34:35 2020 +0200

    Bug 40091: Load HTTPS Everywhere as a builtin addon in desktop
    
    This loads HTTPS Everywhere as a builtin addon from a hardcoded
    resource:// URI in desktop. It also ensures that the non-builtin
    HTTPS Everywhere addon is always uninstalled on browser startup.
    
    The reason of making this desktop-only is that there are some issues
    when installing a builtin extension from geckoview side, making
    the extension not available on first startup. So, at least for
    now we handle the Fenix case separately. See #40118 for a followup
    for investigating these.
---
 browser/components/BrowserGlue.jsm                 | 37 ++++++++++++++++++++++
 toolkit/components/extensions/Extension.jsm        | 10 ++++--
 .../mozapps/extensions/internal/XPIProvider.jsm    | 13 ++++++++
 3 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/browser/components/BrowserGlue.jsm b/browser/components/BrowserGlue.jsm
index dc956bc796166..7c81eaaccf775 100644
--- a/browser/components/BrowserGlue.jsm
+++ b/browser/components/BrowserGlue.jsm
@@ -45,6 +45,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
   DownloadsViewableInternally:
     "resource:///modules/DownloadsViewableInternally.jsm",
   E10SUtils: "resource://gre/modules/E10SUtils.jsm",
+  ExtensionData: "resource://gre/modules/Extension.jsm",
   ExtensionsUI: "resource:///modules/ExtensionsUI.jsm",
   FeatureGate: "resource://featuregates/FeatureGate.jsm",
   FxAccounts: "resource://gre/modules/FxAccounts.jsm",
@@ -119,6 +120,13 @@ XPCOMUtils.defineLazyServiceGetters(this, {
   PushService: ["@mozilla.org/push/Service;1", "nsIPushService"],
 });
 
+XPCOMUtils.defineLazyServiceGetters(this, {
+  resProto: [
+    "@mozilla.org/network/protocol;1?name=resource",
+    "nsISubstitutingProtocolHandler",
+  ],
+});
+
 const PREF_PDFJS_ISDEFAULT_CACHE_STATE = "pdfjs.enabledCache.state";
 
 /**
@@ -1399,6 +1407,35 @@ BrowserGlue.prototype = {
       "resource://builtin-themes/alpenglow/"
     );
 
+    // Install https-everywhere builtin addon if needed.
+    (async () => {
+      const HTTPS_EVERYWHERE_ID = "https-everywhere-eff@xxxxxxx";
+      const HTTPS_EVERYWHERE_BUILTIN_URL =
+        "resource://torbutton/content/extensions/https-everywhere/";
+      // This does something similar as GeckoViewWebExtension.jsm: it tries
+      // to load the manifest to retrieve the version of the builtin and
+      // compares it to the currently installed one to see whether we need
+      // to install or not. Here we delegate that to
+      // AddonManager.maybeInstallBuiltinAddon.
+      try {
+        const resolvedURI = Services.io.newURI(
+          resProto.resolveURI(Services.io.newURI(HTTPS_EVERYWHERE_BUILTIN_URL))
+        );
+        const extensionData = new ExtensionData(resolvedURI);
+        const manifest = await extensionData.loadManifest();
+
+        await AddonManager.maybeInstallBuiltinAddon(
+          HTTPS_EVERYWHERE_ID,
+          manifest.version,
+          HTTPS_EVERYWHERE_BUILTIN_URL
+        );
+      } catch (e) {
+        const log = Log.repository.getLogger("HttpsEverywhereBuiltinLoader");
+        log.addAppender(new Log.ConsoleAppender(new Log.BasicFormatter()));
+        log.error("Could not install https-everywhere extension", e);
+      }
+    })();
+
     if (AppConstants.MOZ_NORMANDY) {
       Normandy.init();
     }
diff --git a/toolkit/components/extensions/Extension.jsm b/toolkit/components/extensions/Extension.jsm
index 08c5cf8a9190d..783ec7c3391dc 100644
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -267,6 +267,7 @@ const LOGGER_ID_BASE = "addons.webextension.";
 const UUID_MAP_PREF = "extensions.webextensions.uuids";
 const LEAVE_STORAGE_PREF = "extensions.webextensions.keepStorageOnUninstall";
 const LEAVE_UUID_PREF = "extensions.webextensions.keepUuidOnUninstall";
+const PERSISTENT_EXTENSIONS = new Set(["https-everywhere-eff@xxxxxxx"]);
 
 const COMMENT_REGEXP = new RegExp(
   String.raw`
@@ -413,7 +414,8 @@ var ExtensionAddonObserver = {
       );
     }
 
-    if (!Services.prefs.getBoolPref(LEAVE_STORAGE_PREF, false)) {
+    if (!Services.prefs.getBoolPref(LEAVE_STORAGE_PREF, false) &&
+      !PERSISTENT_EXTENSIONS.has(addon.id)) {
       // Clear browser.storage.local backends.
       AsyncShutdown.profileChangeTeardown.addBlocker(
         `Clear Extension Storage ${addon.id} (File Backend)`,
@@ -461,7 +463,8 @@ var ExtensionAddonObserver = {
 
     ExtensionPermissions.removeAll(addon.id);
 
-    if (!Services.prefs.getBoolPref(LEAVE_UUID_PREF, false)) {
+    if (!Services.prefs.getBoolPref(LEAVE_UUID_PREF, false) &&
+      !PERSISTENT_EXTENSIONS.has(addon.id)) {
       // Clear the entry in the UUID map
       UUIDMap.remove(addon.id);
     }
@@ -2696,7 +2699,8 @@ class Extension extends ExtensionData {
           );
         } else if (
           this.startupReason === "ADDON_INSTALL" &&
-          !Services.prefs.getBoolPref(LEAVE_STORAGE_PREF, false)
+          !Services.prefs.getBoolPref(LEAVE_STORAGE_PREF, false) &&
+          !PERSISTENT_EXTENSIONS.has(this.id)
         ) {
           // If the extension has been just installed, set it as migrated,
           // because there will not be any data to migrate.
diff --git a/toolkit/mozapps/extensions/internal/XPIProvider.jsm b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
index 04d57a42348e7..fd1e3f75935da 100644
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -1495,6 +1495,19 @@ var XPIStates = {
           continue;
         }
 
+        // Uninstall HTTPS Everywhere if it is installed in the user profile.
+        if (
+          id === "https-everywhere-eff@xxxxxxx" &&
+          loc.name === KEY_APP_PROFILE
+        ) {
+          logger.debug(
+            "Uninstalling the HTTPS Everywhere extension from user profile."
+          );
+          loc.installer.uninstallAddon(id);
+          changed = true;
+          continue;
+        }
+
         let xpiState = loc.get(id);
         if (!xpiState) {
           // If the location is not supported for sideloading, skip new

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits