Verified Commit f3e0e0fc authored by henry's avatar henry Committed by ma1
Browse files

fixup! TB 40026 [android]: Implement Security Level settings on Android.

TB 43783: Expose SecurityLevelPrefs.setSecurityLevelAndRestart to
android integration.
parent e039ae44
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -49,6 +49,9 @@ public class TorAndroidIntegration implements BundleEventListener {
  private static final String EVENT_SETTINGS_CHANGED = "GeckoView:Tor:SettingsChanged";

  // Events we emit
  // TODO: Integrate the security level API. tor-browser#43820
  private static final String EVENT_SECURITY_LEVEL_GET = "GeckoView:Tor:SecurityLevelGet";
  private static final String EVENT_SECURITY_LEVEL_SET_BEFORE_RESTART = "GeckoView:Tor:SecurityLevelSetBeforeRestart";
  private static final String EVENT_SETTINGS_GET = "GeckoView:Tor:SettingsGet";
  private static final String EVENT_SETTINGS_SET = "GeckoView:Tor:SettingsSet";
  private static final String EVENT_BOOTSTRAP_BEGIN = "GeckoView:Tor:BootstrapBegin";
+17 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
  TorProviderBuilder: "resource://gre/modules/TorProviderBuilder.sys.mjs",
  TorProviderTopics: "resource://gre/modules/TorProviderBuilder.sys.mjs",
  TorSettings: "resource://gre/modules/TorSettings.sys.mjs",
  SecurityLevelPrefs: "resources://gre/modules/SecurityLevel.sys.mjs",
});

const Prefs = Object.freeze({
@@ -34,6 +35,8 @@ const EmittedEvents = Object.freeze({
});

const ListenedEvents = Object.freeze({
  securityLevelGet: "GeckoView:Tor:SecurityLevelGet",
  securityLevelSetBeforeRestart: "GeckoView:Tor:SecurityLevelSetBeforeRestart",
  settingsGet: "GeckoView:Tor:SettingsGet",
  // The data is passed directly to TorSettings.
  settingsSet: "GeckoView:Tor:SettingsSet",
@@ -171,6 +174,20 @@ class TorAndroidIntegrationImpl {
    logger.debug(`Received event ${event}`, data);
    try {
      switch (event) {
        case ListenedEvents.securityLevelGet:
          // "standard"/"safer"/"safest"
          // TODO: Switch to securityLevelSummary to allow android to handle
          // "custom" security level. tor-browser#43819
          callback?.onSuccess(lazy.SecurityLevelPrefs.securityLevel);
          break;
        case ListenedEvents.securityLevelSetBeforeRestart:
          lazy.SecurityLevelPrefs.setSecurityLevelBeforeRestart(data.levelName);
          // Let the caller know that the setting is applied and the browser
          // should be restarted now.
          // NOTE: The caller must wait for this callback before triggering
          // the restart.
          callback?.onSuccess();
          break;
        case ListenedEvents.settingsGet:
          callback?.onSuccess(lazy.TorSettings.getSettings());
          return;