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 @@
// the same name will be overridden each other.
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)
return;
var getFilePromises = launchData.items.map(function(item) {
var entry = item.entry;
return new Promise(function(fullfill, reject) {
entry.file(
function(file) {
fullfill({
var videos = [];
initializeQueue.run(function(fulfill) {
var isolatedEntries = launchData.items.map(function(item) {
return item.entry;
});
chrome.fileBrowserPrivate.resolveIsolatedEntries(isolatedEntries,
function(externalEntries) {
videos = externalEntries.map(function(entry) {
return Object.freeze({
entry: entry,
file: file,
fileUrl: window.URL.createObjectURL(file)
title: entry.name,
url: entry.toURL(),
});
},
function() {
fullfill({entry: entry, file: null, fileUrl: null});
});
});
});
fulfill();
}.wrap());
}.wrap());
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.
open('', 'error'); // Empty URL shows the error message.
initializeQueue.run(function(fulfill) {
if (videos.length > 0) {
open(videos);
} else {
// TODO(yoshiki): handle error in a smarter way.
open('', 'error'); // Empty URL shows the error message.
}
fulfill();
}.wrap());
}.wrap());
}
/**
* Opens player window.
* @param {Array.<Object>} videos List of videos to play.
**/
*/
function open(videos) {
chrome.app.window.create('video_player.html', {
id: 'video',
......
......@@ -245,17 +245,16 @@ function unload() {
/**
* Loads the video file.
* @param {string} url URL of the video file.
* @param {string} title Title of the video file.
* @param {Object} video Data of the video file.
* @param {function()=} opt_callback Completion callback.
* @private
*/
VideoPlayer.prototype.loadVideo_ = function(url, title, opt_callback) {
VideoPlayer.prototype.loadVideo_ = function(video, opt_callback) {
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');
if (this.currentPos_ === (this.videos_.length - 1))
......@@ -290,7 +289,7 @@ VideoPlayer.prototype.loadVideo_ = function(url, title, opt_callback) {
document.querySelector('#video-container').appendChild(this.videoElement_);
this.controls.attachMedia(this.videoElement_);
this.videoElement_.src = url;
this.videoElement_.src = video.url;
}
this.videoElement_.load();
......@@ -392,7 +391,7 @@ VideoPlayer.prototype.advance_ = function(direction) {
*/
VideoPlayer.prototype.reloadCurrentVideo_ = function(opt_callback) {
var currentVideo = this.videos_[this.currentPos_];
this.loadVideo_(currentVideo.fileUrl, currentVideo.entry.name, opt_callback);
this.loadVideo_(currentVideo, opt_callback);
};
/**
......
......@@ -55,9 +55,6 @@
"app": {
"background": {
"scripts": [
"js/error_util.js",
"js/test_util.js",
"js/background.js",
"chrome://resources/js/cr.js",
"chrome://resources/js/cr/event_target.js",
"chrome://resources/js/cr/ui/array_data_model.js",
......@@ -66,7 +63,11 @@
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/common/js/async_util.js",
"chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/common/js/volume_manager_common.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 .
......
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