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