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

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

Issue 10391103: [File Manager] Add/remove Google Drive folder in the open File Manager when Drive enabled/disabled … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // The list of archives requested to mount. We will show contents once 364 // The list of archives requested to mount. We will show contents once
365 // archive is mounted, but only for mounts from within this filebrowser tab. 365 // archive is mounted, but only for mounts from within this filebrowser tab.
366 this.mountRequests_ = []; 366 this.mountRequests_ = [];
367 this.unmountRequests_ = []; 367 this.unmountRequests_ = [];
368 chrome.fileBrowserPrivate.onMountCompleted.addListener( 368 chrome.fileBrowserPrivate.onMountCompleted.addListener(
369 this.onMountCompleted_.bind(this)); 369 this.onMountCompleted_.bind(this));
370 370
371 chrome.fileBrowserPrivate.onFileChanged.addListener( 371 chrome.fileBrowserPrivate.onFileChanged.addListener(
372 this.onFileChanged_.bind(this)); 372 this.onFileChanged_.bind(this));
373 373
374 this.networkConnectionState_ = null; 374 var queryGDataPreferences = function() {
375 chrome.fileBrowserPrivate.getGDataPreferences(
376 this.onGDataPreferencesChanged_.bind(this));
377 }.bind(this);
378 queryGDataPreferences();
379 chrome.fileBrowserPrivate.onGDataPreferencesChanged.
380 addListener(queryGDataPreferences);
381
375 var queryNetworkConnectionState = function() { 382 var queryNetworkConnectionState = function() {
376 chrome.fileBrowserPrivate.getNetworkConnectionState( 383 chrome.fileBrowserPrivate.getNetworkConnectionState(
377 this.onNetworkConnectionChanged_.bind(this)); 384 this.onNetworkConnectionChanged_.bind(this));
378 }.bind(this); 385 }.bind(this);
379 queryNetworkConnectionState(); 386 queryNetworkConnectionState();
380 chrome.fileBrowserPrivate.onNetworkConnectionChanged. 387 chrome.fileBrowserPrivate.onNetworkConnectionChanged.
381 addListener(queryNetworkConnectionState); 388 addListener(queryNetworkConnectionState);
382 389
383 var invokeHandler = !this.params_.selectOnly; 390 var invokeHandler = !this.params_.selectOnly;
384 if (this.isStartingOnGData_()) { 391 if (this.isStartingOnGData_()) {
(...skipping 11 matching lines...) Expand all
396 this.setupCurrentDirectory_( 403 this.setupCurrentDirectory_(
397 invokeHandler, false /* blankWhileOpeningAFile */); 404 invokeHandler, false /* blankWhileOpeningAFile */);
398 }.bind(this); 405 }.bind(this);
399 this.directoryModel_.addEventListener('directory-changed', 406 this.directoryModel_.addEventListener('directory-changed',
400 this.setupCurrentDirectoryPostponed_); 407 this.setupCurrentDirectoryPostponed_);
401 } else { 408 } else {
402 this.setupCurrentDirectory_( 409 this.setupCurrentDirectory_(
403 invokeHandler, true /* blankWhileOpeningAFile */); 410 invokeHandler, true /* blankWhileOpeningAFile */);
404 } 411 }
405 412
413 if (this.isGDataEnabled())
414 this.setupGDataWelcome_();
415
406 this.summarizeSelection_(); 416 this.summarizeSelection_();
407 417
408 var sortField = 418 var sortField =
409 window.localStorage['sort-field-' + this.dialogType_] || 419 window.localStorage['sort-field-' + this.dialogType_] ||
410 'modificationTime'; 420 'modificationTime';
411 var sortDirection = 421 var sortDirection =
412 window.localStorage['sort-direction-' + this.dialogType_] || 'desc'; 422 window.localStorage['sort-direction-' + this.dialogType_] || 'desc';
413 this.directoryModel_.sortFileList(sortField, sortDirection); 423 this.directoryModel_.sortFileList(sortField, sortDirection);
414 424
415 this.refocus(); 425 this.refocus();
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 this.dialogContainer_.setAttribute('gdata', true); 582 this.dialogContainer_.setAttribute('gdata', true);
573 583
574 this.syncButton = this.dialogDom_.querySelector('#gdata-sync-settings'); 584 this.syncButton = this.dialogDom_.querySelector('#gdata-sync-settings');
575 this.syncButton.addEventListener('click', this.onGDataPrefClick_.bind( 585 this.syncButton.addEventListener('click', this.onGDataPrefClick_.bind(
576 this, 'cellularDisabled', false /* not inverted */)); 586 this, 'cellularDisabled', false /* not inverted */));
577 587
578 this.hostedButton = this.dialogDom_.querySelector('#gdata-hosted-settings'); 588 this.hostedButton = this.dialogDom_.querySelector('#gdata-hosted-settings');
579 this.hostedButton.addEventListener('click', this.onGDataPrefClick_.bind( 589 this.hostedButton.addEventListener('click', this.onGDataPrefClick_.bind(
580 this, 'hostedFilesDisabled', true /* inverted */)); 590 this, 'hostedFilesDisabled', true /* inverted */));
581 591
582 this.gdataPreferences_ = null;
583 var queryGDataPreferences = function() {
584 chrome.fileBrowserPrivate.getGDataPreferences(
585 this.onGDataPreferencesChanged_.bind(this));
586 }.bind(this);
587 queryGDataPreferences();
588 chrome.fileBrowserPrivate.onGDataPreferencesChanged.
589 addListener(queryGDataPreferences);
590
591 cr.ui.ComboButton.decorate(this.taskItems_); 592 cr.ui.ComboButton.decorate(this.taskItems_);
592 this.taskItems_.addEventListener('select', 593 this.taskItems_.addEventListener('select',
593 this.onTaskItemClicked_.bind(this)); 594 this.onTaskItemClicked_.bind(this));
594 595
595 this.dialogDom_.ownerDocument.defaultView.addEventListener( 596 this.dialogDom_.ownerDocument.defaultView.addEventListener(
596 'resize', this.onResize_.bind(this)); 597 'resize', this.onResize_.bind(this));
597 598
598 if (str('ASH') == '1') 599 if (str('ASH') == '1')
599 this.dialogDom_.setAttribute('ash', 'true'); 600 this.dialogDom_.setAttribute('ash', 'true');
600 601
601 this.filePopup_ = null; 602 this.filePopup_ = null;
602 603
603 this.dialogDom_.querySelector('#search-box').addEventListener( 604 this.dialogDom_.querySelector('#search-box').addEventListener(
604 'input', this.onSearchBoxUpdate_.bind(this)); 605 'input', this.onSearchBoxUpdate_.bind(this));
605 606
606 // Populate the static localized strings. 607 // Populate the static localized strings.
607 i18nTemplate.process(this.document_, localStrings.templateData); 608 i18nTemplate.process(this.document_, localStrings.templateData);
608 }; 609 };
609 610
610 /** 611 /**
611 * Constructs table and grid (heavy operation). 612 * Constructs table and grid (heavy operation).
612 **/ 613 **/
613 FileManager.prototype.initFileList_ = function() { 614 FileManager.prototype.initFileList_ = function() {
614 // Always sharing the data model between the detail/thumb views confuses 615 // Always sharing the data model between the detail/thumb views confuses
615 // them. Instead we maintain this bogus data model, and hook it up to the 616 // them. Instead we maintain this bogus data model, and hook it up to the
616 // view that is not in use. 617 // view that is not in use.
617 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); 618 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]);
618 this.emptySelectionModel_ = new cr.ui.ListSelectionModel(); 619 this.emptySelectionModel_ = new cr.ui.ListSelectionModel();
619 620
620 var sigleSelection = 621 var singleSelection =
621 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE || 622 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE ||
622 this.dialogType_ == FileManager.DialogType.SELECT_FOLDER || 623 this.dialogType_ == FileManager.DialogType.SELECT_FOLDER ||
623 this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE; 624 this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE;
624 625
625 this.directoryModel_ = new DirectoryModel( 626 this.directoryModel_ = new DirectoryModel(
626 this.filesystem_.root, 627 this.filesystem_.root,
627 sigleSelection, 628 singleSelection,
628 FileManager.isGDataEnabled(),
629 this.metadataCache_); 629 this.metadataCache_);
630 630
631 if (FileManager.isGDataEnabled())
632 this.initGDataWelcomeBanners_();
633
634 var dataModel = this.directoryModel_.getFileList(); 631 var dataModel = this.directoryModel_.getFileList();
635 var collator = this.collator_; 632 var collator = this.collator_;
636 // TODO(dgozman): refactor comparison functions together with 633 // TODO(dgozman): refactor comparison functions together with
637 // render/update/display. 634 // render/update/display.
638 dataModel.setCompareFunction('name', function(a, b) { 635 dataModel.setCompareFunction('name', function(a, b) {
639 return collator.compare(a.name, b.name); 636 return collator.compare(a.name, b.name);
640 }); 637 });
641 dataModel.setCompareFunction('modificationTime', 638 dataModel.setCompareFunction('modificationTime',
642 this.compareMtime_.bind(this)); 639 this.compareMtime_.bind(this));
643 dataModel.setCompareFunction('size', 640 dataModel.setCompareFunction('size',
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 return self.renderRoot_(entry); 673 return self.renderRoot_(entry);
677 }; 674 };
678 675
679 this.rootsList_.selectionModel = 676 this.rootsList_.selectionModel =
680 this.directoryModel_.getRootsListSelectionModel(); 677 this.directoryModel_.getRootsListSelectionModel();
681 678
682 // TODO(dgozman): add "Add a drive" item. 679 // TODO(dgozman): add "Add a drive" item.
683 this.rootsList_.dataModel = this.directoryModel_.getRootsList(); 680 this.rootsList_.dataModel = this.directoryModel_.getRootsList();
684 this.directoryModel_.updateRoots(function() { 681 this.directoryModel_.updateRoots(function() {
685 self.rootsList_.endBatchUpdates(); 682 self.rootsList_.endBatchUpdates();
686 }, false); 683 }, this.getGDataAccessMode_());
687 }; 684 };
688 685
689 /** 686 /**
690 * @param {boolean} dirChanged True if we just changed to GData directory, 687 * @param {boolean} dirChanged True if we just changed to GData directory,
691 * False if "Retry" button clicked. 688 * False if "Retry" button clicked.
692 */ 689 */
693 FileManager.prototype.initGData_ = function(dirChanged) { 690 FileManager.prototype.initGData_ = function(dirChanged) {
694 this.initGDataUnmountedPanel_(); 691 this.initGDataUnmountedPanel_();
695 692
696 this.unmountedPanel_.removeAttribute('error'); 693 this.unmountedPanel_.removeAttribute('error');
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 730
734 FileManager.prototype.clearGDataLoadingTimer_ = function(message) { 731 FileManager.prototype.clearGDataLoadingTimer_ = function(message) {
735 if (this.gdataLoadingTimer_) { 732 if (this.gdataLoadingTimer_) {
736 clearTimeout(this.gdataLoadingTimer_); 733 clearTimeout(this.gdataLoadingTimer_);
737 this.gdataLoadingTimer_ = null; 734 this.gdataLoadingTimer_ = null;
738 } 735 }
739 }; 736 };
740 737
741 FileManager.prototype.onGDataUnreachable_ = function(message) { 738 FileManager.prototype.onGDataUnreachable_ = function(message) {
742 console.warn(message); 739 console.warn(message);
740 this.gdataMounted_ = false;
741 this.gdataMountInfo_ = null;
742 this.clearGDataLoadingTimer_();
743 if (this.isOnGData()) { 743 if (this.isOnGData()) {
744 this.unmountedPanel_.removeAttribute('loading'); 744 this.unmountedPanel_.removeAttribute('loading');
745 this.unmountedPanel_.setAttribute('error', true); 745 this.unmountedPanel_.setAttribute('error', true);
746 this.unmountedPanel_.setAttribute('retry', true); 746 this.unmountedPanel_.setAttribute('retry', true);
747 } 747 }
748 }; 748 };
749 749
750 FileManager.prototype.initGDataUnmountedPanel_ = function() { 750 FileManager.prototype.initGDataUnmountedPanel_ = function() {
751 if (this.unmountedPanel_.firstElementChild) 751 if (this.unmountedPanel_.firstElementChild)
752 return; 752 return;
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 setVisibility('visible'); 2332 setVisibility('visible');
2333 self.previewThumbnails_.textContent = ''; 2333 self.previewThumbnails_.textContent = '';
2334 self.onResize_(); 2334 self.onResize_();
2335 } 2335 }
2336 2336
2337 function setVisibility(visibility) { 2337 function setVisibility(visibility) {
2338 panel.setAttribute('visibility', visibility); 2338 panel.setAttribute('visibility', visibility);
2339 } 2339 }
2340 }; 2340 };
2341 2341
2342 FileManager.isGDataEnabled = function() { 2342 FileManager.prototype.isGDataEnabled = function() {
2343 return str('ENABLE_GDATA') == '1'; 2343 return this.getGDataPreferences_().driveEnabled;
2344 };
2345
2346 FileManager.prototype.updateGDataAccess_ = function() {
2347 if (this.isGDataEnabled())
2348 this.setupGDataWelcome_();
2349 else
2350 this.cleanupGDataWelcome_();
2351
2352 var changeDirectory = !this.isGDataEnabled() && this.isOnGData();
2353
2354 this.directoryModel_.updateRoots(function() {
2355 if (changeDirectory)
2356 this.directoryModel_.changeDirectory(
2357 this.directoryModel_.getDefaultDirectory());
2358 }.bind(this), this.getGDataAccessMode_());
2359 };
2360
2361 FileManager.prototype.getGDataAccessMode_ = function() {
2362 if (!this.isGDataEnabled())
2363 return DirectoryModel.GDATA_ACCESS_DISABLED;
2364 if (!this.gdataMounted_)
2365 return DirectoryModel.GDATA_ACCESS_LAZY;
2366 return DirectoryModel.GDATA_ACCESS_FULL;
2344 }; 2367 };
2345 2368
2346 FileManager.prototype.isOnGData = function() { 2369 FileManager.prototype.isOnGData = function() {
2347 return this.directoryModel_ && 2370 return this.directoryModel_ &&
2348 this.directoryModel_.getCurrentRootPath() == 2371 this.directoryModel_.getCurrentRootPath() ==
2349 '/' + DirectoryModel.GDATA_DIRECTORY; 2372 '/' + DirectoryModel.GDATA_DIRECTORY;
2350 }; 2373 };
2351 2374
2352 FileManager.prototype.isStartingOnGData_ = function() { 2375 FileManager.prototype.isStartingOnGData_ = function() {
2353 var path = this.getPathFromUrlOrParams_(); 2376 var path = this.getPathFromUrlOrParams_();
2354 return path && 2377 return path &&
2355 FileManager.isGDataEnabled() && 2378 this.isGDataEnabled() &&
2356 DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA; 2379 DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA;
2357 }; 2380 };
2358 2381
2359 FileManager.prototype.getMetadataProvider = function() { 2382 FileManager.prototype.getMetadataProvider = function() {
2360 return this.metadataProvider_; 2383 return this.metadataProvider_;
2361 }; 2384 };
2362 2385
2363 /** 2386 /**
2364 * Callback called when tasks for selected files are determined. 2387 * Callback called when tasks for selected files are determined.
2365 * @param {Object} selection Selection is passed here, since this.selection 2388 * @param {Object} selection Selection is passed here, since this.selection
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
2578 }.bind(this)); 2601 }.bind(this));
2579 return; 2602 return;
2580 } 2603 }
2581 callback(urls); 2604 callback(urls);
2582 }.bind(this)); 2605 }.bind(this));
2583 } else { 2606 } else {
2584 callback(urls); 2607 callback(urls);
2585 } 2608 }
2586 }; 2609 };
2587 2610
2611 FileManager.prototype.getGDataPreferences_ = function() {
2612 return this.gdataPreferences_ ||
2613 { driveEnabled: str('ENABLE_GDATA') == '1' };
2614 };
2615
2616 FileManager.prototype.getNetworkConnectionState_ = function() {
2617 return this.networkConnectionState_ || {};
2618 };
2619
2588 FileManager.prototype.onNetworkConnectionChanged_ = function(state) { 2620 FileManager.prototype.onNetworkConnectionChanged_ = function(state) {
2589 console.log(state.online, state.type); 2621 console.log(state.online ? 'online' : 'offline', state.type);
2590 this.networkConnectionState_ = state; 2622 this.networkConnectionState_ = state;
2591 this.directoryModel_.setOffline(!state.online); 2623 this.directoryModel_.setOffline(!state.online);
2592 this.updateConnectionState_(); 2624 this.updateConnectionState_();
2593 }; 2625 };
2594 2626
2595 FileManager.prototype.onGDataPreferencesChanged_ = function(preferences) { 2627 FileManager.prototype.onGDataPreferencesChanged_ = function(preferences) {
2628 var gdataWasEnabled = this.isGDataEnabled();
2596 this.gdataPreferences_ = preferences; 2629 this.gdataPreferences_ = preferences;
2630 if (gdataWasEnabled != this.isGDataEnabled())
2631 this.updateGDataAccess_();
2632
2597 if (preferences.cellularDisabled) 2633 if (preferences.cellularDisabled)
2598 this.syncButton.setAttribute('checked', 'checked'); 2634 this.syncButton.setAttribute('checked', 'checked');
2599 else 2635 else
2600 this.syncButton.removeAttribute('checked'); 2636 this.syncButton.removeAttribute('checked');
2601 2637
2602 if (!preferences.hostedFilesDisabled) 2638 if (!preferences.hostedFilesDisabled)
2603 this.hostedButton.setAttribute('checked', 'checked'); 2639 this.hostedButton.setAttribute('checked', 'checked');
2604 else 2640 else
2605 this.hostedButton.removeAttribute('checked'); 2641 this.hostedButton.removeAttribute('checked');
2606 2642
2607 this.updateConnectionState_(); 2643 this.updateConnectionState_();
2608 }; 2644 };
2609 2645
2610 FileManager.prototype.updateConnectionState_ = function() { 2646 FileManager.prototype.updateConnectionState_ = function() {
2611 if (this.isOffline()) 2647 if (this.isOffline())
2612 this.dialogContainer_.setAttribute('connection', 'offline'); 2648 this.dialogContainer_.setAttribute('connection', 'offline');
2613 else if (this.isOnMeteredConnection()) 2649 else if (this.isOnMeteredConnection())
2614 this.dialogContainer_.setAttribute('connection', 'metered'); 2650 this.dialogContainer_.setAttribute('connection', 'metered');
2615 else 2651 else
2616 this.dialogContainer_.removeAttribute('connection'); 2652 this.dialogContainer_.removeAttribute('connection');
2617 }; 2653 };
2618 2654
2619 FileManager.prototype.isOnMeteredConnection = function() { 2655 FileManager.prototype.isOnMeteredConnection = function() {
2620 return this.gdataPreferences_ && 2656 return this.getGDataPreferences_().cellularDisabled &&
2621 this.gdataPreferences_.cellularDisabled && 2657 this.getNetworkConnectionState_().online &&
2622 this.networkConnectionState_ && 2658 this.getNetworkConnectionState_().type == 'cellular';
2623 this.networkConnectionState_.online &&
2624 this.networkConnectionState_.type == 'cellular';
2625 }; 2659 };
2626 2660
2627 FileManager.prototype.isOffline = function() { 2661 FileManager.prototype.isOffline = function() {
2628 return this.networkConnectionState_ && !this.networkConnectionState_.online; 2662 return !this.getNetworkConnectionState_().online;
2629 }; 2663 };
2630 2664
2631 FileManager.prototype.isOnReadonlyDirectory = function() { 2665 FileManager.prototype.isOnReadonlyDirectory = function() {
2632 return this.directoryModel_.isReadOnly(); 2666 return this.directoryModel_.isReadOnly();
2633 }; 2667 };
2634 2668
2635 /** 2669 /**
2636 * Event handler called when some volume was mounted or unmouted. 2670 * Event handler called when some volume was mounted or unmouted.
2637 */ 2671 */
2638 FileManager.prototype.onMountCompleted_ = function(event) { 2672 FileManager.prototype.onMountCompleted_ = function(event) {
(...skipping 16 matching lines...) Expand all
2655 // the timer fires after the mount because onDirectoryChanged_ will hide 2689 // the timer fires after the mount because onDirectoryChanged_ will hide
2656 // the unmounted panel. 2690 // the unmounted panel.
2657 if (this.setupCurrentDirectoryPostponed_) { 2691 if (this.setupCurrentDirectoryPostponed_) {
2658 this.setupCurrentDirectoryPostponed_(false /* execute */); 2692 this.setupCurrentDirectoryPostponed_(false /* execute */);
2659 } else if (this.isOnGData() && 2693 } else if (this.isOnGData() &&
2660 this.directoryModel_.getCurrentDirEntry().unmounted) { 2694 this.directoryModel_.getCurrentDirEntry().unmounted) {
2661 // We are currently on an unmounted GData directory, force a rescan. 2695 // We are currently on an unmounted GData directory, force a rescan.
2662 changeDirectoryTo = this.directoryModel_.getCurrentRootPath(); 2696 changeDirectoryTo = this.directoryModel_.getCurrentRootPath();
2663 } 2697 }
2664 } else { 2698 } else {
2665 this.gdataMounted_ = false;
2666 this.gdataMountInfo_ = null;
2667 this.clearGDataLoadingTimer_();
2668 this.onGDataUnreachable_('GData ' + 2699 this.onGDataUnreachable_('GData ' +
2669 (mounted ? ('mount failed: ' + event.status) : 'unmounted')); 2700 (mounted ? ('mount failed: ' + event.status) : 'unmounted'));
2670 if (this.setupCurrentDirectoryPostponed_) { 2701 if (this.setupCurrentDirectoryPostponed_) {
2671 this.setupCurrentDirectoryPostponed_(true /* cancel */); 2702 this.setupCurrentDirectoryPostponed_(true /* cancel */);
2672 // Change to unmounted GData root. 2703 // Change to unmounted GData root.
2673 changeDirectoryTo = '/' + DirectoryModel.GDATA_DIRECTORY; 2704 changeDirectoryTo = '/' + DirectoryModel.GDATA_DIRECTORY;
2674 } 2705 }
2675 } 2706 }
2676 } 2707 }
2677 2708
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2722 } 2753 }
2723 } 2754 }
2724 2755
2725 // Even if something failed root list should be rescanned. 2756 // Even if something failed root list should be rescanned.
2726 // Failed mounts can "give" us new devices which might be formatted, 2757 // Failed mounts can "give" us new devices which might be formatted,
2727 // so we have to refresh root list then. 2758 // so we have to refresh root list then.
2728 this.directoryModel_.updateRoots(function() { 2759 this.directoryModel_.updateRoots(function() {
2729 if (changeDirectoryTo) { 2760 if (changeDirectoryTo) {
2730 this.directoryModel_.changeDirectory(changeDirectoryTo); 2761 this.directoryModel_.changeDirectory(changeDirectoryTo);
2731 } 2762 }
2732 }.bind(this), this.gdataMounted_); 2763 }.bind(this), this.getGDataAccessMode_());
2733 }.bind(this)); 2764 }.bind(this));
2734 }; 2765 };
2735 2766
2736 /** 2767 /**
2737 * Event handler called when some internal task should be executed. 2768 * Event handler called when some internal task should be executed.
2738 */ 2769 */
2739 FileManager.prototype.onFileTaskExecute_ = function(id, urls) { 2770 FileManager.prototype.onFileTaskExecute_ = function(id, urls) {
2740 if (id == 'play') { 2771 if (id == 'play') {
2741 var position = 0; 2772 var position = 0;
2742 if (urls.length == 1) { 2773 if (urls.length == 1) {
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
3515 this.dialogContainer_.setAttribute('unmounted', true); 3546 this.dialogContainer_.setAttribute('unmounted', true);
3516 else { 3547 else {
3517 this.dialogContainer_.removeAttribute('unmounted'); 3548 this.dialogContainer_.removeAttribute('unmounted');
3518 // Need to resize explicitly because the list container had display:none. 3549 // Need to resize explicitly because the list container had display:none.
3519 this.onResize_(); 3550 this.onResize_();
3520 } 3551 }
3521 3552
3522 if (this.isOnGData()) { 3553 if (this.isOnGData()) {
3523 this.dialogContainer_.setAttribute('gdata', true); 3554 this.dialogContainer_.setAttribute('gdata', true);
3524 if (event.newDirEntry.unmounted) { 3555 if (event.newDirEntry.unmounted) {
3525 this.initGData_(true /* directory changed */); 3556 if (event.newDirEntry.error)
3557 this.onGDataUnreachable_('File error ' + event.newDirEntry.error);
3558 else
3559 this.initGData_(true /* directory changed */);
3526 } 3560 }
3527 } else { 3561 } else {
3528 this.dialogContainer_.removeAttribute('gdata'); 3562 this.dialogContainer_.removeAttribute('gdata');
3529 } 3563 }
3530 }; 3564 };
3531 3565
3532 FileManager.prototype.findListItemForEvent_ = function(event) { 3566 FileManager.prototype.findListItemForEvent_ = function(event) {
3533 return this.findListItemForNode_(event.srcElement); 3567 return this.findListItemForNode_(event.srcElement);
3534 }; 3568 };
3535 3569
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
4371 4405
4372 handleSplitterDragEnd: function(e) { 4406 handleSplitterDragEnd: function(e) {
4373 Splitter.prototype.handleSplitterDragEnd.apply(this, arguments); 4407 Splitter.prototype.handleSplitterDragEnd.apply(this, arguments);
4374 this.ownerDocument.documentElement.classList.remove('col-resize'); 4408 this.ownerDocument.documentElement.classList.remove('col-resize');
4375 } 4409 }
4376 }; 4410 };
4377 4411
4378 customSplitter.decorate(splitterElement); 4412 customSplitter.decorate(splitterElement);
4379 }; 4413 };
4380 4414
4381 FileManager.prototype.initGDataWelcomeBanners_ = function() { 4415 FileManager.prototype.setupGDataWelcome_ = function() {
4416 this.gdataWelcomeHandler_ = this.createGDataWelcomeHandler_();
4417 if (this.gdataWelcomeHandler_) {
4418 this.directoryModel_.addEventListener('scan-completed',
4419 this.gdataWelcomeHandler_);
4420 this.directoryModel_.addEventListener('rescan-completed',
4421 this.gdataWelcomeHandler_);
4422 }
4423 };
4424
4425 FileManager.prototype.cleanupGDataWelcome_ = function() {
4426 this.showGDataWelcome_('none');
4427
4428 if (this.gdataWelcomeHandler_) {
4429 this.directoryModel_.removeEventListener('scan-completed',
4430 this.gdataWelcomeHandler_);
4431 this.directoryModel_.removeEventListener('rescan-completed',
4432 this.gdataWelcomeHandler_);
4433 this.gdataWelcomeHandler_ = null;
4434 }
4435 };
4436
4437 FileManager.prototype.showGDataWelcome_ = function(type) {
4438 if (this.dialogContainer_.getAttribute('gdrive-welcome') != type) {
4439 this.dialogContainer_.setAttribute('gdrive-welcome', type);
4440 this.requestResize_(200); // Resize only after the animation is done.
4441 }
4442 };
4443
4444 FileManager.prototype.createGDataWelcomeHandler_ = function() {
4382 var WELCOME_HEADER_COUNTER_KEY = 'gdataWelcomeHeaderCounter'; 4445 var WELCOME_HEADER_COUNTER_KEY = 'gdataWelcomeHeaderCounter';
4383 var WELCOME_HEADER_COUNTER_LIMIT = 5; 4446 var WELCOME_HEADER_COUNTER_LIMIT = 5;
4384 4447
4385 function getHeaderCounter() { 4448 function getHeaderCounter() {
4386 return parseInt(localStorage[WELCOME_HEADER_COUNTER_KEY] || '0'); 4449 return parseInt(localStorage[WELCOME_HEADER_COUNTER_KEY] || '0');
4387 } 4450 }
4388 4451
4389 if (getHeaderCounter() >= WELCOME_HEADER_COUNTER_LIMIT) 4452 if (getHeaderCounter() >= WELCOME_HEADER_COUNTER_LIMIT)
4390 return; 4453 return null;
4391 4454
4392 function createDiv(className, parent) { 4455 function createDiv(className, parent) {
4393 var div = parent.ownerDocument.createElement('div'); 4456 var div = parent.ownerDocument.createElement('div');
4394 div.className = className; 4457 div.className = className;
4395 parent.appendChild(div); 4458 parent.appendChild(div);
4396 return div; 4459 return div;
4397 } 4460 }
4398 4461
4399 var self = this; 4462 var self = this;
4400 4463
4401 var RESIZE_DELAY = 200; // Resize only after the animation is done. 4464 function showBanner(type, messageId) {
4465 if (!self.dialogContainer_.hasAttribute('gdrive-welcome-style')) {
4466 self.dialogContainer_.setAttribute('gdrive-welcome-style', true);
4467 var style = self.document_.createElement('link');
4468 style.rel = 'stylesheet';
4469 style.href = 'css/gdrive_welcome.css';
4470 self.document_.head.appendChild(style);
4471 style.onload = function() { showBanner(type, messageId) };
4472 return;
4473 }
4402 4474
4403 function showBanner(type, messageId) { 4475 self.showGDataWelcome_(type);
4404 self.dialogContainer_.setAttribute('gdrive-welcome', type);
4405 self.requestResize_(RESIZE_DELAY);
4406 4476
4407 var container = self.dialogDom_.querySelector('.gdrive-welcome.' + type); 4477 var container = self.dialogDom_.querySelector('.gdrive-welcome.' + type);
4408 if (container.firstElementChild) 4478 if (container.firstElementChild)
4409 return; // Do not re-create. 4479 return; // Do not re-create.
4410 4480
4411 var wrapper = createDiv('gdrive-welcome-wrapper', container); 4481 var wrapper = createDiv('gdrive-welcome-wrapper', container);
4412 createDiv('gdrive-welcome-icon', wrapper); 4482 createDiv('gdrive-welcome-icon', wrapper);
4413 4483
4414 var close = createDiv('cr-dialog-close', wrapper); 4484 var close = createDiv('cr-dialog-close', wrapper);
4415 close.addEventListener('click', closeBanner); 4485 close.addEventListener('click', closeBanner);
(...skipping 16 matching lines...) Expand all
4432 4502
4433 var dismiss = createDiv('gdrive-welcome-dismiss plain-link', links); 4503 var dismiss = createDiv('gdrive-welcome-dismiss plain-link', links);
4434 dismiss.textContent = str('GDATA_WELCOME_DISMISS'); 4504 dismiss.textContent = str('GDATA_WELCOME_DISMISS');
4435 dismiss.addEventListener('click', closeBanner); 4505 dismiss.addEventListener('click', closeBanner);
4436 } 4506 }
4437 4507
4438 var previousDirWasOnGData = false; 4508 var previousDirWasOnGData = false;
4439 4509
4440 function maybeShowBanner() { 4510 function maybeShowBanner() {
4441 if (!self.isOnGData()) { 4511 if (!self.isOnGData()) {
4442 self.dialogContainer_.removeAttribute('gdrive-welcome'); 4512 self.showGDataWelcome_('none');
4443 self.requestResize_(RESIZE_DELAY);
4444 previousDirWasOnGData = false; 4513 previousDirWasOnGData = false;
4445 return; 4514 return;
4446 } 4515 }
4447 4516
4448 var counter = getHeaderCounter(); 4517 var counter = getHeaderCounter();
4449 4518
4450 if (self.directoryModel_.getFileList().length == 0 && counter == 0) { 4519 if (self.directoryModel_.getFileList().length == 0 && counter == 0) {
4451 // Only show the full page banner if the header banner was never shown. 4520 // Only show the full page banner if the header banner was never shown.
4452 // Do not increment the counter. 4521 // Do not increment the counter.
4453 showBanner('page', 'GDATA_WELCOME_TEXT_LONG'); 4522 showBanner('page', 'GDATA_WELCOME_TEXT_LONG');
4454 } else if (counter < WELCOME_HEADER_COUNTER_LIMIT) { 4523 } else if (counter < WELCOME_HEADER_COUNTER_LIMIT) {
4455 // We do not want to increment the counter when the user navigates 4524 // We do not want to increment the counter when the user navigates
4456 // between different directories on GDrive, but we increment the counter 4525 // between different directories on GDrive, but we increment the counter
4457 // once anyway to prevent the full page banner from showing. 4526 // once anyway to prevent the full page banner from showing.
4458 if (!previousDirWasOnGData || counter == 0) 4527 if (!previousDirWasOnGData || counter == 0)
4459 localStorage[WELCOME_HEADER_COUNTER_KEY] = ++counter; 4528 localStorage[WELCOME_HEADER_COUNTER_KEY] = ++counter;
4460 showBanner('header', 'GDATA_WELCOME_TEXT_SHORT'); 4529 showBanner('header', 'GDATA_WELCOME_TEXT_SHORT');
4461 } else { 4530 } else {
4462 closeBanner(); 4531 closeBanner();
4463 } 4532 }
4464 previousDirWasOnGData = true; 4533 previousDirWasOnGData = true;
4465 } 4534 }
4466 4535
4467 function closeBanner() { 4536 function closeBanner() {
4468 self.directoryModel_.removeEventListener('scan-completed', 4537 self.cleanupGDataWelcome_();
4469 maybeShowBanner);
4470 self.directoryModel_.removeEventListener('rescan-completed',
4471 maybeShowBanner);
4472
4473 self.dialogContainer_.removeAttribute('gdrive-welcome');
4474 self.requestResize_(RESIZE_DELAY);
4475
4476 // Stop showing the welcome banner. 4538 // Stop showing the welcome banner.
4477 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; 4539 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT;
4478 } 4540 }
4479 4541
4480 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); 4542 return maybeShowBanner;
4481 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner);
4482
4483 var style = this.document_.createElement('link');
4484 style.rel = 'stylesheet';
4485 style.href = 'css/gdrive_welcome.css';
4486 this.document_.head.appendChild(style);
4487 }; 4543 };
4488 })(); 4544 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/js/directory_model.js ('k') | chrome/browser/resources/file_manager/js/mock_chrome.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698