[tor-commits] [tor-browser/tor-browser-84.0-10.5-1] Bug 40125: Expose Security Level pref in GeckoView

sysrqb at torproject.org sysrqb at torproject.org
Wed Dec 9 17:49:53 UTC 2020


commit 25e6e8827fb800eca1dd5854936f8957dbf19e12
Author: Matthew Finkel <sysrqb at torproject.org>
Date:   Mon Sep 14 02:52:28 2020 +0000

    Bug 40125: Expose Security Level pref in GeckoView
---
 mobile/android/geckoview/api.txt                   |  3 ++
 .../mozilla/geckoview/GeckoRuntimeSettings.java    | 33 ++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/mobile/android/geckoview/api.txt b/mobile/android/geckoview/api.txt
index 1c01a3f6731b..946446a97f30 100644
--- a/mobile/android/geckoview/api.txt
+++ b/mobile/android/geckoview/api.txt
@@ -633,6 +633,7 @@ package org.mozilla.geckoview {
     method @Nullable public GeckoRuntime getRuntime();
     method @Nullable public Rect getScreenSizeOverride();
     method @Nullable public RuntimeTelemetry.Delegate getTelemetryDelegate();
+    method public int getTorSecurityLevel();
     method public boolean getUseMaxScreenDepth();
     method public boolean getWebFontsEnabled();
     method public boolean getWebManifestEnabled();
@@ -650,6 +651,7 @@ package org.mozilla.geckoview {
     method @NonNull public GeckoRuntimeSettings setLoginAutofillEnabled(boolean);
     method @NonNull public GeckoRuntimeSettings setPreferredColorScheme(int);
     method @NonNull public GeckoRuntimeSettings setRemoteDebuggingEnabled(boolean);
+    method @NonNull public GeckoRuntimeSettings setTorSecurityLevel(int);
     method @NonNull public GeckoRuntimeSettings setWebFontsEnabled(boolean);
     method @NonNull public GeckoRuntimeSettings setWebManifestEnabled(boolean);
     field public static final int COLOR_SCHEME_DARK = 1;
@@ -685,6 +687,7 @@ package org.mozilla.geckoview {
     method @NonNull public GeckoRuntimeSettings.Builder remoteDebuggingEnabled(boolean);
     method @NonNull public GeckoRuntimeSettings.Builder screenSizeOverride(int, int);
     method @NonNull public GeckoRuntimeSettings.Builder telemetryDelegate(@NonNull RuntimeTelemetry.Delegate);
+    method @NonNull public GeckoRuntimeSettings.Builder torSecurityLevel(int);
     method @NonNull public GeckoRuntimeSettings.Builder useMaxScreenDepth(boolean);
     method @NonNull public GeckoRuntimeSettings.Builder webFontsEnabled(boolean);
     method @NonNull public GeckoRuntimeSettings.Builder webManifest(boolean);
diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
index 97c33665fc18..662b34c476ae 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
@@ -446,6 +446,17 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
             getSettings().mForceUserScalable.set(flag);
             return this;
         }
+
+        /**
+         * Set security level.
+         *
+         * @param level A value determining the security level. Default is 0.
+         * @return This Builder instance.
+         */
+        public @NonNull Builder torSecurityLevel(final int level) {
+            getSettings().mTorSecurityLevel.set(level);
+            return this;
+        }
     }
 
     private GeckoRuntime mRuntime;
@@ -494,6 +505,8 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
             "browser.ui.zoom.force-user-scalable", false);
     /* package */ final Pref<Boolean> mAutofillLogins = new Pref<Boolean>(
         "signon.autofillForms", true);
+    /* package */ final Pref<Integer> mTorSecurityLevel = new Pref<>(
+        "extensions.torbutton.security_slider", 4);
 
     /* package */ int mPreferredColorScheme = COLOR_SCHEME_SYSTEM;
 
@@ -1132,6 +1145,26 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
         return this;
     }
 
+    /**
+     * Gets the current security level.
+     *
+     * @return current security protection level
+     */
+    public int getTorSecurityLevel() {
+        return mTorSecurityLevel.get();
+    }
+
+    /**
+     * Sets the Tor Security Level.
+     *
+     * @param level security protection level
+     * @return This GeckoRuntimeSettings instance.
+     */
+    public @NonNull GeckoRuntimeSettings setTorSecurityLevel(final int level) {
+        mTorSecurityLevel.commit(level);
+        return this;
+    }
+
     @Override // Parcelable
     public void writeToParcel(final Parcel out, final int flags) {
         super.writeToParcel(out, flags);





More information about the tor-commits mailing list