OLD | NEW |
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.fetchManifest_(); | 23 this.fetchManifest_(); |
24 this.initDom_(); | |
25 } | 24 } |
26 | 25 |
27 // Anonymous 'namespace'. | 26 // Anonymous 'namespace'. |
28 // TODO(bshe): Get rid of anonymous namespace. | 27 // TODO(bshe): Get rid of anonymous namespace. |
29 (function() { | 28 (function() { |
30 | 29 |
31 /** | 30 /** |
32 * Base URL of the manifest file. | 31 * Base URL of the manifest file. |
33 */ | 32 */ |
34 /** @const */ var ManifestBaseURL = 'https://commondatastorage.googleapis.' + | 33 /** @const */ var ManifestBaseURL = 'https://commondatastorage.googleapis.' + |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 this.manifest_ = {}; | 75 this.manifest_ = {}; |
77 } | 76 } |
78 }; | 77 }; |
79 | 78 |
80 /** | 79 /** |
81 * Requests wallpaper manifest file from server. | 80 * Requests wallpaper manifest file from server. |
82 */ | 81 */ |
83 WallpaperManager.prototype.fetchManifest_ = function() { | 82 WallpaperManager.prototype.fetchManifest_ = function() { |
84 var xhr = new XMLHttpRequest(); | 83 var xhr = new XMLHttpRequest(); |
85 var locale = navigator.language; | 84 var locale = navigator.language; |
86 xhr.open('GET', ManifestBaseURL + locale + '.json', false); | 85 xhr.open('GET', ManifestBaseURL + locale + '.json', true); |
87 xhr.send(null); | 86 xhr.send(null); |
88 // TODO(bshe): We should save the downloaded manifest to local disk. Other | 87 var self = this; |
89 // components may want to use it (i.e. screen saver). | 88 |
90 if (xhr.status === 200) { | 89 xhr.addEventListener('load', function(e) { |
91 this.parseManifest_(xhr.responseText); | 90 // TODO(bshe): We should save the downloaded manifest to local disk. Other |
92 } else { | 91 // components may want to use it (i.e. screen saver). |
93 // Fall back to en locale if current locale is not supported. | |
94 xhr.open('GET', ManifestBaseURL + 'en.json', false); | |
95 xhr.send(null); | |
96 if (xhr.status === 200) { | 92 if (xhr.status === 200) { |
97 this.parseManifest_(xhr.responseText); | 93 self.parseManifest_(xhr.responseText); |
| 94 self.initDom_(); |
98 } else { | 95 } else { |
99 this.manifest_ = {}; | 96 // Fall back to en locale if current locale is not supported. |
100 this.butterBar_.showError_(str('connectionFailed')); | 97 xhr.open('GET', ManifestBaseURL + 'en.json', true); |
| 98 xhr.send(null); |
| 99 xhr.addEventListener('load', function(e) { |
| 100 if (xhr.status === 200) { |
| 101 self.parseManifest_(xhr.responseText); |
| 102 } else { |
| 103 self.manifest_ = {}; |
| 104 self.butterBar_.showError_(str('connectionFailed')); |
| 105 } |
| 106 self.initDom_(); |
| 107 }); |
101 } | 108 } |
102 } | 109 }); |
103 | 110 |
104 // TODO(bshe): Fall back to saved manifest if there is a problem fetching | 111 // TODO(bshe): Fall back to saved manifest if there is a problem fetching |
105 // manifest from server. | 112 // manifest from server. |
106 }; | 113 }; |
107 | 114 |
108 /** | 115 /** |
109 * One-time initialization of various DOM nodes. | 116 * One-time initialization of various DOM nodes. |
110 */ | 117 */ |
111 WallpaperManager.prototype.initDom_ = function() { | 118 WallpaperManager.prototype.initDom_ = function() { |
112 i18nTemplate.process(this.document_, loadTimeData); | 119 i18nTemplate.process(this.document_, loadTimeData); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 selectedItem = wallpaperInfo; | 384 selectedItem = wallpaperInfo; |
378 } | 385 } |
379 } | 386 } |
380 } | 387 } |
381 this.wallpaperGrid_.dataModel = wallpapersDataModel; | 388 this.wallpaperGrid_.dataModel = wallpapersDataModel; |
382 this.wallpaperGrid_.selectedItem = selectedItem; | 389 this.wallpaperGrid_.selectedItem = selectedItem; |
383 } | 390 } |
384 }; | 391 }; |
385 | 392 |
386 })(); | 393 })(); |
OLD | NEW |