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

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

Powered by Google App Engine
This is Rietveld 408576698