Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js

Issue 11028121: Convert wallpaper picker to v2 app (Closed) Base URL: http://git.chromium.org/chromium/src.git@AppsV2
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * WallpaperManager constructor. 6 * WallpaperManager constructor.
7 * 7 *
8 * WallpaperManager objects encapsulate the functionality of the wallpaper 8 * WallpaperManager objects encapsulate the functionality of the wallpaper
9 * manager extension. 9 * manager extension.
10 * 10 *
11 * @constructor 11 * @constructor
12 * @param {HTMLElement} dialogDom The DOM node containing the prototypical 12 * @param {HTMLElement} dialogDom The DOM node containing the prototypical
13 * extension UI. 13 * extension UI.
14 */ 14 */
15 15
16 function WallpaperManager(dialogDom) { 16 function WallpaperManager(dialogDom) {
17 this.dialogDom_ = dialogDom; 17 this.dialogDom_ = dialogDom;
18 this.document_ = dialogDom.ownerDocument; 18 this.document_ = dialogDom.ownerDocument;
19 this.selectedCategory = null; 19 this.selectedCategory = null;
20 this.butterBar_ = new ButterBar(this.dialogDom_); 20 this.butterBar_ = new ButterBar(this.dialogDom_);
21 this.customWallpaperData_ = null; 21 this.customWallpaperData_ = null;
22 this.currentWallpaper_ = null; 22 this.currentWallpaper_ = null;
23 this.wallpaperRequest_ = null;
23 this.fetchManifest_(); 24 this.fetchManifest_();
24 this.initDom_();
25 } 25 }
26 26
27 // Anonymous 'namespace'. 27 // Anonymous 'namespace'.
28 // TODO(bshe): Get rid of anonymous namespace. 28 // TODO(bshe): Get rid of anonymous namespace.
29 (function() { 29 (function() {
30 30
31 /** 31 /**
32 * Base URL of the manifest file. 32 * Base URL of the manifest file.
33 */ 33 */
34 /** @const */ var ManifestBaseURL = 'https://commondatastorage.googleapis.' + 34 /** @const */ var ManifestBaseURL = 'https://commondatastorage.googleapis.' +
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 this.manifest_ = {}; 76 this.manifest_ = {};
77 } 77 }
78 }; 78 };
79 79
80 /** 80 /**
81 * Requests wallpaper manifest file from server. 81 * Requests wallpaper manifest file from server.
82 */ 82 */
83 WallpaperManager.prototype.fetchManifest_ = function() { 83 WallpaperManager.prototype.fetchManifest_ = function() {
84 var xhr = new XMLHttpRequest(); 84 var xhr = new XMLHttpRequest();
85 var locale = navigator.language; 85 var locale = navigator.language;
86 var urls = [ 86 xhr.open('GET', ManifestBaseURL + locale + '.json', true);
87 ManifestBaseURL + locale + '.json', 87 var self = this;
88 // Fallback url. Use 'en' locale by default. 88 try {
89 ManifestBaseURL + 'en.json']; 89 xhr.send(null);
90 90 xhr.addEventListener('load', function(e) {
91 for (var i = 0; i < urls.length; i++) {
92 xhr.open('GET', urls[i], false);
93 try {
94 xhr.send(null);
95 // TODO(bshe): We should save the downloaded manifest to local disk. 91 // TODO(bshe): We should save the downloaded manifest to local disk.
96 // Other components may want to use it (i.e. screen saver). 92 // 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.
97 if (xhr.status === 200) { 93 if (xhr.status === 200) {
98 this.parseManifest_(xhr.responseText); 94 self.parseManifest_(xhr.responseText);
99 return; 95 self.initDom_();
96 } else {
97 // Fall back to en locale if current locale is not supported.
98 var xhrFallBack = new XMLHttpRequest();
99 xhrFallBack.open('GET', ManifestBaseURL + 'en.json', true);
100 try {
101 xhrFallBack.send(null);
102 xhrFallBack.addEventListener('load', function(e) {
103 if (xhrFallBack.status === 200) {
104 self.parseManifest_(xhrFallBack.responseText);
105 } else {
106 self.manifest_ = {};
107 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
108 }
109 self.initDom_();
110 });
111 } catch (e) {
112 this.manifest_ = {};
113 this.butterBar_.showError_(str('connectionFailed'));
114 self.initDom_();
115 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:
116 }
100 } 117 }
101 } catch (e) { 118 });
119 } catch (e) {
102 this.manifest_ = {}; 120 this.manifest_ = {};
103 this.butterBar_.showError_(str('connectionFailed')); 121 this.butterBar_.showError_(str('connectionFailed'));
122 self.initDom_();
104 return; 123 return;
105 }
106 } 124 }
107 this.manifest_ = {};
108 this.butterBar_.showError_(str('connectionFailed'));
109 125
110 // TODO(bshe): Fall back to saved manifest if there is a problem fetching 126 // TODO(bshe): Fall back to saved manifest if there is a problem fetching
111 // manifest from server. 127 // manifest from server.
112 }; 128 };
113 129
114 /** 130 /**
115 * One-time initialization of various DOM nodes. 131 * One-time initialization of various DOM nodes.
116 */ 132 */
117 WallpaperManager.prototype.initDom_ = function() { 133 WallpaperManager.prototype.initDom_ = function() {
118 i18nTemplate.process(this.document_, loadTimeData); 134 i18nTemplate.process(this.document_, loadTimeData);
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 selectedItem = wallpaperInfo; 418 selectedItem = wallpaperInfo;
403 } 419 }
404 } 420 }
405 } 421 }
406 this.wallpaperGrid_.dataModel = wallpapersDataModel; 422 this.wallpaperGrid_.dataModel = wallpapersDataModel;
407 this.wallpaperGrid_.selectedItem = selectedItem; 423 this.wallpaperGrid_.selectedItem = selectedItem;
408 } 424 }
409 }; 425 };
410 426
411 })(); 427 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698