Bug 669154 - Dont open locale picker window if the system locale is available. r=mfinkle, a=mfinkle
authorWes Johnston <wjohnston@mozilla.com>
Tue, 12 Jul 2011 10:25:35 -0700
changeset 72694 df47e2abac6c8b8b647e4cac5c2de572492bd3a9
parent 72693 183f76b8367b906fb0a4f326dbd4204221f6e97c
child 72695 d78bbed90c65b77bcdb4616816b80426e29aab61
push id241
push userwjohnston@mozilla.com
push dateWed, 20 Jul 2011 21:00:44 +0000
treeherdermozilla-aurora@df47e2abac6c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, mfinkle
bugs669154
milestone7.0a2
Bug 669154 - Dont open locale picker window if the system locale is available. r=mfinkle, a=mfinkle
mobile/chrome/content/localePicker.js
mobile/components/BrowserCLH.js
--- a/mobile/chrome/content/localePicker.js
+++ b/mobile/chrome/content/localePicker.js
@@ -312,53 +312,34 @@ function localesMatch(aLocale1, aLocale2
   let short1 = aLocale1.split("-")[0];
   let short2 = aLocale2.split("-")[0];
   return (short1 == short2) ? GOOD_MATCH : NO_MATCH;
 }
 
 function start() {
   let mouseModule = new MouseModule();
 
+  // if we have gotten this far, we can assume that we don't have anything matching the system
+  // locale and we should show the locale picker
   let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry);
   chrome.QueryInterface(Ci.nsIToolkitChromeRegistry);
   let availableLocales = chrome.getLocalesForPackage("browser");
-
-  let localeService = Cc["@mozilla.org/intl/nslocaleservice;1"].getService(Ci.nsILocaleService);
-  let systemLocale = localeService.getSystemLocale().getCategory("NSILOCALE_CTYPE");
-  let matchingLocale = "";
-
-  let bestMatch = NO_MATCH;
-
   let strings = Services.strings.createBundle("chrome://browser/content/languages.properties");
   LocaleUI.availableLocales = [];
   while (availableLocales.hasMore()) {
     let locale = availableLocales.getNext();
 
     let label = locale;
     try { label = strings.GetStringFromName(locale); }
     catch (e) { }
     LocaleUI.availableLocales.push({addon: { id: locale, name: label, targetLocale: locale }});
-
-    // see if we have a locale that looks like the system locale
-    // if it is not the current locale, switch to it
-    let match = localesMatch(systemLocale, locale);
-    if (match > bestMatch) {
-      bestMatch = match;
-      matchingLocale = locale;
-    }
   }
 
-  if (matchingLocale) {
-    if (matchingLocale != chrome.getSelectedLocale("browser"))
-      LocaleUI.language = matchingLocale;
-    LocaleUI.closeWindow();
-  } else {
-    LocaleUI._language = chrome.getSelectedLocale("browser");
-    LocaleUI.updateStrings();
-  }
+  LocaleUI._language = chrome.getSelectedLocale("browser");
+  LocaleUI.updateStrings();
 
   // update the page strings and show the correct page
   LocaleUI.defaultLanguage = LocaleUI._language;
   window.addEventListener("resize", resizeHandler, false);
 }
 
 function resizeHandler() {
   let elements = document.getElementsByClassName("window-width");
--- a/mobile/components/BrowserCLH.js
+++ b/mobile/components/BrowserCLH.js
@@ -115,16 +115,33 @@ function getHomePage() {
 }
 
 function showPanelWhenReady(aWindow, aPage) {
   aWindow.addEventListener("UIReadyDelayed", function(aEvent) {
     aWindow.BrowserUI.showPanel(aPage);
   }, false);
 }
 
+function haveSystemLocale() {
+  let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry);
+  chrome.QueryInterface(Ci.nsIToolkitChromeRegistry);
+  let availableLocales = chrome.getLocalesForPackage("browser");
+
+  let localeService = Cc["@mozilla.org/intl/nslocaleservice;1"].getService(Ci.nsILocaleService);
+  let systemLocale = localeService.getSystemLocale().getCategory("NSILOCALE_CTYPE");
+  systemLocale = systemLocale.split("-")[0];
+  let systemLocaleRegEx = new RegExp("^" + systemLocale);
+
+  while (availableLocales.hasMore()) {
+    let locale = availableLocales.getNext();
+    if (systemLocaleRegEx.test(locale))
+      return true;
+  }
+  return false;
+}
 
 function BrowserCLH() { }
 
 BrowserCLH.prototype = {
   //
   // nsICommandLineHandler
   //
   handle: function fs_handle(aCmdLine) {
@@ -202,17 +219,17 @@ BrowserCLH.prototype = {
 
         // Override the default if we have a URL passed on command line
         if (uris.length > 0) {
           defaultURL = uris[0].spec;
           uris = uris.slice(1);
         }
 
         // Show the locale selector if we have a new profile
-        if (needHomepageOverride() == "new profile" && Services.prefs.getBoolPref("browser.firstrun.show.localepicker")) {
+        if (needHomepageOverride() == "new profile" && Services.prefs.getBoolPref("browser.firstrun.show.localepicker") && !haveSystemLocale()) {
           win = openWindow(null, "chrome://browser/content/localePicker.xul", "_blank", "chrome,dialog=no,all", defaultURL);
           aCmdLine.preventDefault = true;
           return;
         }
 
         win = openWindow(null, "chrome://browser/content/browser.xul", "_blank", "chrome,dialog=no,all", defaultURL);
       }