Bug 1542566 - Put Android system locale before app default in Accept-Language. r=snorp
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 07 May 2019 22:03:04 +0000
changeset 472975 e20b442b0ee386a6bd20b562d0e381eec4f41ca5
parent 472974 ac53bb1ed24af124bdb644067dda1fd7a41f4924
child 472976 7f32b838169018a9355ccba9a243bd311e319aed
push id35983
push userncsoregi@mozilla.com
push dateWed, 08 May 2019 03:38:51 +0000
treeherdermozilla-central@0e9e744accd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1542566
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1542566 - Put Android system locale before app default in Accept-Language. r=snorp Differential Revision: https://phabricator.services.mozilla.com/D29906
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -1766,19 +1766,17 @@ var BrowserApp = {
 
         console.log("New OS locale.");
 
         // Ensure that this choice is immediately persisted, because
         // Gecko won't be told again if it forgets.
         Services.prefs.setCharPref("intl.locale.os", languageTag);
         Services.prefs.savePrefFile(null);
 
-        let appLocale = this.getUALocalePref();
-
-        this.computeAcceptLanguages(languageTag, appLocale);
+        this.computeAcceptLanguages(languageTag);
 
         // Rebuild strings, in case we're mirroring OS locale.
         Strings.flush();
         break;
       }
 
       case "Locale:Changed": {
         if (data) {
@@ -1790,17 +1788,17 @@ var BrowserApp = {
         console.log("Gecko display locale: " + this.getUALocalePref());
 
         // Rebuild strings to reflect the new locale.
         Strings.flush();
 
         // Make sure we use the right Accept-Language header.
         let osLocale = Services.prefs.getCharPref("intl.locale.os");
 
-        this.computeAcceptLanguages(osLocale, data && data.languageTag);
+        this.computeAcceptLanguages(osLocale);
         break;
       }
 
       case "Passwords:Init": {
         let storage = Cc["@mozilla.org/login-manager/storage/mozStorage;1"].
                       getService(Ci.nsILoginManagerStorage);
         storage.initialize();
         GlobalEventDispatcher.unregisterListener(this, event);
@@ -2148,64 +2146,62 @@ var BrowserApp = {
    * Set intl.accept_languages accordingly.
    *
    * After Bug 881510 this will also accept a real Accept-Language choice as
    * input; all Accept-Language logic lives here.
    *
    * osLocale should never be null, but this method is safe regardless.
    * appLocale may explicitly be null.
    */
-  computeAcceptLanguages(osLocale, appLocale) {
+  computeAcceptLanguages(osLocale) {
     let defaultBranch = Services.prefs.getDefaultBranch(null);
     let defaultAccept = defaultBranch.getComplexValue("intl.accept_languages", Ci.nsIPrefLocalizedString).data;
     console.log("Default intl.accept_languages = " + defaultAccept);
 
     // A guard for potential breakage. Bug 438031.
     // This should not be necessary, because we're reading from the default branch,
     // but better safe than sorry.
     if (defaultAccept && defaultAccept.startsWith("chrome://")) {
       defaultAccept = null;
     } else {
       // Ensure lowercase everywhere so we can compare.
       defaultAccept = defaultAccept.toLowerCase();
     }
 
-    if (appLocale) {
-      appLocale = appLocale.toLowerCase();
-    }
-
     try {
         const resistFingerprinting = Services.prefs.getBoolPref("privacy.resistFingerprinting");
         if (resistFingerprinting) {
           osLocale = null;
         }
     } catch (e) {}
 
+    // Explicitly-set app prefs come first:
+    let chosen = Services.prefs.getCharPref("intl.locale.requested", "")
+                               .split(",")
+                               .map((x) => x.trim().toLowerCase())
+                               .filter((x) => x.length > 0);
+
+    // OS prefs come second:
     if (osLocale) {
       osLocale = osLocale.toLowerCase();
-    }
-
-    // Eliminate values if they're present in the default.
-    let chosen;
+      if (!chosen.includes(osLocale)) {
+        chosen.push(osLocale);
+      }
+    }
+
+    // Default app prefs come third:
     if (defaultAccept) {
       // intl.accept_languages is a comma-separated list, with no q-value params. Those
       // are added when the header is generated.
-      chosen = defaultAccept.split(",")
-                            .map((x) => x.trim())
-                            .filter((x) => (x != appLocale && x != osLocale));
-    } else {
-      chosen = [];
-    }
-
-    if (osLocale) {
-      chosen.unshift(osLocale);
-    }
-
-    if (appLocale && appLocale != osLocale) {
-      chosen.unshift(appLocale);
+      let defaults = defaultAccept.split(",").map((x) => x.trim());
+      for (let locale of defaults) {
+        if (!chosen.includes(locale)) {
+          chosen.push(locale);
+        }
+      }
     }
 
     let result = chosen.join(",");
     console.log("Setting intl.accept_languages to " + result);
     this.setLocalizedPref("intl.accept_languages", result);
   },
 
   // nsIAndroidBrowserApp