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

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

Issue 10978022: Center wallpaper picker when open and open author's website in a new window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only allow one instance of wallpaper picker. Created 8 years, 2 months 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 *
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } else { 168 } else {
169 window.close(); 169 window.close();
170 } 170 }
171 }; 171 };
172 172
173 /** 173 /**
174 * Sets wallpaper to the corresponding wallpaper of selected thumbnail. 174 * Sets wallpaper to the corresponding wallpaper of selected thumbnail.
175 */ 175 */
176 WallpaperManager.prototype.onThumbnailClicked_ = function() { 176 WallpaperManager.prototype.onThumbnailClicked_ = function() {
177 var selectedItem = this.wallpaperGrid_.selectedItem; 177 var selectedItem = this.wallpaperGrid_.selectedItem;
178 if (!selectedItem || !selectedItem.dynamicURL || 178 if (selectedItem && selectedItem.dynamicURL &&
179 this.wallpaperGrid_.inProgramSelection) 179 !this.wallpaperGrid_.inProgramSelection) {
180 return; 180 var wallpaperURL = selectedItem.baseURL + HighResolutionSuffix;
181 181
182 // TODO(bshe): Only download one high resolution wallpaper from server. 182 if (this.wallpaperRequest_)
183 // Resize the high resolution wallpaper to screen sized wallpaper for 183 this.wallpaperRequest_.abort();
184 // devices with small screen.
185 var wallpaperURL = selectedItem.baseURL + HighResolutionSuffix;
186 184
187 if (this.wallpaperRequest_) 185 this.wallpaperRequest_ = new XMLHttpRequest();
188 this.wallpaperRequest_.abort(); 186 this.wallpaperRequest_.open('GET', wallpaperURL, true);
189 // TODO(bshe): XMLHttpRequest may be cancelled by window.close(). We should 187 this.wallpaperRequest_.responseType = 'arraybuffer';
190 // either wait for response before closing window or use an extension 188 this.wallpaperRequest_.send(null);
191 // background page to get response afte window closed. 189 this.butterBar_.setRequest(this.wallpaperRequest_);
192 this.wallpaperRequest_ = new XMLHttpRequest(); 190 var self = this;
193 this.wallpaperRequest_.open('GET', wallpaperURL, true); 191 this.wallpaperRequest_.addEventListener('load', function(e) {
194 this.wallpaperRequest_.responseType = 'arraybuffer'; 192 if (self.wallpaperRequest_.status === 200) {
195 this.wallpaperRequest_.send(null); 193 var image = self.wallpaperRequest_.response;
196 this.butterBar_.setRequest(this.wallpaperRequest_); 194 chrome.wallpaperPrivate.setWallpaper(image,
197 var self = this; 195 selectedItem.layout,
198 this.wallpaperRequest_.addEventListener('load', function(e) { 196 wallpaperURL);
199 if (self.wallpaperRequest_.status === 200) { 197 self.currentWallpaper_ = wallpaperURL;
200 var image = self.wallpaperRequest_.response; 198 } else {
201 chrome.wallpaperPrivate.setWallpaper(image, 199 self.butterBar_.showError_(str('downloadFailed'));
202 selectedItem.layout, 200 }
203 wallpaperURL); 201 self.wallpaperRequest_ = null;
204 self.currentWallpaper_ = wallpaperURL; 202 });
205 } else { 203 }
206 self.butterBar_.showError_(str('downloadFailed'));
207 }
208 self.wallpaperRequest_ = null;
209 });
210 this.setWallpaperAttribution_(selectedItem); 204 this.setWallpaperAttribution_(selectedItem);
211 }; 205 };
212 206
213 /** 207 /**
214 * Set attributions of wallpaper with given URL. If URL is not valid, clear 208 * Set attributions of wallpaper with given URL. If URL is not valid, clear
215 * the attributions. 209 * the attributions.
216 * @param {{baseURL: string, dynamicURL: string, layout: string, 210 * @param {{baseURL: string, dynamicURL: string, layout: string,
217 * author: string, authorWebsite: string}} 211 * author: string, authorWebsite: string}}
218 * selectedItem selected wallpaper item in grid. 212 * selectedItem selected wallpaper item in grid.
219 * @private 213 * @private
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 selectedItem = wallpaperInfo; 377 selectedItem = wallpaperInfo;
384 } 378 }
385 } 379 }
386 } 380 }
387 this.wallpaperGrid_.dataModel = wallpapersDataModel; 381 this.wallpaperGrid_.dataModel = wallpapersDataModel;
388 this.wallpaperGrid_.selectedItem = selectedItem; 382 this.wallpaperGrid_.selectedItem = selectedItem;
389 } 383 }
390 }; 384 };
391 385
392 })(); 386 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698