[tor-commits] [Git][tpo/applications/tor-browser][tor-browser-115.7.0esr-13.5-1] 2 commits: fixup! Bug 40597: Implement TorSettings module
Pier Angelo Vendrame (@pierov)
git at gitlab.torproject.org
Thu Jan 25 17:05:40 UTC 2024
Pier Angelo Vendrame pushed to branch tor-browser-115.7.0esr-13.5-1 at The Tor Project / Applications / Tor Browser
Commits:
f49834e2 by Dan Ballard at 2024-01-25T17:05:18+00:00
fixup! Bug 40597: Implement TorSettings module
Bug 42252: Fix typo in documents
- - - - -
db59cb25 by Dan Ballard at 2024-01-25T17:05:18+00:00
fixup! Bug 42247: Android helpers for the TorProvider
Bug 42252: Add support for TorController in firefox-android
- - - - -
4 changed files:
- mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java
- mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorSettings.java
- mobile/android/geckoview/src/main/java/org/mozilla/geckoview/androidlegacysettings/TorLegacyAndroidSettings.java
- toolkit/modules/TorSettings.sys.mjs
Changes:
=====================================
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java
=====================================
@@ -82,6 +82,10 @@ public class TorIntegrationAndroid implements BundleEventListener {
private final HashMap<Integer, MeekTransport> mMeeks = new HashMap<>();
private int mMeekCounter;
+ // mSettings is a java side copy of the authoritative settings in the JS code.
+ // it's useful to maintain as the ui may be fetching these options often and
+ // we don't watch each fetch to be a passthrough to JS with JSON serialization and
+ // deserialization each time
private TorSettings mSettings = null;
/* package */ TorIntegrationAndroid(Context context) {
@@ -557,11 +561,38 @@ public class TorIntegrationAndroid implements BundleEventListener {
void onSettingsRequested();
}
- public @NonNull GeckoResult<GeckoBundle> getSettings() {
- return EventDispatcher.getInstance().queryBundle(EVENT_SETTINGS_GET);
+ private @NonNull void reloadSettings() {
+ EventDispatcher.getInstance().queryBundle(EVENT_SETTINGS_GET).then( new GeckoResult.OnValueListener<GeckoBundle, Void>() {
+ public GeckoResult<Void> onValue(final GeckoBundle bundle) {
+ mSettings = new TorSettings(bundle);
+ return new GeckoResult<Void>();
+ }
+ });
+ }
+
+ public TorSettings getSettings() {
+ return mSettings;
+ }
+
+ public void setSettings(final TorSettings settings, boolean save, boolean apply) {
+ mSettings = settings;
+
+ emitSetSettings(settings, save, apply).then(
+ new GeckoResult.OnValueListener<Void, Void>() {
+ public GeckoResult<Void> onValue(Void v) {
+ return new GeckoResult<Void>();
+ }
+ },
+ new GeckoResult.OnExceptionListener<Void>() {
+ public GeckoResult<Void> onException(final Throwable e) {
+ Log.e(TAG, "Failed to set settings", e);
+ reloadSettings();
+ return new GeckoResult<Void>();
+ }
+ });
}
- public @NonNull GeckoResult<Void> setSettings(final TorSettings settings, boolean save, boolean apply) {
+ private @NonNull GeckoResult<Void> emitSetSettings(final TorSettings settings, boolean save, boolean apply) {
GeckoBundle bundle = new GeckoBundle(3);
bundle.putBoolean("save", save);
bundle.putBoolean("apply", apply);
=====================================
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorSettings.java
=====================================
@@ -2,24 +2,8 @@ package org.mozilla.geckoview;
import android.util.Log;
-import org.json.JSONArray;
-import org.json.JSONObject;
import org.mozilla.gecko.util.GeckoBundle;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
-import java.io.SequenceInputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Locale;
-import java.util.stream.Collectors;
-
public class TorSettings {
public enum BridgeSource {
@@ -76,6 +60,35 @@ public class TorSettings {
}
}
+ public enum BridgeBuiltinType {
+ /* TorSettings.sys.mjs ~ln43: string: obfs4|meek-azure|snowflake|etc */
+ Invalid("invalid"),
+ Obfs4("obfs4"),
+ MeekAzure("meek-azure"),
+ Snowflake("snowflake");
+
+
+ private String type;
+
+ BridgeBuiltinType(String type) {
+ this.type = type;
+ }
+
+ public String toString() {
+ return type;
+ }
+
+ public static BridgeBuiltinType fromString(String s) {
+ switch (s) {
+ case "obfs4": return Obfs4;
+ case "meek-azure": return MeekAzure;
+ case "snowflake": return Snowflake;
+ }
+ return Invalid;
+ }
+
+ }
+
private boolean loaded = false;
public boolean enabled = true;
@@ -85,7 +98,7 @@ public class TorSettings {
// bridges section
public boolean bridgesEnabled = false;
public BridgeSource bridgesSource = BridgeSource.Invalid;
- public String bridgesBuiltinType = "";
+ public BridgeBuiltinType bridgesBuiltinType = BridgeBuiltinType.Invalid;
public String[] bridgeBridgeStrings;
// proxy section
@@ -112,7 +125,7 @@ public class TorSettings {
bridgesEnabled = bridges.getBoolean("enabled");
bridgesSource = BridgeSource.fromInt(bridges.getInt("source"));
- bridgesBuiltinType = bridges.getString("builtin_type");
+ bridgesBuiltinType = BridgeBuiltinType.fromString(bridges.getString("builtin_type"));
bridgeBridgeStrings = bridges.getStringArray("bridge_strings");
quickstart = qs.getBoolean("enabled");
@@ -143,7 +156,7 @@ public class TorSettings {
bridges.putBoolean("enabled", bridgesEnabled);
bridges.putInt("source", bridgesSource.toInt());
- bridges.putString("builtin_type", bridgesBuiltinType);
+ bridges.putString("builtin_type", bridgesBuiltinType.toString());
bridges.putStringArray("bridge_strings", bridgeBridgeStrings);
qs.putBoolean("enabled", quickstart);
=====================================
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/androidlegacysettings/TorLegacyAndroidSettings.java
=====================================
@@ -1,11 +1,5 @@
package org.mozilla.geckoview.androidlegacysettings;
-import java.io.IOException;
-
-import android.content.SharedPreferences;
-
-import org.mozilla.gecko.GeckoAppShell;
-
import org.mozilla.geckoview.TorSettings;
public class TorLegacyAndroidSettings {
@@ -54,10 +48,10 @@ public class TorLegacyAndroidSettings {
switch (userDefinedBridgeList) {
case "obfs4":
case "snowflake":
- settings.bridgesBuiltinType = userDefinedBridgeList;
+ settings.bridgesBuiltinType = TorSettings.BridgeBuiltinType.fromString(userDefinedBridgeList);
break;
case "meek":
- settings.bridgesBuiltinType = "meek-azure";
+ settings.bridgesBuiltinType = TorSettings.BridgeBuiltinType.MeekAzure;
break;
default:
settings.bridgesSource = TorSettings.BridgeSource.Invalid;
=====================================
toolkit/modules/TorSettings.sys.mjs
=====================================
@@ -40,7 +40,7 @@ const TorSettingsPrefs = Object.freeze({
enabled: "torbrowser.settings.bridges.enabled",
/* int: See TorBridgeSource */
source: "torbrowser.settings.bridges.source",
- /* string: obfs4|meek_azure|snowflake|etc */
+ /* string: obfs4|meek-azure|snowflake|etc */
builtin_type: "torbrowser.settings.bridges.builtin_type",
/* preference branch: each child branch should be a bridge string */
bridge_strings: "torbrowser.settings.bridges.bridge_strings",
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/308d6a6487eecfa9927fe52cdb3c0372588bb015...db59cb25cdd960b9b6200d9a6294445df12144f5
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/308d6a6487eecfa9927fe52cdb3c0372588bb015...db59cb25cdd960b9b6200d9a6294445df12144f5
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/tor-commits/attachments/20240125/f77df66b/attachment-0001.htm>
More information about the tor-commits
mailing list