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 /** @inheritDoc */ | 31 /** @inheritDoc */ |
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(result) { |
42 self.textContent = ''; | 38 if (result.success) { |
43 imageEl.src = window.URL.createObjectURL(xhr.response); | 39 var data = new Int8Array(result.data); |
40 var blob = new Blob([data]); | |
41 imageEl.src = window.URL.createObjectURL(blob); | |
44 imageEl.addEventListener('load', function(e) { | 42 imageEl.addEventListener('load', function(e) { |
45 window.URL.revokeObjectURL(this.src); | 43 window.URL.revokeObjectURL(this.src); |
46 }); | 44 }); |
47 self.appendChild(imageEl); | 45 self.appendChild(imageEl); |
46 } else { | |
47 var xhr = new XMLHttpRequest(); | |
48 xhr.open('GET', self.dataItem.baseURL + ThumbnailSuffix, true); | |
49 xhr.responseType = 'arraybuffer'; | |
50 xhr.send(null); | |
51 xhr.addEventListener('load', function(e) { | |
52 if (xhr.status === 200) { | |
53 self.textContent = ''; | |
54 chrome.wallpaperPrivate.saveThumbnail(xhr.response, | |
55 self.dataItem.baseURL); | |
56 var data = new Int8Array(xhr.response); | |
57 var blob = new Blob([data]); | |
flackr
2012/11/27 22:04:36
Combine these two lines, you only use data here.
bshe
2012/11/28 18:54:26
Done.
flackr
2012/12/03 19:02:30
This doesn't look done.
bshe
2012/12/03 19:39:32
Sorry. I changed the one at line 38 but somehow fo
| |
58 imageEl.src = window.URL.createObjectURL(blob); | |
59 imageEl.addEventListener('load', function(e) { | |
60 window.URL.revokeObjectURL(this.src); | |
61 }); | |
62 self.appendChild(imageEl); | |
flackr
2012/11/27 22:04:36
The list of thumbnails grow as we fetch them? We s
bshe
2012/11/28 18:54:26
The img tag is added to a div. And the div has wid
flackr
2012/12/03 19:02:30
Yes that sounds good to me.
| |
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 |