[tbb-commits] [Git][tpo/applications/tor-browser][tor-browser-115.11.0esr-13.0-1] 2 commits: fixup! Bug 40199: Avoid using system locale for intl.accept_languages in GeckoView
Pier Angelo Vendrame (@pierov)
git at gitlab.torproject.org
Mon May 13 09:45:39 UTC 2024
Pier Angelo Vendrame pushed to branch tor-browser-115.11.0esr-13.0-1 at The Tor Project / Applications / Tor Browser
Commits:
eb5afe56 by Pier Angelo Vendrame at 2024-05-13T11:45:28+02:00
fixup! Bug 40199: Avoid using system locale for intl.accept_languages in GeckoView
Revert "Bug 40199: Avoid using system locale for intl.accept_languages in GeckoView"
This reverts commit ff97b6fb06850784785e6993c256bef315b2525f.
- - - - -
970e6b90 by Pier Angelo Vendrame at 2024-05-13T11:45:30+02:00
Bug 42562: Normalized the Accepted Languages on Android.
The OS language might be outside the list of actually supported
languages and it might leak the user's region.
Therefore, we force the locale reported in Accept-Language to match one
we support with translations, even when it means using a not exact
region tag.
- - - - -
1 changed file:
- mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
Changes:
=====================================
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
=====================================
@@ -22,7 +22,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
import java.util.Locale;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoSystemStateListener;
@@ -455,6 +456,16 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
return this;
}
+ public @NonNull Builder supportedLocales(final Collection<String> locales) {
+ getSettings().mSupportedLocales.clear();
+ for (String tag : locales) {
+ Locale locale = Locale.forLanguageTag(tag);
+ getSettings().mSupportedLocales.put(locale, locale);
+ getSettings().mSupportedLocales.put(new Locale(locale.getLanguage()), locale);
+ }
+ return this;
+ }
+
/**
* Sets whether we should spoof locale to English for webpages.
*
@@ -539,6 +550,7 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
/* package */ int mScreenHeightOverride;
/* package */ Class<? extends Service> mCrashHandler;
/* package */ String[] mRequestedLocales;
+ /* package */ HashMap<Locale, Locale> mSupportedLocales = new HashMap<>();
/* package */ RuntimeTelemetry.Proxy mTelemetryProxy;
/**
@@ -595,6 +607,7 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
mRequestedLocales = settings.mRequestedLocales;
mConfigFilePath = settings.mConfigFilePath;
mTelemetryProxy = settings.mTelemetryProxy;
+ mSupportedLocales = settings.mSupportedLocales;
}
/* package */ void commit() {
@@ -803,30 +816,39 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
EventDispatcher.getInstance().dispatch("GeckoView:SetLocale", data);
}
+ private Locale getLocaleIfSupported(String tag) {
+ Locale exact = Locale.forLanguageTag(tag);
+ if (mSupportedLocales.containsKey(exact)) {
+ return exact;
+ }
+ Locale fallback = new Locale(exact.getLanguage());
+ return mSupportedLocales.get(fallback);
+ }
+
private String computeAcceptLanguages() {
- final ArrayList<String> locales = new ArrayList<String>();
-
- // In Desktop, these are defined in the `intl.accept_languages` localized property.
- // At some point we should probably use the same values here, but for now we use a simple
- // strategy which will hopefully result in reasonable acceptLanguage values.
- if (mRequestedLocales != null && mRequestedLocales.length > 0) {
- String locale = mRequestedLocales[0].toLowerCase(Locale.ROOT);
- // No need to include `en-us` twice.
- if (!locale.equals("en-us")) {
- locales.add(locale);
- if (locale.contains("-")) {
- String lang = locale.split("-")[0];
- // No need to include `en` twice.
- if (!lang.equals("en")) {
- locales.add(lang);
- }
+ Locale locale = null;
+ if (mRequestedLocales != null) {
+ for (String tag : mRequestedLocales) {
+ locale = getLocaleIfSupported(tag);
+ if (locale != null) {
+ break;
}
}
}
- locales.add("en-us");
- locales.add("en");
-
- return TextUtils.join(",", locales);
+ if (locale == null) {
+ for (final String tag : getDefaultLocales()) {
+ locale = getLocaleIfSupported(tag);
+ if (locale != null) {
+ break;
+ }
+ }
+ }
+ String acceptLanguages = locale != null ? locale.toString().replace('_', '-') : "en-US";
+ if (acceptLanguages.equals("en-US")) {
+ // For consistency with spoof English.
+ acceptLanguages += ", en";
+ }
+ return acceptLanguages;
}
private static String[] getDefaultLocales() {
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/f87ae3f10dfb2a8f7cb182465cea4ff091fae6f2...970e6b90b0bd924e8042416cdf878694fc4dad7d
--
This project does not include diff previews in email notifications.
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/f87ae3f10dfb2a8f7cb182465cea4ff091fae6f2...970e6b90b0bd924e8042416cdf878694fc4dad7d
You're receiving this email because of your account on gitlab.torproject.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20240513/79e83db0/attachment-0001.htm>
More information about the tbb-commits
mailing list