Roll src/third_party/skia d32087a:1052f51
[chromium-blink-merge.git] / ui / file_manager / video_player / js / background.js
blob3b7adacbcc52f53fa49d6779c8f08b18bb8a428b
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
3 // found in the LICENSE file.
5 /**
6 * Icon of the video player.
7 * TODO(yoshiki): Consider providing an exact size icon, instead of relying
8 * on downsampling by ash.
10 * @type {string}
11 * @const
13 var ICON_IMAGE = 'images/icon/video-player-64.png';
15 /**
16 * Configuration of the video player panel.
17 * @type {Object}
19 var windowCreateOptions = {
20 frame: 'none',
21 minWidth: 480,
22 minHeight: 270
25 /**
26 * Backgound object. This is necessary for AppWindowWrapper.
27 * @type {BackgroundBase}
29 var background = new BackgroundBase();
32 var generateWindowId = (function() {
33 var seq = 0;
34 return function() {
35 return 'VIDEO_PLAYER_APP_' + seq++;
36 }.wrap();
37 }.wrap())();
39 /**
40 * Opens player window.
41 * @param {!Array<string>} urls List of videos to play and index to start
42 * playing.
43 * @return {!Promise} Promise to be fulfilled on success, or rejected on error.
45 function openVideoPlayerWindow(urls) {
46 var position = 0;
47 var startUrl = (position < urls.length) ? urls[position] : '';
48 var windowId = null;
50 return new Promise(function(fulfill, reject) {
51 util.URLsToEntries(urls).then(function(result) {
52 fulfill(result.entries);
53 }.wrap()).catch(reject);
54 }.wrap()).then(function(entries) {
55 if (entries.length === 0)
56 return Promise.reject('No file to open.');
58 // Adjusts the position to start playing.
59 var maybePosition = util.entriesToURLs(entries).indexOf(startUrl);
60 if (maybePosition !== -1)
61 position = maybePosition;
63 windowId = generateWindowId();
65 // Opens the video player window.
66 return new Promise(function(fulfill, reject) {
67 var urls = util.entriesToURLs(entries);
68 var videoPlayer = new AppWindowWrapper('video_player.html',
69 windowId,
70 windowCreateOptions);
72 videoPlayer.launch(
73 {items: urls, position: position},
74 false,
75 fulfill.bind(null, videoPlayer));
76 }.wrap());
77 }.wrap()).then(function(videoPlayer) {
78 var appWindow = videoPlayer.rawAppWindow;
80 if (chrome.test)
81 appWindow.contentWindow.loadMockCastExtensionForTest = true;
83 videoPlayer.setIcon(ICON_IMAGE);
84 appWindow.focus();
86 return windowId;
87 }.wrap()).catch(function(error) {
88 console.error('Launch failed' + error.stack || error);
89 return Promise.reject(error);
90 }.wrap());
93 background.setLaunchHandler(openVideoPlayerWindow);