commit ddb756b26d890966efc914c409fb402d862e762c
parent 0d7541332615737a7afb4f479c6db02e83edb4ba
Author: Alex Catarineu <acat@torproject.org>
Date: Fri, 16 Oct 2020 10:45:17 +0200
BB 30605: Honor privacy.spoof_english in Android
This checks `privacy.spoof_english` whenever `setLocales` is
called from Fenix side and sets `intl.accept_languages`
accordingly.
Bug 40198: Expose privacy.spoof_english pref in GeckoView
Diffstat:
3 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/mobile/android/geckoview/api.txt b/mobile/android/geckoview/api.txt
@@ -1056,6 +1056,7 @@ package org.mozilla.geckoview {
method @NonNull public boolean getSameDocumentNavigationOverridesLoadType();
method @NonNull public String getSameDocumentNavigationOverridesLoadTypeForceDisable();
method @Nullable public Rect getScreenSizeOverride();
+ method public boolean getSpoofEnglish();
method public boolean getTranslationsOfferPopup();
method @NonNull public List<String> getTrustedRecursiveResolverExcludedDomains();
method @NonNull public String getTrustedRecursiveResolverUri();
@@ -1110,6 +1111,7 @@ package org.mozilla.geckoview {
method @NonNull public GeckoRuntimeSettings setRemoteSettingCrashPullNeverShowAgain(boolean);
method @NonNull public GeckoRuntimeSettings setSameDocumentNavigationOverridesLoadType(boolean);
method @NonNull public GeckoRuntimeSettings setSameDocumentNavigationOverridesLoadTypeForceDisable(@NonNull String);
+ method @NonNull public GeckoRuntimeSettings setSpoofEnglish(boolean);
method @NonNull public GeckoRuntimeSettings setTranslationsOfferPopup(boolean);
method @NonNull public GeckoRuntimeSettings setTrustedRecursiveResolverExcludedDomains(@NonNull List<String>);
method @NonNull public GeckoRuntimeSettings setTrustedRecursiveResolverMode(int);
@@ -1181,6 +1183,7 @@ package org.mozilla.geckoview {
method @NonNull public GeckoRuntimeSettings.Builder setLnaEnabled(@NonNull Boolean);
method @NonNull public GeckoRuntimeSettings.Builder setSameDocumentNavigationOverridesLoadType(boolean);
method @NonNull public GeckoRuntimeSettings.Builder setSameDocumentNavigationOverridesLoadTypeForceDisable(@NonNull String);
+ method @NonNull public GeckoRuntimeSettings.Builder spoofEnglish(boolean);
method @NonNull public GeckoRuntimeSettings.Builder translationsOfferPopup(boolean);
method @NonNull public GeckoRuntimeSettings.Builder trustedRecursiveResolverMode(int);
method @NonNull public GeckoRuntimeSettings.Builder trustedRecursiveResolverUri(@NonNull String);
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
@@ -725,6 +725,17 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
return this;
}
+
+ /**
+ * Sets whether we should spoof locale to English for webpages.
+ *
+ * @param flag True if we should spoof locale to English for webpages, false otherwise.
+ * @return This Builder instance.
+ */
+ public @NonNull Builder spoofEnglish(final boolean flag) {
+ getSettings().mSpoofEnglish.set(flag ? 2 : 1);
+ return this;
+ }
}
private GeckoRuntime mRuntime;
@@ -856,6 +867,7 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
new PrefWithoutDefault<Boolean>("browser.crashReports.requestedNeverShowAgain");
/* package */ final PrefWithoutDefault<String> mCrliteChannel =
new PrefWithoutDefault<String>("security.pki.crlite_channel");
+ /* package */ final Pref<Integer> mSpoofEnglish = new Pref<>("privacy.spoof_english", 0);
/* package */ int mPreferredColorScheme = COLOR_SCHEME_SYSTEM;
@@ -2493,6 +2505,26 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
return mAppZygoteProcess;
}
+ /**
+ * Get whether we should spoof locale to English for webpages.
+ *
+ * @return Whether we should spoof locale to English for webpages.
+ */
+ public boolean getSpoofEnglish() {
+ return mSpoofEnglish.get() == 2;
+ }
+
+ /**
+ * Set whether we should spoof locale to English for webpages.
+ *
+ * @param flag A flag determining whether we should locale to English for webpages.
+ * @return This GeckoRuntimeSettings instance.
+ */
+ public @NonNull GeckoRuntimeSettings setSpoofEnglish(final boolean flag) {
+ mSpoofEnglish.commit(flag ? 2 : 1);
+ return this;
+ }
+
@Override // Parcelable
public void writeToParcel(final Parcel out, final int flags) {
super.writeToParcel(out, flags);
diff --git a/mobile/shared/components/geckoview/GeckoViewStartup.sys.mjs b/mobile/shared/components/geckoview/GeckoViewStartup.sys.mjs
@@ -12,6 +12,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
DoHController: "moz-src:///toolkit/components/doh/DoHController.sys.mjs",
EventDispatcher: "resource://gre/modules/Messaging.sys.mjs",
PdfJs: "resource://pdf.js/PdfJs.sys.mjs",
+ RFPHelper: "resource://gre/modules/RFPHelper.sys.mjs",
});
const { debug, warn } = GeckoViewUtils.initLogging("Startup");
@@ -368,6 +369,10 @@ export class GeckoViewStartup {
if (aData.requestedLocales) {
Services.locale.requestedLocales = aData.requestedLocales;
}
+ lazy.RFPHelper._handleSpoofEnglishChanged();
+ if (Services.prefs.getIntPref("privacy.spoof_english", 0) === 2) {
+ break;
+ }
const pls = Cc["@mozilla.org/pref-localizedstring;1"].createInstance(
Ci.nsIPrefLocalizedString
);