Bug 675252 - Store buildid when locales are installed and make sure it is current on startup. r=mfinkle
authorWes Johnston <wjohnston@mozilla.com>
Fri, 02 Sep 2011 09:37:54 -0700
changeset 76473 4dad5acf5a1eef83ac96a1fd60245b9a9c393b39
parent 76472 b47c8ec93ccb9beaea96be9ddf180601b76e25ae
child 76474 c8cd6f227ead2c458492ece453c83c5f8d7e3a28
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersmfinkle
bugs675252
milestone9.0a1
Bug 675252 - Store buildid when locales are installed and make sure it is current on startup. r=mfinkle
mobile/app/mobile.js
mobile/chrome/content/localePicker.js
mobile/components/BrowserCLH.js
mobile/components/UpdatePrompt.js
--- a/mobile/app/mobile.js
+++ b/mobile/app/mobile.js
@@ -212,16 +212,17 @@ pref("extensions.getAddons.recommended.b
 pref("extensions.getAddons.recommended.url", "https://services.addons.mozilla.org/%LOCALE%/mobile/api/%API_VERSION%/list/featured/all/%MAX_RESULTS%/%OS%/%VERSION%");
 pref("extensions.getAddons.search.browseURL", "https://addons.mozilla.org/%LOCALE%/mobile/search?q=%TERMS%");
 pref("extensions.getAddons.search.url", "https://services.addons.mozilla.org/%LOCALE%/mobile/api/%API_VERSION%/search/%TERMS%/all/%MAX_RESULTS%/%OS%/%VERSION%");
 pref("extensions.getAddons.browseAddons", "https://addons.mozilla.org/%LOCALE%/mobile/");
 pref("extensions.getAddons.get.url", "https://services.addons.mozilla.org/%LOCALE%/mobile/api/%API_VERSION%/search/guid:%IDS%?src=mobile&appOS=%OS%&appVersion=%VERSION%&tMain=%TIME_MAIN%&tFirstPaint=%TIME_FIRST_PAINT%&tSessionRestored=%TIME_SESSION_RESTORED%");
 
 /* preference for the locale picker */
 pref("extensions.getLocales.get.url", "");
+pref("extensions.compatability.locales.buildid", "0");
 
 /* blocklist preferences */
 pref("extensions.blocklist.enabled", true);
 pref("extensions.blocklist.interval", 86400);
 pref("extensions.blocklist.url", "https://addons.mozilla.org/blocklist/3/%APP_ID%/%APP_VERSION%/%PRODUCT%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/%PING_COUNT%/%TOTAL_PING_COUNT%/%DAYS_SINCE_LAST_PING%/");
 pref("extensions.blocklist.detailsURL", "https://www.mozilla.com/%LOCALE%/blocklist/");
 
 /* block popups by default, and notify the user about blocked popups */
--- a/mobile/chrome/content/localePicker.js
+++ b/mobile/chrome/content/localePicker.js
@@ -209,16 +209,18 @@ let LocaleUI = {
       this._currentInstall = null;
     // restore the last known "good" locale
     this.locale = this.defaultLocale;
     this.updateStrings();
     this.closePicker();
   },
 
   closeWindow : function() {
+    var buildID =  Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo).platformBuildID;
+    Services.prefs.setCharPref("extensions.compatability.locales.buildid", buildID);
     // Trying to close this window and open a new one results in a corrupt UI.
     if (LocaleUI._currentInstall) {
       // a new locale was installed, restart the browser
       let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
       Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
     
       if (cancelQuit.data == false) {
         let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
--- a/mobile/components/BrowserCLH.js
+++ b/mobile/components/BrowserCLH.js
@@ -121,16 +121,22 @@ function showPanelWhenReady(aWindow, aPa
 function haveSystemLocale() {
   let localeService = Cc["@mozilla.org/intl/nslocaleservice;1"].getService(Ci.nsILocaleService);
   let systemLocale = localeService.getSystemLocale().getCategory("NSILOCALE_CTYPE");
   return isLocaleAvailable(systemLocale);
 }
 
 function checkCurrentLocale() {
   if (Services.prefs.prefHasUserValue("general.useragent.locale")) {
+    // if the user has a compatable locale from a different buildid, we need to update
+    var buildID = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo).appBuildID;
+    let localeBuildID = Services.prefs.getCharPref("extensions.compatability.locales.buildid");
+    if (buildID != localeBuildID)
+      return false;
+
     let currentLocale = Services.prefs.getCharPref("general.useragent.locale");
     return isLocaleAvailable(currentLocale);
   }
   return true;
 }
 
 function isLocaleAvailable(aLocale) {
   let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry);
@@ -234,17 +240,17 @@ BrowserCLH.prototype = {
         let defaultURL = getHomePage();
 
         // 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
+        // Show the locale selector if we have a new profile, or if the selected locale is no longer compatible
         let showLocalePicker = Services.prefs.getBoolPref("browser.firstrun.show.localepicker")
         if ((needHomepageOverride() == "new profile" && showLocalePicker && !haveSystemLocale()) || !checkCurrentLocale()) {
           browserWin = openWindow(null, "chrome://browser/content/localePicker.xul", "_blank", "chrome,dialog=no,all", defaultURL);
           aCmdLine.preventDefault = true;
           return;
         }
 
         browserWin = openWindow(null, "chrome://browser/content/browser.xul", "_blank", "chrome,dialog=no,all", defaultURL);
--- a/mobile/components/UpdatePrompt.js
+++ b/mobile/components/UpdatePrompt.js
@@ -233,16 +233,19 @@ UpdatePrompt.prototype = {
     LocaleRepository.getLocales((function(aLocales) {
       aLocales.forEach(function(aLocale, aIndex, aArray) {
         let index = aPending.indexOf(aLocale.addon.id);
         if (index > -1) {
           aListener._installing.push(aLocale.addon.id);
           aLocale.addon.install.install();
         }
       }, this);
+      // store the buildid of these locales so that we can disable locales when the
+      // user updates through a non-updater channel
+      Services.prefs.setCharPref("extensions.compatability.locales.buildid", aUpdate.buildID);
     }).bind(this), { buildID: aUpdate.buildID });
   },
 
   showUpdateInstalled: function UP_showUpdateInstalled() {
     if (!this._enabled || !getPref("getBoolPref", "app.update.showInstalledUI", false))
       return;
 
     let title = gBrandBundle.GetStringFromName("brandShortName");