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

Side by Side Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 10384155: [filemanager] Content metadata moved to the cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Bug Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 * FileManager constructor. 6 * FileManager constructor.
7 * 7 *
8 * FileManager objects encapsulate the functionality of the file selector 8 * FileManager objects encapsulate the functionality of the file selector
9 * dialogs, as well as the full screen file manager application (though the 9 * dialogs, as well as the full screen file manager application (though the
10 * latter is not yet implemented). 10 * latter is not yet implemented).
(...skipping 16 matching lines...) Expand all
27 27
28 this.butterTimer_ = null; 28 this.butterTimer_ = null;
29 this.currentButter_ = null; 29 this.currentButter_ = null;
30 this.butterLastShowTime_ = 0; 30 this.butterLastShowTime_ = 0;
31 31
32 this.filesystemObserverId_ = null; 32 this.filesystemObserverId_ = null;
33 this.gdataObserverId_ = null; 33 this.gdataObserverId_ = null;
34 34
35 this.commands_ = {}; 35 this.commands_ = {};
36 36
37 this.thumbnailUrlCache_ = {};
38
39 this.document_ = dialogDom.ownerDocument; 37 this.document_ = dialogDom.ownerDocument;
40 this.dialogType_ = this.params_.type || FileManager.DialogType.FULL_PAGE; 38 this.dialogType_ = this.params_.type || FileManager.DialogType.FULL_PAGE;
41 39
42 metrics.recordEnum('Create', this.dialogType_, 40 metrics.recordEnum('Create', this.dialogType_,
43 [FileManager.DialogType.SELECT_FOLDER, 41 [FileManager.DialogType.SELECT_FOLDER,
44 FileManager.DialogType.SELECT_SAVEAS_FILE, 42 FileManager.DialogType.SELECT_SAVEAS_FILE,
45 FileManager.DialogType.SELECT_OPEN_FILE, 43 FileManager.DialogType.SELECT_OPEN_FILE,
46 FileManager.DialogType.SELECT_OPEN_MULTI_FILE, 44 FileManager.DialogType.SELECT_OPEN_MULTI_FILE,
47 FileManager.DialogType.FULL_PAGE]); 45 FileManager.DialogType.FULL_PAGE]);
48 46
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 * FileWatcher that also watches for metadata changes. 259 * FileWatcher that also watches for metadata changes.
262 * @extends {FileWatcher} 260 * @extends {FileWatcher}
263 */ 261 */
264 FileManager.MetadataFileWatcher = function(fileManager) { 262 FileManager.MetadataFileWatcher = function(fileManager) {
265 FileWatcher.call(this, 263 FileWatcher.call(this,
266 fileManager.filesystem_.root, 264 fileManager.filesystem_.root,
267 fileManager.directoryModel_, 265 fileManager.directoryModel_,
268 fileManager.volumeManager_); 266 fileManager.volumeManager_);
269 this.metadataCache_ = fileManager.metadataCache_; 267 this.metadataCache_ = fileManager.metadataCache_;
270 268
271 this.filesystemChanngeHandler_ = 269 this.filesystemChangeHandler_ =
272 fileManager.updateMetadataInUI_.bind(fileManager, 'filesystem'); 270 fileManager.updateMetadataInUI_.bind(fileManager, 'filesystem');
273 this.gdataChanngeHandler_ = 271 this.thumbnailChangeHandler_ =
272 fileManager.updateMetadataInUI_.bind(fileManager, 'thumbnail');
273 this.gdataChangeHandler_ =
274 fileManager.updateMetadataInUI_.bind(fileManager, 'gdata'); 274 fileManager.updateMetadataInUI_.bind(fileManager, 'gdata');
275 275
276 this.filesystemObserverId_ = null; 276 this.filesystemObserverId_ = null;
277 this.thumbnailObserverId_ = null;
277 this.gdataObserverId_ = null; 278 this.gdataObserverId_ = null;
278 279
279 // Holds the directories known to contain files with stale metadata 280 // Holds the directories known to contain files with stale metadata
280 // as URL to bool map. 281 // as URL to bool map.
281 this.directoriesWithStaleMetadata_ = {}; 282 this.directoriesWithStaleMetadata_ = {};
282 }; 283 };
283 284
284 FileManager.MetadataFileWatcher.prototype.__proto__ = FileWatcher.prototype; 285 FileManager.MetadataFileWatcher.prototype.__proto__ = FileWatcher.prototype;
285 286
286 /** 287 /**
287 * Changed metadata observers for the new directory. 288 * Changed metadata observers for the new directory.
288 * @override 289 * @override
289 * @param {DirectoryEntryi?} entry New watched directory entry. 290 * @param {DirectoryEntryi?} entry New watched directory entry.
290 * @override 291 * @override
291 */ 292 */
292 FileManager.MetadataFileWatcher.prototype.changeWatchedEntry = 293 FileManager.MetadataFileWatcher.prototype.changeWatchedEntry =
293 function(entry) { 294 function(entry) {
294 FileWatcher.prototype.changeWatchedEntry.call(this, entry); 295 FileWatcher.prototype.changeWatchedEntry.call(this, entry);
295 296
296 if (this.filesystemObserverId_) 297 if (this.filesystemObserverId_)
297 this.metadataCache_.removeObserver(this.filesystemObserverId_); 298 this.metadataCache_.removeObserver(this.filesystemObserverId_);
299 if (this.thumbnailObserverId_)
300 this.metadataCache_.removeObserver(this.thumbnailObserverId_);
298 if (this.gdataObserverId_) 301 if (this.gdataObserverId_)
299 this.metadataCache_.removeObserver(this.gdataObserverId_); 302 this.metadataCache_.removeObserver(this.gdataObserverId_);
300 this.filesystemObserverId_ = null; 303 this.filesystemObserverId_ = null;
301 this.gdataObserverId_ = null; 304 this.gdataObserverId_ = null;
302 if (!entry) 305 if (!entry)
303 return; 306 return;
304 307
305 this.filesystemObserverId_ = this.metadataCache_.addObserver( 308 this.filesystemObserverId_ = this.metadataCache_.addObserver(
306 entry, 309 entry,
307 MetadataCache.CHILDREN, 310 MetadataCache.CHILDREN,
308 'filesystem', 311 'filesystem',
309 this.filesystemChanngeHandler_); 312 this.filesystemChangeHandler_);
313
314 this.thumbnailObserverId_ = this.metadataCache_.addObserver(
315 entry,
316 MetadataCache.CHILDREN,
317 'thumbnail',
318 this.thumbnailChangeHandler_);
310 319
311 if (DirectoryModel.getRootType(entry.fullPath) == 320 if (DirectoryModel.getRootType(entry.fullPath) ==
312 DirectoryModel.RootType.GDATA) { 321 DirectoryModel.RootType.GDATA) {
313 this.gdataObserverId_ = this.metadataCache_.addObserver( 322 this.gdataObserverId_ = this.metadataCache_.addObserver(
314 entry, 323 entry,
315 MetadataCache.CHILDREN, 324 MetadataCache.CHILDREN,
316 'gdata', 325 'gdata',
317 this.gdataChanngeHandler_); 326 this.gdataChangeHandler_);
318 } 327 }
319 }; 328 };
320 329
321 /** 330 /**
322 * @override 331 * @override
323 */ 332 */
324 FileManager.MetadataFileWatcher.prototype.onFileInWatchedDirectoryChanged = 333 FileManager.MetadataFileWatcher.prototype.onFileInWatchedDirectoryChanged =
325 function() { 334 function() {
326 FileWatcher.prototype.onFileInWatchedDirectoryChanged.apply(this); 335 FileWatcher.prototype.onFileInWatchedDirectoryChanged.apply(this);
327 delete this.directoriesWithStaleMetadata_[ 336 delete this.directoriesWithStaleMetadata_[
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 }; 438 };
430 439
431 /** 440 /**
432 * Continue initializing the file manager after resolving roots. 441 * Continue initializing the file manager after resolving roots.
433 */ 442 */
434 FileManager.prototype.init_ = function() { 443 FileManager.prototype.init_ = function() {
435 metrics.startInterval('Load.DOM'); 444 metrics.startInterval('Load.DOM');
436 this.initCommands_(); 445 this.initCommands_();
437 446
438 this.metadataCache_ = MetadataCache.createFull(); 447 this.metadataCache_ = MetadataCache.createFull();
448 // PyAuto tests monitor this state by polling this variable
449 this.__defineGetter__('workerInitialized_', function() {
450 return this.metadataCache_.isInitialized();
451 }.bind(this));
439 452
440 this.dateFormatter_ = v8Intl.DateTimeFormat( 453 this.dateFormatter_ = v8Intl.DateTimeFormat(
441 {} /* default locale */, 454 {} /* default locale */,
442 {year: 'numeric', month: 'short', day: 'numeric', 455 {year: 'numeric', month: 'short', day: 'numeric',
443 hour: 'numeric', minute: 'numeric'}); 456 hour: 'numeric', minute: 'numeric'});
444 this.timeFormatter_ = v8Intl.DateTimeFormat( 457 this.timeFormatter_ = v8Intl.DateTimeFormat(
445 {} /* default locale */, 458 {} /* default locale */,
446 {hour: 'numeric', minute: 'numeric'}); 459 {hour: 'numeric', minute: 'numeric'});
447 460
448 this.collator_ = this.locale_.createCollator({ 461 this.collator_ = this.locale_.createCollator({
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 511
499 var sortField = 512 var sortField =
500 window.localStorage['sort-field-' + this.dialogType_] || 513 window.localStorage['sort-field-' + this.dialogType_] ||
501 'modificationTime'; 514 'modificationTime';
502 var sortDirection = 515 var sortDirection =
503 window.localStorage['sort-direction-' + this.dialogType_] || 'desc'; 516 window.localStorage['sort-direction-' + this.dialogType_] || 'desc';
504 this.directoryModel_.sortFileList(sortField, sortDirection); 517 this.directoryModel_.sortFileList(sortField, sortDirection);
505 518
506 this.refocus(); 519 this.refocus();
507 520
508 this.metadataProvider_ =
509 new MetadataProvider(this.filesystem_.root.toURL());
510
511 // PyAuto tests monitor this state by polling this variable
512 this.__defineGetter__('workerInitialized_', function() {
513 return self.getMetadataProvider().isInitialized();
514 });
515
516 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) 521 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE)
517 this.initDataTransferOperations_(); 522 this.initDataTransferOperations_();
518 523
519 this.table_.endBatchUpdates(); 524 this.table_.endBatchUpdates();
520 this.grid_.endBatchUpdates(); 525 this.grid_.endBatchUpdates();
521 526
522 // Show the page now unless it's already delayed. 527 // Show the page now unless it's already delayed.
523 this.delayShow_(0); 528 this.delayShow_(0);
524 529
525 metrics.recordInterval('Load.DOM'); 530 metrics.recordInterval('Load.DOM');
(...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 }; 1746 };
1742 1747
1743 /** 1748 /**
1744 * Create a box containing a centered thumbnail image. 1749 * Create a box containing a centered thumbnail image.
1745 * 1750 *
1746 * @param {Entry} entry Entry which thumbnail is generating for. 1751 * @param {Entry} entry Entry which thumbnail is generating for.
1747 * @param {boolean} True if fill, false if fit. 1752 * @param {boolean} True if fill, false if fit.
1748 * @param {function(HTMLElement)} opt_imageLoadCallback Callback called when 1753 * @param {function(HTMLElement)} opt_imageLoadCallback Callback called when
1749 * the image has been loaded before inserting 1754 * the image has been loaded before inserting
1750 * it into the DOM. 1755 * it into the DOM.
1751 * @return {HTMLDivElement} Thumbnal box. 1756 * @param {HTMLDivElement=} opt_box Existing box to render in.
1757 * @return {HTMLDivElement} Thumbnail box.
1752 */ 1758 */
1753 FileManager.prototype.renderThumbnailBox_ = function(entry, fill, 1759 FileManager.prototype.renderThumbnailBox_ = function(
1754 opt_imageLoadCallback) { 1760 entry, fill, opt_imageLoadCallback, opt_box) {
1755 var box = this.document_.createElement('div');
1756 box.className = 'img-container';
1757 var img = this.document_.createElement('img');
1758 var self = this; 1761 var self = this;
1759 1762
1763 var box;
1764 if (opt_box) {
1765 box = opt_box;
1766 } else {
1767 box = this.document_.createElement('div');
1768 box.className = 'img-container';
1769 }
1770 var img = box.querySelector('img') || this.document_.createElement('img');
1771
1760 function onThumbnailURL(iconType, url, transform) { 1772 function onThumbnailURL(iconType, url, transform) {
1761 self.thumbnailUrlCache_[entry.fullPath] = {
1762 iconType: iconType,
1763 url: url,
1764 transform: transform
1765 };
1766 img.onload = function() { 1773 img.onload = function() {
1767 self.centerImage_(img.style, img.width, img.height, fill); 1774 self.centerImage_(img.style, img.width, img.height, fill);
1768 if (opt_imageLoadCallback) 1775 if (opt_imageLoadCallback)
1769 opt_imageLoadCallback(img, transform); 1776 opt_imageLoadCallback(img, transform);
1770 box.appendChild(img); 1777 if (img.parentNode != box)
1778 box.appendChild(img);
1771 }; 1779 };
1772 img.onerror = function() { 1780 img.onerror = function() {
1773 // Use the default icon if we could not fetch the correct one. 1781 // Use the default icon if we could not fetch the correct one.
1774 img.src = FileType.getPreviewArt(iconType); 1782 img.src = FileType.getPreviewArt(iconType);
1775 transform = null; 1783 transform = null;
1776 util.applyTransform(box, transform); 1784 util.applyTransform(box, transform);
1777 1785
1778 var cached = self.thumbnailUrlCache_[entry.fullPath]; 1786 // Failing to fetch a thumbnail likely means that the thumbnail URL
1779 if (!cached.failed) { 1787 // is now stale. Request a refresh of the current directory, to get
1780 cached.failed = true; 1788 // the new thumbnail URLs. Once the directory is refreshed, we'll get
1781 // Failing to fetch a thumbnail likely means that the thumbnail URL 1789 // notified via onFileChanged event.
1782 // is now stale. Request a refresh of the current directory, to get 1790 self.fileWatcher_.requestMetadataRefresh(entry);
1783 // the new thumbnail URLs. Once the directory is refreshed, we'll get
1784 // notified via onFileChanged event.
1785 self.fileWatcher_.requestMetadataRefresh(entry);
1786 }
1787 }; 1791 };
1788 img.src = url; 1792 img.src = url;
1789 util.applyTransform(box, transform); 1793 util.applyTransform(box, transform);
1790 } 1794 }
1791 1795
1792 // TODO(dgozman): move to new metadata cache. 1796 this.getThumbnailURL(entry, onThumbnailURL);
1793 var cached = this.thumbnailUrlCache_[entry.fullPath];
1794 // Don't reuse the cached URL if we are now retrying.
1795 if (cached && !cached.failed)
1796 onThumbnailURL(cached.iconType, cached.url, cached.transform);
1797 else {
1798 if (cached && cached.failed) {
1799 delete cached.failed;
1800 this.metadataProvider_.reset(entry.toURL()); // Clear the cache.
1801 }
1802 this.getThumbnailURL(entry, onThumbnailURL);
1803 }
1804 1797
1805 return box; 1798 return box;
1806 }; 1799 };
1807 1800
1808 FileManager.prototype.decorateThumbnail_ = function(li, entry) { 1801 FileManager.prototype.decorateThumbnail_ = function(li, entry) {
1809 li.className = 'thumbnail-item'; 1802 li.className = 'thumbnail-item';
1810 1803
1811 if (this.showCheckboxes_) 1804 if (this.showCheckboxes_)
1812 li.appendChild(this.renderSelectionCheckbox_(entry)); 1805 li.appendChild(this.renderSelectionCheckbox_(entry));
1813 1806
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 if (!checkbox) return; 2095 if (!checkbox) return;
2103 checkbox.style.display = ''; 2096 checkbox.style.display = '';
2104 checkbox.checked = gdata.pinned; 2097 checkbox.checked = gdata.pinned;
2105 }; 2098 };
2106 2099
2107 FileManager.prototype.refreshCurrentDirectoryMetadata_ = function() { 2100 FileManager.prototype.refreshCurrentDirectoryMetadata_ = function() {
2108 var entries = this.directoryModel_.getFileList().slice(); 2101 var entries = this.directoryModel_.getFileList().slice();
2109 // We don't pass callback here. When new metadata arrives, we have an 2102 // We don't pass callback here. When new metadata arrives, we have an
2110 // observer registered to update the UI. 2103 // observer registered to update the UI.
2111 2104
2112 this.metadataCache_.clear(entries, 'filesystem'); 2105 // TODO(dgozman): refresh content metadata only when modificationTime
2113 this.metadataCache_.get(entries, 'filesystem', null); 2106 // changed.
2107 this.metadataCache_.clear(entries, 'filesystem|thumbnail|media');
2108 this.metadataCache_.get(entries, 'filesystem|thumbnail', null);
2114 if (this.isOnGData()) { 2109 if (this.isOnGData()) {
2115 this.metadataCache_.clear(entries, 'gdata'); 2110 this.metadataCache_.clear(entries, 'gdata');
2116 this.metadataCache_.get(entries, 'gdata', null); 2111 this.metadataCache_.get(entries, 'gdata', null);
2117 } 2112 }
2118 }; 2113 };
2119 2114
2120 FileManager.prototype.dailyUpdateModificationTime_ = function() { 2115 FileManager.prototype.dailyUpdateModificationTime_ = function() {
2121 var fileList = this.directoryModel_.getFileList(); 2116 var fileList = this.directoryModel_.getFileList();
2122 var urls = []; 2117 var urls = [];
2123 for (var i = 0; i < fileList.length; i++) { 2118 for (var i = 0; i < fileList.length; i++) {
2124 urls.push(fileList.item(i).toURL()); 2119 urls.push(fileList.item(i).toURL());
2125 } 2120 }
2126 this.metadataCache_.get( 2121 this.metadataCache_.get(
2127 fileList.slice(), 'filesystem', 2122 fileList.slice(), 'filesystem',
2128 this.updateMetadataInUI_.bind(this, 'filesystem', urls)); 2123 this.updateMetadataInUI_.bind(this, 'filesystem', urls));
2129 2124
2130 setTimeout(this.dailyUpdateModificationTime_.bind(this), 2125 setTimeout(this.dailyUpdateModificationTime_.bind(this),
2131 MILLISECONDS_IN_DAY); 2126 MILLISECONDS_IN_DAY);
2132 }; 2127 };
2133 2128
2134 FileManager.prototype.updateMetadataInUI_ = function( 2129 FileManager.prototype.updateMetadataInUI_ = function(
2135 type, urls, properties) { 2130 type, urls, properties) {
2136 if (this.listType_ != FileManager.ListType.DETAIL) return; 2131 var isDetail = this.listType_ == FileManager.ListType.DETAIL;
2132 var isThumbnail = this.listType_ == FileManager.ListType.THUMBNAIL;
2137 2133
2138 var items = {}; 2134 var items = {};
2139 var entries = {}; 2135 var entries = {};
2140 var dm = this.directoryModel_.getFileList(); 2136 var dm = this.directoryModel_.getFileList();
2141 for (var index = 0; index < dm.length; index++) { 2137 for (var index = 0; index < dm.length; index++) {
2142 var listItem = this.currentList_.getListItemByIndex(index); 2138 var listItem = this.currentList_.getListItemByIndex(index);
2143 if (!listItem) continue; 2139 if (!listItem) continue;
2144 var entry = dm.item(index); 2140 var entry = dm.item(index);
2145 var url = entry.toURL(); 2141 var url = entry.toURL();
2146 items[url] = listItem; 2142 items[url] = listItem;
2147 entries[url] = entry; 2143 entries[url] = entry;
2148 } 2144 }
2149 2145
2150 for (var index = 0; index < urls.length; index++) { 2146 for (var index = 0; index < urls.length; index++) {
2151 var url = urls[index]; 2147 var url = urls[index];
2152 if (!(url in items)) continue; 2148 if (!(url in items)) continue;
2153 var listItem = items[url]; 2149 var listItem = items[url];
2154 var entry = entries[url]; 2150 var entry = entries[url];
2155 var props = properties[index]; 2151 var props = properties[index];
2156 if (type == 'filesystem') { 2152 if (type == 'filesystem' && isDetail) {
2157 this.updateDate_(listItem.querySelector('.date'), props); 2153 this.updateDate_(listItem.querySelector('.date'), props);
2158 this.updateSize_(listItem.querySelector('.size'), entry, props); 2154 this.updateSize_(listItem.querySelector('.size'), entry, props);
2159 } else if (type == 'gdata') { 2155 } else if (type == 'gdata') {
2160 var offline = listItem.querySelector('.offline'); 2156 if (isDetail) {
2161 if (offline) // This column is only present in full page mode. 2157 var offline = listItem.querySelector('.offline');
2162 this.updateOffline_(offline, props); 2158 if (offline) // This column is only present in full page mode.
2159 this.updateOffline_(offline, props);
2160 }
2163 this.updateGDataStyle_(listItem, entry, props); 2161 this.updateGDataStyle_(listItem, entry, props);
2162 } else if (type == 'thumbnail' && isThumbnail) {
2163 var box = listItem.querySelector('.img-container');
2164 this.renderThumbnailBox_(entry, false /* fit, not fill */,
2165 null /* callback */, box);
2164 } 2166 }
2165 } 2167 }
2166 }; 2168 };
2167 2169
2168 /** 2170 /**
2169 * Restore the item which is being renamed while refreshing the file list. Do 2171 * Restore the item which is being renamed while refreshing the file list. Do
2170 * nothing if no item is being renamed or such an item disappeared. 2172 * nothing if no item is being renamed or such an item disappeared.
2171 * 2173 *
2172 * While refreshing file list it gets repopulated with new file entries. 2174 * While refreshing file list it gets repopulated with new file entries.
2173 * There is not a big difference wether DOM items stay the same or not. 2175 * There is not a big difference wether DOM items stay the same or not.
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 function setVisibility(visibility) { 2493 function setVisibility(visibility) {
2492 panel.setAttribute('visibility', visibility); 2494 panel.setAttribute('visibility', visibility);
2493 } 2495 }
2494 }; 2496 };
2495 2497
2496 FileManager.prototype.isOnGData = function() { 2498 FileManager.prototype.isOnGData = function() {
2497 return this.directoryModel_.getCurrentRootType() == 2499 return this.directoryModel_.getCurrentRootType() ==
2498 DirectoryModel.RootType.GDATA; 2500 DirectoryModel.RootType.GDATA;
2499 }; 2501 };
2500 2502
2501 FileManager.prototype.getMetadataProvider = function() {
2502 return this.metadataProvider_;
2503 };
2504
2505 /** 2503 /**
2506 * Creates combobox item based on task. 2504 * Creates combobox item based on task.
2507 * @param {Object} task Task to convert. 2505 * @param {Object} task Task to convert.
2508 * @return {Object} Item appendable to combobox drop-down list. 2506 * @return {Object} Item appendable to combobox drop-down list.
2509 */ 2507 */
2510 FileManager.prototype.createComboboxItem_ = function(task) { 2508 FileManager.prototype.createComboboxItem_ = function(task) {
2511 return { label: task.title, iconUrl: task.iconUrl, task: task }; 2509 return { label: task.title, iconUrl: task.iconUrl, task: task };
2512 } 2510 }
2513 2511
2514 /** 2512 /**
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
2997 var context = { 2995 var context = {
2998 // We show the root label in readonly warning (e.g. archive name). 2996 // We show the root label in readonly warning (e.g. archive name).
2999 readonlyDirName: 2997 readonlyDirName:
3000 readonly ? 2998 readonly ?
3001 (self.isOnGData() ? 2999 (self.isOnGData() ?
3002 self.getRootLabel_( 3000 self.getRootLabel_(
3003 DirectoryModel.getRootPath(currentDir.fullPath)) : 3001 DirectoryModel.getRootPath(currentDir.fullPath)) :
3004 self.directoryModel_.getRootName()) : 3002 self.directoryModel_.getRootName()) :
3005 null, 3003 null,
3006 saveDirEntry: readonly ? downloadsDir : currentDir, 3004 saveDirEntry: readonly ? downloadsDir : currentDir,
3007 metadataProvider: self.getMetadataProvider(), 3005 rootUrl: self.filesystem_.root.toURL(),
3008 getShareActions: self.getShareActions_.bind(self), 3006 getShareActions: self.getShareActions_.bind(self),
3009 onNameChange: function(name) { 3007 onNameChange: function(name) {
3010 self.document_.title = gallerySelection = name; 3008 self.document_.title = gallerySelection = name;
3011 self.updateLocation_(true /*replace*/, dirPath + '/' + name); 3009 self.updateLocation_(true /*replace*/, dirPath + '/' + name);
3012 }, 3010 },
3013 onClose: function() { 3011 onClose: function() {
3014 if (singleSelection) 3012 if (singleSelection)
3015 self.directoryModel_.selectEntry(gallerySelection); 3013 self.directoryModel_.selectEntry(gallerySelection);
3016 history.back(1); 3014 history.back(1);
3017 }, 3015 },
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
3161 currentWidth = Math.min(currentWidth, 3159 currentWidth = Math.min(currentWidth,
3162 containerWidth - pathWidth - collapsedWidth); 3160 containerWidth - pathWidth - collapsedWidth);
3163 bc.lastChild.style.width = (currentWidth - lastCrumbSeparatorWidth) + 'px'; 3161 bc.lastChild.style.width = (currentWidth - lastCrumbSeparatorWidth) + 'px';
3164 }; 3162 };
3165 3163
3166 FileManager.prototype.getThumbnailURL = function(entry, callback) { 3164 FileManager.prototype.getThumbnailURL = function(entry, callback) {
3167 if (!entry) 3165 if (!entry)
3168 return; 3166 return;
3169 3167
3170 var iconType = FileType.getIcon(entry); 3168 var iconType = FileType.getIcon(entry);
3169 var metadataCache = this.metadataCache_;
3171 3170
3172 function returnStockIcon() { 3171 function returnStockIcon() {
3173 callback(iconType, FileType.getPreviewArt(iconType)); 3172 callback(iconType, FileType.getPreviewArt(iconType), '');
3174 } 3173 }
3175 3174
3176 var self = this; 3175 function tryUsingImageUrl() {
3177 this.getMetadataProvider().fetch(entry.toURL(), function(metadata) { 3176 metadataCache.get(entry, 'filesystem|media', function(metadata) {
3178 if (metadata.thumbnailURL) { 3177 if (FileType.canUseImageUrlForPreview(
3179 callback(iconType, metadata.thumbnailURL, 3178 metadata.media.width,
3180 metadata.thumbnailTransform); 3179 metadata.media.height,
3180 metadata.filesystem.size)) {
3181 callback(iconType, entry.toURL(), metadata.media.imageTransform);
3182 } else {
3183 returnStockIcon();
3184 }
3185 });
3186 }
3187
3188 metadataCache.get(entry, 'thumbnail', function(thumbnail) {
3189 if (thumbnail) {
3190 callback(iconType, thumbnail.url, thumbnail.transform);
3181 } else if (iconType == 'image') { 3191 } else if (iconType == 'image') {
3182 self.metadataCache_.get(entry, 'filesystem', function(filesystem) { 3192 tryUsingImageUrl();
3183 if (FileType.canUseImageUrlForPreview(metadata, filesystem.size)) {
3184 callback(iconType, entry.toURL(), metadata.imageTransform);
3185 } else {
3186 returnStockIcon();
3187 }
3188 });
3189 } else { 3193 } else {
3190 returnStockIcon(); 3194 returnStockIcon();
3191 } 3195 }
3192 }); 3196 });
3193 }; 3197 };
3194 3198
3195 FileManager.prototype.focusCurrentList_ = function() { 3199 FileManager.prototype.focusCurrentList_ = function() {
3196 if (this.listType_ == FileManager.ListType.DETAIL) 3200 if (this.listType_ == FileManager.ListType.DETAIL)
3197 this.table_.focus(); 3201 this.table_.focus();
3198 else // this.listType_ == FileManager.ListType.THUMBNAIL) 3202 else // this.listType_ == FileManager.ListType.THUMBNAIL)
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
3375 if (this.selection && 3379 if (this.selection &&
3376 this.selection.totalCount == 1 && 3380 this.selection.totalCount == 1 &&
3377 this.selection.entries[0].isFile && 3381 this.selection.entries[0].isFile &&
3378 this.filenameInput_.value != this.selection.entries[0].name) { 3382 this.filenameInput_.value != this.selection.entries[0].name) {
3379 this.filenameInput_.value = this.selection.entries[0].name; 3383 this.filenameInput_.value = this.selection.entries[0].name;
3380 } 3384 }
3381 } 3385 }
3382 3386
3383 this.updateOkButton_(); 3387 this.updateOkButton_();
3384 3388
3385 var newThumbnailUrlCache = {};
3386 if (this.selection) {
3387 var entries = this.selection.entries;
3388 for (var i = 0; i < entries.length; i++) {
3389 var path = entries[i].fullPath;
3390 if (path in this.thumbnailUrlCache_)
3391 newThumbnailUrlCache[path] = this.thumbnailUrlCache_[path];
3392 }
3393 }
3394 this.thumbnailUrlCache_ = newThumbnailUrlCache;
3395
3396 setTimeout(this.onSelectionChangeComplete_.bind(this, event), 0); 3389 setTimeout(this.onSelectionChangeComplete_.bind(this, event), 0);
3397 }; 3390 };
3398 3391
3399 /** 3392 /**
3400 * Handle selection change related tasks that won't run properly during 3393 * Handle selection change related tasks that won't run properly during
3401 * the actual selection change event. 3394 * the actual selection change event.
3402 */ 3395 */
3403 FileManager.prototype.onSelectionChangeComplete_ = function(event) { 3396 FileManager.prototype.onSelectionChangeComplete_ = function(event) {
3404 // Inform tests it's OK to click buttons now. 3397 // Inform tests it's OK to click buttons now.
3405 chrome.test.sendMessage('selection-change-complete'); 3398 chrome.test.sendMessage('selection-change-complete');
(...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after
4607 function closeBanner() { 4600 function closeBanner() {
4608 self.cleanupGDataWelcome_(); 4601 self.cleanupGDataWelcome_();
4609 // Stop showing the welcome banner. 4602 // Stop showing the welcome banner.
4610 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; 4603 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT;
4611 } 4604 }
4612 4605
4613 return maybeShowBanner; 4606 return maybeShowBanner;
4614 }; 4607 };
4615 })(); 4608 })();
4616 4609
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/gallery.html ('k') | chrome/browser/resources/file_manager/js/file_type.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698