Bug 1142758 - Use the getLocalizedValue language when falling back to manifest values r=ferjm
authorFabrice Desré <fabrice@mozilla.com>
Thu, 19 Mar 2015 10:06:32 -0700
changeset 263697 64bf333eab25b82847b87a1a48bd69a79f60209c
parent 263696 bb07b28bfd196346ad43bdfb96053e0e5004a105
child 263698 75e1ae7917ea701d0b9441296a1b8f5911f0ef39
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersferjm
bugs1142758
milestone39.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 1142758 - Use the getLocalizedValue language when falling back to manifest values r=ferjm
dom/apps/AppsUtils.jsm
dom/apps/Langpacks.jsm
dom/apps/Webapps.jsm
--- a/dom/apps/AppsUtils.jsm
+++ b/dom/apps/AppsUtils.jsm
@@ -780,36 +780,41 @@ this.AppsUtils = {
 
     return appsService.getManifestURLByLocalId(appId);
   },
 }
 
 /**
  * Helper object to access manifest information with locale support
  */
-this.ManifestHelper = function(aManifest, aOrigin, aManifestURL) {
+this.ManifestHelper = function(aManifest, aOrigin, aManifestURL, aLang) {
   // If the app is packaged, we resolve uris against the origin.
   // If it's not, against the manifest url.
 
   if (!aOrigin || !aManifestURL) {
     throw Error("ManifestHelper needs both origin and manifestURL");
   }
 
   this._baseURI = Services.io.newURI(
     aOrigin.startsWith("app://") ? aOrigin : aManifestURL, null, null);
 
   // We keep the manifest url in all cases since we need it to
   // resolve the package path for packaged apps.
   this._manifestURL = Services.io.newURI(aManifestURL, null, null);
 
   this._manifest = aManifest;
-  let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"]
-                 .getService(Ci.nsIXULChromeRegistry)
-                 .QueryInterface(Ci.nsIToolkitChromeRegistry);
-  let locale = chrome.getSelectedLocale("global").toLowerCase();
+
+  let locale = aLang;
+  if (!locale) {
+    let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"]
+                   .getService(Ci.nsIXULChromeRegistry)
+                   .QueryInterface(Ci.nsIToolkitChromeRegistry);
+    locale = chrome.getSelectedLocale("global").toLowerCase();
+  }
+
   this._localeRoot = this._manifest;
 
   if (this._manifest.locales && this._manifest.locales[locale]) {
     this._localeRoot = this._manifest.locales[locale];
   }
   else if (this._manifest.locales) {
     // try with the language part of the locale ("en" for en-GB) only
     let lang = locale.split('-')[0];
--- a/dom/apps/Langpacks.jsm
+++ b/dom/apps/Langpacks.jsm
@@ -240,17 +240,17 @@ this.Langpacks = {
           }
         },
         () => { getValueFromManifest(aManifest); }
       );
     }
 
     // We need to get the app with the manifest since the version is only
     // available in the manifest.
-    this._appFromManifestURL(aData.manifestURL, aData.entryPoint)
+    this._appFromManifestURL(aData.manifestURL, aData.entryPoint, aData.lang)
       .then(aApp => {
         let manifest = aApp.manifest;
 
         // No langpack for this app or we have langpack(s) for this app, but
         // not for this language.
         // Fallback to the manifest values.
         if (!this._data[aData.manifestURL] ||
             !this._data[aData.manifestURL].langs[aData.lang]) {
--- a/dom/apps/Webapps.jsm
+++ b/dom/apps/Webapps.jsm
@@ -4669,17 +4669,17 @@ this.DOMApplicationRegistry = {
     });
   },
 
   getAppByManifestURL: function(aManifestURL) {
     return AppsUtils.getAppByManifestURL(this.webapps, aManifestURL);
   },
 
   // Returns a promise that resolves to the app object with the manifest.
-  getFullAppByManifestURL: function(aManifestURL, aEntryPoint) {
+  getFullAppByManifestURL: function(aManifestURL, aEntryPoint, aLang) {
     let app = this.getAppByManifestURL(aManifestURL);
     if (!app) {
       return Promise.reject("NoSuchApp");
     }
 
     return this.getManifestFor(aManifestURL).then((aManifest) => {
       let manifest = aEntryPoint && aManifest.entry_points &&
                      aManifest.entry_points[aEntryPoint]
@@ -4687,17 +4687,18 @@ this.DOMApplicationRegistry = {
         : aManifest;
 
       // `version` doesn't change based on entry points, and we need it
       // to check langpack versions.
       if (manifest !== aManifest) {
         manifest.version = aManifest.version;
       }
 
-      app.manifest = new ManifestHelper(manifest, app.origin, app.manifestURL);
+      app.manifest =
+        new ManifestHelper(manifest, app.origin, app.manifestURL, aLang);
       return app;
     });
   },
 
   _getAppWithManifest: Task.async(function*(aManifestURL) {
     let app = this.getAppByManifestURL(aManifestURL);
     if (!app) {
       throw new Error("NO_SUCH_APP");