| Index: chrome/browser/resources/file_manager/js/background.js
|
| diff --git a/chrome/browser/resources/file_manager/js/background.js b/chrome/browser/resources/file_manager/js/background.js
|
| index 8b5e83fd1f998cce6998fd4bc1e73c0a0351b205..23e3502be2a46d22849cc08c25ce79be8ddccf3c 100644
|
| --- a/chrome/browser/resources/file_manager/js/background.js
|
| +++ b/chrome/browser/resources/file_manager/js/background.js
|
| @@ -387,10 +387,12 @@ function reopenFileManagers() {
|
| }
|
|
|
| /**
|
| + * Executes a file browser task.
|
| + *
|
| * @param {string} action Task id.
|
| * @param {Object} details Details object.
|
| */
|
| -function executeFileBrowserTask(action, details) {
|
| +function onExecute(action, details) {
|
| var urls = details.entries.map(function(e) { return e.toURL() });
|
|
|
| switch (action) {
|
| @@ -469,9 +471,9 @@ function launchVideoPlayer(url) {
|
| }
|
|
|
| /**
|
| - * Launch the app.
|
| + * Launches the app.
|
| */
|
| -function launch() {
|
| +function onLaunched() {
|
| if (nextFileManagerWindowID == 0) {
|
| // The app just launched. Remove window state records that are not needed
|
| // any more.
|
| @@ -491,13 +493,41 @@ function launch() {
|
| /**
|
| * Restarted the app, restore windows.
|
| */
|
| -function restart() {
|
| +function onRestarted() {
|
| reopenFileManagers();
|
| audioPlayer.reopen();
|
| videoPlayer.reopen();
|
| }
|
|
|
| /**
|
| + * Handles clicks on a custom item on the launcher context menu.
|
| + * @param {OnClickData} info Event details.
|
| + */
|
| +function onContextMenuClicked(info) {
|
| + if (info.menuItemId == 'new-window') {
|
| + // Find the focused window (if any) and use it's current path for the
|
| + // new window. If not found, then launch with the default path.
|
| + for (var key in appWindows) {
|
| + try {
|
| + if (appWindows[key].contentWindow.isFocused()) {
|
| + var appState = {
|
| + defaultPath: appWindows[key].contentWindow.appState.defaultPath
|
| + };
|
| + launchFileManager(appState);
|
| + return;
|
| + }
|
| + } catch (ignore) {
|
| + // The isFocused method may not be defined during initialization.
|
| + // Therefore, wrapped with a try-catch block.
|
| + }
|
| + }
|
| +
|
| + // Launch with the default path.
|
| + launchFileManager();
|
| + }
|
| +}
|
| +
|
| +/**
|
| * Closes the background page, if it is not needed.
|
| */
|
| function maybeCloseBackgroundPage() {
|
| @@ -506,11 +536,34 @@ function maybeCloseBackgroundPage() {
|
| close();
|
| }
|
|
|
| -chrome.app.runtime.onLaunched.addListener(launch);
|
| -chrome.app.runtime.onRestarted.addListener(restart);
|
| +/**
|
| + * Initializes the context menu.
|
| + * @param {Object} strings Hash array of strings.
|
| + */
|
| +function initContextMenu(strings) {
|
| + chrome.contextMenus.create({
|
| + id: 'new-window',
|
| + contexts: ['launcher'],
|
| + title: strings['NEW_WINDOW_BUTTON_LABEL']
|
| + });
|
| +}
|
|
|
| -function addExecuteHandler() {
|
| - chrome.fileBrowserHandler.onExecute.addListener(executeFileBrowserTask);
|
| +/**
|
| + * Initializes the background page of Files.app.
|
| + */
|
| +function initApp() {
|
| + // Fetch strings and save in the local storage, before initializing handlers.
|
| + chrome.fileBrowserPrivate.getStrings(function(strings) {
|
| + initContextMenu(strings);
|
| + // Save and initialize handlers.
|
| + chrome.storage.local.set({strings: strings}, function() {
|
| + chrome.fileBrowserHandler.onExecute.addListener(onExecute);
|
| + chrome.app.runtime.onLaunched.addListener(onLaunched);
|
| + chrome.app.runtime.onRestarted.addListener(onRestarted);
|
| + chrome.contextMenus.onClicked.addListener(onContextMenuClicked);
|
| + });
|
| + });
|
| }
|
|
|
| -addExecuteHandler();
|
| +// Initialize Files.app.
|
| +initApp();
|
|
|