Richard Pospesel pushed to branch tor-browser-99.0.0b3-11.5-1 at The Tor Project / Applications / fenix
Commits: 1f564fb6 by hackademix at 2022-08-25T21:38:50+00:00 fixup! Modify Add-on support
- - - - -
4 changed files:
- .gitignore - app/src/main/java/org/mozilla/fenix/components/TorBrowserFeatures.kt - app/src/main/java/org/mozilla/fenix/utils/Settings.kt - app/src/main/res/values/preference_keys.xml
Changes:
===================================== .gitignore ===================================== @@ -103,3 +103,7 @@ test_artifacts/
# Web extensions: manifest.json files are generated manifest.json + +# Other files modified at build time +.experimenter.json +
===================================== app/src/main/java/org/mozilla/fenix/components/TorBrowserFeatures.kt ===================================== @@ -6,15 +6,19 @@
package org.mozilla.fenix.components
+import android.os.StrictMode import android.content.Context import mozilla.components.concept.engine.webextension.WebExtension import mozilla.components.concept.engine.webextension.WebExtensionRuntime import mozilla.components.support.base.log.logger.Logger +import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.settings +import org.mozilla.fenix.tor.TorEvents import java.io.IOException
object TorBrowserFeatures { private val logger = Logger("torbrowser-features") + private const val NOSCRIPT_ID = "{73a6fe31-595d-460b-a920-fcc0f8843232}"
private fun installNoScript( context: Context, @@ -25,11 +29,15 @@ object TorBrowserFeatures { /** * Copy the xpi from assets to cacheDir, we do not care if the file is later deleted. */ - val addonPath = - context.cacheDir.resolve("{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi") + val xpiName = "$NOSCRIPT_ID.xpi" + val addonPath = context.cacheDir.resolve(xpiName) + val policy = StrictMode.getThreadPolicy() try { - context.assets.open("extensions/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi") + context.assets.open("extensions/$xpiName") .use { inStream -> + // we don't want penaltyDeath() on disk write + StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.LAX) + addonPath.outputStream().use { outStream -> inStream.copyTo(outStream) } @@ -37,13 +45,15 @@ object TorBrowserFeatures { } catch (throwable: IOException) { onError(throwable) return + } finally { + StrictMode.setThreadPolicy(policy) }
/** * Install with a file:// URI pointing to the temp location where the addon was copied to. */ runtime.installWebExtension( - id = "{73a6fe31-595d-460b-a920-fcc0f8843232}", + id = NOSCRIPT_ID, url = addonPath.toURI().toString(), onSuccess = { extension -> runtime.setAllowedInPrivateBrowsing( @@ -89,8 +99,7 @@ object TorBrowserFeatures {
/** * Install NoScript as a user WebExtension if we have not already done so. - * AMO signature is checked, and AMO automatic updates will work. The extension should - * behave as if the user had installed it manually. + * AMO signature is checked, but automatic updates still need to be enabled. */ if (!context.settings().noscriptInstalled) { installNoScript( @@ -105,5 +114,40 @@ object TorBrowserFeatures { } ) } + + /** + * If we have not done it yet, enable automatic updates for NoScript and force a + * one-time immediate update check, in order to upgrade old profiles and ensure we've got + * the latest stable AMO version available on first startup. + * We will do it as soon as the Tor is connected, to prevent early addonUpdater activation + * causing automatic update checks failures (components.addonUpdater being a lazy prop). + * The extension, from then on, should behave as if the user had installed it manually. + */ + if (context.settings().noscriptUpdated == 0) { + context.components.torController.registerTorListener(object : TorEvents { + override fun onTorConnected() { + context.components.torController.unregisterTorListener(this) + // Enable automatic updates + context.components.addonUpdater.registerForFutureUpdates(NOSCRIPT_ID) + // Force an immediate update check + context.components.addonUpdater.update(NOSCRIPT_ID) + context.settings().noscriptUpdated = 1 + } + + @SuppressWarnings("EmptyFunctionBlock") + override fun onTorConnecting() { + } + + @SuppressWarnings("EmptyFunctionBlock") + override fun onTorStopped() { + } + + @SuppressWarnings("EmptyFunctionBlock") + override fun onTorStatusUpdate(entry: String?, status: String?) { + } + }) + } } + + }
===================================== app/src/main/java/org/mozilla/fenix/utils/Settings.kt ===================================== @@ -1370,4 +1370,9 @@ class Settings(private val appContext: Context) : PreferencesHolder { appContext.getPreferenceKey(R.string.pref_key_noscript_installed), default = false ) + + var noscriptUpdated by intPreference( + appContext.getPreferenceKey(R.string.pref_key_noscript_updated), + default = 0 + ) }
===================================== app/src/main/res/values/preference_keys.xml ===================================== @@ -291,6 +291,7 @@ <string name="pref_key_pocket_homescreen_recommendations" translatable="false">pref_key_pocket_homescreen_recommendations</string>
<string name="pref_key_noscript_installed" translatable="false">pref_key_noscript_installed</string> + <string name="pref_key_noscript_updated" translatable="false">pref_key_noscript_updated</string>
<!-- Security Level Settings --> <string name="pref_key_tor_security_level_settings" translatable="false">pref_key_tor_security_level_settings</string>
View it on GitLab: https://gitlab.torproject.org/tpo/applications/fenix/-/commit/1f564fb657f872...
tbb-commits@lists.torproject.org