Commit 322a01d7 authored by yoshiki@chromium.org's avatar yoshiki@chromium.org

Video Player: Use external entries instead of isolated entries

This patch migrates entries to external entries, as preparation for taking an advantage of external entries.

BUG=none
TEST=video player works
R=hirono@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284903 0039d316-1c4b-4281-b951-d872f2087c98
parent 8864b31f
...@@ -9,42 +9,66 @@ ...@@ -9,42 +9,66 @@
// the same name will be overridden each other. // the same name will be overridden each other.
var appWindowsForTest = {}; var appWindowsForTest = {};
chrome.app.runtime.onLaunched.addListener(function(launchData) { var initializeQueue = new AsyncUtil.Queue();
// Initializes the strings. This needs for the volume manager.
initializeQueue.run(function(fulfill) {
chrome.fileBrowserPrivate.getStrings(function(stringData) {
loadTimeData.data = stringData;
fulfill();
}.wrap());
}.wrap());
// Initializes the volume manager. This needs for isolated entries.
initializeQueue.run(function(fulfill) {
VolumeManager.getInstance(fulfill);
}.wrap());
chrome.app.runtime.onLaunched.addListener(onLaunched);
/**
* Called when an app is launched.
* @param {Object} launchData Launch data.
*/
function onLaunched(launchData) {
if (!launchData || !launchData.items || launchData.items.length == 0) if (!launchData || !launchData.items || launchData.items.length == 0)
return; return;
var getFilePromises = launchData.items.map(function(item) { var videos = [];
var entry = item.entry;
return new Promise(function(fullfill, reject) { initializeQueue.run(function(fulfill) {
entry.file( var isolatedEntries = launchData.items.map(function(item) {
function(file) { return item.entry;
fullfill({
entry: entry,
file: file,
fileUrl: window.URL.createObjectURL(file)
});
},
function() {
fullfill({entry: entry, file: null, fileUrl: null});
}); });
chrome.fileBrowserPrivate.resolveIsolatedEntries(isolatedEntries,
function(externalEntries) {
videos = externalEntries.map(function(entry) {
return Object.freeze({
entry: entry,
title: entry.name,
url: entry.toURL(),
}); });
}); });
fulfill();
}.wrap());
}.wrap());
Promise.all(getFilePromises).then(function(results) { initializeQueue.run(function(fulfill) {
results = results.filter(function(result) { return result.file !== null; }); if (videos.length > 0) {
if (results.length > 0) open(videos);
open(results); } else {
}.wrap(),
function() {
// TODO(yoshiki): handle error in a smarter way. // TODO(yoshiki): handle error in a smarter way.
open('', 'error'); // Empty URL shows the error message. open('', 'error'); // Empty URL shows the error message.
}
fulfill();
}.wrap()); }.wrap());
}.wrap()); }
/** /**
* Opens player window. * Opens player window.
* @param {Array.<Object>} videos List of videos to play. * @param {Array.<Object>} videos List of videos to play.
**/ */
function open(videos) { function open(videos) {
chrome.app.window.create('video_player.html', { chrome.app.window.create('video_player.html', {
id: 'video', id: 'video',
......
...@@ -245,17 +245,16 @@ function unload() { ...@@ -245,17 +245,16 @@ function unload() {
/** /**
* Loads the video file. * Loads the video file.
* @param {string} url URL of the video file. * @param {Object} video Data of the video file.
* @param {string} title Title of the video file.
* @param {function()=} opt_callback Completion callback. * @param {function()=} opt_callback Completion callback.
* @private * @private
*/ */
VideoPlayer.prototype.loadVideo_ = function(url, title, opt_callback) { VideoPlayer.prototype.loadVideo_ = function(video, opt_callback) {
this.unloadVideo(); this.unloadVideo();
document.title = title; document.title = video.title;
document.querySelector('#title').innerText = title; document.querySelector('#title').innerText = video.title;
var videoPlayerElement = document.querySelector('#video-player'); var videoPlayerElement = document.querySelector('#video-player');
if (this.currentPos_ === (this.videos_.length - 1)) if (this.currentPos_ === (this.videos_.length - 1))
...@@ -290,7 +289,7 @@ VideoPlayer.prototype.loadVideo_ = function(url, title, opt_callback) { ...@@ -290,7 +289,7 @@ VideoPlayer.prototype.loadVideo_ = function(url, title, opt_callback) {
document.querySelector('#video-container').appendChild(this.videoElement_); document.querySelector('#video-container').appendChild(this.videoElement_);
this.controls.attachMedia(this.videoElement_); this.controls.attachMedia(this.videoElement_);
this.videoElement_.src = url; this.videoElement_.src = video.url;
} }
this.videoElement_.load(); this.videoElement_.load();
...@@ -392,7 +391,7 @@ VideoPlayer.prototype.advance_ = function(direction) { ...@@ -392,7 +391,7 @@ VideoPlayer.prototype.advance_ = function(direction) {
*/ */
VideoPlayer.prototype.reloadCurrentVideo_ = function(opt_callback) { VideoPlayer.prototype.reloadCurrentVideo_ = function(opt_callback) {
var currentVideo = this.videos_[this.currentPos_]; var currentVideo = this.videos_[this.currentPos_];
this.loadVideo_(currentVideo.fileUrl, currentVideo.entry.name, opt_callback); this.loadVideo_(currentVideo, opt_callback);
}; };
/** /**
......
...@@ -55,9 +55,6 @@ ...@@ -55,9 +55,6 @@
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
"js/error_util.js",
"js/test_util.js",
"js/background.js",
"chrome://resources/js/cr.js", "chrome://resources/js/cr.js",
"chrome://resources/js/cr/event_target.js", "chrome://resources/js/cr/event_target.js",
"chrome://resources/js/cr/ui/array_data_model.js", "chrome://resources/js/cr/ui/array_data_model.js",
...@@ -66,7 +63,11 @@ ...@@ -66,7 +63,11 @@
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/common/js/async_util.js", "chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/common/js/async_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/foreground/js/file_type.js" "chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/foreground/js/file_type.js",
"js/error_util.js",
"js/test_util.js",
// The main background script must be at the end.
"js/background.js"
] ]
}, },
// The following ids are cast extension's ids . // The following ids are cast extension's ids .
......
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