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

Side by Side Diff: ui/file_manager/video_player/js/background.js

Issue 414623003: Video Player: Use external entries instead of isolated entries (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 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 // Stores the app windows OLNY for test purpose. 7 // Stores the app windows OLNY for test purpose.
8 // 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
9 // the same name will be overridden each other. 9 // the same name will be overridden each other.
10 var appWindowsForTest = {}; 10 var appWindowsForTest = {};
11 11
12 chrome.app.runtime.onLaunched.addListener(function(launchData) { 12 var initializeQueue = new AsyncUtil.Queue();
13
14 // Initializes the strings. This needs for the volume manager.
15 initializeQueue.run(function(fulfill) {
16 chrome.fileBrowserPrivate.getStrings(function(stringData) {
17 loadTimeData.data = stringData;
18 fulfill();
19 }.wrap());
20 }.wrap());
21
22 // Initializes the volume manager. This needs for isolated entries.
23 initializeQueue.run(function(fulfill) {
24 VolumeManager.getInstance(fulfill);
25 }.wrap());
26
27 // Registers a handler.
28 initializeQueue.run(function(fulfill) {
29 chrome.app.runtime.onLaunched.addListener(onLaunched);
hirono 2014/07/23 02:48:58 I'm not sure if it is OK to register the onLaunche
yoshiki 2014/07/23 03:49:39 I'm also not sure but I think it's better to care.
30 fulfill();
31 }.wrap());
32
33 /**
34 * Called when an app is launched.
35 * @param {Object} launchData Launch data.
36 */
37 function onLaunched(launchData) {
13 if (!launchData || !launchData.items || launchData.items.length == 0) 38 if (!launchData || !launchData.items || launchData.items.length == 0)
14 return; 39 return;
15 40
16 var getFilePromises = launchData.items.map(function(item) { 41 var launchQueue = new AsyncUtil.Queue();
17 var entry = item.entry; 42 var videos = [];
18 return new Promise(function(fullfill, reject) { 43
19 entry.file( 44 launchQueue.run(function(fulfill) {
20 function(file) { 45 var isolatedEntries = launchData.items.map(function(item) {
21 fullfill({ 46 return item.entry;
47 });
48
49 chrome.fileBrowserPrivate.resolveIsolatedEntries(isolatedEntries,
50 function(externalEntries) {
51 videos = externalEntries.map(function(entry) {
52 return {
22 entry: entry, 53 entry: entry,
23 file: file, 54 title: entry.name,
24 fileUrl: window.URL.createObjectURL(file) 55 url: entry.toURL(),
25 }); 56 };
26 },
27 function() {
28 fullfill({entry: entry, file: null, fileUrl: null});
29 }); 57 });
30 }); 58 fulfill();
59 }.wrap());
31 }); 60 });
hirono 2014/07/23 02:48:58 Should wrap here?
yoshiki 2014/07/23 03:49:39 Done.
32 61
33 Promise.all(getFilePromises).then(function(results) { 62 launchQueue.run(function(fulfill) {
34 results = results.filter(function(result) { return result.file !== null; }); 63 if (videos.length > 0) {
35 if (results.length > 0) 64 open(videos);
36 open(results); 65 } else {
37 }.wrap(), 66 // TODO(yoshiki): handle error in a smarter way.
38 function() { 67 open('', 'error'); // Empty URL shows the error message.
39 // TODO(yoshiki): handle error in a smarter way. 68 }
40 open('', 'error'); // Empty URL shows the error message. 69 fulfill();
41 }.wrap()); 70 }.wrap());
42 }.wrap()); 71 }
43 72
44 /** 73 /**
45 * Opens player window. 74 * Opens player window.
46 * @param {Array.<Object>} videos List of videos to play. 75 * @param {Array.<Object>} videos List of videos to play.
47 **/ 76 */
48 function open(videos) { 77 function open(videos) {
49 chrome.app.window.create('video_player.html', { 78 chrome.app.window.create('video_player.html', {
50 id: 'video', 79 id: 'video',
51 frame: 'none', 80 frame: 'none',
52 singleton: false, 81 singleton: false,
53 minWidth: 480, 82 minWidth: 480,
54 minHeight: 270 83 minHeight: 270
55 }, 84 },
56 function(createdWindow) { 85 function(createdWindow) {
57 // Stores the window for test purpose. 86 // Stores the window for test purpose.
58 appWindowsForTest[videos[0].entry.name] = createdWindow; 87 appWindowsForTest[videos[0].entry.name] = createdWindow;
59 88
60 createdWindow.setIcon('images/200/icon.png'); 89 createdWindow.setIcon('images/200/icon.png');
61 createdWindow.contentWindow.videos = videos; 90 createdWindow.contentWindow.videos = videos;
62 chrome.runtime.sendMessage({ready: true}, function() {}); 91 chrome.runtime.sendMessage({ready: true}, function() {});
63 }.wrap()); 92 }.wrap());
64 } 93 }
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