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); |
35 var self = this; | 39 var self = this; |
36 chrome.wallpaperPrivate.getThumbnail(this.dataItem.baseURL, | 40 xhr.addEventListener('load', function(e) { |
37 function(data) { | 41 if (xhr.status === 200) { |
38 if (data) { | 42 self.textContent = ''; |
39 var blob = new Blob([new Int8Array(data)]); | 43 imageEl.src = window.URL.createObjectURL(xhr.response); |
40 imageEl.src = window.URL.createObjectURL(blob); | |
41 imageEl.addEventListener('load', function(e) { | 44 imageEl.addEventListener('load', function(e) { |
42 window.URL.revokeObjectURL(this.src); | 45 window.URL.revokeObjectURL(this.src); |
43 }); | 46 }); |
44 self.appendChild(imageEl); | 47 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 }); | |
65 } | 48 } |
66 }); | 49 }); |
67 }, | 50 }, |
68 }; | 51 }; |
69 | 52 |
70 /** | 53 /** |
71 * Creates a selection controller that wraps selection on grid ends | 54 * Creates a selection controller that wraps selection on grid ends |
72 * and translates Enter presses into 'activate' events. | 55 * and translates Enter presses into 'activate' events. |
73 * @param {cr.ui.ListSelectionModel} selectionModel The selection model to | 56 * @param {cr.ui.ListSelectionModel} selectionModel The selection model to |
74 * interact with. | 57 * interact with. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 this.columns = 0; | 158 this.columns = 0; |
176 this.redraw(); | 159 this.redraw(); |
177 this.focus(); | 160 this.focus(); |
178 } | 161 } |
179 }; | 162 }; |
180 | 163 |
181 return { | 164 return { |
182 WallpaperThumbnailsGrid: WallpaperThumbnailsGrid | 165 WallpaperThumbnailsGrid: WallpaperThumbnailsGrid |
183 }; | 166 }; |
184 }); | 167 }); |
OLD | NEW |