richard pushed to branch tor-browser-115.7.0esr-13.5-1 at The Tor Project / Applications / Tor Browser
Commits: bb028644 by Pier Angelo Vendrame at 2024-01-26T11:31:15+01:00 fixup! Bug 40597: Implement TorSettings module
Bug 42384: Use TorSettings's initialization promise to handle race conditions
We now have a race condition for which the notification about TorSettings being ready is sent before TorConnect can observe this topic. A while ago, we introduced an initialization promise to TorSettings, therefore we can use it instead of Service.obs and avoid this race condition.
Also, fixed quicksettings ignored in TorSettings.setSettings.
- - - - - a48e4389 by Pier Angelo Vendrame at 2024-01-26T11:35:10+01:00 fixup! Bug 42247: Android helpers for the TorProvider
Update the cached mSettings whenever someone one the GeckoView side changes any TorSettings settings.
- - - - -
4 changed files:
- mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java - toolkit/modules/TorAndroidIntegration.sys.mjs - toolkit/modules/TorConnect.sys.mjs - toolkit/modules/TorSettings.sys.mjs
Changes:
===================================== mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java ===================================== @@ -47,6 +47,8 @@ public class TorIntegrationAndroid implements BundleEventListener { private static final String EVENT_BOOTSTRAP_COMPLETE = "GeckoView:Tor:BootstrapComplete"; private static final String EVENT_BOOTSTRAP_ERROR = "GeckoView:Tor:BootstrapError"; private static final String EVENT_SETTINGS_OPEN = "GeckoView:Tor:OpenSettings"; + private static final String EVENT_SETTINGS_READY = "GeckoView:Tor:SettingsReady"; + private static final String EVENT_SETTINGS_CHANGED = "GeckoView:Tor:SettingsChanged";
// Events we emit private static final String EVENT_SETTINGS_GET = "GeckoView:Tor:SettingsGet"; @@ -57,7 +59,6 @@ public class TorIntegrationAndroid implements BundleEventListener { private static final String EVENT_BOOTSTRAP_BEGIN_AUTO = "GeckoView:Tor:BootstrapBeginAuto"; private static final String EVENT_BOOTSTRAP_CANCEL = "GeckoView:Tor:BootstrapCancel"; private static final String EVENT_BOOTSTRAP_GET_STATE = "GeckoView:Tor:BootstrapGetState"; - private static final String EVENT_SETTINGS_READY = "GeckoView:Tor:SettingsReady";
private static final String CONTROL_PORT_FILE = "/control-ipc"; private static final String SOCKS_FILE = "/socks-ipc"; @@ -112,6 +113,7 @@ public class TorIntegrationAndroid implements BundleEventListener { EVENT_MEEK_START, EVENT_MEEK_STOP, EVENT_SETTINGS_READY, + EVENT_SETTINGS_CHANGED, EVENT_BOOTSTRAP_STATE_CHANGED, EVENT_BOOTSTRAP_PROGRESS, EVENT_BOOTSTRAP_COMPLETE, @@ -136,6 +138,14 @@ public class TorIntegrationAndroid implements BundleEventListener { } catch(Exception e) { Log.e(TAG, "SettingsLoader error: "+ e.toString()); } + } else if (EVENT_SETTINGS_CHANGED.equals(event)) { + GeckoBundle newSettings = message.getBundle("settings"); + if (newSettings != null) { + // TODO: Should we notify listeners? + mSettings = new TorSettings(newSettings); + } else { + Log.w(TAG, "Ignoring a settings changed event that did not have the new settings."); + } } else if (EVENT_BOOTSTRAP_STATE_CHANGED.equals(event)) { String state = message.getString("state"); for (BootstrapStateChangeListener listener: mBootstrapStateListeners) {
===================================== toolkit/modules/TorAndroidIntegration.sys.mjs ===================================== @@ -124,6 +124,15 @@ class TorAndroidIntegrationImpl { settings: lazy.TorSettings.getSettings(), }); break; + case lazy.TorSettingsTopics.SettingsChanged: + // For Android we push also the settings object to avoid a round trip on + // the event dispatcher. + lazy.EventDispatcher.instance.sendRequest({ + type: EmittedEvents.settingsChanged, + changes: subj.wrappedJSObject.changes ?? [], + settings: lazy.TorSettings.getSettings(), + }); + break; } }
===================================== toolkit/modules/TorConnect.sys.mjs ===================================== @@ -878,10 +878,11 @@ export const TorConnect = (() => { console.log(`TorConnect: Observing topic '${addTopic}'`); };
+ TorSettings.initializedPromise.then(() => this._settingsInitialized()); + // register the Tor topics we always care about observeTopic(TorTopics.ProcessExited); observeTopic(TorTopics.LogHasWarnOrErr); - observeTopic(TorSettingsTopics.Ready); } },
@@ -889,29 +890,6 @@ export const TorConnect = (() => { console.log(`TorConnect: Observed ${topic}`);
switch (topic) { - /* We need to wait until TorSettings have been loaded and applied before we can Quickstart */ - case TorSettingsTopics.Ready: { - // tor-browser#41907: This is only a workaround to avoid users being - // bounced back to the initial panel without any explanation. - // Longer term we should disable the clickable elements, or find a UX - // to prevent this from happening (e.g., allow buttons to be clicked, - // but show an intermediate starting state, or a message that tor is - // starting while the butons are disabled, etc...). - if (this.state !== TorConnectState.Initial) { - console.warn( - "TorConnect: Seen the torsettings:ready after the state has already changed, ignoring the notification." - ); - break; - } - if (this.shouldQuickStart) { - // Quickstart - this._changeState(TorConnectState.Bootstrapping); - } else { - // Configuring - this._changeState(TorConnectState.Configuring); - } - break; - } case TorTopics.LogHasWarnOrErr: { this._logHasWarningOrError = true; break; @@ -941,6 +919,28 @@ export const TorConnect = (() => { } },
+ _settingsInitialized() { + // tor-browser#41907: This is only a workaround to avoid users being + // bounced back to the initial panel without any explanation. + // Longer term we should disable the clickable elements, or find a UX + // to prevent this from happening (e.g., allow buttons to be clicked, + // but show an intermediate starting state, or a message that tor is + // starting while the butons are disabled, etc...). + if (this.state !== TorConnectState.Initial) { + console.warn( + "TorConnect: Seen the torsettings:ready after the state has already changed, ignoring the notification." + ); + return; + } + if (this.shouldQuickStart) { + // Quickstart + this._changeState(TorConnectState.Bootstrapping); + } else { + // Configuring + this._changeState(TorConnectState.Configuring); + } + }, + /* Various getters */
===================================== toolkit/modules/TorSettings.sys.mjs ===================================== @@ -992,6 +992,10 @@ class TorSettingsImpl { // Hold off on lots of notifications until all settings are changed. this.freezeNotifications(); try { + if ("quickstart" in settings) { + this.quickstart.enabled = !!settings.quickstart.enabled; + } + if ("bridges" in settings) { this.bridges.enabled = !!settings.bridges.enabled; // Currently, disabling bridges in the UI does not remove the lines,
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/db59cb2...
tbb-commits@lists.torproject.org