Commit 99c7cbd3 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

Bug 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 05836bb1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
  PdfJs: "resource://pdf.js/PdfJs.sys.mjs",
  Preferences: "resource://gre/modules/Preferences.sys.mjs",
  RFPHelper: "resource://gre/modules/RFPHelper.sys.mjs",
  TorAndroidIntegration: "resource://gre/modules/TorAndroidIntegration.sys.mjs",
  TorDomainIsolator: "resource://gre/modules/TorDomainIsolator.sys.mjs",
});

@@ -259,6 +260,7 @@ class GeckoViewStartup {
          "GeckoView:SetLocale",
        ]);

        lazy.TorAndroidIntegration.init();
        lazy.TorDomainIsolator.init();

        Services.obs.addObserver(this, "browser-idle-startup-tasks-finished");
+16 −0
Original line number Diff line number Diff line
@@ -224,6 +224,8 @@ public final class GeckoRuntime implements Parcelable {
  private final ProfilerController mProfilerController;
  private final GeckoScreenChangeListener mScreenChangeListener;

  private TorIntegrationAndroid mTorIntegration;

  private GeckoRuntime() {
    mWebExtensionController = new WebExtensionController(this);
    mContentBlockingController = new ContentBlockingController();
@@ -478,6 +480,8 @@ public final class GeckoRuntime implements Parcelable {
      mScreenChangeListener.enable();
    }

    mTorIntegration = new TorIntegrationAndroid(context);

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

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

    GeckoThread.forceQuit();
  }

@@ -994,6 +1002,14 @@ public final class GeckoRuntime implements Parcelable {
    return mPushController;
  }

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

  /**
   * Appends notes to crash report.
   *
+16 −0
Original line number Diff line number Diff line
@@ -487,6 +487,11 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
      getSettings().mSecurityLevel.set(level);
      return this;
    }

    public @NonNull Builder useNewBootstrap(final boolean flag) {
      getSettings().mUseNewBootstrap.set(flag);
      return this;
    }
  }

  private GeckoRuntime mRuntime;
@@ -538,6 +543,8 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
  /* package */ final Pref<Integer> mSpoofEnglish = new Pref<>("privacy.spoof_english", 0);
  /* package */ final Pref<Integer> mSecurityLevel =
      new Pref<>("browser.security_level.security_slider", 4);
  /* package */ final Pref<Boolean> mUseNewBootstrap =
      new Pref<>("browser.tor_android.use_new_bootstrap", false);

  /* package */ int mPreferredColorScheme = COLOR_SCHEME_SYSTEM;

@@ -1341,6 +1348,15 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
    return this;
  }

  public boolean getUseNewBootstrap() {
    return mUseNewBootstrap.get();
  }

  public @NonNull GeckoRuntimeSettings setUseNewBootstrap(final boolean flag) {
    mUseNewBootstrap.commit(flag);
    return this;
  }

  @Override // Parcelable
  public void writeToParcel(final Parcel out, final int flags) {
    super.writeToParcel(out, flags);
+10 −0
Original line number Diff line number Diff line
@@ -2493,6 +2493,16 @@ public class GeckoSession {
    return mEventDispatcher.queryBoolean("GeckoView:IsPdfJs");
  }

  /**
   * 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> getTorCircuit() {
    return mEventDispatcher.queryBundle("GeckoView:GetTorCircuit");
  }

  /**
   * 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
+666 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading