Chromium Code Reviews| Index: chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js |
| diff --git a/chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js b/chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js |
| index c8696a65fae22dd457c0f7d1137627805defb1e0..4f740c12063c6cd692f8b735e77a8c96e3d953a4 100644 |
| --- a/chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js |
| +++ b/chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js |
| @@ -20,8 +20,8 @@ function WallpaperManager(dialogDom) { |
| this.butterBar_ = new ButterBar(this.dialogDom_); |
| this.customWallpaperData_ = null; |
| this.currentWallpaper_ = null; |
| + this.wallpaperRequest_ = null; |
| this.fetchManifest_(); |
| - this.initDom_(); |
| } |
| // Anonymous 'namespace'. |
| @@ -83,29 +83,45 @@ function WallpaperManager(dialogDom) { |
| WallpaperManager.prototype.fetchManifest_ = function() { |
| var xhr = new XMLHttpRequest(); |
| var locale = navigator.language; |
| - var urls = [ |
| - ManifestBaseURL + locale + '.json', |
| - // Fallback url. Use 'en' locale by default. |
| - ManifestBaseURL + 'en.json']; |
| - |
| - for (var i = 0; i < urls.length; i++) { |
| - xhr.open('GET', urls[i], false); |
| - try { |
| - xhr.send(null); |
| + xhr.open('GET', ManifestBaseURL + locale + '.json', true); |
| + var self = this; |
| + try { |
| + xhr.send(null); |
| + xhr.addEventListener('load', function(e) { |
| // TODO(bshe): We should save the downloaded manifest to local disk. |
| // Other components may want to use it (i.e. screen saver). |
|
miket_OOO
2012/11/12 21:39:46
e.g., not i.e.
bshe
2012/11/12 22:24:28
Done.
|
| if (xhr.status === 200) { |
| - this.parseManifest_(xhr.responseText); |
| - return; |
| + self.parseManifest_(xhr.responseText); |
| + self.initDom_(); |
| + } else { |
| + // Fall back to en locale if current locale is not supported. |
| + var xhrFallBack = new XMLHttpRequest(); |
| + xhrFallBack.open('GET', ManifestBaseURL + 'en.json', true); |
| + try { |
| + xhrFallBack.send(null); |
| + xhrFallBack.addEventListener('load', function(e) { |
| + if (xhrFallBack.status === 200) { |
| + self.parseManifest_(xhrFallBack.responseText); |
| + } else { |
| + self.manifest_ = {}; |
| + self.butterBar_.showError_(str('connectionFailed')); |
|
miket_OOO
2012/11/12 21:39:46
What does the cast do here?
flackr
2012/11/12 22:00:34
str is a function which returns the localized stri
bshe
2012/11/12 22:24:28
you mean str('..')? It gets the localized string f
|
| + } |
| + self.initDom_(); |
| + }); |
| + } catch (e) { |
| + this.manifest_ = {}; |
| + this.butterBar_.showError_(str('connectionFailed')); |
| + self.initDom_(); |
| + return; |
|
flackr
2012/11/12 22:00:34
Is there a reason for unrolling the for loop into
bshe
2012/11/12 23:53:38
We now use async xmlhttp request. I wrote a sync l
flackr
2012/11/13 02:19:07
Ah of course, this can still be done asynchronousl
bshe
2012/11/13 15:24:46
Agree. I will keep it this way.
On 2012/11/13 02:
|
| + } |
| } |
| - } catch (e) { |
| + }); |
| + } catch (e) { |
| this.manifest_ = {}; |
| this.butterBar_.showError_(str('connectionFailed')); |
| + self.initDom_(); |
| return; |
| - } |
| } |
| - this.manifest_ = {}; |
| - this.butterBar_.showError_(str('connectionFailed')); |
| // TODO(bshe): Fall back to saved manifest if there is a problem fetching |
| // manifest from server. |