| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 * @typedef {{ | 6 * @typedef {{ |
| 7 * cache: (boolean|undefined), | 7 * cache: (boolean|undefined), |
| 8 * priority: (number|undefined), | 8 * priority: (number|undefined), |
| 9 * taskId: number, | 9 * taskId: number, |
| 10 * timestamp: (number|undefined), | 10 * timestamp: (number|undefined), |
| 11 * url: string | 11 * url: string, |
| 12 * orientation: ImageOrientation |
| 12 * }} | 13 * }} |
| 13 */ | 14 */ |
| 14 var LoadImageRequest; | 15 var LoadImageRequest; |
| 15 | 16 |
| 16 /** | 17 /** |
| 17 * Creates and starts downloading and then resizing of the image. Finally, | 18 * Creates and starts downloading and then resizing of the image. Finally, |
| 18 * returns the image using the callback. | 19 * returns the image using the callback. |
| 19 * | 20 * |
| 20 * @param {string} id Request ID. | 21 * @param {string} id Request ID. |
| 21 * @param {Cache} cache Cache object. | 22 * @param {Cache} cache Cache object. |
| 23 * @param {!PiexLoader} piexLoader Piex loader for RAW file. |
| 22 * @param {LoadImageRequest} request Request message as a hash array. | 24 * @param {LoadImageRequest} request Request message as a hash array. |
| 23 * @param {function(Object)} callback Callback used to send the response. | 25 * @param {function(Object)} callback Callback used to send the response. |
| 24 * @constructor | 26 * @constructor |
| 25 */ | 27 */ |
| 26 function Request(id, cache, request, callback) { | 28 function Request(id, cache, piexLoader, request, callback) { |
| 27 /** | 29 /** |
| 28 * @type {string} | 30 * @type {string} |
| 29 * @private | 31 * @private |
| 30 */ | 32 */ |
| 31 this.id_ = id; | 33 this.id_ = id; |
| 32 | 34 |
| 33 /** | 35 /** |
| 34 * @type {Cache} | 36 * @type {Cache} |
| 35 * @private | 37 * @private |
| 36 */ | 38 */ |
| 37 this.cache_ = cache; | 39 this.cache_ = cache; |
| 38 | 40 |
| 39 /** | 41 /** |
| 42 * @type {!PiexLoader} |
| 43 * @private |
| 44 */ |
| 45 this.piexLoader_ = piexLoader; |
| 46 |
| 47 /** |
| 40 * @type {LoadImageRequest} | 48 * @type {LoadImageRequest} |
| 41 * @private | 49 * @private |
| 42 */ | 50 */ |
| 43 this.request_ = request; | 51 this.request_ = request; |
| 44 | 52 |
| 45 /** | 53 /** |
| 46 * @type {function(Object)} | 54 * @type {function(Object)} |
| 47 * @private | 55 * @private |
| 48 */ | 56 */ |
| 49 this.sendResponse_ = callback; | 57 this.sendResponse_ = callback; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 }.bind(this); | 227 }.bind(this); |
| 220 | 228 |
| 221 // Download data urls directly since they are not supported by XmlHttpRequest. | 229 // Download data urls directly since they are not supported by XmlHttpRequest. |
| 222 var dataUrlMatches = this.request_.url.match(/^data:([^,;]*)[,;]/); | 230 var dataUrlMatches = this.request_.url.match(/^data:([^,;]*)[,;]/); |
| 223 if (dataUrlMatches) { | 231 if (dataUrlMatches) { |
| 224 this.image_.src = this.request_.url; | 232 this.image_.src = this.request_.url; |
| 225 this.contentType_ = dataUrlMatches[1]; | 233 this.contentType_ = dataUrlMatches[1]; |
| 226 return; | 234 return; |
| 227 } | 235 } |
| 228 | 236 |
| 237 // Load RAW images by using Piex loader instead of XHR. |
| 238 if (FileType.getTypeForName(this.request_.url).type === 'raw') { |
| 239 this.piexLoader_.load(this.request_.url).then(function(data) { |
| 240 var blob = new Blob([data.thumbnail], {type: 'image/jpeg'}); |
| 241 var url = URL.createObjectURL(blob); |
| 242 this.image_.src = url; |
| 243 this.request_.orientation = data.orientation; |
| 244 }.bind(this), function(error) { |
| 245 console.error('PiexLoaderError: ', error); |
| 246 onFailure(); |
| 247 }); |
| 248 return; |
| 249 } |
| 250 |
| 229 // Fetch the image via authorized XHR and parse it. | 251 // Fetch the image via authorized XHR and parse it. |
| 230 var parseImage = function(contentType, blob) { | 252 var parseImage = function(contentType, blob) { |
| 231 if (contentType) | 253 if (contentType) |
| 232 this.contentType_ = contentType; | 254 this.contentType_ = contentType; |
| 233 | |
| 234 this.image_.src = URL.createObjectURL(blob); | 255 this.image_.src = URL.createObjectURL(blob); |
| 235 }.bind(this); | 256 }.bind(this); |
| 236 | 257 |
| 237 // Request raw data via XHR. | 258 // Request raw data via XHR. |
| 238 this.xhr_.load(this.request_.url, parseImage, onFailure); | 259 this.xhr_.load(this.request_.url, parseImage, onFailure); |
| 239 }; | 260 }; |
| 240 | 261 |
| 241 /** | 262 /** |
| 242 * Creates a XmlHttpRequest wrapper with injected OAuth2 authentication headers. | 263 * Creates a XmlHttpRequest wrapper with injected OAuth2 authentication headers. |
| 243 * @constructor | 264 * @constructor |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 this.image_.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAA' + | 523 this.image_.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAA' + |
| 503 'ABAAEAAAICTAEAOw=='; | 524 'ABAAEAAAICTAEAOw=='; |
| 504 | 525 |
| 505 this.xhr_.onload = function() {}; | 526 this.xhr_.onload = function() {}; |
| 506 this.xhr_.abort(); | 527 this.xhr_.abort(); |
| 507 | 528 |
| 508 // Dispose memory allocated by Canvas. | 529 // Dispose memory allocated by Canvas. |
| 509 this.canvas_.width = 0; | 530 this.canvas_.width = 0; |
| 510 this.canvas_.height = 0; | 531 this.canvas_.height = 0; |
| 511 }; | 532 }; |
| OLD | NEW |