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 cr.define('wallpapers', function() { | 5 cr.define('wallpapers', function() { |
6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
7 /** @const */ var Grid = cr.ui.Grid; | 7 /** @const */ var Grid = cr.ui.Grid; |
8 /** @const */ var GridItem = cr.ui.GridItem; | 8 /** @const */ var GridItem = cr.ui.GridItem; |
9 /** @const */ var GridSelectionController = cr.ui.GridSelectionController; | 9 /** @const */ var GridSelectionController = cr.ui.GridSelectionController; |
10 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 10 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
(...skipping 14 matching lines...) Expand all Loading... |
25 return el; | 25 return el; |
26 } | 26 } |
27 | 27 |
28 WallpaperThumbnailsGridItem.prototype = { | 28 WallpaperThumbnailsGridItem.prototype = { |
29 __proto__: GridItem.prototype, | 29 __proto__: GridItem.prototype, |
30 | 30 |
31 /** @override */ | 31 /** @override */ |
32 decorate: function() { | 32 decorate: function() { |
33 GridItem.prototype.decorate.call(this); | 33 GridItem.prototype.decorate.call(this); |
34 var imageEl = cr.doc.createElement('img'); | 34 var imageEl = cr.doc.createElement('img'); |
35 var xhr = new XMLHttpRequest(); | |
36 xhr.open('GET', this.dataItem.baseURL + ThumbnailSuffix, true); | |
37 xhr.responseType = 'blob'; | |
38 xhr.send(null); | |
39 var self = this; | 35 var self = this; |
40 xhr.addEventListener('load', function(e) { | 36 chrome.wallpaperPrivate.getThumbnail(this.dataItem.baseURL, |
41 if (xhr.status === 200) { | 37 function(data) { |
42 self.textContent = ''; | 38 if (data) { |
43 imageEl.src = window.URL.createObjectURL(xhr.response); | 39 var blob = new Blob([new Int8Array(data)]); |
| 40 imageEl.src = window.URL.createObjectURL(blob); |
44 imageEl.addEventListener('load', function(e) { | 41 imageEl.addEventListener('load', function(e) { |
45 window.URL.revokeObjectURL(this.src); | 42 window.URL.revokeObjectURL(this.src); |
46 }); | 43 }); |
47 self.appendChild(imageEl); | 44 self.appendChild(imageEl); |
| 45 } else { |
| 46 var xhr = new XMLHttpRequest(); |
| 47 xhr.open('GET', self.dataItem.baseURL + ThumbnailSuffix, true); |
| 48 xhr.responseType = 'arraybuffer'; |
| 49 xhr.send(null); |
| 50 xhr.addEventListener('load', function(e) { |
| 51 if (xhr.status === 200) { |
| 52 self.textContent = ''; |
| 53 chrome.wallpaperPrivate.saveThumbnail(self.dataItem.baseURL, |
| 54 xhr.response); |
| 55 var blob = new Blob([new Int8Array(xhr.response)]); |
| 56 imageEl.src = window.URL.createObjectURL(blob); |
| 57 // TODO(bshe): We currently use empty div to reserve space for |
| 58 // thumbnail. Use a placeholder like "loading" image may better. |
| 59 imageEl.addEventListener('load', function(e) { |
| 60 window.URL.revokeObjectURL(this.src); |
| 61 }); |
| 62 self.appendChild(imageEl); |
| 63 } |
| 64 }); |
48 } | 65 } |
49 }); | 66 }); |
50 }, | 67 }, |
51 }; | 68 }; |
52 | 69 |
53 /** | 70 /** |
54 * Creates a selection controller that wraps selection on grid ends | 71 * Creates a selection controller that wraps selection on grid ends |
55 * and translates Enter presses into 'activate' events. | 72 * and translates Enter presses into 'activate' events. |
56 * @param {cr.ui.ListSelectionModel} selectionModel The selection model to | 73 * @param {cr.ui.ListSelectionModel} selectionModel The selection model to |
57 * interact with. | 74 * interact with. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 this.columns = 0; | 175 this.columns = 0; |
159 this.redraw(); | 176 this.redraw(); |
160 this.focus(); | 177 this.focus(); |
161 } | 178 } |
162 }; | 179 }; |
163 | 180 |
164 return { | 181 return { |
165 WallpaperThumbnailsGrid: WallpaperThumbnailsGrid | 182 WallpaperThumbnailsGrid: WallpaperThumbnailsGrid |
166 }; | 183 }; |
167 }); | 184 }); |
OLD | NEW |