Commit d3deb8df authored by hirono@chromium.org's avatar hirono@chromium.org

Files.app: Re-open Gallery.app when the new entries are opened.

Previously the existing Galley.app window do nothing when new entries are opened
in Files.app. This CL make the Gallery.app reopen its window.

BUG=358698
TEST=manually
R=mtomasz@chromium.org

Review URL: https://codereview.chromium.org/294593003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271356 0039d316-1c4b-4281-b951-d872f2087c98
parent dafeaa3d
......@@ -91,6 +91,12 @@ function getChildren(entry) {
return readEntries();
}
/**
* Promise to be fulfilled with single application window.
* @param {AppWindow}
*/
var appWindowPromise = null;
chrome.app.runtime.onLaunched.addListener(function(launchData) {
// Skip if files are not selected.
if (!launchData || !launchData.items || launchData.items.length == 0)
......@@ -130,18 +136,50 @@ chrome.app.runtime.onLaunched.addListener(function(launchData) {
});
});
// Open application window.
chrome.app.window.create(
'gallery.html',
{
id: 'gallery',
minWidth: 160,
minHeight: 100,
frame: 'none'
},
function(appWindow) {
appWindow.contentWindow.launchData = launchData;
appWindow.contentWindow.backgroundComponentsPromise =
backgroundComponentsPromise;
// Close previous window.
var closePromise;
if (appWindowPromise) {
closePromise = appWindowPromise.then(function(appWindow) {
return new Promise(function(fulfill) {
appWindow.close();
appWindow.onClosed.addListener(fulfill);
});
});
} else {
closePromise = Promise.resolve();
}
var createdWindowPromise = closePromise.then(function() {
return new Promise(function(fulfill) {
chrome.app.window.create(
'gallery.html',
{
id: 'gallery',
minWidth: 160,
minHeight: 100,
frame: 'none'
},
function(appWindow) {
appWindow.contentWindow.addEventListener(
'load', fulfill.bind(null, appWindow));
});
});
});
appWindowPromise = Promise.all([
createdWindowPromise,
backgroundComponentsPromise,
]).then(function(args) {
args[0].contentWindow.initialize(args[1]);
return args[0];
});
// Open entries.
Promise.all([
appWindowPromise,
allEntriesPromise,
selectedEntriesPromise
]).then(function(args) {
args[0].contentWindow.loadEntries(args[1], args[2]);
}).catch(function(error) {
console.error(error.stack || error);
});
});
......@@ -860,17 +860,24 @@ Gallery.prototype.updateButtons_ = function() {
}
};
window.addEventListener('load', function() {
Promise.all([
window.backgroundComponentsPromise,
window.launchData.entriesPromise
]).then(function(args) {
var backgroundComponents = args[0];
var entries = args[1];
window.loadTimeData.data = backgroundComponents.stringData;
var gallery = new Gallery(backgroundComponents.volumeManager);
gallery.load(entries.allEntries, entries.selectedEntries);
}).catch(function(error) {
console.error(error.stack || error);
});
});
/**
* Singleton gallery.
* @type {Gallery}
*/
var gallery = null;
/**
* Initialize the window.
* @param {Object} backgroundComponents Background components.
*/
window.initialize = function(backgroundComponents) {
window.loadTimeData.data = backgroundComponents.stringData;
gallery = new Gallery(backgroundComponents.volumeManager);
};
/**
* Loads entries.
*/
window.loadEntries = function(entries, selectedEntries) {
gallery.load(entries, selectedEntries);
};
......@@ -52,7 +52,6 @@
// util.js and async_util.js should be included before volume_manager.js.
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/common/js/util.js",
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/common/js/async_util.js",
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/common/js/path_util.js",
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/common/js/volume_manager_common.js",
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/background/js/volume_manager.js",
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/background/js/test_util.js",
......
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