OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Namespace object for the utilities. | 5 // Namespace object for the utilities. |
6 var ImageUtil = {}; | 6 var ImageUtil = {}; |
7 | 7 |
8 /** | 8 /** |
9 * Performance trace. | 9 * Performance trace. |
10 */ | 10 */ |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 var tmpCallback = this.callback_; | 504 var tmpCallback = this.callback_; |
505 this.callback_ = null; | 505 this.callback_ = null; |
506 var emptyCanvas = assertInstanceof(this.document_.createElement('canvas'), | 506 var emptyCanvas = assertInstanceof(this.document_.createElement('canvas'), |
507 HTMLCanvasElement); | 507 HTMLCanvasElement); |
508 emptyCanvas.width = 0; | 508 emptyCanvas.width = 0; |
509 emptyCanvas.height = 0; | 509 emptyCanvas.height = 0; |
510 tmpCallback(emptyCanvas, opt_error); | 510 tmpCallback(emptyCanvas, opt_error); |
511 }; | 511 }; |
512 onError = onError.bind(this); | 512 onError = onError.bind(this); |
513 | 513 |
514 var loadImage = function() { | 514 var loadImage = function(url) { |
515 ImageUtil.metrics.startInterval(ImageUtil.getMetricName('LoadTime')); | 515 ImageUtil.metrics.startInterval(ImageUtil.getMetricName('LoadTime')); |
516 this.timeout_ = 0; | 516 this.timeout_ = 0; |
517 | 517 |
518 this.image_.onload = function() { | 518 this.image_.onload = function() { |
519 this.image_.onerror = null; | 519 this.image_.onerror = null; |
520 this.image_.onload = null; | 520 this.image_.onload = null; |
521 this.metadataModel_.get([entry], ['contentImageTransform']).then( | 521 this.metadataModel_.get([entry], ['contentImageTransform']).then( |
522 function(metadataItems) { | 522 function(metadataItems) { |
523 onTransform(this.image_, metadataItems[0].contentImageTransform); | 523 onTransform(this.image_, metadataItems[0].contentImageTransform); |
524 }.bind(this)); | 524 }.bind(this)); |
525 }.bind(this); | 525 }.bind(this); |
526 | 526 |
527 // The error callback has an optional error argument, which in case of a | 527 // The error callback has an optional error argument, which in case of a |
528 // general error should not be specified | 528 // general error should not be specified |
529 this.image_.onerror = onError.bind(this, 'GALLERY_IMAGE_ERROR'); | 529 this.image_.onerror = onError.bind(this, 'GALLERY_IMAGE_ERROR'); |
530 | 530 |
531 // Load the image directly. The query parameter is workaround for | 531 if (this.image_.src === url) |
yawano
2015/04/02 05:56:34
Why do you do this check here? Does it become to h
hirono
2015/04/02 07:55:47
There are two possible case.
* Currently SlideMo
| |
532 // crbug.com/379678, which force to update the contents of the image. | 532 this.image_.onload(); |
533 this.image_.src = entry.toURL() + '?nocache=' + Date.now(); | 533 else |
534 this.image_.src = url; | |
534 }.bind(this); | 535 }.bind(this); |
535 | 536 |
536 // Loads the image. If already loaded, then forces a reload. | 537 // Loads the image. If already loaded, then forces a reload. |
537 var startLoad = this.resetImage_.bind(this, function() { | 538 var startLoad = this.resetImage_.bind(this, function() { |
538 loadImage(); | 539 // Obtain target URL. |
540 if (FileType.isRaw(entry)) { | |
541 ImageLoaderClient.getInstance().load(entry.toURL(), function(result) { | |
542 loadImage(result.data); | |
yawano
2015/04/02 05:56:34
What happens if ImageLoaderClient fails to load an
hirono
2015/04/02 07:55:47
Done.
| |
543 }, { | |
544 cache: true, | |
545 timestamp: item.getMetadataItem().modificationTime && | |
546 item.getMetadataItem().modificationTime.getTime(), | |
547 priority: 0 // Use highest priority to show main image. | |
548 }); | |
549 return; | |
550 } | |
551 | |
552 // Load the image directly. The query parameter is workaround for | |
553 // crbug.com/379678, which force to update the contents of the image. | |
554 loadImage(entry.toURL() + '?nocache=' + Date.now()); | |
539 }.bind(this), onError); | 555 }.bind(this), onError); |
540 | 556 |
541 if (opt_delay) { | 557 if (opt_delay) { |
542 this.timeout_ = setTimeout(startLoad, opt_delay); | 558 this.timeout_ = setTimeout(startLoad, opt_delay); |
543 } else { | 559 } else { |
544 startLoad(); | 560 startLoad(); |
545 } | 561 } |
546 }; | 562 }; |
547 | 563 |
548 /** | 564 /** |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 ImageUtil.getMetricName = function(name) { | 741 ImageUtil.getMetricName = function(name) { |
726 return 'PhotoEditor.' + name; | 742 return 'PhotoEditor.' + name; |
727 }; | 743 }; |
728 | 744 |
729 /** | 745 /** |
730 * Used for metrics reporting, keep in sync with the histogram description. | 746 * Used for metrics reporting, keep in sync with the histogram description. |
731 * @type {Array.<string>} | 747 * @type {Array.<string>} |
732 * @const | 748 * @const |
733 */ | 749 */ |
734 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; | 750 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; |
OLD | NEW |