Richard Pospesel pushed to branch tor-browser-99.0.0b3-11.5-1 at The Tor Project / Applications / fenix

Commits:

4 changed files:

Changes:

  • .gitignore
    ... ... @@ -103,3 +103,7 @@ test_artifacts/
    103 103
     
    
    104 104
     # Web extensions: manifest.json files are generated
    
    105 105
     manifest.json
    
    106
    +
    
    107
    +# Other files modified at build time
    
    108
    +.experimenter.json
    
    109
    +

  • app/src/main/java/org/mozilla/fenix/components/TorBrowserFeatures.kt
    ... ... @@ -6,15 +6,19 @@
    6 6
     
    
    7 7
     package org.mozilla.fenix.components
    
    8 8
     
    
    9
    +import android.os.StrictMode
    
    9 10
     import android.content.Context
    
    10 11
     import mozilla.components.concept.engine.webextension.WebExtension
    
    11 12
     import mozilla.components.concept.engine.webextension.WebExtensionRuntime
    
    12 13
     import mozilla.components.support.base.log.logger.Logger
    
    14
    +import org.mozilla.fenix.ext.components
    
    13 15
     import org.mozilla.fenix.ext.settings
    
    16
    +import org.mozilla.fenix.tor.TorEvents
    
    14 17
     import java.io.IOException
    
    15 18
     
    
    16 19
     object TorBrowserFeatures {
    
    17 20
         private val logger = Logger("torbrowser-features")
    
    21
    +    private const val NOSCRIPT_ID = "{73a6fe31-595d-460b-a920-fcc0f8843232}"
    
    18 22
     
    
    19 23
         private fun installNoScript(
    
    20 24
             context: Context,
    
    ... ... @@ -25,11 +29,15 @@ object TorBrowserFeatures {
    25 29
             /**
    
    26 30
              * Copy the xpi from assets to cacheDir, we do not care if the file is later deleted.
    
    27 31
              */
    
    28
    -        val addonPath =
    
    29
    -            context.cacheDir.resolve("{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi")
    
    32
    +        val xpiName = "$NOSCRIPT_ID.xpi"
    
    33
    +        val addonPath = context.cacheDir.resolve(xpiName)
    
    34
    +        val policy = StrictMode.getThreadPolicy()
    
    30 35
             try {
    
    31
    -            context.assets.open("extensions/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi")
    
    36
    +            context.assets.open("extensions/$xpiName")
    
    32 37
                     .use { inStream ->
    
    38
    +                    // we don't want penaltyDeath() on disk write
    
    39
    +                    StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.LAX)
    
    40
    +
    
    33 41
                         addonPath.outputStream().use { outStream ->
    
    34 42
                             inStream.copyTo(outStream)
    
    35 43
                         }
    
    ... ... @@ -37,13 +45,15 @@ object TorBrowserFeatures {
    37 45
             } catch (throwable: IOException) {
    
    38 46
                 onError(throwable)
    
    39 47
                 return
    
    48
    +        } finally {
    
    49
    +            StrictMode.setThreadPolicy(policy)
    
    40 50
             }
    
    41 51
     
    
    42 52
             /**
    
    43 53
              * Install with a file:// URI pointing to the temp location where the addon was copied to.
    
    44 54
              */
    
    45 55
             runtime.installWebExtension(
    
    46
    -            id = "{73a6fe31-595d-460b-a920-fcc0f8843232}",
    
    56
    +            id = NOSCRIPT_ID,
    
    47 57
                 url = addonPath.toURI().toString(),
    
    48 58
                 onSuccess = { extension ->
    
    49 59
                     runtime.setAllowedInPrivateBrowsing(
    
    ... ... @@ -89,8 +99,7 @@ object TorBrowserFeatures {
    89 99
     
    
    90 100
             /**
    
    91 101
              *  Install NoScript as a user WebExtension if we have not already done so.
    
    92
    -         *  AMO signature is checked, and AMO automatic updates will work. The extension should
    
    93
    -         *  behave as if the user had installed it manually.
    
    102
    +         *  AMO signature is checked, but automatic updates still need to be enabled.
    
    94 103
              */
    
    95 104
             if (!context.settings().noscriptInstalled) {
    
    96 105
                 installNoScript(
    
    ... ... @@ -105,5 +114,40 @@ object TorBrowserFeatures {
    105 114
                     }
    
    106 115
                 )
    
    107 116
             }
    
    117
    +
    
    118
    +        /**
    
    119
    +         *  If we have not done it yet, enable automatic updates for NoScript and force a
    
    120
    +         *  one-time immediate update check, in order to upgrade old profiles and ensure we've got
    
    121
    +         *  the latest stable AMO version available on first startup.
    
    122
    +         *  We will do it as soon as the Tor is connected, to prevent early addonUpdater activation
    
    123
    +         *  causing automatic update checks failures (components.addonUpdater being a lazy prop).
    
    124
    +         *  The extension, from then on, should behave as if the user had installed it manually.
    
    125
    +         */
    
    126
    +        if (context.settings().noscriptUpdated == 0) {
    
    127
    +            context.components.torController.registerTorListener(object : TorEvents {
    
    128
    +                override fun onTorConnected() {
    
    129
    +                    context.components.torController.unregisterTorListener(this)
    
    130
    +                    // Enable automatic updates
    
    131
    +                    context.components.addonUpdater.registerForFutureUpdates(NOSCRIPT_ID)
    
    132
    +                    // Force an immediate update check
    
    133
    +                    context.components.addonUpdater.update(NOSCRIPT_ID)
    
    134
    +                    context.settings().noscriptUpdated = 1
    
    135
    +                }
    
    136
    +
    
    137
    +                @SuppressWarnings("EmptyFunctionBlock")
    
    138
    +                override fun onTorConnecting() {
    
    139
    +                }
    
    140
    +
    
    141
    +                @SuppressWarnings("EmptyFunctionBlock")
    
    142
    +                override fun onTorStopped() {
    
    143
    +                }
    
    144
    +
    
    145
    +                @SuppressWarnings("EmptyFunctionBlock")
    
    146
    +                override fun onTorStatusUpdate(entry: String?, status: String?) {
    
    147
    +                }
    
    148
    +            })
    
    149
    +        }
    
    108 150
         }
    
    151
    +
    
    152
    +
    
    109 153
     }

  • app/src/main/java/org/mozilla/fenix/utils/Settings.kt
    ... ... @@ -1370,4 +1370,9 @@ class Settings(private val appContext: Context) : PreferencesHolder {
    1370 1370
             appContext.getPreferenceKey(R.string.pref_key_noscript_installed),
    
    1371 1371
             default = false
    
    1372 1372
         )
    
    1373
    +
    
    1374
    +    var noscriptUpdated by intPreference(
    
    1375
    +        appContext.getPreferenceKey(R.string.pref_key_noscript_updated),
    
    1376
    +        default = 0
    
    1377
    +    )
    
    1373 1378
     }

  • app/src/main/res/values/preference_keys.xml
    ... ... @@ -291,6 +291,7 @@
    291 291
         <string name="pref_key_pocket_homescreen_recommendations" translatable="false">pref_key_pocket_homescreen_recommendations</string>
    
    292 292
     
    
    293 293
         <string name="pref_key_noscript_installed" translatable="false">pref_key_noscript_installed</string>
    
    294
    +    <string name="pref_key_noscript_updated" translatable="false">pref_key_noscript_updated</string>
    
    294 295
     
    
    295 296
         <!-- Security Level Settings -->
    
    296 297
         <string name="pref_key_tor_security_level_settings" translatable="false">pref_key_tor_security_level_settings</string>