Index: chrome/browser/resources/file_manager/foreground/js/image_editor/image_view.js |
diff --git a/chrome/browser/resources/file_manager/foreground/js/image_editor/image_view.js b/chrome/browser/resources/file_manager/foreground/js/image_editor/image_view.js |
index 7c3bd5621ef0a46e9b028502f0e44419499f30b5..40c20a2f0ed4a5392e6e21a2f8c60c56ff635805 100644 |
--- a/chrome/browser/resources/file_manager/foreground/js/image_editor/image_view.js |
+++ b/chrome/browser/resources/file_manager/foreground/js/image_editor/image_view.js |
@@ -46,8 +46,8 @@ function ImageView(container, viewport, metadataCache) { |
*/ |
this.screenImage_ = null; |
- this.localImageTransformFetcher_ = function(url, callback) { |
- metadataCache.get(url, 'fetchedMedia', function(fetchedMedia) { |
+ this.localImageTransformFetcher_ = function(entry, callback) { |
+ metadataCache.get(entry, 'fetchedMedia', function(fetchedMedia) { |
callback(fetchedMedia.imageTransform); |
}); |
}; |
@@ -296,7 +296,7 @@ ImageView.prototype.cancelLoad = function() { |
* Loads the thumbnail first, then replaces it with the main image. |
* Takes into account the image orientation encoded in the metadata. |
* |
- * @param {string} url Image url. |
+ * @param {Entry} entry Image entry. |
hirono
2013/12/09 06:53:50
FileEntry?
mtomasz
2013/12/10 02:37:34
Done.
|
* @param {Object} metadata Metadata. |
* @param {Object} effect Transition effect object. |
* @param {function(number} displayCallback Called when the image is displayed |
@@ -304,7 +304,7 @@ ImageView.prototype.cancelLoad = function() { |
* @param {function(number} loadCallback Called when the image is fully loaded. |
* The parameter is the load type. |
*/ |
-ImageView.prototype.load = function(url, metadata, effect, |
+ImageView.prototype.load = function(entry, metadata, effect, |
displayCallback, loadCallback) { |
if (effect) { |
// Skip effects when reloading repeatedly very quickly. |
@@ -322,10 +322,10 @@ ImageView.prototype.load = function(url, metadata, effect, |
var self = this; |
- this.contentID_ = url; |
+ this.contentEntry_ = entry; |
this.contentRevision_ = -1; |
- var loadingVideo = FileType.getMediaType(url) == 'video'; |
+ var loadingVideo = FileType.getMediaType(entry) == 'video'; |
if (loadingVideo) { |
var video = this.document_.createElement('video'); |
var videoPreview = !!(metadata.thumbnail && metadata.thumbnail.url); |
@@ -356,7 +356,7 @@ ImageView.prototype.load = function(url, metadata, effect, |
video.addEventListener('loadedmetadata', onVideoLoadSuccess); |
video.addEventListener('error', onVideoLoadError); |
- video.src = url; |
+ video.src = entry.toURL(); |
video.load(); |
return; |
} |
@@ -365,12 +365,12 @@ ImageView.prototype.load = function(url, metadata, effect, |
// evicted later by the prefetched image. |
this.contentCache_.evictLRU(); |
- var cached = this.contentCache_.getItem(this.contentID_); |
+ var cached = this.contentCache_.getItem(this.contentEntry_); |
if (cached) { |
displayMainImage(ImageView.LOAD_TYPE_CACHED_FULL, |
false /* no preview */, cached); |
} else { |
- var cachedScreen = this.screenCache_.getItem(this.contentID_); |
+ var cachedScreen = this.screenCache_.getItem(this.contentEntry_); |
var imageWidth = metadata.media && metadata.media.width || |
metadata.drive && metadata.drive.imageWidth; |
var imageHeight = metadata.media && metadata.media.height || |
@@ -396,7 +396,7 @@ ImageView.prototype.load = function(url, metadata, effect, |
success ? thumbnailLoader.getImage() : null); |
}); |
} else { |
- loadMainImage(ImageView.LOAD_TYPE_IMAGE_FILE, url, |
+ loadMainImage(ImageView.LOAD_TYPE_IMAGE_FILE, entry, |
false /* no preview*/, 0 /* delay */); |
} |
} |
@@ -411,12 +411,12 @@ ImageView.prototype.load = function(url, metadata, effect, |
true /* preview */); |
if (displayCallback) displayCallback(); |
} |
- loadMainImage(loadType, url, !!canvas, |
+ loadMainImage(loadType, entry, !!canvas, |
(effect && canvas) ? effect.getSafeInterval() : 0); |
} |
- function loadMainImage(loadType, contentURL, previewShown, delay) { |
- if (self.prefetchLoader_.isLoading(contentURL)) { |
+ function loadMainImage(loadType, contentEntry, previewShown, delay) { |
+ if (self.prefetchLoader_.isLoading(contentEntry)) { |
// The image we need is already being prefetched. Initiating another load |
// would be a waste. Hijack the load instead by overriding the callback. |
self.prefetchLoader_.setCallback( |
@@ -431,7 +431,7 @@ ImageView.prototype.load = function(url, metadata, effect, |
self.prefetchLoader_.cancel(); // The prefetch was doing something useless. |
self.imageLoader_.load( |
- contentURL, |
+ contentEntry, |
self.localImageTransformFetcher_, |
displayMainImage.bind(null, loadType, previewShown), |
delay); |
@@ -475,26 +475,26 @@ ImageView.prototype.load = function(url, metadata, effect, |
/** |
* Prefetch an image. |
* |
- * @param {string} url The image url. |
+ * @param {Entry} entry The image entry. |
hirono
2013/12/09 06:53:50
FileEntry?
mtomasz
2013/12/10 02:37:34
Done.
|
* @param {number} delay Image load delay in ms. |
*/ |
-ImageView.prototype.prefetch = function(url, delay) { |
+ImageView.prototype.prefetch = function(entry, delay) { |
var self = this; |
function prefetchDone(canvas) { |
if (canvas.width) |
- self.contentCache_.putItem(url, canvas); |
+ self.contentCache_.putItem(entry, canvas); |
} |
- var cached = this.contentCache_.getItem(url); |
+ var cached = this.contentCache_.getItem(entry); |
if (cached) { |
prefetchDone(cached); |
- } else if (FileType.getMediaType(url) == 'image') { |
+ } else if (FileType.getMediaType(entry) == 'image') { |
hirono
2013/12/09 06:53:50
=== is preferred.
mtomasz
2013/12/10 02:37:34
Done.
|
// Evict the LRU item before we allocate the new canvas to avoid unneeded |
// strain on memory. |
this.contentCache_.evictLRU(); |
this.prefetchLoader_.load( |
- url, |
+ entry, |
this.localImageTransformFetcher_, |
prefetchDone, |
delay); |
@@ -504,12 +504,12 @@ ImageView.prototype.prefetch = function(url, delay) { |
/** |
* Rename the current image. |
hirono
2013/12/09 06:53:50
Renames
mtomasz
2013/12/10 02:37:34
Done.
|
* |
- * @param {string} newUrl The new image url. |
+ * @param {Entry} newEntry The new image Entry. |
hirono
2013/12/09 06:53:50
FileEntry?
mtomasz
2013/12/10 02:37:34
Done.
|
*/ |
-ImageView.prototype.changeUrl = function(newUrl) { |
- this.contentCache_.renameItem(this.contentID_, newUrl); |
- this.screenCache_.renameItem(this.contentID_, newUrl); |
- this.contentID_ = newUrl; |
+ImageView.prototype.changeEntry = function(newEntry) { |
+ this.contentCache_.renameItem(this.contentEntry_, newEntry); |
+ this.screenCache_.renameItem(this.contentEntry_, newEntry); |
+ this.contentEntry_ = newEntry; |
}; |
/** |
@@ -585,8 +585,8 @@ ImageView.prototype.replaceContent_ = function( |
this.container_.appendChild(this.contentCanvas_); |
this.contentCanvas_.classList.add('fullres'); |
- this.contentCache_.putItem(this.contentID_, this.contentCanvas_, true); |
- this.screenCache_.putItem(this.contentID_, this.screenImage_); |
+ this.contentCache_.putItem(this.contentEntry_, this.contentCanvas_, true); |
+ this.screenCache_.putItem(this.contentEntry_, this.screenImage_); |
// TODO(kaznacheev): It is better to pass screenImage_ as it is usually |
// much smaller than contentCanvas_ and still contains the entire image. |
@@ -795,37 +795,39 @@ ImageView.Cache = function(capacity) { |
/** |
* Fetch the item from the cache. |
* |
- * @param {string} id The item ID. |
+ * @param {FileEntry} entry The entry. |
* @return {Object} The cached item. |
*/ |
-ImageView.Cache.prototype.getItem = function(id) { return this.map_[id] }; |
+ImageView.Cache.prototype.getItem = function(entry) { |
+ return this.map_[entry.toURL()]; |
+}; |
/** |
* Put the item into the cache. |
- * @param {string} id The item ID. |
+ * @param {FileEntry} entry The entry. |
* @param {Object} item The item object. |
* @param {boolean=} opt_keepLRU True if the LRU order should not be modified. |
*/ |
-ImageView.Cache.prototype.putItem = function(id, item, opt_keepLRU) { |
- var pos = this.order_.indexOf(id); |
+ImageView.Cache.prototype.putItem = function(entry, item, opt_keepLRU) { |
+ var pos = this.order_.indexOf(entry.toURL()); |
- if ((pos >= 0) != (id in this.map_)) |
+ if ((pos >= 0) != (entry.toURL() in this.map_)) |
throw new Error('Inconsistent cache state'); |
- if (id in this.map_) { |
+ if (entry.toURL() in this.map_) { |
hirono
2013/12/09 06:53:50
Can we save the entry directory into the this.map_
mtomasz
2013/12/10 02:37:34
AFAIR objects as keys are not supported.
|
if (!opt_keepLRU) { |
// Move to the end (most recently used). |
this.order_.splice(pos, 1); |
- this.order_.push(id); |
+ this.order_.push(entry.toURL()); |
} |
} else { |
this.evictLRU(); |
- this.order_.push(id); |
+ this.order_.push(entry.toURL()); |
} |
- if ((pos >= 0) && (item != this.map_[id])) |
- this.deleteItem_(this.map_[id]); |
- this.map_[id] = item; |
+ if ((pos >= 0) && (item != this.map_[entry.toURL()])) |
+ this.deleteItem_(this.map_[entry.toURL()]); |
+ this.map_[entry.toURL()] = item; |
if (this.order_.length > this.capacity_) |
throw new Error('Exceeded cache capacity'); |
@@ -836,28 +838,28 @@ ImageView.Cache.prototype.putItem = function(id, item, opt_keepLRU) { |
*/ |
ImageView.Cache.prototype.evictLRU = function() { |
if (this.order_.length == this.capacity_) { |
- var id = this.order_.shift(); |
- this.deleteItem_(this.map_[id]); |
- delete this.map_[id]; |
+ var url = this.order_.shift(); |
+ this.deleteItem_(this.map_[url]); |
+ delete this.map_[url]; |
} |
}; |
/** |
- * Change the id of an entry. |
- * @param {string} oldId The old ID. |
- * @param {string} newId The new ID. |
+ * Change the Entry. |
+ * @param {FileEntry} oldEntry The old Entry. |
+ * @param {FileEntry} newEntry The new Entry. |
*/ |
-ImageView.Cache.prototype.renameItem = function(oldId, newId) { |
- if (oldId == newId) |
+ImageView.Cache.prototype.renameItem = function(oldEntry, newEntry) { |
+ if (oldEntry.toURL() == newEntry.toURL()) |
return; // No need to rename. |
- var pos = this.order_.indexOf(oldId); |
+ var pos = this.order_.indexOf(oldEntry.toURL()); |
if (pos < 0) |
return; // Not cached. |
- this.order_[pos] = newId; |
- this.map_[newId] = this.map_[oldId]; |
- delete this.map_[oldId]; |
+ this.order_[pos] = newEntry.toURL(); |
+ this.map_[newEntry.toURL()] = this.map_[oldEntry.toURL()]; |
+ delete this.map_[oldEntry.toURL()]; |
}; |
/** |