*/
BackgroundComponents.load = function() {
var stringDataPromise = new Promise(function(fulfill) {
- chrome.fileBrowserPrivate.getStrings(function(stringData) {
+ chrome.fileManagerPrivate.getStrings(function(stringData) {
loadTimeData.data = stringData;
fulfill(stringData);
});
*/
function resolveEntries(entries) {
return new Promise(function(fulfill, reject) {
- chrome.fileBrowserPrivate.resolveIsolatedEntries(entries,
- function(externalEntries) {
- if (!chrome.runtime.lastError)
- fulfill(externalEntries);
- else
- reject(chrome.runtime.lastError);
- });
+ chrome.fileManagerPrivate.resolveIsolatedEntries(
+ entries, function(externalEntries) {
+ if (!chrome.runtime.lastError)
+ fulfill(externalEntries);
+ else
+ reject(chrome.runtime.lastError);
+ });
});
}
/**
* Promise to be fulfilled with single application window.
+ * This can be null when the window is not opened.
* @type {Promise}
*/
-var appWindowPromise = Promise.resolve(null);
+var appWindowPromise = null;
/**
- * Promise to be fulfilled with the current window is closed.
+ * Promise to be fulfilled with entries that are used for reopening the
+ * application window.
* @type {Promise}
*/
-var closingPromise = Promise.resolve(null);
+var reopenEntriesPromsie = null;
/**
* Launches the application with entries.
*
* @param {Promise} selectedEntriesPromise Promise to be fulfilled with the
- * entries that are stored in the exteranl file system (not in the isolated
+ * entries that are stored in the external file system (not in the isolated
* file system).
+ * @return {Promise} Promise to be fulfilled after the application is launched.
*/
function launch(selectedEntriesPromise) {
// If there is the previous window, close the window.
- appWindowPromise = appWindowPromise.then(function(appWindow) {
- if (appWindow) {
+ if (appWindowPromise) {
+ reopenEntriesPromsie = selectedEntriesPromise;
+ appWindowPromise.then(function(appWindow) {
appWindow.close();
- return closingPromise;
- }
- });
+ });
+ return Promise.reject('The window has already opened.');
+ }
+ reopenEntriesPromsie = null;
// Create a new window.
- appWindowPromise = appWindowPromise.then(function() {
- return new Promise(function(fulfill) {
- chrome.app.window.create(
- 'gallery.html',
- {
- id: 'gallery',
- innerBounds: {
- minWidth: 800,
- minHeight: 300
- },
- frame: 'none'
+ appWindowPromise = new Promise(function(fulfill) {
+ chrome.app.window.create(
+ 'gallery.html',
+ {
+ id: 'gallery',
+ innerBounds: {
+ minWidth: 820,
+ minHeight: 544
},
- function(appWindow) {
- appWindow.contentWindow.addEventListener(
- 'load', fulfill.bind(null, appWindow));
- closingPromise = new Promise(function(fulfill) {
- appWindow.onClosed.addListener(fulfill);
- });
+ frame: 'none'
+ },
+ function(appWindow) {
+ appWindow.contentWindow.addEventListener(
+ 'load', fulfill.bind(null, appWindow));
+ appWindow.onClosed.addListener(function() {
+ appWindowPromise = null;
+ if (reopenEntriesPromsie)
+ launch(reopenEntriesPromsie);
});
- });
- });
-
- // Initialize the window document.
- appWindowPromise = Promise.all([
- appWindowPromise,
- backgroundComponentsPromise,
- ]).then(function(args) {
- args[0].contentWindow.initialize(args[1]);
- return args[0];
+ });
});
-
// If only 1 entry is selected, retrieve entries in the same directory.
// Otherwise, just use the selectedEntries as an entry set.
var allEntriesPromise = selectedEntriesPromise.then(function(entries) {
}
});
- // Open entries.
+ // Initialize the window document.
return Promise.all([
appWindowPromise,
- allEntriesPromise,
- selectedEntriesPromise
+ backgroundComponentsPromise,
]).then(function(args) {
- args[0].contentWindow.loadEntries(args[1], args[2]);
+ args[0].contentWindow.initialize(args[1]);
+ return Promise.all([
+ allEntriesPromise,
+ selectedEntriesPromise
+ ]).then(function(entries) {
+ args[0].contentWindow.loadEntries(entries[0], entries[1]);
+ });
});
}
// If is is run in the browser test, wait for the test resources are installed
// as a component extension, and then load the test resources.
if (chrome.test) {
+ /** @type {string} */
+ window.testExtensionId = 'ejhcmmdhhpdhhgmifplfmjobgegbibkn';
chrome.runtime.onMessageExternal.addListener(function(message) {
if (message.name !== 'testResourceLoaded')
return;
var script = document.createElement('script');
script.src =
- 'chrome-extension://ejhcmmdhhpdhhgmifplfmjobgegbibkn' +
- '/gallery/test_loader.js';
+ 'chrome-extension://' + window.testExtensionId +
+ '/common/test_loader.js';
document.documentElement.appendChild(script);
});
}