[tbb-commits] [tor-browser/tor-browser-82.0-10.0-1] Bug 40199: Avoid using system locale for intl.accept_languages in GeckoView

sysrqb at torproject.org sysrqb at torproject.org
Fri Oct 23 18:06:34 UTC 2020


commit de1e216305d3d86ad9a5d925a668115e331685a2
Author: Alex Catarineu <acat at torproject.org>
Date:   Tue Oct 20 17:44:36 2020 +0200

    Bug 40199: Avoid using system locale for intl.accept_languages in GeckoView
---
 .../mozilla/geckoview/GeckoRuntimeSettings.java    | 26 +++++++++++++---------
 1 file changed, 16 insertions(+), 10 deletions(-)

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 85517821b59a..b7c080557470 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
@@ -783,19 +783,25 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
     private String computeAcceptLanguages() {
         ArrayList<String> locales = new ArrayList<String>();
 
-        // Explicitly-set app prefs come first:
-        if (mRequestedLocales != null) {
-            for (String locale : mRequestedLocales) {
-                locales.add(locale.toLowerCase());
-            }
-        }
-        // OS prefs come second:
-        for (String locale : getDefaultLocales()) {
-            locale = locale.toLowerCase();
-            if (!locales.contains(locale)) {
+        // 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();
+            // 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);
+                    }
+                }
             }
         }
+        locales.add("en-us");
+        locales.add("en");
 
         return TextUtils.join(",", locales);
     }





More information about the tbb-commits mailing list