Bug 1908116 - Add Nimbus support for FPP on Android. r=amejiamarmol,geckoview-reviewers,android-reviewers,owlish

Differential Revision: https://phabricator.services.mozilla.com/D216689
This commit is contained in:
Tim Huang
2024-07-19 19:17:02 +00:00
parent 55276db34c
commit 05982704c3
8 changed files with 194 additions and 3 deletions

View File

@@ -1339,6 +1339,14 @@ class GeckoEngine(
override var fingerprintingProtectionPrivateBrowsing: Boolean
get() = runtime.settings.fingerprintingProtectionPrivateBrowsing
set(value) { runtime.settings.setFingerprintingProtectionPrivateBrowsing(value) }
override var fingerprintingProtectionOverrides: String
get() = runtime.settings.fingerprintingProtectionOverrides
set(value) { runtime.settings.setFingerprintingProtectionOverrides(value) }
override var fdlibmMathEnabled: Boolean
get() = runtime.settings.fdlibmMathEnabled
set(value) { runtime.settings.setFdlibmMathEnabled(value) }
}.apply {
defaultSettings?.let {
this.javascriptEnabled = it.javascriptEnabled
@@ -1366,6 +1374,8 @@ class GeckoEngine(
this.globalPrivacyControlEnabled = it.globalPrivacyControlEnabled
this.fingerprintingProtection = it.fingerprintingProtection
this.fingerprintingProtectionPrivateBrowsing = it.fingerprintingProtectionPrivateBrowsing
this.fingerprintingProtectionOverrides = it.fingerprintingProtectionOverrides
this.fdlibmMathEnabled = it.fdlibmMathEnabled
this.emailTrackerBlockingPrivateBrowsing = it.emailTrackerBlockingPrivateBrowsing
}
}

View File

@@ -263,6 +263,16 @@ abstract class Settings {
* Setting to control whether privacy.fingerprintingProtection.pbmode is enabled.
*/
open var fingerprintingProtectionPrivateBrowsing: Boolean by UnsupportedSetting()
/**
* Setting to enable or disable certain fingerprinting protection features.
*/
open var fingerprintingProtectionOverrides: String by UnsupportedSetting()
/**
* Setting to control whehter to use fdlibm for Math.sin, Math.cos, and Math.tan.
*/
open var fdlibmMathEnabled: Boolean by UnsupportedSetting()
}
/**
@@ -304,6 +314,8 @@ data class DefaultSettings(
override var globalPrivacyControlEnabled: Boolean = false,
override var fingerprintingProtection: Boolean = false,
override var fingerprintingProtectionPrivateBrowsing: Boolean = true,
override var fingerprintingProtectionOverrides: String = "",
override var fdlibmMathEnabled: Boolean = false,
override var cookieBannerHandlingMode: CookieBannerHandlingMode = CookieBannerHandlingMode.DISABLED,
override var cookieBannerHandlingModePrivateBrowsing: CookieBannerHandlingMode =
CookieBannerHandlingMode.DISABLED,

View File

@@ -498,6 +498,36 @@ features:
value:
enabled: false
fingerprinting-protection:
description: Control Fingerprinting Protection
variables:
enabled:
description: If true, the feature is active.
type: Boolean
default: false
enabled-normal:
description: >
Enables / disables fingerprinting protection in normal browsing mode.
type: Boolean
default: false
enabled-private:
description: >
Enables / disables fingerprinting protection in private browsing mode.
type: Boolean
default: true
overrides:
description: >
The protection overrides to add or remove fingerprinting protection
targets. Please check RFPTargets.inc for all supported targets.
type: String
default: ""
fdlibm-math:
description: >
Uses a different math backend for Math.sin/cos/tan in JavaScript that
exposes less entropy
type: Boolean
default: false
types:
objects: {}

View File

@@ -151,8 +151,25 @@ class Core(
),
httpsOnlyMode = context.settings().getHttpsOnlyMode(),
globalPrivacyControlEnabled = context.settings().shouldEnableGlobalPrivacyControl,
fingerprintingProtection = context.settings().blockSuspectedFingerprinters,
fingerprintingProtectionPrivateBrowsing = context.settings().blockSuspectedFingerprintersPrivateBrowsing,
fingerprintingProtection =
if (FxNimbus.features.fingerprintingProtection.value().enabled) {
FxNimbus.features.fingerprintingProtection.value().enabledNormal
} else {
context.settings().blockSuspectedFingerprinters
},
fingerprintingProtectionPrivateBrowsing =
if (FxNimbus.features.fingerprintingProtection.value().enabled) {
FxNimbus.features.fingerprintingProtection.value().enabledPrivate
} else {
context.settings().blockSuspectedFingerprintersPrivateBrowsing
},
fingerprintingProtectionOverrides =
if (FxNimbus.features.fingerprintingProtection.value().enabled) {
FxNimbus.features.fingerprintingProtection.value().overrides
} else {
""
},
fdlibmMathEnabled = FxNimbus.features.fingerprintingProtection.value().fdlibmMath,
cookieBannerHandlingMode = context.settings().getCookieBannerHandling(),
cookieBannerHandlingModePrivateBrowsing = context.settings().getCookieBannerHandlingPrivateMode(),
cookieBannerHandlingDetectOnlyMode = context.settings().shouldEnableCookieBannerDetectOnly,

View File

@@ -871,7 +871,9 @@ package org.mozilla.geckoview {
method @Nullable public Boolean getExtensionsProcessEnabled();
method public boolean getExtensionsWebAPIEnabled();
method @NonNull public Bundle getExtras();
method public boolean getFdlibmMathEnabled();
method public boolean getFingerprintingProtection();
method @NonNull public String getFingerprintingProtectionOverrides();
method public boolean getFingerprintingProtectionPrivateBrowsing();
method public boolean getFontInflationEnabled();
method public float getFontSizeFactor();
@@ -906,7 +908,9 @@ package org.mozilla.geckoview {
method @NonNull public GeckoRuntimeSettings setExtensionsProcessCrashTimeframe(@NonNull Long);
method @NonNull public GeckoRuntimeSettings setExtensionsProcessEnabled(boolean);
method @NonNull public GeckoRuntimeSettings setExtensionsWebAPIEnabled(boolean);
method @NonNull public GeckoRuntimeSettings setFdlibmMathEnabled(boolean);
method @NonNull public GeckoRuntimeSettings setFingerprintingProtection(boolean);
method @NonNull public GeckoRuntimeSettings setFingerprintingProtectionOverrides(@NonNull String);
method @NonNull public GeckoRuntimeSettings setFingerprintingProtectionPrivateBrowsing(boolean);
method @NonNull public GeckoRuntimeSettings setFontInflationEnabled(boolean);
method @NonNull public GeckoRuntimeSettings setFontSizeFactor(float);

View File

@@ -485,4 +485,72 @@ class RuntimeSettingsTest : BaseSessionTest() {
equalTo(false),
)
}
@Test
fun fingerprintingProtectionOverrides() {
val geckoRuntimeSettings = sessionRule.runtime.settings
geckoRuntimeSettings.setFingerprintingProtectionOverrides(
"+NavigatorHWConcurrency,+CanvasRandomization",
)
assertThat(
"Fingerprint Protection overrides settings should be set to the expected value",
geckoRuntimeSettings.fingerprintingProtectionOverrides,
equalTo("+NavigatorHWConcurrency,+CanvasRandomization"),
)
val overrides =
(sessionRule.getPrefs("privacy.fingerprintingProtection.overrides").get(0)) as String
assertThat(
"Fingerprint Protection overrides pref should be set to the expected value",
overrides,
equalTo("+NavigatorHWConcurrency,+CanvasRandomization"),
)
}
@Test
fun fdlibmMathEnabling() {
val geckoRuntimeSettings = sessionRule.runtime.settings
geckoRuntimeSettings.setFdlibmMathEnabled(true)
assertThat(
"Fdlibm math settings should be set to the expected value",
geckoRuntimeSettings.fdlibmMathEnabled,
equalTo(true),
)
val enabled =
(sessionRule.getPrefs("javascript.options.use_fdlibm_for_sin_cos_tan").get(0)) as Boolean
assertThat(
"Fdlibm math pref should be set to the expected value",
enabled,
equalTo(true),
)
}
@Test
fun fdlibmMathDisabling() {
val geckoRuntimeSettings = sessionRule.runtime.settings
geckoRuntimeSettings.setFdlibmMathEnabled(false)
assertThat(
"Fdlibm math settings should be set to the expected value",
geckoRuntimeSettings.fdlibmMathEnabled,
equalTo(false),
)
val enabled =
(sessionRule.getPrefs("javascript.options.use_fdlibm_for_sin_cos_tan").get(0)) as Boolean
assertThat(
"Fdlibm math pref should be set to the expected value",
enabled,
equalTo(false),
)
}
}

View File

@@ -638,6 +638,10 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
new Pref<Boolean>("privacy.fingerprintingProtection", false);
/* package */ final Pref<Boolean> mFingerprintingProtectionPrivateMode =
new Pref<Boolean>("privacy.fingerprintingProtection.pbmode", true);
/* package */ final Pref<String> mFingerprintingProtectionOverrides =
new Pref<>("privacy.fingerprintingProtection.overrides", "");
/* package */ final Pref<Boolean> mFdlibmMathEnabled =
new Pref<Boolean>("javascript.options.use_fdlibm_for_sin_cos_tan", false);
/* package */ int mPreferredColorScheme = COLOR_SCHEME_SYSTEM;
@@ -800,6 +804,30 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
return this;
}
/**
* Set the Fingerprint protection overrides
*
* @param overrides The overrides value to add or remove fingerprinting protection targets. Please
* check RFPTargets.inc for all supported targets.
* @return This GeckoRuntimeSettings instance
*/
public @NonNull GeckoRuntimeSettings setFingerprintingProtectionOverrides(
@NonNull final String overrides) {
mFingerprintingProtectionOverrides.commit(overrides);
return this;
}
/**
* Set the pref to control whether to use fdlibm for Math.sin, Math.cos, and Math.tan.
*
* @param enabled Whether we set the pref to true or false
* @return This GeckoRuntimeSettings instance
*/
public @NonNull GeckoRuntimeSettings setFdlibmMathEnabled(final boolean enabled) {
mFdlibmMathEnabled.commit(enabled);
return this;
}
/**
* Get whether Fingerprint protection is enabled in all tabs.
*
@@ -818,6 +846,24 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
return mFingerprintingProtectionPrivateMode.get();
}
/**
* Get Fingerprint protection overrides.
*
* @return The string of the fingerprinting protection overrides.
*/
public @NonNull String getFingerprintingProtectionOverrides() {
return mFingerprintingProtectionOverrides.get();
}
/**
* Get whether to use fdlibm for Math.sin, Math.cos, and Math.tan.
*
* @return Whether the fdlibm is used
*/
public boolean getFdlibmMathEnabled() {
return mFdlibmMathEnabled.get();
}
/**
* Get whether Extensions Process support is enabled.
*

View File

@@ -16,8 +16,12 @@ exclude: true
## v130
- ⚠️ Removed [`TranslationState`][127.4] constructor, please use the new [`TranslationState`][127.3] constructor with `hasVisibleChange`. ([bug 1895275]({{bugzilla}}1895275))
- Added support for controlling `privacy.fingerprintingProtection` and `privacy.fingerprintingProtection.pbmode` via [`GeckoRuntimeSettings.setFingerprintingProtection`][130.1]
- Added support for controlling `privacy.fingerprintingProtection.overrides` via [`GeckoRuntimeSettings.setFingerprintingProtectionOverrides`][130.2]
- Added support for controlling `javascript.options.use_fdlibm_for_sin_cos_tan` via [`GeckoRuntimeSettings.setFdlibmMathEnabled`][130.3]
[130.1]: {{javadoc_uri}}/GeckoRuntimeSettings.html#setFingerprintingProtection
[130.2]: {{javadoc_uri}}/GeckoRuntimeSettings.html#setFingerprintingProtectionOverrides
[130.3]: {{javadoc_uri}}/GeckoRuntimeSettings.html#setFdlibmMathEnabled
## v129
- Added [`ERROR_ADMIN_INSTALL_ONLY`][129.1] to `WebExtension.InstallException.ErrorCodes`. ([bug 1902222]({{bugzilla}}1902222))
@@ -1589,4 +1593,4 @@ to allow adding gecko profiler markers.
[65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport(android.content.Context,android.os.Bundle,java.lang.String)
[65.25]: {{javadoc_uri}}/GeckoResult.html
[api-version]: 54de491a757351b552176a5686609f62afb23da6
[api-version]: 7b1cb6d9ef1ceccb52aec8efea1bf9c5e668430d