| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 chrome.app.runtime.onLaunched.addListener(function() { | 5 function launchFileManager(launchData) { |
| 6 chrome.app.window.create('main.html', { | 6 var options = { |
| 7 height: 800, | 7 defaultWidth: Math.round(window.screen.availWidth * 0.8), |
| 8 width: 1000 | 8 defaultHeight: Math.round(window.screen.availHeight * 0.8) |
| 9 }; |
| 10 |
| 11 chrome.app.window.create('main.html', options, function(newWindow) { |
| 12 newWindow.contentWindow.launchData = launchData; |
| 9 }); | 13 }); |
| 14 } |
| 15 |
| 16 chrome.app.runtime.onLaunched.addListener(launchFileManager); |
| 17 |
| 18 chrome.fileBrowserHandler.onExecute.addListener(function(id, details) { |
| 19 var urls = details.entries.map(function(e) { return e.toURL() }); |
| 20 switch (id) { |
| 21 case 'play': |
| 22 launchAudioPlayer({items: urls, position: 0}); |
| 23 break; |
| 24 |
| 25 case 'watch': |
| 26 launchVideoPlayer(urls[0]); |
| 27 break; |
| 28 |
| 29 default: |
| 30 // Every other action opens the main Files app window. |
| 31 var launchData = {}; |
| 32 launchData.action = id; |
| 33 launchData.defaultPath = details.entries[0].fullPath; |
| 34 launchFileManager(launchData); |
| 35 break; |
| 36 } |
| 10 }); | 37 }); |
| 11 | 38 |
| 12 /** | 39 /** |
| 13 * Wrapper for a singleton app window. | 40 * Wrapper for a singleton app window. |
| 14 * @constructor | 41 * @constructor |
| 15 */ | 42 */ |
| 16 function SingletonWindow() { | 43 function SingletonWindow() { |
| 17 this.window_ = null; | 44 this.window_ = null; |
| 18 this.creating_ = false; | 45 this.creating_ = false; |
| 19 } | 46 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 31 if (this.window_ && !this.window_.contentWindow.closed) { | 58 if (this.window_ && !this.window_.contentWindow.closed) { |
| 32 this.window_.focus(); | 59 this.window_.focus(); |
| 33 this.window_.contentWindow.reload(launchData); | 60 this.window_.contentWindow.reload(launchData); |
| 34 return; | 61 return; |
| 35 } | 62 } |
| 36 | 63 |
| 37 this.launchData_ = launchData; | 64 this.launchData_ = launchData; |
| 38 if (this.creating_) | 65 if (this.creating_) |
| 39 return; // The window is being created, will use the updated launch data. | 66 return; // The window is being created, will use the updated launch data. |
| 40 | 67 |
| 68 options.id = url; |
| 41 this.creating_ = true; | 69 this.creating_ = true; |
| 42 chrome.app.window.create(url, options, function(newWindow) { | 70 chrome.app.window.create(url, options, function(newWindow) { |
| 43 this.window_ = newWindow; | 71 this.window_ = newWindow; |
| 44 this.window_.contentWindow.launchData = this.launchData_; | 72 this.window_.contentWindow.launchData = this.launchData_; |
| 45 this.creating_ = false; | 73 this.creating_ = false; |
| 46 this.window_.onClosed.addListener(function() { | 74 this.window_.onClosed.addListener(function() { |
| 47 this.window_.contentWindow_.unload(); | 75 this.window_.contentWindow_.unload(); |
| 48 }.bind(this)); | 76 }.bind(this)); |
| 49 }.bind(this)); | 77 }.bind(this)); |
| 50 }; | 78 }; |
| 51 | 79 |
| 52 var audioPlayer = new SingletonWindow(); | 80 var audioPlayer = new SingletonWindow(); |
| 53 | 81 |
| 54 /** | 82 /** |
| 55 * Launch the audio player or load the playlist into the existing player. | 83 * Launch the audio player or load the playlist into the existing player. |
| 56 * | 84 * |
| 57 * @param {Object} playlist Playlist. | 85 * @param {Object} playlist Playlist. |
| 58 */ | 86 */ |
| 59 function launchAudioPlayer(playlist) { | 87 function launchAudioPlayer(playlist) { |
| 60 var WIDTH = 280; | 88 var WIDTH = 280; |
| 61 var MIN_HEIGHT = 35 + 58; | 89 var MIN_HEIGHT = 35 + 58; |
| 62 var MAX_HEIGHT = 35 + 58 * 3; | 90 var MAX_HEIGHT = 35 + 58 * 3; |
| 63 var BOTTOM = 80; | 91 var BOTTOM = 80; |
| 64 var RIGHT = 20; | 92 var RIGHT = 20; |
| 65 | 93 |
| 66 var param = { | 94 var options = { |
| 67 id: 'audio', | |
| 68 defaultLeft: (window.screen.availWidth - WIDTH - RIGHT), | 95 defaultLeft: (window.screen.availWidth - WIDTH - RIGHT), |
| 69 defaultTop: (window.screen.availHeight - MIN_HEIGHT - BOTTOM), | 96 defaultTop: (window.screen.availHeight - MIN_HEIGHT - BOTTOM), |
| 70 minHeight: MIN_HEIGHT, | 97 minHeight: MIN_HEIGHT, |
| 71 maxHeight: MAX_HEIGHT, | 98 maxHeight: MAX_HEIGHT, |
| 72 height: MIN_HEIGHT, | 99 height: MIN_HEIGHT, |
| 73 minWidth: WIDTH, | 100 minWidth: WIDTH, |
| 74 maxWidth: WIDTH, | 101 maxWidth: WIDTH, |
| 75 width: WIDTH | 102 width: WIDTH |
| 76 }; | 103 }; |
| 77 | 104 |
| 78 audioPlayer.open('mediaplayer.html', param, playlist); | 105 audioPlayer.open('mediaplayer.html', options, playlist); |
| 79 } | 106 } |
| 80 | 107 |
| 81 var videoPlayer = new SingletonWindow(); | 108 var videoPlayer = new SingletonWindow(); |
| 82 | 109 |
| 83 /** | 110 /** |
| 84 * Launch video player. | 111 * Launch video player. |
| 85 * @param {string} url Video url. | 112 * @param {string} url Video url. |
| 86 */ | 113 */ |
| 87 function launchVideoPlayer(url) { | 114 function launchVideoPlayer(url) { |
| 88 var param = { | 115 var options = { |
| 89 id: 'video', | |
| 90 hidden: true // Will be shown when the video loads. | 116 hidden: true // Will be shown when the video loads. |
| 91 }; | 117 }; |
| 92 | 118 |
| 93 videoPlayer.open('video_player.html', param, {url: url}); | 119 videoPlayer.open('video_player.html', options, {url: url}); |
| 94 } | 120 } |
| OLD | NEW |