Commit 7412fe2c authored by hirono@chromium.org's avatar hirono@chromium.org

Use resolveIsolatedEntries in the separated new Gallery.app.

The API is added crrev.com/270720.

BUG=358698
TEST=run the new Gallery.app.
R=mtomasz@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270960 0039d316-1c4b-4281-b951-d872f2087c98
parent 54fd1633
......@@ -199,6 +199,8 @@
"common/js/error_util.js",
"common/js/path_util.js",
"common/js/util.js",
"common/js/volume_manager_common.js",
"foreground/js/file_type.js",
"foreground/js/metadata/byte_reader.js",
"foreground/js/metadata/exif_parser.js",
"foreground/js/metadata/function_parallel.js",
......
......@@ -34,6 +34,9 @@
<include name="IDR_FILE_MANAGER_VOLUME_MANAGER_JS" file="file_manager/background/js/volume_manager.js" flattenhtml="false" type="BINDATA" />
<include name="IDR_FILE_MANAGER_VOLUME_MANAGER_COMMON_JS" file="file_manager/common/js/volume_manager_common.js" flattenhtml="false" type="BINDATA" />
<!-- Scripts referred by the gallery app. -->
<include name="IDR_FILE_MANAGER_FILE_TYPE_JS" file="file_manager/foreground/js/file_type.js" flattenhtml="false" type="BINDATA" />
<!-- Scripts required by the metadata parser worker. -->
<include name="IDR_FILE_MANAGER_UTIL" file="file_manager/common/js/util.js" type="BINDATA" />
<include name="IDR_FILE_MANAGER_METADATA_DISPATCHER" file="file_manager/foreground/js/metadata/metadata_dispatcher.js" type="BINDATA" />
......
......@@ -4,44 +4,144 @@
'use strict';
var stringData = new Promise(function(fulfill) {
chrome.fileBrowserPrivate.getStrings(function(stringData) {
loadTimeData.data = stringData;
fulfill(stringData);
/**
* @param {Object.<string, string>} stringData String data.
* @param {VolumeManager} volumeManager Volume manager.
*/
function BackgroundComponents(stringData, volumeManager) {
/**
* String data.
* @type {Object.<string, string>}
*/
this.stringData = stringData;
/**
* Volume manager.
* @type {VolumeManager}
*/
this.volumeManager = volumeManager;
Object.freeze(this);
}
/**
* Loads background component.
* @return {Promise} Promise fulfilled with BackgroundComponents.
*/
BackgroundComponents.load = function() {
var stringDataPromise = new Promise(function(fulfill) {
chrome.fileBrowserPrivate.getStrings(function(stringData) {
loadTimeData.data = stringData;
fulfill(stringData);
});
});
});
// VolumeManager should be obtained after stringData initialized.
var volumeManager = stringData.then(function() {
return new Promise(function(fulfill) {
VolumeManager.getInstance(fulfill);
// VolumeManager should be obtained after stringData initialized.
var volumeManagerPromise = stringDataPromise.then(function() {
return new Promise(function(fulfill) {
VolumeManager.getInstance(fulfill);
});
});
});
var backgroundComponent = Promise.all([stringData, volumeManager]).
then(function(args) {
return {
stringData: args[0],
volumeManager: args[1]
};
return Promise.all([stringDataPromise, volumeManagerPromise]).then(
function(args) {
return new BackgroundComponents(args[0], args[1]);
});
};
/**
* Promise to be fulfilled with singleton instance of background components.
* @type {Promise}
*/
var backgroundComponentsPromise = BackgroundComponents.load();
/**
* Resolves file system names and obtains entries.
* @param {Array.<FileEntry>} entries Names of isolated file system.
* @return {Promise} Promise to be fulfilled with an entry array.
*/
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);
});
});
}
/**
* Obtains child entries.
* @param {DirectoryEntry} entry Directory entry.
* @return {Promise} Promise to be fulfilled with child entries.
*/
function getChildren(entry) {
var reader = entry.createReader();
var readEntries = function() {
return new Promise(reader.readEntries.bind(reader)).then(function(entries) {
if (entries.length === 0)
return [];
return readEntries().then(function(nextEntries) {
return entries.concat(nextEntries);
});
});
};
return readEntries();
}
chrome.app.runtime.onLaunched.addListener(function(launchData) {
// Skip if files are not selected.
if (!launchData || !launchData.items || launchData.items.length == 0)
return;
// Obtains entries in non-isolated file systems.
// The entries in launchData are stored in the isolated file system.
// We need to map the isolated entries to the normal entries to retrieve their
// parent directory.
var isolatedEntries = launchData.items.map(function(item) {
return item.entry;
});
var selectedEntriesPromise = backgroundComponentsPromise.then(function() {
return resolveEntries(isolatedEntries);
});
// 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) {
if (entries.length === 1) {
var parent = new Promise(entries[0].getParent.bind(entries[0]));
return parent.then(getChildren).then(function(entries) {
return entries.filter(FileType.isImageOrVideo);
});
} else {
return entries;
}
});
// Store the selected and all entries to the launchData.
launchData.entriesPromise = Promise.all([selectedEntriesPromise,
allEntriesPromise]).then(
function(args) {
return Object.freeze({
selectedEntries: args[0],
allEntries: args[1]
});
});
// Open application window.
chrome.app.window.create(
'gallery.html',
{
id: 'video',
id: 'gallery',
minWidth: 160,
minHeight: 100,
frame: 'none'
},
function(appWindow) {
appWindow.contentWindow.launchData = launchData;
appWindow.contentWindow.backgroundComponent = backgroundComponent;
appWindow.contentWindow.backgroundComponentsPromise =
backgroundComponentsPromise;
});
});
......@@ -887,15 +887,16 @@ Gallery.prototype.updateButtons_ = function() {
};
window.addEventListener('load', function() {
var entries = window.launchData.items.map(
function(item) { return item.entry; });
window.backgroundComponent.
then(function(inBackgroundComponent) {
window.loadTimeData.data = inBackgroundComponent.stringData;
var gallery = new Gallery(inBackgroundComponent.volumeManager);
gallery.load(entries, entries);
}).
catch(function(error) {
console.error(error.stack || error);
});
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);
});
});
......@@ -13,6 +13,7 @@
},
"permissions": [
"fileSystem",
"fileBrowserHandler",
"fileBrowserPrivate",
"fullscreen",
"mediaPlayerPrivate",
......@@ -55,6 +56,7 @@
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/background/js/volume_manager.js",
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/background/js/test_util.js",
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/common/js/error_util.js",
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/foreground/js/file_type.js",
"js/background.js"
]
},
......
......@@ -75,8 +75,10 @@ function ImageLoader() {
* @const
* @type {Array.<string>}
*/
ImageLoader.ALLOWED_CLIENTS =
['hhaomjibdihmijegdhdafkllkbggdgoj']; // File Manager's extension id.
ImageLoader.ALLOWED_CLIENTS = [
'hhaomjibdihmijegdhdafkllkbggdgoj', // File Manager's extension id.
'nlkncpkkdoccmpiclbokaimcnedabhhm' // Gallery extension id.
];
/**
* Handles a request. Depending on type of the request, starts or stops
......
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