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

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

Issue 11280300: Revert 171011 - Broke Linux ChromiumOS Tests (dbg)(2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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 | Annotate | Revision Log
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.storage_ = chrome.storage.local;
19 this.document_ = dialogDom.ownerDocument; 18 this.document_ = dialogDom.ownerDocument;
20 this.selectedCategory = null; 19 this.selectedCategory = null;
21 this.butterBar_ = new ButterBar(this.dialogDom_); 20 this.butterBar_ = new ButterBar(this.dialogDom_);
22 this.customWallpaperData_ = null; 21 this.customWallpaperData_ = null;
23 this.currentWallpaper_ = null; 22 this.currentWallpaper_ = null;
24 this.wallpaperRequest_ = null; 23 this.wallpaperRequest_ = null;
25 this.fetchManifest_(); 24 this.fetchManifest_();
26 } 25 }
27 26
28 // Anonymous 'namespace'. 27 // Anonymous 'namespace'.
29 // TODO(bshe): Get rid of anonymous namespace. 28 // TODO(bshe): Get rid of anonymous namespace.
30 (function() { 29 (function() {
31 30
32 /** 31 /**
33 * Base URL of the manifest file. 32 * Base URL of the manifest file.
34 */ 33 */
35 /** @const */ var ManifestBaseURL = 'https://commondatastorage.googleapis.' + 34 /** @const */ var ManifestBaseURL = 'https://commondatastorage.googleapis.' +
36 'com/chromeos-wallpaper-public/manifest_'; 35 'com/chromeos-wallpaper-public/manifest_';
37 36
38 /** 37 /**
39 * Suffix to append to baseURL if requesting high resoultion wallpaper. 38 * Suffix to append to baseURL if requesting high resoultion wallpaper.
40 */ 39 */
41 /** @const */ var HighResolutionSuffix = '_high_resolution.jpg'; 40 /** @const */ var HighResolutionSuffix = '_high_resolution.jpg';
42 41
43 /** 42 /**
44 * Key to access wallpaper manifest in chrome.local.storage.
45 */
46 /** @const */ var AccessManifestKey = 'wallpaper-picker-manifest-key';
47
48 /**
49 * Returns a translated string. 43 * Returns a translated string.
50 * 44 *
51 * Wrapper function to make dealing with translated strings more concise. 45 * Wrapper function to make dealing with translated strings more concise.
52 * Equivilant to localStrings.getString(id). 46 * Equivilant to localStrings.getString(id).
53 * 47 *
54 * @param {string} id The id of the string to return. 48 * @param {string} id The id of the string to return.
55 * @return {string} The translated string. 49 * @return {string} The translated string.
56 */ 50 */
57 function str(id) { 51 function str(id) {
58 return loadTimeData.getString(id); 52 return loadTimeData.getString(id);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 loop.next(); 112 loop.next();
119 } 113 }
120 }); 114 });
121 xhr.open('GET', url, true); 115 xhr.open('GET', url, true);
122 xhr.send(null); 116 xhr.send(null);
123 } catch (e) { 117 } catch (e) {
124 loop.failure(); 118 loop.failure();
125 } 119 }
126 }; 120 };
127 121
128 if (navigator.onLine) { 122 asyncFetchManifestFromUrls(urls, fetchManifestAsync,
129 asyncFetchManifestFromUrls(urls, fetchManifestAsync, 123 this.onLoadManifestSuccess_.bind(this),
130 this.onLoadManifestSuccess_.bind(this), 124 this.onLoadManifestFailed_.bind(this));
131 this.onLoadManifestFailed_.bind(this));
132 } else {
133 // If device is offline, fetches manifest from local storage.
134 // TODO(bshe): Always loading the offline manifest first and replacing
135 // with the online one when available.
136 this.onLoadManifestFailed_();
137 }
138 }; 125 };
139 126
140 /** 127 /**
141 * Sets manifest loaded from server. Called after manifest is successfully 128 * Sets manifest loaded from server. Called after manifest is successfully
142 * loaded. 129 * loaded.
143 * @param {object} manifest The parsed manifest file. 130 * @param {object} manifest The parsed manifest file.
144 */ 131 */
145 WallpaperManager.prototype.onLoadManifestSuccess_ = function(manifest) { 132 WallpaperManager.prototype.onLoadManifestSuccess_ = function(manifest) {
146 this.manifest_ = manifest; 133 this.manifest_ = manifest;
147 var items = {};
148 items[AccessManifestKey] = manifest;
149 this.storage_.set(items, function() {});
150 this.initDom_(); 134 this.initDom_();
151 }; 135 };
152 136
153 // Sets manifest to previously saved object if any and shows connection error. 137 // Sets manifest to an empty object and shows connection error. Called after
154 // Called after manifest failed to load. 138 // manifest failed to load.
155 WallpaperManager.prototype.onLoadManifestFailed_ = function() { 139 WallpaperManager.prototype.onLoadManifestFailed_ = function() {
156 var self = this; 140 // TODO(bshe): Fall back to saved manifest if there is a problem fetching
157 this.storage_.get(AccessManifestKey, function(items) { 141 // manifest from server.
158 self.manifest_ = items[AccessManifestKey] ? items[AccessManifestKey] : {}; 142 this.manifest_ = {};
159 self.butterBar_.showError_(str('connectionFailed'), 143 this.butterBar_.showError_(str('connectionFailed'),
160 {help_url: LEARN_MORE_URL}); 144 {help_url: LEARN_MORE_URL});
161 self.initDom_(); 145 this.initDom_();
162 });
163 }; 146 };
164 147
165 /** 148 /**
166 * One-time initialization of various DOM nodes. 149 * One-time initialization of various DOM nodes.
167 */ 150 */
168 WallpaperManager.prototype.initDom_ = function() { 151 WallpaperManager.prototype.initDom_ = function() {
169 i18nTemplate.process(this.document_, loadTimeData); 152 i18nTemplate.process(this.document_, loadTimeData);
170 this.initCategoriesList_(); 153 this.initCategoriesList_();
171 this.initThumbnailsGrid_(); 154 this.initThumbnailsGrid_();
172 155
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 selectedItem = wallpaperInfo; 441 selectedItem = wallpaperInfo;
459 } 442 }
460 } 443 }
461 } 444 }
462 this.wallpaperGrid_.dataModel = wallpapersDataModel; 445 this.wallpaperGrid_.dataModel = wallpapersDataModel;
463 this.wallpaperGrid_.selectedItem = selectedItem; 446 this.wallpaperGrid_.selectedItem = selectedItem;
464 } 447 }
465 }; 448 };
466 449
467 })(); 450 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698