Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: ui/file_manager/gallery/js/gallery.js

Issue 529413002: Rename DriveProvider to ExternalProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Called from the main frame when unloading. 8 * Called from the main frame when unloading.
9 * @param {boolean=} opt_exiting True if the app is exiting. 9 * @param {boolean=} opt_exiting True if the app is exiting.
10 */ 10 */
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 */ 58 */
59 GalleryDataModel.MAX_SCREEN_IMAGE_CACHE_ = 5; 59 GalleryDataModel.MAX_SCREEN_IMAGE_CACHE_ = 5;
60 60
61 GalleryDataModel.prototype = { 61 GalleryDataModel.prototype = {
62 __proto__: cr.ui.ArrayDataModel.prototype 62 __proto__: cr.ui.ArrayDataModel.prototype
63 }; 63 };
64 64
65 /** 65 /**
66 * Saves new image. 66 * Saves new image.
67 * 67 *
68 * @param {VolumeManager} volumeManager Volume manager instance.
68 * @param {Gallery.Item} item Original gallery item. 69 * @param {Gallery.Item} item Original gallery item.
69 * @param {Canvas} canvas Canvas containing new image. 70 * @param {Canvas} canvas Canvas containing new image.
70 * @param {boolean} overwrite Whether to overwrite the image to the item or not. 71 * @param {boolean} overwrite Whether to overwrite the image to the item or not.
71 * @return {Promise} Promise to be fulfilled with when the operation completes. 72 * @return {Promise} Promise to be fulfilled with when the operation completes.
72 */ 73 */
73 GalleryDataModel.prototype.saveItem = function(item, canvas, overwrite) { 74 GalleryDataModel.prototype.saveItem = function(
75 volumeManager, item, canvas, overwrite) {
74 var oldEntry = item.getEntry(); 76 var oldEntry = item.getEntry();
75 var oldMetadata = item.getMetadata(); 77 var oldMetadata = item.getMetadata();
78 var oldLocationInfo = item.getLocationInfo();
76 var metadataEncoder = ImageEncoder.encodeMetadata( 79 var metadataEncoder = ImageEncoder.encodeMetadata(
77 item.getMetadata(), canvas, 1 /* quality */); 80 item.getMetadata(), canvas, 1 /* quality */);
78 var newMetadata = ContentProvider.ConvertContentMetadata( 81 var newMetadata = ContentProvider.ConvertContentMetadata(
79 metadataEncoder.getMetadata(), 82 metadataEncoder.getMetadata(),
80 MetadataCache.cloneMetadata(item.getMetadata())); 83 MetadataCache.cloneMetadata(item.getMetadata()));
81 if (newMetadata.filesystem) 84 if (newMetadata.filesystem)
82 newMetadata.filesystem.modificationTime = new Date(); 85 newMetadata.filesystem.modificationTime = new Date();
83 if (newMetadata.drive) 86 if (newMetadata.external)
84 newMetadata.drive.present = true; 87 newMetadata.external.present = true;
85 88
86 return new Promise(function(fulfill, reject) { 89 return new Promise(function(fulfill, reject) {
87 item.saveToFile( 90 item.saveToFile(
91 volumeManager,
88 this.fallbackSaveDirectory, 92 this.fallbackSaveDirectory,
89 overwrite, 93 overwrite,
90 canvas, 94 canvas,
91 metadataEncoder, 95 metadataEncoder,
92 function(success) { 96 function(success) {
93 if (!success) { 97 if (!success) {
94 reject('Failed to save the image.'); 98 reject('Failed to save the image.');
95 return; 99 return;
96 } 100 }
97 101
(...skipping 12 matching lines...) Expand all
110 // Need an update of metdataCache. 114 // Need an update of metdataCache.
111 this.metadataCache_.set( 115 this.metadataCache_.set(
112 item.getEntry(), 116 item.getEntry(),
113 Gallery.METADATA_TYPE, 117 Gallery.METADATA_TYPE,
114 newMetadata); 118 newMetadata);
115 } else { 119 } else {
116 // New entry is added and the item now tracks it. 120 // New entry is added and the item now tracks it.
117 // Add another item for the old entry. 121 // Add another item for the old entry.
118 var anotherItem = new Gallery.Item( 122 var anotherItem = new Gallery.Item(
119 oldEntry, 123 oldEntry,
124 oldLocationInfo,
120 oldMetadata, 125 oldMetadata,
121 this.metadataCache_, 126 this.metadataCache_,
122 item.isOriginal(), 127 item.isOriginal());
123 item.isReadOnly());
124 // The item must be added behind the existing item so that it does 128 // The item must be added behind the existing item so that it does
125 // not change the index of the existing item. 129 // not change the index of the existing item.
126 // TODO(hirono): Update the item index of the selection model 130 // TODO(hirono): Update the item index of the selection model
127 // correctly. 131 // correctly.
128 this.splice(this.indexOf(item) + 1, 0, anotherItem); 132 this.splice(this.indexOf(item) + 1, 0, anotherItem);
129 } 133 }
130 134
131 fulfill(); 135 fulfill();
132 }.bind(this)); 136 }.bind(this));
133 }.bind(this)); 137 }.bind(this));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 loadTimeData: {} 204 loadTimeData: {}
201 }; 205 };
202 this.container_ = document.querySelector('.gallery'); 206 this.container_ = document.querySelector('.gallery');
203 this.document_ = document; 207 this.document_ = document;
204 this.metadataCache_ = this.context_.metadataCache; 208 this.metadataCache_ = this.context_.metadataCache;
205 this.volumeManager_ = volumeManager; 209 this.volumeManager_ = volumeManager;
206 this.selectedEntry_ = null; 210 this.selectedEntry_ = null;
207 this.metadataCacheObserverId_ = null; 211 this.metadataCacheObserverId_ = null;
208 this.onExternallyUnmountedBound_ = this.onExternallyUnmounted_.bind(this); 212 this.onExternallyUnmountedBound_ = this.onExternallyUnmounted_.bind(this);
209 213
210 this.dataModel_ = new GalleryDataModel(this.context_.metadataCache); 214 this.dataModel_ = new GalleryDataModel(
215 this.context_.metadataCache);
211 var downloadVolumeInfo = this.volumeManager_.getCurrentProfileVolumeInfo( 216 var downloadVolumeInfo = this.volumeManager_.getCurrentProfileVolumeInfo(
212 VolumeManagerCommon.VolumeType.DOWNLOADS); 217 VolumeManagerCommon.VolumeType.DOWNLOADS);
213 downloadVolumeInfo.resolveDisplayRoot().then(function(entry) { 218 downloadVolumeInfo.resolveDisplayRoot().then(function(entry) {
214 this.dataModel_.fallbackSaveDirectory = entry; 219 this.dataModel_.fallbackSaveDirectory = entry;
215 }.bind(this)).catch(function(error) { 220 }.bind(this)).catch(function(error) {
216 console.error( 221 console.error(
217 'Failed to obtain the fallback directory: ' + (error.stack || error)); 222 'Failed to obtain the fallback directory: ' + (error.stack || error));
218 }); 223 });
219 this.selectionModel_ = new cr.ui.ListSelectionModel(); 224 this.selectionModel_ = new cr.ui.ListSelectionModel();
220 225
(...skipping 26 matching lines...) Expand all
247 * @const 252 * @const
248 * @type {number} 253 * @type {number}
249 */ 254 */
250 Gallery.MOSAIC_BACKGROUND_INIT_DELAY = 1000; 255 Gallery.MOSAIC_BACKGROUND_INIT_DELAY = 1000;
251 256
252 /** 257 /**
253 * Types of metadata Gallery uses (to query the metadata cache). 258 * Types of metadata Gallery uses (to query the metadata cache).
254 * @const 259 * @const
255 * @type {string} 260 * @type {string}
256 */ 261 */
257 Gallery.METADATA_TYPE = 'thumbnail|filesystem|media|drive'; 262 Gallery.METADATA_TYPE = 'thumbnail|filesystem|media|external';
258 263
259 /** 264 /**
260 * Initializes listeners. 265 * Initializes listeners.
261 * @private 266 * @private
262 */ 267 */
263 Gallery.prototype.initListeners_ = function() { 268 Gallery.prototype.initListeners_ = function() {
264 this.keyDownBound_ = this.onKeyDown_.bind(this); 269 this.keyDownBound_ = this.onKeyDown_.bind(this);
265 this.document_.body.addEventListener('keydown', this.keyDownBound_); 270 this.document_.body.addEventListener('keydown', this.keyDownBound_);
266 271
267 this.inactivityWatcher_ = new MouseInactivityWatcher( 272 this.inactivityWatcher_ = new MouseInactivityWatcher(
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 this.volumeManager_, 379 this.volumeManager_,
375 this.toggleMode_.bind(this, null)); 380 this.toggleMode_.bind(this, null));
376 381
377 this.slideMode_ = new SlideMode(this.container_, 382 this.slideMode_ = new SlideMode(this.container_,
378 content, 383 content,
379 this.toolbar_, 384 this.toolbar_,
380 this.prompt_, 385 this.prompt_,
381 this.dataModel_, 386 this.dataModel_,
382 this.selectionModel_, 387 this.selectionModel_,
383 this.context_, 388 this.context_,
389 this.volumeManager_,
384 this.toggleMode_.bind(this), 390 this.toggleMode_.bind(this),
385 str); 391 str);
386 392
387 this.slideMode_.addEventListener('image-displayed', function() { 393 this.slideMode_.addEventListener('image-displayed', function() {
388 cr.dispatchSimpleEvent(this, 'image-displayed'); 394 cr.dispatchSimpleEvent(this, 'image-displayed');
389 }.bind(this)); 395 }.bind(this));
390 this.slideMode_.addEventListener('image-saved', function() { 396 this.slideMode_.addEventListener('image-saved', function() {
391 cr.dispatchSimpleEvent(this, 'image-saved'); 397 cr.dispatchSimpleEvent(this, 'image-saved');
392 }.bind(this)); 398 }.bind(this));
393 399
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 // Obtains metadata for chunk. 488 // Obtains metadata for chunk.
483 var entries = chunk.map(function(chunkItem) { 489 var entries = chunk.map(function(chunkItem) {
484 return chunkItem.entry; 490 return chunkItem.entry;
485 }); 491 });
486 self.metadataCache_.get(entries, Gallery.METADATA_TYPE, fulfill); 492 self.metadataCache_.get(entries, Gallery.METADATA_TYPE, fulfill);
487 }).then(function(metadataList) { 493 }).then(function(metadataList) {
488 if (chunk.length !== metadataList.length) 494 if (chunk.length !== metadataList.length)
489 return Promise.reject('Failed to load metadata.'); 495 return Promise.reject('Failed to load metadata.');
490 496
491 // Add items to the model. 497 // Add items to the model.
492 var items = chunk.map(function(chunkItem, index) { 498 var items = [];
493 var volumeInfo = self.volumeManager_.getVolumeInfo(chunkItem.entry); 499 chunk.forEach(function(chunkItem, index) {
500 var locationInfo = self.volumeManager_.getLocationInfo(chunkItem.entry);
501 if (!locationInfo) // Skip the item, since gone.
502 return;
494 var clonedMetadata = MetadataCache.cloneMetadata(metadataList[index]); 503 var clonedMetadata = MetadataCache.cloneMetadata(metadataList[index]);
495 return new Gallery.Item( 504 items.push(new Gallery.Item(
496 chunkItem.entry, 505 chunkItem.entry,
506 locationInfo,
497 clonedMetadata, 507 clonedMetadata,
498 self.metadataCache_, 508 self.metadataCache_,
499 /* original */ true, 509 /* original */ true));
500 /* readonly */ !!(volumeInfo && volumeInfo.isReadOnly));
501 }); 510 });
502 self.dataModel_.push.apply(self.dataModel_, items); 511 self.dataModel_.push.apply(self.dataModel_, items);
503 512
504 // Apply the selection. 513 // Apply the selection.
505 var selectionUpdated = false; 514 var selectionUpdated = false;
506 for (var i = 0; i < chunk.length; i++) { 515 for (var i = 0; i < chunk.length; i++) {
507 if (!chunk[i].selected) 516 if (!chunk[i].selected)
508 continue; 517 continue;
509 var index = self.dataModel_.indexOf(items[i]); 518 var index = self.dataModel_.indexOf(items[i]);
510 if (index < 0) 519 if (index < 0)
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 this.selectedEntry_ = selectedItem.getEntry(); 852 this.selectedEntry_ = selectedItem.getEntry();
844 selectedEntryURL = this.selectedEntry_.toURL(); 853 selectedEntryURL = this.selectedEntry_.toURL();
845 854
846 // Update cache. 855 // Update cache.
847 selectedItem.touch(); 856 selectedItem.touch();
848 this.dataModel_.evictCache(); 857 this.dataModel_.evictCache();
849 858
850 // Update the title and the display name. 859 // Update the title and the display name.
851 if (numSelectedItems === 1) { 860 if (numSelectedItems === 1) {
852 document.title = this.selectedEntry_.name; 861 document.title = this.selectedEntry_.name;
853 this.filenameEdit_.disabled = selectedItem.isReadOnly(); 862 this.filenameEdit_.disabled = selectedItem.getLocationInfo().isReadOnly;
854 this.filenameEdit_.value = 863 this.filenameEdit_.value =
855 ImageUtil.getDisplayNameFromName(this.selectedEntry_.name); 864 ImageUtil.getDisplayNameFromName(this.selectedEntry_.name);
856 this.shareButton_.hidden = !selectedItem.isOnDrive(); 865 this.shareButton_.hidden = !selectedItem.getLocationInfo().isDriveBased;
857 } else { 866 } else {
858 if (this.context_.curDirEntry) { 867 if (this.context_.curDirEntry) {
859 // If the Gallery was opened on search results the search query will not 868 // If the Gallery was opened on search results the search query will not
860 // be recorded in the app state and the relaunch will just open the 869 // be recorded in the app state and the relaunch will just open the
861 // gallery in the curDirEntry directory. 870 // gallery in the curDirEntry directory.
862 document.title = this.context_.curDirEntry.name; 871 document.title = this.context_.curDirEntry.name;
863 } else { 872 } else {
864 document.title = ''; 873 document.title = '';
865 } 874 }
866 this.filenameEdit_.disabled = true; 875 this.filenameEdit_.disabled = true;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 window.loadTimeData.data = backgroundComponents.stringData; 1025 window.loadTimeData.data = backgroundComponents.stringData;
1017 gallery = new Gallery(backgroundComponents.volumeManager); 1026 gallery = new Gallery(backgroundComponents.volumeManager);
1018 }; 1027 };
1019 1028
1020 /** 1029 /**
1021 * Loads entries. 1030 * Loads entries.
1022 */ 1031 */
1023 window.loadEntries = function(entries, selectedEntries) { 1032 window.loadEntries = function(entries, selectedEntries) {
1024 gallery.load(entries, selectedEntries); 1033 gallery.load(entries, selectedEntries);
1025 }; 1034 };
OLDNEW
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/ui/breadcrumbs_controller.js ('k') | ui/file_manager/gallery/js/gallery_item.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698