Commit 523837c5 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

TB 42247: Android helpers for the TorProvider

GeckoView is missing some API we use on desktop for the integration
with the tor daemon, such as subprocess.
Therefore, we need to implement them in Java and plumb the data
back and forth between JS and Java.
parent f05c2ede
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -140,3 +140,4 @@ pref("browser.torsettings.log_level", "Warn");
pref("browser.torMoat.loglevel", "Warn");
pref("browser.tordomainisolator.loglevel", "Warn");
pref("browser.torcircuitpanel.loglevel", "Log");
pref("browser.tor_android.log_level", "Info");
+16 −0
Original line number Diff line number Diff line
@@ -270,6 +270,8 @@ public final class GeckoRuntime implements Parcelable {
  private final CrashPullController.CrashPullProxy mCrashPullProxy;
  private final GeckoScreenChangeListener mScreenChangeListener;

  private TorAndroidIntegration mTorIntegration;

  private GeckoRuntime() {
    mWebExtensionController = new WebExtensionController(this);
    mContentBlockingController = new ContentBlockingController();
@@ -586,6 +588,8 @@ public final class GeckoRuntime implements Parcelable {
    // Warm up window context of default display.
    GeckoAppShell.maybeInitScreen();

    mTorIntegration = new TorAndroidIntegration(context);

    ProfilerController.addMarker(
        "GeckoView Initialization START", ProfilerController.getProfilerTime());
    return true;
@@ -701,6 +705,10 @@ public final class GeckoRuntime implements Parcelable {
      mScreenChangeListener.disable();
    }

    if (mTorIntegration != null) {
      mTorIntegration.shutdown();
    }

    GeckoThread.forceQuit();
  }

@@ -1187,6 +1195,14 @@ public final class GeckoRuntime implements Parcelable {
        "mobile-telemetry-pref-changed", isEnabled ? "enabled" : "disabled");
  }

  /**
   * Get the Tor integration controller for this runtime.
   */
  @UiThread
  public @NonNull TorAndroidIntegration getTorIntegrationController() {
    return mTorIntegration;
  }

  /**
   * Appends notes to crash report.
   *
+18 −0
Original line number Diff line number Diff line
@@ -2814,6 +2814,24 @@ public class GeckoSession {
    mEventDispatcher.dispatch("GeckoView:FlushSessionState", null);
  }

  /**
   * Try to get last circuit used in this session, if possible.
   *
   * @return The circuit information as a {@link GeckoResult} object.
   */
  @AnyThread
  public @NonNull GeckoResult<GeckoBundle> getTorCircuits() {
    return mEventDispatcher.queryBundle("GeckoView:GetTorCircuits");
  }

  /**
   * Change the circuit for this session.
   */
  @UiThread
  public void newTorCircuit() {
    mEventDispatcher.dispatch("GeckoView:NewTorCircuit", null);
  }

  /**
   * Set this GeckoSession as active or inactive, which represents if the session is currently
   * visible or not. Setting a GeckoSession to inactive will significantly reduce its memory
+751 −0

File added.

Preview size limit exceeded, changes collapsed.

+14 −0
Original line number Diff line number Diff line
package org.mozilla.geckoview;

import org.mozilla.gecko.util.GeckoBundle;

// Class to receive BootstrappingStatus object from TorConnect.sys.mjs ~ln698
public class TorBootstrappingStatus {
    public int progress; // percent of bootstrap progress
    public boolean hasWarning; //  Whether this bootstrap has a warning in the tor log

    public TorBootstrappingStatus(GeckoBundle bundle) {
        progress = bundle.getInt("progress");
        hasWarning = bundle.getBoolean("hasWarning");
    }
}
Loading