[tbb-commits] [tor-browser/tor-browser-78.2.0esr-10.0-1] Bug 40091: Load HTTPS Everywhere as a builtin addon in desktop

gk at torproject.org gk at torproject.org
Wed Sep 9 09:31:08 UTC 2020


commit 0062275ca3ac484d8005fa057a5a02eb76b42517
Author: Alex Catarineu <acat at torproject.org>
Date:   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.
---
 browser/components/BrowserGlue.jsm                 | 36 ++++++++++++++++++++++
 .../mozapps/extensions/internal/XPIProvider.jsm    |  8 +++++
 2 files changed, 44 insertions(+)

diff --git a/browser/components/BrowserGlue.jsm b/browser/components/BrowserGlue.jsm
index ec38d0ca8b33..901d18a6b414 100644
--- a/browser/components/BrowserGlue.jsm
+++ b/browser/components/BrowserGlue.jsm
@@ -56,6 +56,13 @@ XPCOMUtils.defineLazyServiceGetter(
   "nsIPushService"
 );
 
+XPCOMUtils.defineLazyServiceGetters(this, {
+  resProto: [
+    "@mozilla.org/network/protocol;1?name=resource",
+    "nsISubstitutingProtocolHandler",
+  ],
+});
+
 const PREF_PDFJS_ISDEFAULT_CACHE_STATE = "pdfjs.enabledCache.state";
 
 /**
@@ -675,6 +682,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
     "resource://gre/modules/ContextualIdentityService.jsm",
   Corroborate: "resource://gre/modules/Corroborate.jsm",
   Discovery: "resource:///modules/Discovery.jsm",
+  ExtensionData: "resource://gre/modules/Extension.jsm",
   ExtensionsUI: "resource:///modules/ExtensionsUI.jsm",
   FirefoxMonitor: "resource:///modules/FirefoxMonitor.jsm",
   FxAccounts: "resource://gre/modules/FxAccounts.jsm",
@@ -1330,6 +1338,34 @@ BrowserGlue.prototype = {
       "resource:///modules/themes/dark/"
     );
 
+    // Install https-everywhere builtin addon if needed.
+    (async () => {
+      const HTTPS_EVERYWHERE_ID = "https-everywhere-eff at eff.org";
+      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/mozapps/extensions/internal/XPIProvider.jsm b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
index 794c206fb453..d199ac48ecae 100644
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -1491,6 +1491,14 @@ var XPIStates = {
           continue;
         }
 
+        // Uninstall non-builtin https-everywhere-eff extension.
+        if (id === "https-everywhere-eff at eff.org" && !loc.isBuiltin) {
+          logger.debug("Uninstalling the HTTPS Everywhere extension.");
+          loc.installer.uninstallAddon(id);
+          changed = true;
+          continue;
+        }
+
         let xpiState = loc.get(id);
         if (!xpiState) {
           // If the location is not supported for sideloading, skip new





More information about the tbb-commits mailing list