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 // Setting the src of an img to an empty string can crash the browser, so we | 5 // Setting the src of an img to an empty string can crash the browser, so we |
6 // use an empty 1x1 gif instead. | 6 // use an empty 1x1 gif instead. |
7 | 7 |
8 /** | 8 /** |
9 * FileManager constructor. | 9 * FileManager constructor. |
10 * | 10 * |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 this.filenameInput_ = this.dialogDom_.querySelector('.filename-input'); | 628 this.filenameInput_ = this.dialogDom_.querySelector('.filename-input'); |
629 this.taskItems_ = this.dialogDom_.querySelector('.tasks'); | 629 this.taskItems_ = this.dialogDom_.querySelector('.tasks'); |
630 this.okButton_ = this.dialogDom_.querySelector('.ok'); | 630 this.okButton_ = this.dialogDom_.querySelector('.ok'); |
631 this.cancelButton_ = this.dialogDom_.querySelector('.cancel'); | 631 this.cancelButton_ = this.dialogDom_.querySelector('.cancel'); |
632 this.deleteButton_ = this.dialogDom_.querySelector('.delete-button'); | 632 this.deleteButton_ = this.dialogDom_.querySelector('.delete-button'); |
633 this.table_ = this.dialogDom_.querySelector('.detail-table'); | 633 this.table_ = this.dialogDom_.querySelector('.detail-table'); |
634 this.grid_ = this.dialogDom_.querySelector('.thumbnail-grid'); | 634 this.grid_ = this.dialogDom_.querySelector('.thumbnail-grid'); |
635 this.spinner_ = this.dialogDom_.querySelector('.spinner'); | 635 this.spinner_ = this.dialogDom_.querySelector('.spinner'); |
636 this.showSpinner_(false); | 636 this.showSpinner_(false); |
637 this.butter_ = this.dialogDom_.querySelector('.butter-bar'); | 637 this.butter_ = this.dialogDom_.querySelector('.butter-bar'); |
638 this.unmountedPanel_ = this.dialogDom_.querySelector('.unmounted-panel'); | |
638 | 639 |
639 cr.ui.Table.decorate(this.table_); | 640 cr.ui.Table.decorate(this.table_); |
640 cr.ui.Grid.decorate(this.grid_); | 641 cr.ui.Grid.decorate(this.grid_); |
641 | 642 |
642 this.downloadsWarning_ = | 643 this.downloadsWarning_ = |
643 this.dialogDom_.querySelector('.downloads-warning'); | 644 this.dialogDom_.querySelector('.downloads-warning'); |
644 var html = util.htmlUnescape(str('DOWNLOADS_DIRECTORY_WARNING')); | 645 var html = util.htmlUnescape(str('DOWNLOADS_DIRECTORY_WARNING')); |
645 this.downloadsWarning_.lastElementChild.innerHTML = html; | 646 this.downloadsWarning_.lastElementChild.innerHTML = html; |
646 var link = this.downloadsWarning_.querySelector('a'); | 647 var link = this.downloadsWarning_.querySelector('a'); |
647 link.addEventListener('click', this.onDownloadsWarningClick_.bind(this)); | 648 link.addEventListener('click', this.onDownloadsWarningClick_.bind(this)); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 this.rootsList_.itemConstructor = function(entry) { | 794 this.rootsList_.itemConstructor = function(entry) { |
794 return self.renderRoot_(entry); | 795 return self.renderRoot_(entry); |
795 }; | 796 }; |
796 | 797 |
797 this.rootsList_.selectionModel = this.directoryModel_.rootsListSelection; | 798 this.rootsList_.selectionModel = this.directoryModel_.rootsListSelection; |
798 | 799 |
799 // TODO(dgozman): add "Add a drive" item. | 800 // TODO(dgozman): add "Add a drive" item. |
800 this.rootsList_.dataModel = this.directoryModel_.rootsList; | 801 this.rootsList_.dataModel = this.directoryModel_.rootsList; |
801 this.directoryModel_.updateRoots(function() { | 802 this.directoryModel_.updateRoots(function() { |
802 self.rootsList_.endBatchUpdates(); | 803 self.rootsList_.endBatchUpdates(); |
803 }); | 804 }, this.gdataMounted_); |
804 }; | 805 }; |
805 | 806 |
806 FileManager.prototype.initGData_ = function() { | 807 FileManager.prototype.initGData_ = function(retry) { |
dgozman
2012/03/26 16:30:21
|retry| is not a meaningful name. Does it mean we
Vladislav Kaznacheev
2012/03/27 09:25:35
changed to |dirChanged|
On 2012/03/26 16:30:21, dg
| |
808 if (this.gdataMountTimer_) // Already mounting, do nothing. | |
809 return; | |
810 | |
811 this.initUnmountedPanel_(); | |
812 | |
813 this.unmountedPanel_.removeAttribute('error'); | |
814 if (retry) { | |
815 // When retrying we do not hide "Retry" and "Learn more". | |
816 this.unmountedPanel_.setAttribute('loading', true); | |
817 } else { | |
818 // When trying on a GData directory change we want to see a clear panel. | |
819 this.unmountedPanel_.removeAttribute('retry'); | |
820 this.unmountedPanel_.removeAttribute('loading'); | |
821 setTimeout(function() { | |
822 if (this.gdataMountTimer_) { // Still mounting. | |
823 this.unmountedPanel_.setAttribute('loading', true); | |
824 } | |
825 }.bind(this), 500); // Avoid flicker if the mount is quick. | |
826 } | |
827 | |
807 metrics.startInterval('Load.GData'); | 828 metrics.startInterval('Load.GData'); |
808 chrome.fileBrowserPrivate.addMount('', 'gdata', {}); | 829 chrome.fileBrowserPrivate.addMount('', 'gdata', {}); |
809 if (this.gdataMountTimer_) { | 830 |
810 clearTimeout(this.gdataMountTimer_); | 831 this.gdataMountTimer_ = setTimeout( |
832 this.onGDataUnreachable_.bind(this, 'GData mount timeout'), | |
833 10 * 1000) ; | |
834 }; | |
835 | |
836 FileManager.prototype.onGDataUnreachable_ = function(message) { | |
837 console.warn(message); | |
838 this.gdataMountTimer_ = null; | |
839 if (this.isOnGData()) { | |
840 this.unmountedPanel_.removeAttribute('loading'); | |
841 this.unmountedPanel_.setAttribute('error', true); | |
842 this.unmountedPanel_.setAttribute('retry', true); | |
811 } | 843 } |
812 this.gdataMountTimer_ = setTimeout(function() { | 844 }; |
813 this.gdataMountTimer_ = null; | 845 |
814 if (this.isOnGData()) { | 846 FileManager.prototype.initUnmountedPanel_ = function() { |
dgozman
2012/03/26 16:30:21
Consider not so generic |gdataPanel| or |gdataNotM
Vladislav Kaznacheev
2012/03/27 09:25:35
Done.
| |
815 // TODO(kaznacheev): show the message in the file list space. | 847 if (this.unmountedPanel_.firstElementChild) |
816 this.alert.show('Could not connect to GData'); | 848 return; |
817 } | 849 |
818 }.bind(this), 10 * 1000); | 850 var loading = this.document_.createElement('div'); |
851 loading.className = 'gdata loading'; | |
852 loading.textContent = strf('GDATA_LOADING', str('GDATA_PRODUCT_NAME')); | |
853 this.unmountedPanel_.appendChild(loading); | |
854 | |
855 var error = this.document_.createElement('div'); | |
856 error.className = 'gdata error'; | |
857 error.textContent = strf('GDATA_CANNOT_REACH', str('GDATA_PRODUCT_NAME')); | |
858 this.unmountedPanel_.appendChild(error); | |
859 | |
860 var retry = this.document_.createElement('button'); | |
861 retry.className = 'gdata retry'; | |
862 retry.textContent = str('GDATA_RETRY'); | |
863 retry.onclick = this.initGData_.bind(this, true /* retry */); | |
864 this.unmountedPanel_.appendChild(retry); | |
865 | |
866 var learnMore = this.document_.createElement('div'); | |
867 learnMore.className = 'gdata learn-more'; | |
868 this.unmountedPanel_.appendChild(learnMore); | |
869 | |
870 var learnMoreLink = this.document_.createElement('a'); | |
871 learnMoreLink.textContent = str('GDATA_LEARN_MORE'); | |
872 learnMoreLink.href = 'javascript://'; // TODO: Set a proper link URL. | |
873 learnMoreLink.className = 'gdata learn-more'; | |
874 learnMore.appendChild(learnMoreLink); | |
819 }; | 875 }; |
820 | 876 |
821 /** | 877 /** |
822 * Get the icon type for a given Entry. | 878 * Get the icon type for a given Entry. |
823 * | 879 * |
824 * @param {Entry} entry An Entry subclass (FileEntry or DirectoryEntry). | 880 * @param {Entry} entry An Entry subclass (FileEntry or DirectoryEntry). |
825 * @return {string} | 881 * @return {string} |
826 */ | 882 */ |
827 FileManager.prototype.getIconType = function(entry) { | 883 FileManager.prototype.getIconType = function(entry) { |
828 if (!('cachedIconType_' in entry)) | 884 if (!('cachedIconType_' in entry)) |
(...skipping 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2542 "mountPath": event.mountPath, | 2598 "mountPath": event.mountPath, |
2543 "sourceUrl": event.sourceUrl, | 2599 "sourceUrl": event.sourceUrl, |
2544 "mountType": event.mountType, | 2600 "mountType": event.mountType, |
2545 "mountCondition": event.status | 2601 "mountCondition": event.status |
2546 }; | 2602 }; |
2547 if (this.isOnGData()) { | 2603 if (this.isOnGData()) { |
2548 // We are currently on an unmounted GData directory, force a rescan. | 2604 // We are currently on an unmounted GData directory, force a rescan. |
2549 changeDirectoryTo = this.directoryModel_.rootPath; | 2605 changeDirectoryTo = this.directoryModel_.rootPath; |
2550 } | 2606 } |
2551 } else { | 2607 } else { |
2608 this.onGDataUnreachable_('GData mount failed: ' + event.status); | |
2552 this.gdataMounted_ = false; | 2609 this.gdataMounted_ = false; |
2553 this.gdataMountInfo_ = null; | 2610 this.gdataMountInfo_ = null; |
2554 } | 2611 } |
2555 } | 2612 } |
2556 | 2613 |
2557 chrome.fileBrowserPrivate.getMountPoints(function(mountPoints) { | 2614 chrome.fileBrowserPrivate.getMountPoints(function(mountPoints) { |
2558 self.setMountPoints_(mountPoints); | 2615 self.setMountPoints_(mountPoints); |
2559 if (event.eventType == 'mount') { | 2616 if (event.eventType == 'mount') { |
2560 // Mount request finished - remove it. | 2617 // Mount request finished - remove it. |
2561 var index = self.mountRequests_.indexOf(event.sourceUrl); | 2618 var index = self.mountRequests_.indexOf(event.sourceUrl); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2599 changeDirectoryTo = '/' + DirectoryModel.DOWNLOADS_DIRECTORY; | 2656 changeDirectoryTo = '/' + DirectoryModel.DOWNLOADS_DIRECTORY; |
2600 } | 2657 } |
2601 | 2658 |
2602 // Even if something failed root list should be rescanned. | 2659 // Even if something failed root list should be rescanned. |
2603 // Failed mounts can "give" us new devices which might be formatted, | 2660 // Failed mounts can "give" us new devices which might be formatted, |
2604 // so we have to refresh root list then. | 2661 // so we have to refresh root list then. |
2605 self.directoryModel_.updateRoots(function() { | 2662 self.directoryModel_.updateRoots(function() { |
2606 if (changeDirectoryTo) { | 2663 if (changeDirectoryTo) { |
2607 self.directoryModel_.changeDirectory(changeDirectoryTo); | 2664 self.directoryModel_.changeDirectory(changeDirectoryTo); |
2608 } | 2665 } |
2609 }); | 2666 }, self.gdataMounted_); |
2610 }); | 2667 }); |
2611 }; | 2668 }; |
2612 | 2669 |
2613 /** | 2670 /** |
2614 * Event handler called when some internal task should be executed. | 2671 * Event handler called when some internal task should be executed. |
2615 */ | 2672 */ |
2616 FileManager.prototype.onFileTaskExecute_ = function(id, urls) { | 2673 FileManager.prototype.onFileTaskExecute_ = function(id, urls) { |
2617 if (id == 'play') { | 2674 if (id == 'play') { |
2618 var position = 0; | 2675 var position = 0; |
2619 if (urls.length == 1) { | 2676 if (urls.length == 1) { |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3463 } | 3520 } |
3464 chrome.fileBrowserPrivate.removeFileWatch(this.watchedDirectoryUrl_, | 3521 chrome.fileBrowserPrivate.removeFileWatch(this.watchedDirectoryUrl_, |
3465 function(result) { | 3522 function(result) { |
3466 if (!result) { | 3523 if (!result) { |
3467 console.log('Failed to remove file watch'); | 3524 console.log('Failed to remove file watch'); |
3468 } | 3525 } |
3469 }); | 3526 }); |
3470 this.watchedDirectoryUrl_ = null; | 3527 this.watchedDirectoryUrl_ = null; |
3471 } | 3528 } |
3472 | 3529 |
3473 if (event.newDirEntry.fullPath != '/') { | 3530 if (event.newDirEntry.fullPath != '/' && !event.newDirEntry.unmounted) { |
3474 this.watchedDirectoryUrl_ = event.newDirEntry.toURL(); | 3531 this.watchedDirectoryUrl_ = event.newDirEntry.toURL(); |
3475 chrome.fileBrowserPrivate.addFileWatch(this.watchedDirectoryUrl_, | 3532 chrome.fileBrowserPrivate.addFileWatch(this.watchedDirectoryUrl_, |
3476 function(result) { | 3533 function(result) { |
3477 if (!result) { | 3534 if (!result) { |
3478 console.log('Failed to add file watch'); | 3535 console.log('Failed to add file watch'); |
3479 this.watchedDirectoryUrl_ = null; | 3536 this.watchedDirectoryUrl_ = null; |
3480 } | 3537 } |
3481 }.bind(this)); | 3538 }.bind(this)); |
3482 } | 3539 } |
3483 | 3540 |
3484 this.updateVolumeMetadata_(); | 3541 this.updateVolumeMetadata_(); |
3485 | 3542 |
3543 if (event.newDirEntry.unmounted) | |
3544 this.dialogContainer_.setAttribute('unmounted'); | |
3545 else | |
3546 this.dialogContainer_.removeAttribute('unmounted'); | |
3547 | |
3486 if (this.isOnGData()) { | 3548 if (this.isOnGData()) { |
3487 this.dialogContainer_.setAttribute('gdata', true); | 3549 this.dialogContainer_.setAttribute('gdata', true); |
3488 if (!this.requestedGDataMount_) { // Request GData mount only once. | 3550 if (event.newDirEntry.unmounted) { |
3489 this.requestedGDataMount_ = true; | 3551 this.initGData_(false /* first try */); |
3490 this.initGData_(); | |
3491 } | 3552 } |
3492 } else { | 3553 } else { |
3493 this.dialogContainer_.removeAttribute('gdata'); | 3554 this.dialogContainer_.removeAttribute('gdata'); |
3494 } | 3555 } |
3495 }; | 3556 }; |
3496 | 3557 |
3497 FileManager.prototype.updateVolumeMetadata_ = function() { | 3558 FileManager.prototype.updateVolumeMetadata_ = function() { |
3498 var dm = this.directoryModel_; | 3559 var dm = this.directoryModel_; |
3499 if (!dm) return; | 3560 if (!dm) return; |
3500 | 3561 |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4279 }); | 4340 }); |
4280 }, onError); | 4341 }, onError); |
4281 | 4342 |
4282 function onError(err) { | 4343 function onError(err) { |
4283 console.log('Error while checking free space: ' + err); | 4344 console.log('Error while checking free space: ' + err); |
4284 setTimeout(doCheck, 1000 * 60); | 4345 setTimeout(doCheck, 1000 * 60); |
4285 } | 4346 } |
4286 } | 4347 } |
4287 } | 4348 } |
4288 })(); | 4349 })(); |
OLD | NEW |