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

Side by Side 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: Addressed the comments Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/file_manager/video_player/js/video_player.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7
8 // Stores the app windows OLNY for test purpose. 7 // Stores the app windows OLNY for test purpose.
9 // We SHOULD NOT use it as it is except for test, since the files which have 8 // We SHOULD NOT use it as it is except for test, since the files which have
10 // the same name will be overridden each other. 9 // the same name will be overridden each other.
11 var appWindowsForTest = {}; 10 var appWindowsForTest = {};
12 11
13 chrome.app.runtime.onLaunched.addListener(function(launchData) { 12 chrome.app.runtime.onLaunched.addListener(function(launchData) {
14 if (!launchData || !launchData.items || launchData.items.length == 0) 13 if (!launchData || !launchData.items || launchData.items.length == 0)
15 return; 14 return;
16 15
17 var entry = launchData.items[0].entry; 16 var getFilePromises = launchData.items.map(function(item) {
18 entry.file(function(file) { 17 var entry = item.entry;
19 var url = window.URL.createObjectURL(file); 18 return new Promise(function(fullfill, reject) {
20 open(url, entry.name); 19 entry.file(
20 function(file) {
21 fullfill({
22 entry: entry,
23 file: file,
24 fileUrl: window.URL.createObjectURL(file)
25 });
26 },
27 function() {
28 fullfill({entry: entry, file: null, fileUrl: null});
29 });
30 });
31 });
32
33 Promise.all(getFilePromises).then(function(results) {
34 results = results.filter(function(result) { return result.file !== null; });
35 if (results.length > 0)
36 open(results);
21 }.wrap(), 37 }.wrap(),
22 function() { 38 function() {
23 // TODO(yoshiki): handle error in a smarter way. 39 // TODO(yoshiki): handle error in a smarter way.
24 open('', 'error'); // Empty URL shows the error message. 40 open('', 'error'); // Empty URL shows the error message.
25 }.wrap()); 41 }.wrap());
26 }.wrap()); 42 }.wrap());
27 43
28 function open(url, title) { 44 /**
45 * Opens player window.
46 * @param {Array.<Object>} videos List of videos to play.
47 **/
48 function open(videos) {
29 chrome.app.window.create('video_player.html', { 49 chrome.app.window.create('video_player.html', {
30 id: 'video', 50 id: 'video',
31 singleton: false, 51 singleton: false,
32 minWidth: 160, 52 minWidth: 160,
33 minHeight: 100 53 minHeight: 100
34 }, 54 },
35 function(createdWindow) { 55 function(createdWindow) {
36 // Stores the window for test purpose. 56 // Stores the window for test purpose.
37 appWindowsForTest[title] = createdWindow; 57 appWindowsForTest[videos[0].entry.name] = createdWindow;
38 58
39 createdWindow.setIcon('images/200/icon.png'); 59 createdWindow.setIcon('images/200/icon.png');
40 createdWindow.contentWindow.videoUrl = url; 60 createdWindow.contentWindow.videos = videos;
41 createdWindow.contentWindow.videoTitle = title; 61 chrome.runtime.sendMessage({ready: true}, function() {});
42 }.wrap()); 62 }.wrap());
43 } 63 }
OLDNEW
« no previous file with comments | « no previous file | ui/file_manager/video_player/js/video_player.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698