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 * |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 this.wallpaperRequest_.open('GET', wallpaperURL, true); | 186 this.wallpaperRequest_.open('GET', wallpaperURL, true); |
187 this.wallpaperRequest_.responseType = 'arraybuffer'; | 187 this.wallpaperRequest_.responseType = 'arraybuffer'; |
188 this.wallpaperRequest_.send(null); | 188 this.wallpaperRequest_.send(null); |
189 this.butterBar_.setRequest(this.wallpaperRequest_); | 189 this.butterBar_.setRequest(this.wallpaperRequest_); |
190 var self = this; | 190 var self = this; |
191 this.wallpaperRequest_.addEventListener('load', function(e) { | 191 this.wallpaperRequest_.addEventListener('load', function(e) { |
192 if (self.wallpaperRequest_.status === 200) { | 192 if (self.wallpaperRequest_.status === 200) { |
193 var image = self.wallpaperRequest_.response; | 193 var image = self.wallpaperRequest_.response; |
194 chrome.wallpaperPrivate.setWallpaper(image, | 194 chrome.wallpaperPrivate.setWallpaper(image, |
195 selectedItem.layout, | 195 selectedItem.layout, |
196 wallpaperURL); | 196 wallpaperURL, |
| 197 self.onFinished_.bind(self)); |
197 self.currentWallpaper_ = wallpaperURL; | 198 self.currentWallpaper_ = wallpaperURL; |
198 } else { | 199 } else { |
199 self.butterBar_.showError_(str('downloadFailed')); | 200 self.butterBar_.showError_(str('downloadFailed')); |
200 } | 201 } |
201 self.wallpaperRequest_ = null; | 202 self.wallpaperRequest_ = null; |
202 }); | 203 }); |
203 } | 204 } |
204 this.setWallpaperAttribution_(selectedItem); | 205 this.setWallpaperAttribution_(selectedItem); |
205 }; | 206 }; |
206 | 207 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 302 |
302 /** | 303 /** |
303 * Refreshes the custom wallpaper with the current selected layout. | 304 * Refreshes the custom wallpaper with the current selected layout. |
304 * @param {ArrayBuffer} customWallpaper The raw wallpaper file data. | 305 * @param {ArrayBuffer} customWallpaper The raw wallpaper file data. |
305 */ | 306 */ |
306 WallpaperManager.prototype.refreshWallpaper_ = function(customWallpaper) { | 307 WallpaperManager.prototype.refreshWallpaper_ = function(customWallpaper) { |
307 var setWallpaperLayout = $('set-wallpaper-layout'); | 308 var setWallpaperLayout = $('set-wallpaper-layout'); |
308 var layout = | 309 var layout = |
309 setWallpaperLayout.options[setWallpaperLayout.selectedIndex].value; | 310 setWallpaperLayout.options[setWallpaperLayout.selectedIndex].value; |
310 chrome.wallpaperPrivate.setCustomWallpaper(customWallpaper, | 311 chrome.wallpaperPrivate.setCustomWallpaper(customWallpaper, |
311 layout); | 312 layout, |
| 313 this.onFinished_.bind(this)); |
312 this.currentWallpaper_ = 'CUSTOM'; | 314 this.currentWallpaper_ = 'CUSTOM'; |
313 }; | 315 }; |
314 | 316 |
315 /** | 317 /** |
| 318 * Sets wallpaper finished. Displays error message in butter bar if any. |
| 319 * @param {string} error Error message passed by Chrome when setting |
| 320 * wallpaper. Empty string is passed if success. |
| 321 */ |
| 322 WallpaperManager.prototype.onFinished_ = function(error) { |
| 323 if (error) |
| 324 this.butterBar_.showError_(error); |
| 325 else |
| 326 this.butterBar_.hide_(); |
| 327 }; |
| 328 |
| 329 /** |
316 * Handles the layout setting change of custom wallpaper. | 330 * Handles the layout setting change of custom wallpaper. |
317 */ | 331 */ |
318 WallpaperManager.prototype.onWallpaperLayoutChanged_ = function() { | 332 WallpaperManager.prototype.onWallpaperLayoutChanged_ = function() { |
319 if (this.customWallpaperData_) | 333 if (this.customWallpaperData_) |
320 this.refreshWallpaper_(this.customWallpaperData_); | 334 this.refreshWallpaper_(this.customWallpaperData_); |
321 }; | 335 }; |
322 | 336 |
323 /** | 337 /** |
324 * Generates a thumbnail of user selected image file. | 338 * Generates a thumbnail of user selected image file. |
325 * @param {Object} file The file user selected from file manager. | 339 * @param {Object} file The file user selected from file manager. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 selectedItem = wallpaperInfo; | 391 selectedItem = wallpaperInfo; |
378 } | 392 } |
379 } | 393 } |
380 } | 394 } |
381 this.wallpaperGrid_.dataModel = wallpapersDataModel; | 395 this.wallpaperGrid_.dataModel = wallpapersDataModel; |
382 this.wallpaperGrid_.selectedItem = selectedItem; | 396 this.wallpaperGrid_.selectedItem = selectedItem; |
383 } | 397 } |
384 }; | 398 }; |
385 | 399 |
386 })(); | 400 })(); |
OLD | NEW |