Commit 0cf084ad authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Chromium LUCI CQ

Files app: Move global entities used from foreground

Move launchFileManager() from `launcher` namespace and registerDialog()
from global namespace to the interface FileBrowserBackgroundFull.

This keeps consistent all access from foreground page going through this
interface.

Bug: 1133186
Change-Id: I342af2db0aaec75843a9dccff777a6da29d3b9b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2613848Reviewed-by: default avatarJeremie Boulic <jboulic@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841330}
parent e9493f39
...@@ -80,4 +80,21 @@ ...@@ -80,4 +80,21 @@
* @param {boolean} enable * @param {boolean} enable
*/ */
forceFileOperationErrorForTest(enable) {} forceFileOperationErrorForTest(enable) {}
/**
* Registers a dialog (file picker or save as) in the background page.
* Dialogs are opened by the browser directly and should register themselves
* in the background page.
* @param {!Window} window
*/
registerDialog(window) {}
/**
* Launches a new File Manager window.
*
* @param {Object=} opt_appState App state.
* @return {!Promise<chrome.app.window.AppWindow|string>} Resolved with the
* App ID.
*/
async launchFileManager(opt_appState) {}
} }
...@@ -19,14 +19,5 @@ ...@@ -19,14 +19,5 @@
* @type {!BackgroundBase} * @type {!BackgroundBase}
*/ */
this.background; this.background;
/**
* @type {!Object}
*/
this.launcher = {};
} }
/**
* @param {Window} window
*/
registerDialog(window) {}
} }
...@@ -183,6 +183,33 @@ class FileBrowserBackgroundImpl extends BackgroundBaseImpl { ...@@ -183,6 +183,33 @@ class FileBrowserBackgroundImpl extends BackgroundBaseImpl {
fileOperationUtil.forceErrorForTest = enable; fileOperationUtil.forceErrorForTest = enable;
} }
/**
* Registers dialog window to the background page.
*
* @param {!Window} dialogWindow Window of the dialog.
*/
registerDialog(dialogWindow) {
const id = DIALOG_ID_PREFIX + (nextFileManagerDialogID++);
this.dialogs[id] = dialogWindow;
if (window.IN_TEST) {
dialogWindow.IN_TEST = true;
}
dialogWindow.addEventListener('pagehide', () => {
delete this.dialogs[id];
});
}
/**
* Launches a new File Manager window.
*
* @param {Object=} opt_appState App state.
* @return {!Promise<chrome.app.window.AppWindow|string>} Resolved with the
* App ID.
*/
async launchFileManager(opt_appState) {
return launcher.launchFileManager(opt_appState);
}
/** /**
* Opens the volume root (or opt directoryPath) in main UI. * Opens the volume root (or opt directoryPath) in main UI.
* *
...@@ -553,21 +580,6 @@ const DIALOG_ID_PREFIX = 'dialog#'; ...@@ -553,21 +580,6 @@ const DIALOG_ID_PREFIX = 'dialog#';
*/ */
let nextFileManagerDialogID = 0; let nextFileManagerDialogID = 0;
/**
* Registers dialog window to the background page.
*
* @param {!Window} dialogWindow Window of the dialog.
*/
/* #export */ function registerDialog(dialogWindow) {
const id = DIALOG_ID_PREFIX + (nextFileManagerDialogID++);
window.background.dialogs[id] = dialogWindow;
if (window.IN_TEST) {
dialogWindow.IN_TEST = true;
}
dialogWindow.addEventListener('pagehide', () => {
delete window.background.dialogs[id];
});
}
/** @const {!string} */ /** @const {!string} */
const GPLUS_PHOTOS_APP_ORIGIN = const GPLUS_PHOTOS_APP_ORIGIN =
...@@ -577,7 +589,8 @@ const GPLUS_PHOTOS_APP_ORIGIN = ...@@ -577,7 +589,8 @@ const GPLUS_PHOTOS_APP_ORIGIN =
* Singleton instance of Background object. * Singleton instance of Background object.
* @type {!FileBrowserBackgroundFull} * @type {!FileBrowserBackgroundFull}
*/ */
window.background = new FileBrowserBackgroundImpl(); /* #export */ const background = new FileBrowserBackgroundImpl();
window.background = background;
/** /**
* Lastly, end recording of the background page Load.BackgroundScript metric. * Lastly, end recording of the background page Load.BackgroundScript metric.
......
...@@ -505,7 +505,7 @@ class FileManager extends cr.EventTarget { ...@@ -505,7 +505,7 @@ class FileManager extends cr.EventTarget {
* @param {Object=} appState App state. * @param {Object=} appState App state.
*/ */
launchFileManager(appState) { launchFileManager(appState) {
this.backgroundPage_.launcher.launchFileManager(appState); this.fileBrowserBackground_.launchFileManager(appState);
} }
/** /**
...@@ -867,7 +867,7 @@ class FileManager extends cr.EventTarget { ...@@ -867,7 +867,7 @@ class FileManager extends cr.EventTarget {
await new Promise(resolve => this.fileBrowserBackground_.ready(resolve)); await new Promise(resolve => this.fileBrowserBackground_.ready(resolve));
loadTimeData.data = this.fileBrowserBackground_.stringData; loadTimeData.data = this.fileBrowserBackground_.stringData;
if (util.runningInBrowser()) { if (util.runningInBrowser()) {
this.backgroundPage_.registerDialog(window); this.fileBrowserBackground_.registerDialog(window);
} }
this.fileOperationManager_ = this.fileOperationManager_ =
this.fileBrowserBackground_.fileOperationManager; this.fileBrowserBackground_.fileOperationManager;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment