[tbb-commits] [Git][tpo/applications/tor-browser][tor-browser-115.6.0esr-13.5-1] 3 commits: fixup! Bug 40933: Add tor-launcher functionality

Pier Angelo Vendrame (@pierov) git at gitlab.torproject.org
Wed Dec 20 20:51:16 UTC 2023



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


Commits:
8649662e by Pier Angelo Vendrame at 2023-12-20T19:16:35+01:00
fixup! Bug 40933: Add tor-launcher functionality

Removed a redundant wrappedJSObject that broke stuff.

- - - - -
7cb6472f by Pier Angelo Vendrame at 2023-12-20T21:49:35+01:00
fixup! Bug 42247: Android helpers for the TorProvider

Bug 42251: Wired bootstrap updates.

- - - - -
d980086a by Pier Angelo Vendrame at 2023-12-20T21:49:46+01:00
fixup! Temporary changes to about:torconnect for Android.

Temporary message to open Android settings from about:torconnect

- - - - -


4 changed files:

- mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java
- toolkit/components/tor-launcher/TorProvider.sys.mjs
- toolkit/modules/TorAndroidIntegration.sys.mjs
- toolkit/modules/TorConnect.sys.mjs


Changes:

=====================================
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java
=====================================
@@ -46,6 +46,11 @@ 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";
+    private static final String EVENT_SETTINGS_OPEN = "GeckoView:Tor:OpenSettings";
 
     // Events we emit
     private static final String EVENT_SETTINGS_GET = "GeckoView:Tor:SettingsGet";
@@ -106,7 +111,12 @@ 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,
+                        EVENT_SETTINGS_OPEN);
     }
 
     @Override // BundleEventListener
@@ -122,6 +132,32 @@ 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);
+            }
+        } else if (EVENT_SETTINGS_OPEN.equals(event)) {
+            for (BootstrapStateChangeListener listener: mBootstrapStateListeners) {
+                listener.onSettingsRequested();
+            }
         }
     }
 
@@ -467,17 +503,12 @@ 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);
+        void onSettingsRequested();
     }
 
     public @NonNull GeckoResult<GeckoBundle> getSettings() {
@@ -514,16 +545,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);
     }


=====================================
toolkit/components/tor-launcher/TorProvider.sys.mjs
=====================================
@@ -875,10 +875,7 @@ export class TorProvider {
    */
   #processBootstrapStatus(statusObj, isNotification) {
     // Notify observers
-    Services.obs.notifyObservers(
-      { wrappedJSObject: statusObj },
-      TorProviderTopics.BootstrapStatus
-    );
+    Services.obs.notifyObservers(statusObj, TorProviderTopics.BootstrapStatus);
 
     if (statusObj.PROGRESS === 100) {
       this.#isBootstrapDone = true;


=====================================
toolkit/modules/TorAndroidIntegration.sys.mjs
=====================================
@@ -25,9 +25,13 @@ const logger = new ConsoleAPI({
   prefix: "TorAndroidIntegration",
 });
 
-const EmittedEvents = Object.freeze( {
+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({


=====================================
toolkit/modules/TorConnect.sys.mjs
=====================================
@@ -7,6 +7,7 @@ import { setTimeout, clearTimeout } from "resource://gre/modules/Timer.sys.mjs";
 const lazy = {};
 
 ChromeUtils.defineESModuleGetters(lazy, {
+  EventDispatcher: "resource://gre/modules/Messaging.sys.mjs",
   MoatRPC: "resource://gre/modules/Moat.sys.mjs",
   TorBootstrapRequest: "resource://gre/modules/TorBootstrapRequest.sys.mjs",
 });
@@ -1092,6 +1093,12 @@ export const TorConnect = (() => {
         Further external commands and helper methods
         */
     openTorPreferences() {
+      if (TorLauncherUtil.isAndroid) {
+        lazy.EventDispatcher.instance.sendRequest({
+          type: "GeckoView:Tor:OpenSettings",
+        });
+        return;
+      }
       const win = lazy.BrowserWindowTracker.getTopWindow();
       win.switchToTabHavingURI("about:preferences#connection", true);
     },



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/e9cc4840f6735d0e54a50e37a1e0a879d66f26a6...d980086af1e949a92914330e2cdab976046bf858

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/e9cc4840f6735d0e54a50e37a1e0a879d66f26a6...d980086af1e949a92914330e2cdab976046bf858
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/tbb-commits/attachments/20231220/14aedebf/attachment-0001.htm>


More information about the tbb-commits mailing list