| Index: chrome/browser/resources/file_manager/js/media/media_util.js
|
| diff --git a/chrome/browser/resources/file_manager/js/media/media_util.js b/chrome/browser/resources/file_manager/js/media/media_util.js
|
| index 2d105007d7baf423fbb954fe5a2aefaedfa77772..c4a58400a2f0d92544f3af1a25db4987c56d483c 100644
|
| --- a/chrome/browser/resources/file_manager/js/media/media_util.js
|
| +++ b/chrome/browser/resources/file_manager/js/media/media_util.js
|
| @@ -12,9 +12,14 @@
|
| * default: IMAGE.
|
| * @param {Object=} opt_metadata Metadata object.
|
| * @param {string=} opt_mediaType Media type.
|
| + * @param {ThumbnailLoader.UseEmbedded=} opt_useEmbedded If to use embedded
|
| + * jpeg thumbnail if available. Default: USE_EMBEDDED.
|
| * @constructor
|
| */
|
| -function ThumbnailLoader(url, opt_loaderType, opt_metadata, opt_mediaType) {
|
| +function ThumbnailLoader(
|
| + url, opt_loaderType, opt_metadata, opt_mediaType, opt_useEmbedded) {
|
| + opt_useEmbedded = opt_useEmbedded || ThumbnailLoader.UseEmbedded.USE_EMBEDDED;
|
| +
|
| this.mediaType_ = opt_mediaType || FileType.getMediaType(url);
|
| this.loaderType_ = opt_loaderType || ThumbnailLoader.LoaderType.IMAGE;
|
|
|
| @@ -35,7 +40,8 @@ function ThumbnailLoader(url, opt_loaderType, opt_metadata, opt_mediaType) {
|
| }
|
| }
|
|
|
| - if (opt_metadata.thumbnail && opt_metadata.thumbnail.url) {
|
| + if (opt_metadata.thumbnail && opt_metadata.thumbnail.url &&
|
| + opt_useEmbedded == ThumbnailLoader.UseEmbedded.USE_EMBEDDED) {
|
| this.thumbnailUrl_ = opt_metadata.thumbnail.url;
|
| this.transform_ = opt_metadata.thumbnail.transform;
|
| } else if (FileType.isImage(url)) {
|
| @@ -85,6 +91,16 @@ ThumbnailLoader.LoaderType = {
|
| };
|
|
|
| /**
|
| + * Whether to use the embedded thumbnail, or not. The embedded thumbnail may
|
| + * be small.
|
| + * @enum {number}
|
| + */
|
| +ThumbnailLoader.UseEmbedded = {
|
| + USE_EMBEDDED: 0,
|
| + NO_EMBEDDED: 1
|
| +};
|
| +
|
| +/**
|
| * Maximum thumbnail's width when generating from the full resolution image.
|
| * @const
|
| * @type {number}
|
| @@ -122,6 +138,7 @@ ThumbnailLoader.prototype.load = function(box, fillMode, opt_optimizationMode,
|
| return;
|
| }
|
|
|
| + this.cancel();
|
| this.canvasUpToDate_ = false;
|
| this.image_ = new Image();
|
| this.image_.onload = function() {
|
| @@ -150,7 +167,7 @@ ThumbnailLoader.prototype.load = function(box, fillMode, opt_optimizationMode,
|
|
|
| // TODO(mtomasz): Smarter calculation of the requested size.
|
| var wasAttached = box.ownerDocument.contains(box);
|
| - var taskId = util.loadImage(
|
| + this.taskId_ = util.loadImage(
|
| this.image_,
|
| this.thumbnailUrl_,
|
| { maxWidth: ThumbnailLoader.THUMBNAIL_MAX_WIDTH,
|
| @@ -166,11 +183,22 @@ ThumbnailLoader.prototype.load = function(box, fillMode, opt_optimizationMode,
|
| return true;
|
| });
|
|
|
| - if (!taskId)
|
| + if (!this.taskId_)
|
| this.image_.classList.add('cached');
|
| };
|
|
|
| /**
|
| + * Cancels loading the current image.
|
| + */
|
| +ThumbnailLoader.prototype.cancel = function() {
|
| + if (this.taskId_) {
|
| + this.image_.onload = function() {};
|
| + this.image_.onerror = function() {};
|
| + util.cancelLoadImage(this.taskId_);
|
| + }
|
| +};
|
| +
|
| +/**
|
| * @return {boolean} True if a valid image is loaded.
|
| */
|
| ThumbnailLoader.prototype.hasValidImage = function() {
|
| @@ -211,20 +239,21 @@ ThumbnailLoader.prototype.loadDetachedImage = function(callback) {
|
| return;
|
| }
|
|
|
| + this.cancel();
|
| this.canvasUpToDate_ = false;
|
| this.image_ = new Image();
|
| this.image_.onload = callback.bind(null, true);
|
| this.image_.onerror = callback.bind(null, false);
|
|
|
| // TODO(mtomasz): Smarter calculation of the requested size.
|
| - var taskId = util.loadImage(
|
| + this.taskId_ = util.loadImage(
|
| this.image_,
|
| this.thumbnailUrl_,
|
| { maxWidth: ThumbnailLoader.THUMBNAIL_MAX_WIDTH,
|
| maxHeight: ThumbnailLoader.THUMBNAIL_MAX_HEIGHT,
|
| cache: true });
|
|
|
| - if (!taskId)
|
| + if (!this.taskId_)
|
| this.image_.classList.add('cached');
|
| };
|
|
|
| @@ -263,7 +292,7 @@ ThumbnailLoader.prototype.attachImage = function(container, fillMode) {
|
| util.applyTransform(container, this.transform_);
|
| ThumbnailLoader.centerImage_(
|
| container, attachableMedia, fillMode, this.isRotated_());
|
| - if (this.image_.parentNode != container) {
|
| + if (attachableMedia.parentNode != container) {
|
| container.textContent = '';
|
| container.appendChild(attachableMedia);
|
| }
|
|
|