[tbb-commits] [Git][tpo/applications/fenix][tor-browser-82.0.0b4-10.0-1] Bug 40062: HTTPS Everywhere is not shown as installed

Matthew Finkel gitlab at torproject.org
Sat Oct 10 14:15:49 UTC 2020



Matthew Finkel pushed to branch tor-browser-82.0.0b4-10.0-1 at The Tor Project / Applications / fenix


Commits:
1e797f95 by Alex Catarineu at 2020-10-10T14:15:25+00:00
Bug 40062: HTTPS Everywhere is not shown as installed

Also 40070: Consider storing the list of recommended addons

This implements our own AddonsProvider, which loads the list of
available addons from assets instead of fetching it from an
endpoint. In this list, we replace https-everywhere by
our https-everywhere-eff, so that the EFF one is shown as installed
in the addons list and the AMO one is not displayed.

Also, we hide the uninstall button for builtin addons.

- - - - -


4 changed files:

- + app/src/main/assets/allowed_addons.json
- app/src/main/java/org/mozilla/fenix/addons/InstalledAddonDetailsFragment.kt
- app/src/main/java/org/mozilla/fenix/components/Components.kt
- + app/src/main/java/org/mozilla/fenix/components/TorAddonCollectionProvider.kt


Changes:

=====================================
app/src/main/assets/allowed_addons.json
=====================================
The diff for this file was not included because it is too large.

=====================================
app/src/main/java/org/mozilla/fenix/addons/InstalledAddonDetailsFragment.kt
=====================================
@@ -21,6 +21,7 @@ import kotlinx.coroutines.launch
 import mozilla.components.feature.addons.Addon
 import mozilla.components.feature.addons.AddonManagerException
 import mozilla.components.feature.addons.ui.translatedName
+import mozilla.components.support.webextensions.WebExtensionSupport.installedExtensions
 import org.mozilla.fenix.HomeActivity
 import org.mozilla.fenix.R
 import org.mozilla.fenix.ext.components
@@ -256,6 +257,8 @@ class InstalledAddonDetailsFragment : Fragment() {
         }
     }
     private fun bindRemoveButton(view: View) {
+        val isBuiltin = installedExtensions[addon.id]?.isBuiltIn() ?: false
+        view.remove_add_on.isVisible = !isBuiltin
         view.remove_add_on.setOnClickListener {
             setAllInteractiveViewsClickable(view, false)
             requireContext().components.addonManager.uninstallAddon(


=====================================
app/src/main/java/org/mozilla/fenix/components/Components.kt
=====================================
@@ -9,7 +9,6 @@ import android.content.Context
 import android.content.Intent
 import androidx.core.net.toUri
 import mozilla.components.feature.addons.AddonManager
-import mozilla.components.feature.addons.amo.AddonCollectionProvider
 import mozilla.components.feature.addons.migration.DefaultSupportedAddonsChecker
 import mozilla.components.feature.addons.migration.SupportedAddonsChecker
 import mozilla.components.feature.addons.update.AddonUpdater
@@ -71,18 +70,7 @@ class Components(private val context: Context) {
         )
     }
 
-    val addonCollectionProvider by lazy {
-        if (!BuildConfig.AMO_COLLECTION.isNullOrEmpty()) {
-            AddonCollectionProvider(
-                context,
-                core.client,
-                collectionName = BuildConfig.AMO_COLLECTION,
-                maxCacheAgeInMinutes = DAY_IN_MINUTES
-            )
-        } else {
-            AddonCollectionProvider(context, core.client, maxCacheAgeInMinutes = DAY_IN_MINUTES)
-        }
-    }
+    val addonCollectionProvider by lazy { TorAddonCollectionProvider(context, core.client) }
 
     val appStartupTelemetry by lazy { AppStartupTelemetry(analytics.metrics) }
 


=====================================
app/src/main/java/org/mozilla/fenix/components/TorAddonCollectionProvider.kt
=====================================
@@ -0,0 +1,60 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Copyright (c) 2020, The Tor Project, Inc.
+
+package org.mozilla.fenix.components
+
+import android.content.Context
+import android.graphics.Bitmap
+import kotlinx.coroutines.withContext
+import mozilla.components.concept.fetch.Client
+import mozilla.components.feature.addons.Addon
+import kotlinx.coroutines.Dispatchers
+import mozilla.components.feature.addons.amo.AddonCollectionProvider
+import java.io.IOException
+
+internal const val COLLECTION_NAME = "tor_browser_collection"
+internal const val ALLOWED_ADDONS_PATH = "allowed_addons.json"
+internal const val MAX_CACHE_AGE = 1000L * 365L * 24L * 60L // 1000 years
+
+class TorAddonCollectionProvider(
+    private val context: Context,
+    client: Client
+) : AddonCollectionProvider(
+    context, client, serverURL = "",
+    collectionName = COLLECTION_NAME,
+    maxCacheAgeInMinutes = MAX_CACHE_AGE
+) {
+    private var isCacheLoaded = false
+
+    @Throws(IOException::class)
+    override suspend fun getAvailableAddons(
+        allowCache: Boolean,
+        readTimeoutInSeconds: Long?
+    ): List<Addon> {
+        ensureCache()
+        return super.getAvailableAddons(true, readTimeoutInSeconds)
+    }
+
+    @Throws(IOException::class)
+    override suspend fun getAddonIconBitmap(addon: Addon): Bitmap? {
+        ensureCache()
+        return super.getAddonIconBitmap(addon)
+    }
+
+    @Throws(IOException::class)
+    private suspend fun ensureCache() {
+        if (isCacheLoaded) {
+            return
+        }
+        return withContext(Dispatchers.IO) {
+            val data = context.assets.open(ALLOWED_ADDONS_PATH).bufferedReader().use {
+                it.readText()
+            }
+            writeToDiskCache(data)
+            isCacheLoaded = true
+        }
+    }
+}



View it on GitLab: https://gitlab.torproject.org/tpo/applications/fenix/-/commit/1e797f9532beeac8882d2b3cb7abd3e4ba3dc7d1

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/fenix/-/commit/1e797f9532beeac8882d2b3cb7abd3e4ba3dc7d1
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/tbb-commits/attachments/20201010/f92bd59d/attachment-0001.htm>


More information about the tbb-commits mailing list