Pier Angelo Vendrame pushed to branch tor-browser-115.7.0esr-13.5-1 at The Tor Project / Applications / Tor Browser

Commits:

4 changed files:

Changes:

  • mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java
    ... ... @@ -82,6 +82,10 @@ public class TorIntegrationAndroid implements BundleEventListener {
    82 82
         private final HashMap<Integer, MeekTransport> mMeeks = new HashMap<>();
    
    83 83
         private int mMeekCounter;
    
    84 84
     
    
    85
    +    // mSettings is a java side copy of the authoritative settings in the JS code.
    
    86
    +    // it's useful to maintain as the ui may be fetching these options often and
    
    87
    +    // we don't watch each fetch to be a passthrough to JS with JSON serialization and
    
    88
    +    // deserialization each time
    
    85 89
         private TorSettings mSettings = null;
    
    86 90
     
    
    87 91
         /* package */ TorIntegrationAndroid(Context context) {
    
    ... ... @@ -557,11 +561,38 @@ public class TorIntegrationAndroid implements BundleEventListener {
    557 561
             void onSettingsRequested();
    
    558 562
         }
    
    559 563
     
    
    560
    -    public @NonNull GeckoResult<GeckoBundle> getSettings() {
    
    561
    -        return EventDispatcher.getInstance().queryBundle(EVENT_SETTINGS_GET);
    
    564
    +    private @NonNull void reloadSettings() {
    
    565
    +        EventDispatcher.getInstance().queryBundle(EVENT_SETTINGS_GET).then( new GeckoResult.OnValueListener<GeckoBundle, Void>() {
    
    566
    +            public GeckoResult<Void> onValue(final GeckoBundle bundle) {
    
    567
    +                mSettings = new TorSettings(bundle);
    
    568
    +                return new GeckoResult<Void>();
    
    569
    +            }
    
    570
    +        });
    
    571
    +    }
    
    572
    +
    
    573
    +    public TorSettings getSettings() {
    
    574
    +        return mSettings;
    
    575
    +    }
    
    576
    +
    
    577
    +    public void setSettings(final TorSettings settings, boolean save, boolean apply) {
    
    578
    +        mSettings = settings;
    
    579
    +
    
    580
    +        emitSetSettings(settings, save, apply).then(
    
    581
    +            new GeckoResult.OnValueListener<Void, Void>() {
    
    582
    +                public GeckoResult<Void> onValue(Void v) {
    
    583
    +                    return new GeckoResult<Void>();
    
    584
    +                }
    
    585
    +            },
    
    586
    +            new GeckoResult.OnExceptionListener<Void>() {
    
    587
    +                public GeckoResult<Void> onException(final Throwable e) {
    
    588
    +                    Log.e(TAG, "Failed to set settings", e);
    
    589
    +                    reloadSettings();
    
    590
    +                    return new GeckoResult<Void>();
    
    591
    +                }
    
    592
    +            });
    
    562 593
         }
    
    563 594
     
    
    564
    -    public @NonNull GeckoResult<Void> setSettings(final TorSettings settings, boolean save, boolean apply) {
    
    595
    +    private @NonNull GeckoResult<Void> emitSetSettings(final TorSettings settings, boolean save, boolean apply) {
    
    565 596
             GeckoBundle bundle = new GeckoBundle(3);
    
    566 597
             bundle.putBoolean("save", save);
    
    567 598
             bundle.putBoolean("apply", apply);
    

  • mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorSettings.java
    ... ... @@ -2,24 +2,8 @@ package org.mozilla.geckoview;
    2 2
     
    
    3 3
     import android.util.Log;
    
    4 4
     
    
    5
    -import org.json.JSONArray;
    
    6
    -import org.json.JSONObject;
    
    7 5
     import org.mozilla.gecko.util.GeckoBundle;
    
    8 6
     
    
    9
    -import java.io.ByteArrayInputStream;
    
    10
    -import java.io.File;
    
    11
    -import java.io.FileOutputStream;
    
    12
    -import java.io.IOException;
    
    13
    -import java.io.InputStream;
    
    14
    -import java.io.PrintStream;
    
    15
    -import java.io.SequenceInputStream;
    
    16
    -import java.io.UnsupportedEncodingException;
    
    17
    -import java.util.ArrayList;
    
    18
    -import java.util.Arrays;
    
    19
    -import java.util.List;
    
    20
    -import java.util.Locale;
    
    21
    -import java.util.stream.Collectors;
    
    22
    -
    
    23 7
     public class TorSettings {
    
    24 8
     
    
    25 9
         public enum BridgeSource {
    
    ... ... @@ -76,6 +60,35 @@ public class TorSettings {
    76 60
             }
    
    77 61
         }
    
    78 62
     
    
    63
    +    public enum BridgeBuiltinType {
    
    64
    +        /* TorSettings.sys.mjs ~ln43:  string: obfs4|meek-azure|snowflake|etc */
    
    65
    +        Invalid("invalid"),
    
    66
    +        Obfs4("obfs4"),
    
    67
    +        MeekAzure("meek-azure"),
    
    68
    +        Snowflake("snowflake");
    
    69
    +
    
    70
    +
    
    71
    +        private String type;
    
    72
    +
    
    73
    +        BridgeBuiltinType(String type) {
    
    74
    +            this.type = type;
    
    75
    +        }
    
    76
    +
    
    77
    +        public String toString() {
    
    78
    +            return type;
    
    79
    +        }
    
    80
    +
    
    81
    +        public static BridgeBuiltinType fromString(String s) {
    
    82
    +            switch (s) {
    
    83
    +                case "obfs4": return Obfs4;
    
    84
    +                case "meek-azure": return MeekAzure;
    
    85
    +                case "snowflake": return Snowflake;
    
    86
    +            }
    
    87
    +            return Invalid;
    
    88
    +        }
    
    89
    +
    
    90
    +    }
    
    91
    +
    
    79 92
         private boolean loaded = false;
    
    80 93
     
    
    81 94
         public boolean enabled = true;
    
    ... ... @@ -85,7 +98,7 @@ public class TorSettings {
    85 98
         // bridges section
    
    86 99
         public boolean bridgesEnabled = false;
    
    87 100
         public BridgeSource bridgesSource = BridgeSource.Invalid;
    
    88
    -    public String bridgesBuiltinType = "";
    
    101
    +    public BridgeBuiltinType bridgesBuiltinType = BridgeBuiltinType.Invalid;
    
    89 102
         public String[] bridgeBridgeStrings;
    
    90 103
     
    
    91 104
         // proxy section
    
    ... ... @@ -112,7 +125,7 @@ public class TorSettings {
    112 125
     
    
    113 126
                 bridgesEnabled = bridges.getBoolean("enabled");
    
    114 127
                 bridgesSource = BridgeSource.fromInt(bridges.getInt("source"));
    
    115
    -            bridgesBuiltinType = bridges.getString("builtin_type");
    
    128
    +            bridgesBuiltinType = BridgeBuiltinType.fromString(bridges.getString("builtin_type"));
    
    116 129
                 bridgeBridgeStrings = bridges.getStringArray("bridge_strings");
    
    117 130
     
    
    118 131
                 quickstart = qs.getBoolean("enabled");
    
    ... ... @@ -143,7 +156,7 @@ public class TorSettings {
    143 156
     
    
    144 157
             bridges.putBoolean("enabled", bridgesEnabled);
    
    145 158
             bridges.putInt("source", bridgesSource.toInt());
    
    146
    -        bridges.putString("builtin_type", bridgesBuiltinType);
    
    159
    +        bridges.putString("builtin_type", bridgesBuiltinType.toString());
    
    147 160
             bridges.putStringArray("bridge_strings", bridgeBridgeStrings);
    
    148 161
     
    
    149 162
             qs.putBoolean("enabled", quickstart);
    

  • mobile/android/geckoview/src/main/java/org/mozilla/geckoview/androidlegacysettings/TorLegacyAndroidSettings.java
    1 1
     package org.mozilla.geckoview.androidlegacysettings;
    
    2 2
     
    
    3
    -import java.io.IOException;
    
    4
    -
    
    5
    -import android.content.SharedPreferences;
    
    6
    -
    
    7
    -import org.mozilla.gecko.GeckoAppShell;
    
    8
    -
    
    9 3
     import org.mozilla.geckoview.TorSettings;
    
    10 4
     
    
    11 5
     public class TorLegacyAndroidSettings {
    
    ... ... @@ -54,10 +48,10 @@ public class TorLegacyAndroidSettings {
    54 48
                 switch (userDefinedBridgeList) {
    
    55 49
                     case "obfs4":
    
    56 50
                     case "snowflake":
    
    57
    -                    settings.bridgesBuiltinType = userDefinedBridgeList;
    
    51
    +                    settings.bridgesBuiltinType = TorSettings.BridgeBuiltinType.fromString(userDefinedBridgeList);
    
    58 52
                         break;
    
    59 53
                     case "meek":
    
    60
    -                    settings.bridgesBuiltinType = "meek-azure";
    
    54
    +                    settings.bridgesBuiltinType = TorSettings.BridgeBuiltinType.MeekAzure;
    
    61 55
                         break;
    
    62 56
                     default:
    
    63 57
                         settings.bridgesSource = TorSettings.BridgeSource.Invalid;
    

  • toolkit/modules/TorSettings.sys.mjs
    ... ... @@ -40,7 +40,7 @@ const TorSettingsPrefs = Object.freeze({
    40 40
         enabled: "torbrowser.settings.bridges.enabled",
    
    41 41
         /* int: See TorBridgeSource */
    
    42 42
         source: "torbrowser.settings.bridges.source",
    
    43
    -    /* string: obfs4|meek_azure|snowflake|etc */
    
    43
    +    /* string: obfs4|meek-azure|snowflake|etc */
    
    44 44
         builtin_type: "torbrowser.settings.bridges.builtin_type",
    
    45 45
         /* preference branch: each child branch should be a bridge string */
    
    46 46
         bridge_strings: "torbrowser.settings.bridges.bridge_strings",