Chromium Code Reviews| 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), |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 // Download data urls directly since they are not supported by XmlHttpRequest. | 230 // Download data urls directly since they are not supported by XmlHttpRequest. |
| 231 var dataUrlMatches = this.request_.url.match(/^data:([^,;]*)[,;]/); | 231 var dataUrlMatches = this.request_.url.match(/^data:([^,;]*)[,;]/); |
| 232 if (dataUrlMatches) { | 232 if (dataUrlMatches) { |
| 233 this.image_.src = this.request_.url; | 233 this.image_.src = this.request_.url; |
| 234 this.contentType_ = dataUrlMatches[1]; | 234 this.contentType_ = dataUrlMatches[1]; |
| 235 return; | 235 return; |
| 236 } | 236 } |
| 237 | 237 |
| 238 // Load RAW images by using Piex loader instead of XHR. | 238 // Load RAW images by using Piex loader instead of XHR. |
| 239 if (FileType.getTypeForName(this.request_.url).type === 'raw') { | 239 if (FileType.getTypeForName(this.request_.url).type === 'raw') { |
| 240 var startTime = new Date(); | |
|
Ben Kwa
2015/04/10 15:57:31
If you don't want to mess with raw Dates there's a
| |
| 240 this.piexLoader_.load(this.request_.url).then(function(data) { | 241 this.piexLoader_.load(this.request_.url).then(function(data) { |
| 242 this.recordRawLoadingTime_(this.request_.url, startTime, new Date()); | |
| 241 var blob = new Blob([data.thumbnail], {type: 'image/jpeg'}); | 243 var blob = new Blob([data.thumbnail], {type: 'image/jpeg'}); |
| 242 var url = URL.createObjectURL(blob); | 244 var url = URL.createObjectURL(blob); |
| 243 this.image_.src = url; | 245 this.image_.src = url; |
| 244 this.request_.orientation = data.orientation; | 246 this.request_.orientation = data.orientation; |
| 245 this.request_.colorSpace = data.colorSpace; | 247 this.request_.colorSpace = data.colorSpace; |
| 246 }.bind(this), function(error) { | 248 }.bind(this), function(error) { |
| 247 console.error('PiexLoaderError: ', error); | 249 console.error('PiexLoaderError: ', error); |
| 248 onFailure(); | 250 onFailure(); |
| 249 }); | 251 }); |
| 250 return; | 252 return; |
| 251 } | 253 } |
| 252 | 254 |
| 253 // Fetch the image via authorized XHR and parse it. | 255 // Fetch the image via authorized XHR and parse it. |
| 254 var parseImage = function(contentType, blob) { | 256 var parseImage = function(contentType, blob) { |
| 255 if (contentType) | 257 if (contentType) |
| 256 this.contentType_ = contentType; | 258 this.contentType_ = contentType; |
| 257 this.image_.src = URL.createObjectURL(blob); | 259 this.image_.src = URL.createObjectURL(blob); |
| 258 }.bind(this); | 260 }.bind(this); |
| 259 | 261 |
| 260 // Request raw data via XHR. | 262 // Request raw data via XHR. |
| 261 this.xhr_.load(this.request_.url, parseImage, onFailure); | 263 this.xhr_.load(this.request_.url, parseImage, onFailure); |
| 262 }; | 264 }; |
| 263 | 265 |
| 264 /** | 266 /** |
| 267 * Records loading time of RAW files. | |
| 268 * @param {string} url | |
| 269 * @param {!Date} startTime | |
| 270 * @param {!Date} endTime | |
| 271 */ | |
| 272 Request.prototype.recordRawLoadingTime_ = function(url, startTime, endTime) { | |
| 273 var type = FileType.getTypeForName(url); | |
| 274 var metricVariable; | |
| 275 switch (type.subtype) { | |
| 276 case 'ARW': | |
| 277 metricVariable = metrics.timing.Variables.RAW_LOAD_ARW; | |
| 278 break; | |
| 279 case 'CR2': | |
| 280 metricVariable = metrics.timing.Variables.RAW_LOAD_CR2; | |
| 281 break; | |
| 282 case 'DNG': | |
| 283 metricVariable = metrics.timing.Variables.RAW_LOAD_DNG; | |
| 284 break; | |
| 285 case 'NEF': | |
| 286 metricVariable = metrics.timing.Variables.RAW_LOAD_NEF; | |
| 287 break; | |
| 288 case 'NRW': | |
| 289 metricVariable = metrics.timing.Variables.RAW_LOAD_NRW; | |
| 290 break; | |
| 291 case 'ORF': | |
| 292 metricVariable = metrics.timing.Variables.RAW_LOAD_ORF; | |
| 293 break; | |
| 294 case 'RAF': | |
| 295 metricVariable = metrics.timing.Variables.RAW_LOAD_RAF; | |
| 296 break; | |
| 297 case 'RW2': | |
| 298 metricVariable = metrics.timing.Variables.RAW_LOAD_RW2; | |
| 299 break; | |
| 300 default: | |
| 301 console.error('Invalid RAW type: ' + type.subtype + '.'); | |
| 302 return; | |
| 303 } | |
| 304 metrics.getTracker().sendTiming( | |
| 305 metrics.Categories.RAW_IMAGE, | |
| 306 metricVariable, | |
| 307 endTime.getTime() - startTime.getTime()); | |
| 308 }; | |
| 309 | |
| 310 /** | |
| 265 * Creates a XmlHttpRequest wrapper with injected OAuth2 authentication headers. | 311 * Creates a XmlHttpRequest wrapper with injected OAuth2 authentication headers. |
| 266 * @constructor | 312 * @constructor |
| 267 */ | 313 */ |
| 268 function AuthorizedXHR() { | 314 function AuthorizedXHR() { |
| 269 this.xhr_ = null; | 315 this.xhr_ = null; |
| 270 this.aborted_ = false; | 316 this.aborted_ = false; |
| 271 } | 317 } |
| 272 | 318 |
| 273 /** | 319 /** |
| 274 * A map which is used to estimate content type from extension. | 320 * A map which is used to estimate content type from extension. |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 this.image_.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAA' + | 573 this.image_.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAA' + |
| 528 'ABAAEAAAICTAEAOw=='; | 574 'ABAAEAAAICTAEAOw=='; |
| 529 | 575 |
| 530 this.xhr_.onload = function() {}; | 576 this.xhr_.onload = function() {}; |
| 531 this.xhr_.abort(); | 577 this.xhr_.abort(); |
| 532 | 578 |
| 533 // Dispose memory allocated by Canvas. | 579 // Dispose memory allocated by Canvas. |
| 534 this.canvas_.width = 0; | 580 this.canvas_.width = 0; |
| 535 this.canvas_.height = 0; | 581 this.canvas_.height = 0; |
| 536 }; | 582 }; |
| OLD | NEW |