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

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

Issue 132453007: Migrate fullPaths to URLs in appState. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 10 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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 * @param {Object=} opt_appState App state. 511 * @param {Object=} opt_appState App state.
512 * @param {number=} opt_id Window id. 512 * @param {number=} opt_id Window id.
513 * @param {LaunchType=} opt_type Launch type. Default: ALWAYS_CREATE. 513 * @param {LaunchType=} opt_type Launch type. Default: ALWAYS_CREATE.
514 * @param {function(string)=} opt_callback Completion callback with the App ID. 514 * @param {function(string)=} opt_callback Completion callback with the App ID.
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 URL. 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) { 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 continue; 532 continue;
533 533
534 // Different current directories. 534 // Different current directories.
535 if (opt_appState.currentDirectoryPath !== 535 if (opt_appState.currentDirectoryURL !==
536 contentWindow.appState.currentDirectoryPath) { 536 contentWindow.appState.currentDirectoryURL) {
537 continue; 537 continue;
538 } 538 }
539 539
540 // Selection path specified, and it is different. 540 // Selection URL specified, and it is different.
541 if (opt_appState.selectionPath && 541 if (opt_appState.selectionURL &&
542 opt_appState.selectionPath !== 542 opt_appState.selectionURL !==
543 contentWindow.appState.selectionPath) { 543 contentWindow.appState.selectionURL) {
544 continue; 544 continue;
545 } 545 }
546 546
547 background.appWindows[key].focus(); 547 background.appWindows[key].focus();
548 if (opt_callback) 548 if (opt_callback)
549 opt_callback(key); 549 opt_callback(key);
550 onTaskCompleted(); 550 onTaskCompleted();
551 return; 551 return;
552 } 552 }
553 } 553 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 return; 662 return;
663 } 663 }
664 664
665 // Every other action opens a Files app window. 665 // Every other action opens a Files app window.
666 var appState = { 666 var appState = {
667 params: { 667 params: {
668 action: action 668 action: action
669 }, 669 },
670 // It is not allowed to call getParent() here, since there may be 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 671 // no permissions to access it at this stage. Therefore we are passing
672 // the selectionPath only, and the currentDirectory will be resolved 672 // the selectionURL only, and the currentDirectory will be resolved
673 // later. 673 // later.
674 selectionPath: details.entries[0].fullPath 674 selectionURL: details.entries[0].toURL()
675 }; 675 };
676 // For mounted devices just focus any Files.app window. The mounted 676 // For mounted devices just focus any Files.app window. The mounted
677 // volume will appear on the navigation list. 677 // volume will appear on the navigation list.
678 var type = action == 'auto-open' ? LaunchType.FOCUS_ANY_OR_CREATE : 678 var type = action == 'auto-open' ? LaunchType.FOCUS_ANY_OR_CREATE :
679 LaunchType.FOCUS_SAME_OR_CREATE; 679 LaunchType.FOCUS_SAME_OR_CREATE;
680 launchFileManager(appState, /* App ID */ undefined, type, nextStep); 680 launchFileManager(appState, /* App ID */ undefined, type, nextStep);
681 }); 681 });
682 break; 682 break;
683 } 683 }
684 }; 684 };
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 videoPlayer.reopen(); 767 videoPlayer.reopen();
768 }; 768 };
769 769
770 /** 770 /**
771 * Handles clicks on a custom item on the launcher context menu. 771 * Handles clicks on a custom item on the launcher context menu.
772 * @param {OnClickData} info Event details. 772 * @param {OnClickData} info Event details.
773 * @private 773 * @private
774 */ 774 */
775 Background.prototype.onContextMenuClicked_ = function(info) { 775 Background.prototype.onContextMenuClicked_ = function(info) {
776 if (info.menuItemId == 'new-window') { 776 if (info.menuItemId == 'new-window') {
777 // 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 url for the
778 // new window. If not found, then launch with the default path. 778 // new window. If not found, then launch with the default url.
779 for (var key in background.appWindows) { 779 for (var key in background.appWindows) {
780 try { 780 try {
781 if (background.appWindows[key].contentWindow.isFocused()) { 781 if (background.appWindows[key].contentWindow.isFocused()) {
782 var appState = { 782 var appState = {
783 // Do not clone the selection path, only the current directory. 783 // Do not clone the selection url, only the current directory.
784 currentDirectoryPath: background.appWindows[key].contentWindow. 784 currentDirectoryURL: background.appWindows[key].contentWindow.
785 appState.currentDirectoryPath 785 appState.currentDirectoryURL
786 }; 786 };
787 launchFileManager(appState); 787 launchFileManager(appState);
788 return; 788 return;
789 } 789 }
790 } catch (ignore) { 790 } catch (ignore) {
791 // The isFocused method may not be defined during initialization. 791 // The isFocused method may not be defined during initialization.
792 // Therefore, wrapped with a try-catch block. 792 // Therefore, wrapped with a try-catch block.
793 } 793 }
794 } 794 }
795 795
796 // Launch with the default path. 796 // Launch with the default URL.
797 launchFileManager(); 797 launchFileManager();
798 } 798 }
799 }; 799 };
800 800
801 /** 801 /**
802 * Initializes the context menu. Recreates if already exists. 802 * Initializes the context menu. Recreates if already exists.
803 * @private 803 * @private
804 */ 804 */
805 Background.prototype.initContextMenu_ = function() { 805 Background.prototype.initContextMenu_ = function() {
806 try { 806 try {
807 chrome.contextMenus.remove('new-window'); 807 chrome.contextMenus.remove('new-window');
808 } catch (ignore) { 808 } catch (ignore) {
809 // There is no way to detect if the context menu is already added, therefore 809 // There is no way to detect if the context menu is already added, therefore
810 // try to recreate it every time. 810 // try to recreate it every time.
811 } 811 }
812 chrome.contextMenus.create({ 812 chrome.contextMenus.create({
813 id: 'new-window', 813 id: 'new-window',
814 contexts: ['launcher'], 814 contexts: ['launcher'],
815 title: str('NEW_WINDOW_BUTTON_LABEL') 815 title: str('NEW_WINDOW_BUTTON_LABEL')
816 }); 816 });
817 }; 817 };
818 818
819 /** 819 /**
820 * Singleton instance of Background. 820 * Singleton instance of Background.
821 * @type {Background} 821 * @type {Background}
822 */ 822 */
823 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