Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4257)

Unified Diff: chrome/renderer/resources/extensions/file_system_custom_bindings.js

Issue 18331017: Support choosing multiple files with fileSystem.chooseEntry. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/file_system_custom_bindings.js
diff --git a/chrome/renderer/resources/extensions/file_system_custom_bindings.js b/chrome/renderer/resources/extensions/file_system_custom_bindings.js
index f66c20d45e868a99a511c1030490a8056fa1eff2..921ff23ca563db98c9148d2f1a83c3663cc8926f 100644
--- a/chrome/renderer/resources/extensions/file_system_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/file_system_custom_bindings.js
@@ -30,30 +30,60 @@ if (window == backgroundPage) {
var callback = request.callback;
request.callback = null;
- var fileSystemId = response.fileSystemId;
- var baseName = response.baseName;
- var id = response.id;
- var fs = GetIsolatedFileSystem(fileSystemId);
-
- try {
- // TODO(koz): fs.root.getFile() makes a trip to the browser process,
- // but it might be possible avoid that by calling
- // WebFrame::createFileEntry().
- fs.root.getFile(baseName, {}, function(fileEntry) {
- entryIdManager.registerEntry(id, fileEntry);
- callback(fileEntry);
- }, function(fileError) {
- lastError.run('fileSystem.' + functionName,
- 'Error getting fileEntry, code: ' + fileError.code,
- request.stack,
- callback);
- });
- } catch (e) {
- lastError.run('fileSystem.' + functionName,
- 'Error in event handler for onLaunched: ' + e.stack,
- request.stack,
- callback);
- }
+ var entries = [];
+ var hasError = false;
+
+ // Loop through the response entries and asynchronously get the
+ // FileEntry for each. We use hasError to ensure that only the first
+ // error is reported. Note that an error can occur either during the
+ // loop or in the asynchronous error callback to getFile.
+ $Array.forEach(response.entries, function(entry) {
+ if (hasError)
+ return;
+ var fileSystemId = entry.fileSystemId;
+ var baseName = entry.baseName;
+ var id = entry.id;
+ var fs = GetIsolatedFileSystem(fileSystemId);
+
+ try {
+ // TODO(koz): fs.root.getFile() makes a trip to the browser process,
+ // but it might be possible avoid that by calling
+ // WebFrame::createFileEntry().
+ fs.root.getFile(baseName, {}, function(fileEntry) {
+ if (hasError)
+ return;
+ entryIdManager.registerEntry(id, fileEntry);
+ entries.push(fileEntry);
+ // Once all entries are ready, pass them to the callback. In the
+ // event of an error, this condition will never be satisfied so
+ // the callback will not be called with any entries.
+ if (entries.length == response.entries.length) {
+ if (response.multiple) {
+ callback(entries);
+ } else {
+ callback(entries[0]);
+ }
+ }
+ }, function(fileError) {
+ if (!hasError) {
+ hasError = true;
+ lastError.run(
+ 'fileSystem.' + functionName,
+ 'Error getting fileEntry, code: ' + fileError.code,
+ request.stack,
+ callback);
+ }
+ });
+ } catch (e) {
+ if (!hasError) {
+ hasError = true;
+ lastError.run('fileSystem.' + functionName,
+ 'Error getting fileEntry: ' + e.stack,
+ request.stack,
+ callback);
+ }
+ }
+ });
}
});
};

Powered by Google App Engine
This is Rietveld 408576698