OLD | NEW |
---|---|
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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 'modificationTime'; | 430 'modificationTime'; |
431 var sortDirection = | 431 var sortDirection = |
432 window.localStorage['sort-direction-' + this.dialogType_] || 'desc'; | 432 window.localStorage['sort-direction-' + this.dialogType_] || 'desc'; |
433 this.directoryModel_.sortFileList(sortField, sortDirection); | 433 this.directoryModel_.sortFileList(sortField, sortDirection); |
434 | 434 |
435 this.refocus(); | 435 this.refocus(); |
436 | 436 |
437 this.metadataProvider_ = | 437 this.metadataProvider_ = |
438 new MetadataProvider(this.filesystem_.root.toURL()); | 438 new MetadataProvider(this.filesystem_.root.toURL()); |
439 | 439 |
440 // Holds the directories known to contain files with stale metadata | |
441 // as URL to bool map. | |
442 this.directoriesWithStaleMetadata_ = {}; | |
443 | |
440 // PyAuto tests monitor this state by polling this variable | 444 // PyAuto tests monitor this state by polling this variable |
441 this.__defineGetter__('workerInitialized_', function() { | 445 this.__defineGetter__('workerInitialized_', function() { |
442 return self.getMetadataProvider().isInitialized(); | 446 return self.getMetadataProvider().isInitialized(); |
443 }); | 447 }); |
444 | 448 |
445 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) | 449 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) |
446 this.initDataTransferOperations_(); | 450 this.initDataTransferOperations_(); |
447 | 451 |
448 this.table_.endBatchUpdates(); | 452 this.table_.endBatchUpdates(); |
449 this.grid_.endBatchUpdates(); | 453 this.grid_.endBatchUpdates(); |
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1667 fractionX = 1; | 1671 fractionX = 1; |
1668 } | 1672 } |
1669 | 1673 |
1670 style.width = percent(fractionX); | 1674 style.width = percent(fractionX); |
1671 style.height = percent(fractionY); | 1675 style.height = percent(fractionY); |
1672 style.left = percent((1 - fractionX) / 2); | 1676 style.left = percent((1 - fractionX) / 2); |
1673 style.top = percent((1 - fractionY) / 2); | 1677 style.top = percent((1 - fractionY) / 2); |
1674 }; | 1678 }; |
1675 | 1679 |
1676 /** | 1680 /** |
1681 * Ask the GData service to re-fetch the metadata for the current directory. | |
1682 */ | |
1683 FileManager.prototype.requestMetadataRefresh = function() { | |
1684 if (!this.isOnGData()) | |
1685 return; | |
1686 // TODO(kaznacheev) This does not really work with GData search. | |
1687 var url = this.getCurrentDirectoryURL(); | |
1688 // Skip if the current directory is now being refreshed. | |
1689 if (this.directoriesWithStaleMetadata_[url]) | |
1690 return; | |
1691 | |
1692 this.directoriesWithStaleMetadata_[url] = true; | |
1693 chrome.fileBrowserPrivate.requestDirectoryRefresh(url); | |
1694 }; | |
1695 | |
1696 /** | |
1677 * Create a box containing a centered thumbnail image. | 1697 * Create a box containing a centered thumbnail image. |
1678 * | 1698 * |
1679 * @param {Entry} entry Entry which thumbnail is generating for. | 1699 * @param {Entry} entry Entry which thumbnail is generating for. |
1680 * @param {boolean} True if fill, false if fit. | 1700 * @param {boolean} True if fill, false if fit. |
1681 * @param {function(HTMLElement)} opt_imageLoadCallback Callback called when | 1701 * @param {function(HTMLElement)} opt_imageLoadCallback Callback called when |
1682 * the image has been loaded before inserting | 1702 * the image has been loaded before inserting |
1683 * it into the DOM. | 1703 * it into the DOM. |
1684 * @return {HTMLDivElement} Thumbnal box. | 1704 * @return {HTMLDivElement} Thumbnal box. |
1685 */ | 1705 */ |
1686 FileManager.prototype.renderThumbnailBox_ = function(entry, fill, | 1706 FileManager.prototype.renderThumbnailBox_ = function(entry, fill, |
1687 opt_imageLoadCallback) { | 1707 opt_imageLoadCallback) { |
1688 var box = this.document_.createElement('div'); | 1708 var box = this.document_.createElement('div'); |
1689 box.className = 'img-container'; | 1709 box.className = 'img-container'; |
1690 var img = this.document_.createElement('img'); | 1710 var img = this.document_.createElement('img'); |
1691 var self = this; | 1711 var self = this; |
1692 | 1712 |
1693 function onThumbnailURL(iconType, url, transform) { | 1713 function onThumbnailURL(iconType, url, transform) { |
1694 self.thumbnailUrlCache_[entry.fullPath] = { | 1714 self.thumbnailUrlCache_[entry.fullPath] = { |
1695 iconType: iconType, | 1715 iconType: iconType, |
1696 url: url, | 1716 url: url, |
1697 transform: transform | 1717 transform: transform, |
dgozman
2012/05/21 16:01:17
extra comma
Vladislav Kaznacheev
2012/05/21 16:12:27
Done.
| |
1698 }; | 1718 }; |
1699 img.onload = function() { | 1719 img.onload = function() { |
1700 self.centerImage_(img.style, img.width, img.height, fill); | 1720 self.centerImage_(img.style, img.width, img.height, fill); |
1701 if (opt_imageLoadCallback) | 1721 if (opt_imageLoadCallback) |
1702 opt_imageLoadCallback(img, transform); | 1722 opt_imageLoadCallback(img, transform); |
1703 box.appendChild(img); | 1723 box.appendChild(img); |
1704 }; | 1724 }; |
1705 img.onerror = function() { | 1725 img.onerror = function() { |
1706 // Use the default icon if we could not fetch the correct one. | 1726 // Use the default icon if we could not fetch the correct one. |
1707 img.src = FileType.getPreviewArt(iconType); | 1727 img.src = FileType.getPreviewArt(iconType); |
1708 transform = null; | 1728 transform = null; |
1709 util.applyTransform(box, transform); | 1729 util.applyTransform(box, transform); |
1730 | |
1731 var cached = self.thumbnailUrlCache_[entry.fullPath]; | |
1732 if (!cached.failed) { | |
1733 cached.failed = true; | |
1734 self.requestMetadataRefresh(); | |
1735 // Failing to fetch a thumbnail likely means that the thumbnail URL | |
1736 // is now stale. Request a refresh of the current directory, to get | |
1737 // the new thumbnail URLs. Once the directory is refreshed, we'll get | |
1738 // notified via onFileChanged event. | |
1739 self.requestMetadataRefresh(); | |
1740 } | |
1710 }; | 1741 }; |
1711 img.src = url; | 1742 img.src = url; |
1712 util.applyTransform(box, transform); | 1743 util.applyTransform(box, transform); |
1713 } | 1744 } |
1714 | 1745 |
1715 // TODO(dgozman): move to new metadata cache. | 1746 // TODO(dgozman): move to new metadata cache. |
1716 var cached = this.thumbnailUrlCache_[entry.fullPath]; | 1747 var cached = this.thumbnailUrlCache_[entry.fullPath]; |
1717 if (cached) | 1748 // Don't reuse the cached URL if we are now retrying. |
1749 if (cached && !cached.failed) | |
1718 onThumbnailURL(cached.iconType, cached.url, cached.transform); | 1750 onThumbnailURL(cached.iconType, cached.url, cached.transform); |
1719 else | 1751 else { |
1752 if (cached && cached.failed) { | |
1753 delete cached.failed; | |
1754 this.metadataProvider_.reset(entry.toURL()); // Clear the cache. | |
1755 } | |
1720 this.getThumbnailURL(entry, onThumbnailURL); | 1756 this.getThumbnailURL(entry, onThumbnailURL); |
1757 } | |
1721 | 1758 |
1722 return box; | 1759 return box; |
1723 }; | 1760 }; |
1724 | 1761 |
1725 FileManager.prototype.decorateThumbnail_ = function(li, entry) { | 1762 FileManager.prototype.decorateThumbnail_ = function(li, entry) { |
1726 li.className = 'thumbnail-item'; | 1763 li.className = 'thumbnail-item'; |
1727 | 1764 |
1728 if (this.showCheckboxes_) | 1765 if (this.showCheckboxes_) |
1729 li.appendChild(this.renderSelectionCheckbox_(entry)); | 1766 li.appendChild(this.renderSelectionCheckbox_(entry)); |
1730 | 1767 |
(...skipping 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3674 if (!result) { | 3711 if (!result) { |
3675 console.log('Failed to remove file watch'); | 3712 console.log('Failed to remove file watch'); |
3676 } | 3713 } |
3677 }); | 3714 }); |
3678 this.watchedDirectoryUrl_ = null; | 3715 this.watchedDirectoryUrl_ = null; |
3679 } | 3716 } |
3680 }; | 3717 }; |
3681 | 3718 |
3682 FileManager.prototype.onFileChanged_ = function(event) { | 3719 FileManager.prototype.onFileChanged_ = function(event) { |
3683 // We receive a lot of events even in folders we are not interested in. | 3720 // We receive a lot of events even in folders we are not interested in. |
3684 if (encodeURI(event.fileUrl) == this.getSearchOrCurrentDirectoryURL()) | 3721 if (encodeURI(event.fileUrl) == this.getSearchOrCurrentDirectoryURL()) { |
3722 // This event is not necessarily caused by the metadata refresh | |
3723 // completion. We clear the map knowing that if the metadata is still | |
3724 // stale then a new re-fetch will be requested. | |
3725 delete this.directoriesWithStaleMetadata_[event.fileUrl]; | |
dgozman
2012/05/21 16:01:17
I do think, you need an escaped fileUrl.
Vladislav Kaznacheev
2012/05/21 16:12:27
Done.
| |
3685 this.directoryModel_.rescanLater(); | 3726 this.directoryModel_.rescanLater(); |
3727 } | |
3686 }; | 3728 }; |
3687 | 3729 |
3688 FileManager.prototype.initiateRename_ = function() { | 3730 FileManager.prototype.initiateRename_ = function() { |
3689 var item = this.currentList_.ensureLeadItemExists(); | 3731 var item = this.currentList_.ensureLeadItemExists(); |
3690 if (!item) | 3732 if (!item) |
3691 return; | 3733 return; |
3692 var label = item.querySelector('.filename-label'); | 3734 var label = item.querySelector('.filename-label'); |
3693 var input = this.renameInput_; | 3735 var input = this.renameInput_; |
3694 | 3736 |
3695 input.value = label.textContent; | 3737 input.value = label.textContent; |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4655 | 4697 |
4656 function closeBanner() { | 4698 function closeBanner() { |
4657 self.cleanupGDataWelcome_(); | 4699 self.cleanupGDataWelcome_(); |
4658 // Stop showing the welcome banner. | 4700 // Stop showing the welcome banner. |
4659 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; | 4701 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; |
4660 } | 4702 } |
4661 | 4703 |
4662 return maybeShowBanner; | 4704 return maybeShowBanner; |
4663 }; | 4705 }; |
4664 })(); | 4706 })(); |
OLD | NEW |