Skip to content
Snippets Groups Projects
Verified Commit 7cb6472f authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame :jack_o_lantern:
Browse files

fixup! Bug 42247: Android helpers for the TorProvider

Bug 42251: Wired bootstrap updates.
parent 8649662e
No related branches found
No related tags found
2 merge requests!898Bug 42252: Add further support for TorController in firefox-android,!878Bug 42251: Wired TorConnect status updates
......@@ -46,6 +46,10 @@ public class TorIntegrationAndroid implements BundleEventListener {
private static final String EVENT_TOR_STOP = "GeckoView:Tor:StopTor";
private static final String EVENT_MEEK_START = "GeckoView:Tor:StartMeek";
private static final String EVENT_MEEK_STOP = "GeckoView:Tor:StopMeek";
private static final String EVENT_BOOTSTRAP_STATE_CHANGED = "GeckoView:Tor:BootstrapStateChanged";
private static final String EVENT_BOOTSTRAP_PROGRESS = "GeckoView:Tor:BootstrapProgress";
private static final String EVENT_BOOTSTRAP_COMPLETE = "GeckoView:Tor:BootstrapComplete";
private static final String EVENT_BOOTSTRAP_ERROR = "GeckoView:Tor:BootstrapError";
// Events we emit
private static final String EVENT_SETTINGS_GET = "GeckoView:Tor:SettingsGet";
......@@ -106,7 +110,11 @@ public class TorIntegrationAndroid implements BundleEventListener {
EVENT_TOR_START,
EVENT_MEEK_START,
EVENT_MEEK_STOP,
EVENT_SETTINGS_READY);
EVENT_SETTINGS_READY,
EVENT_BOOTSTRAP_STATE_CHANGED,
EVENT_BOOTSTRAP_PROGRESS,
EVENT_BOOTSTRAP_COMPLETE,
EVENT_BOOTSTRAP_ERROR);
}
@Override // BundleEventListener
......@@ -122,6 +130,28 @@ public class TorIntegrationAndroid implements BundleEventListener {
stopMeek(message, callback);
} else if (EVENT_SETTINGS_READY.equals(event)) {
loadSettings(message);
} else if (EVENT_BOOTSTRAP_STATE_CHANGED.equals(event)) {
String state = message.getString("state");
for (BootstrapStateChangeListener listener: mBootstrapStateListeners) {
listener.onBootstrapStateChange(state);
}
} else if (EVENT_BOOTSTRAP_PROGRESS.equals(event)) {
double progress = message.getDouble("progress");
String status = message.getString("status");
boolean hasWarnings = message.getBoolean("hasWarnings");
for (BootstrapStateChangeListener listener: mBootstrapStateListeners) {
listener.onBootstrapProgress(progress, status, hasWarnings);
}
} else if (EVENT_BOOTSTRAP_COMPLETE.equals(event)) {
for (BootstrapStateChangeListener listener: mBootstrapStateListeners) {
listener.onBootstrapComplete();
}
} else if (EVENT_BOOTSTRAP_ERROR.equals(event)) {
String msg = message.getString("message");
String details = message.getString("details");
for (BootstrapStateChangeListener listener: mBootstrapStateListeners) {
listener.onBootstrapError(msg, details);
}
}
}
......@@ -467,17 +497,11 @@ public class TorIntegrationAndroid implements BundleEventListener {
}
}
public static class BootstrapState {
// FIXME: We can do better than this :)
public GeckoBundle mBundle;
BootstrapState(GeckoBundle bundle) {
mBundle = bundle;
}
}
public interface BootstrapStateChangeListener {
void onBootstrapStateChange(BootstrapState state);
void onBootstrapStateChange(String state);
void onBootstrapProgress(double progress, String status, boolean hasWarnings);
void onBootstrapComplete();
void onBootstrapError(String message, String details);
}
public @NonNull GeckoResult<GeckoBundle> getSettings() {
......@@ -514,16 +538,6 @@ public class TorIntegrationAndroid implements BundleEventListener {
return EventDispatcher.getInstance().queryVoid(EVENT_BOOTSTRAP_CANCEL);
}
public @NonNull GeckoResult<BootstrapState> getBootstrapState() {
return EventDispatcher.getInstance().queryBundle(EVENT_BOOTSTRAP_GET_STATE).map(new GeckoResult.OnValueMapper<>() {
@AnyThread
@Nullable
public BootstrapState onValue(@Nullable GeckoBundle value) throws Throwable {
return new BootstrapState(value);
}
});
}
public void registerBootstrapStateChangeListener(BootstrapStateChangeListener listener) {
mBootstrapStateListeners.add(listener);
}
......
......@@ -28,6 +28,10 @@ const logger = new ConsoleAPI({
const EmittedEvents = Object.freeze({
settingsReady: "GeckoView:Tor:SettingsReady",
settingsChanged: "GeckoView:Tor:SettingsChanged",
bootstrapStateChanged: "GeckoView:Tor:BootstrapStateChanged",
bootstrapProgress: "GeckoView:Tor:BootstrapProgress",
bootstrapComplete: "GeckoView:Tor:BootstrapComplete",
bootstrapError: "GeckoView:Tor:BootstrapError",
});
const ListenedEvents = Object.freeze({
......@@ -89,6 +93,30 @@ class TorAndroidIntegrationImpl {
}
break;
case lazy.TorConnectTopics.StateChange:
lazy.EventDispatcher.instance.sendRequest({
type: EmittedEvents.bootstrapStateChanged,
state: subj.wrappedJSObject.state ?? "",
});
break;
case lazy.TorConnectTopics.BootstrapProgress:
lazy.EventDispatcher.instance.sendRequest({
type: EmittedEvents.bootstrapProgress,
progress: subj.wrappedJSObject.progress ?? "",
status: subj.wrappedJSObject.status ?? 0,
hasWarnings: subj.wrappedJSObject.hasWarnings ?? false,
});
break;
case lazy.TorConnectTopics.BootstrapComplete:
lazy.EventDispatcher.instance.sendRequest({
type: EmittedEvents.bootstrapComplete,
});
break;
case lazy.TorConnectTopics.BootstrapError:
lazy.EventDispatcher.instance.sendRequest({
type: EmittedEvents.bootstrapError,
message: subj.wrappedJSObject.message ?? "",
details: subj.wrappedJSObject.details ?? "",
});
break;
case lazy.TorSettingsTopics.Ready:
lazy.EventDispatcher.instance.sendRequest({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment