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

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

Issue 144783002: Simplify directory initialization in Files app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up. Created 6 years, 11 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Number of runtime errors catched in the background page. 8 * Number of runtime errors catched in the background page.
9 * @type {number} 9 * @type {number}
10 */ 10 */
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 */ 515 */
516 function launchFileManager(opt_appState, opt_id, opt_type, opt_callback) { 516 function launchFileManager(opt_appState, opt_id, opt_type, opt_callback) {
517 var type = opt_type || LaunchType.ALWAYS_CREATE; 517 var type = opt_type || LaunchType.ALWAYS_CREATE;
518 518
519 // Wait until all windows are created. 519 // Wait until all windows are created.
520 background.queue.run(function(onTaskCompleted) { 520 background.queue.run(function(onTaskCompleted) {
521 // Check if there is already a window with the same path. If so, then 521 // Check if there is already a window with the same path. If so, then
522 // reuse it instead of opening a new one. 522 // reuse it instead of opening a new one.
523 if (type == LaunchType.FOCUS_SAME_OR_CREATE || 523 if (type == LaunchType.FOCUS_SAME_OR_CREATE ||
524 type == LaunchType.FOCUS_ANY_OR_CREATE) { 524 type == LaunchType.FOCUS_ANY_OR_CREATE) {
525 if (opt_appState && opt_appState.defaultPath) { 525 if (opt_appState) {
526 for (var key in background.appWindows) { 526 for (var key in background.appWindows) {
527 if (!key.match(FILES_ID_PATTERN)) 527 if (!key.match(FILES_ID_PATTERN))
528 continue; 528 continue;
529 529
530 var contentWindow = background.appWindows[key].contentWindow; 530 var contentWindow = background.appWindows[key].contentWindow;
531 if (contentWindow.appState && 531 if (!contentWindow.appState)
532 opt_appState.defaultPath == contentWindow.appState.defaultPath) { 532 continue;
533 background.appWindows[key].focus(); 533
534 if (opt_callback) 534 // Different current directories.
535 opt_callback(key); 535 if (opt_appState.currentDirectoryPath !==
536 onTaskCompleted(); 536 contentWindow.appState.currentDirectoryPath) {
537 return; 537 continue;
538 } 538 }
539
540 // Selection path specified, and it is different.
541 if (opt_appState.selectionPath &&
542 opt_appState.selectionPath !==
543 contentWindow.appState.selectionPath) {
544 continue;
545 }
546
547 background.appWindows[key].focus();
548 if (opt_callback)
549 opt_callback(key);
550 onTaskCompleted();
551 return;
539 } 552 }
540 } 553 }
541 } 554 }
542 555
543 // Focus any window if none is focused. Try restored first. 556 // Focus any window if none is focused. Try restored first.
544 if (type == LaunchType.FOCUS_ANY_OR_CREATE) { 557 if (type == LaunchType.FOCUS_ANY_OR_CREATE) {
545 // If there is already a focused window, then finish. 558 // If there is already a focused window, then finish.
546 for (var key in background.appWindows) { 559 for (var key in background.appWindows) {
547 if (!key.match(FILES_ID_PATTERN)) 560 if (!key.match(FILES_ID_PATTERN))
548 continue; 561 continue;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 if (!launchEnable) { 660 if (!launchEnable) {
648 nextStep(); 661 nextStep();
649 return; 662 return;
650 } 663 }
651 664
652 // Every other action opens a Files app window. 665 // Every other action opens a Files app window.
653 var appState = { 666 var appState = {
654 params: { 667 params: {
655 action: action 668 action: action
656 }, 669 },
657 defaultPath: details.entries[0].fullPath 670 // It is not allowed to call getParent() here, since there may be
671 // no permissions to access it at this stage. Therefore we are passing
672 // the selectionPath only, and the currentDirectory will be resolved
673 // later.
674 selectionPath: details.entries[0].fullPath
658 }; 675 };
659 // For mounted devices just focus any Files.app window. The mounted 676 // For mounted devices just focus any Files.app window. The mounted
660 // volume will appear on the navigation list. 677 // volume will appear on the navigation list.
661 var type = action == 'auto-open' ? LaunchType.FOCUS_ANY_OR_CREATE : 678 var type = action == 'auto-open' ? LaunchType.FOCUS_ANY_OR_CREATE :
662 LaunchType.FOCUS_SAME_OR_CREATE; 679 LaunchType.FOCUS_SAME_OR_CREATE;
663 launchFileManager(appState, /* App ID */ undefined, type, nextStep); 680 launchFileManager(appState, /* App ID */ undefined, type, nextStep);
664 }); 681 });
665 break; 682 break;
666 } 683 }
667 }; 684 };
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 * @private 773 * @private
757 */ 774 */
758 Background.prototype.onContextMenuClicked_ = function(info) { 775 Background.prototype.onContextMenuClicked_ = function(info) {
759 if (info.menuItemId == 'new-window') { 776 if (info.menuItemId == 'new-window') {
760 // Find the focused window (if any) and use it's current path for the 777 // Find the focused window (if any) and use it's current path for the
761 // new window. If not found, then launch with the default path. 778 // new window. If not found, then launch with the default path.
762 for (var key in background.appWindows) { 779 for (var key in background.appWindows) {
763 try { 780 try {
764 if (background.appWindows[key].contentWindow.isFocused()) { 781 if (background.appWindows[key].contentWindow.isFocused()) {
765 var appState = { 782 var appState = {
766 defaultPath: background.appWindows[key].contentWindow. 783 // Do not clone the selection path, only the current directory.
767 appState.defaultPath 784 currentDirectoryPath: background.appWindows[key].contentWindow.
785 appState.currentDirectoryPath
768 }; 786 };
769 launchFileManager(appState); 787 launchFileManager(appState);
770 return; 788 return;
771 } 789 }
772 } catch (ignore) { 790 } catch (ignore) {
773 // The isFocused method may not be defined during initialization. 791 // The isFocused method may not be defined during initialization.
774 // Therefore, wrapped with a try-catch block. 792 // Therefore, wrapped with a try-catch block.
775 } 793 }
776 } 794 }
777 795
(...skipping 18 matching lines...) Expand all
796 contexts: ['launcher'], 814 contexts: ['launcher'],
797 title: str('NEW_WINDOW_BUTTON_LABEL') 815 title: str('NEW_WINDOW_BUTTON_LABEL')
798 }); 816 });
799 }; 817 };
800 818
801 /** 819 /**
802 * Singleton instance of Background. 820 * Singleton instance of Background.
803 * @type {Background} 821 * @type {Background}
804 */ 822 */
805 window.background = new Background(); 823 window.background = new Background();
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/url_util_unittest.cc ('k') | chrome/browser/resources/file_manager/common/js/util.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698