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

Unified Diff: ui/file_manager/video_player/js/background.js

Issue 307863004: [Video Player] Re-factoring the code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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: ui/file_manager/video_player/js/background.js
diff --git a/ui/file_manager/video_player/js/background.js b/ui/file_manager/video_player/js/background.js
index 57ff169de2513641e90df9f9b7b208f1cf681bc2..71395bfb35bf9feb032b96c50dd2f97689b6374c 100644
--- a/ui/file_manager/video_player/js/background.js
+++ b/ui/file_manager/video_player/js/background.js
@@ -4,7 +4,6 @@
'use strict';
-
// Stores the app windows OLNY for test purpose.
// We SHOULD NOT use it as it is except for test, since the files which have
// the same name will be overridden each other.
@@ -14,10 +13,27 @@ chrome.app.runtime.onLaunched.addListener(function(launchData) {
if (!launchData || !launchData.items || launchData.items.length == 0)
return;
- var entry = launchData.items[0].entry;
- entry.file(function(file) {
- var url = window.URL.createObjectURL(file);
- open(url, entry.name);
+ var getFilePromises = launchData.items.map(function(item) {
+ var entry = item.entry;
+ return new Promise(function(fullfill, reject) {
+ entry.file(
+ function(file) {
+ fullfill({
+ entry: entry,
+ file: file,
+ fileUrl: window.URL.createObjectURL(file)
+ });
+ },
+ function() {
+ fullfill({entry: entry, file: null, fileUrl: null});
+ });
+ });
+ });
+
+ Promise.all(getFilePromises).then(function(results) {
+ results = results.filter(function(result) { return result.file !== null; });
+ if (results.length > 0)
+ open(results);
}.wrap(),
function() {
// TODO(yoshiki): handle error in a smarter way.
@@ -25,7 +41,11 @@ chrome.app.runtime.onLaunched.addListener(function(launchData) {
}.wrap());
}.wrap());
-function open(url, title) {
+/**
+ * Opens player window.
+ * @param {Array.<Object>} videos List of videos to play.
+ **/
+function open(videos) {
chrome.app.window.create('video_player.html', {
id: 'video',
singleton: false,
@@ -34,10 +54,10 @@ function open(url, title) {
},
function(createdWindow) {
// Stores the window for test purpose.
- appWindowsForTest[title] = createdWindow;
+ appWindowsForTest[videos[0].entry.name] = createdWindow;
createdWindow.setIcon('images/200/icon.png');
- createdWindow.contentWindow.videoUrl = url;
- createdWindow.contentWindow.videoTitle = title;
+ createdWindow.contentWindow.videos = videos;
+ chrome.runtime.sendMessage({ready: true}, function() {});
}.wrap());
}
« no previous file with comments | « no previous file | ui/file_manager/video_player/js/video_player.js » ('j') | ui/file_manager/video_player/js/video_player.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698