| OLD | NEW |
| 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. | |
| 9 // 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. | |
| 11 var appWindowsForTest = {}; | |
| 12 | |
| 13 chrome.app.runtime.onLaunched.addListener(function(launchData) { | 7 chrome.app.runtime.onLaunched.addListener(function(launchData) { |
| 14 if (!launchData || !launchData.items || launchData.items.length == 0) | 8 if (!launchData || !launchData.items || launchData.items.length == 0) |
| 15 return; | 9 return; |
| 16 | 10 |
| 17 var entry = launchData.items[0].entry; | 11 var entry = launchData.items[0].entry; |
| 18 entry.file(function(file) { | 12 entry.file(function(file) { |
| 19 var url = window.URL.createObjectURL(file); | 13 var url = window.URL.createObjectURL(file); |
| 20 open(url, entry.name); | 14 open(url, entry.name); |
| 21 }.wrap(), | 15 }, function() { |
| 22 function() { | |
| 23 // TODO(yoshiki): handle error in a smarter way. | 16 // TODO(yoshiki): handle error in a smarter way. |
| 24 open('', 'error'); // Empty URL shows the error message. | 17 open('', 'error'); // Empty URL shows the error message. |
| 25 }.wrap()); | 18 }); |
| 26 }.wrap()); | 19 }); |
| 27 | 20 |
| 28 function open(url, title) { | 21 function open(url, title) { |
| 29 chrome.app.window.create('video_player.html', { | 22 chrome.app.window.create('video_player.html', { |
| 30 id: 'video', | 23 id: 'video', |
| 31 singleton: false, | 24 singleton: false, |
| 32 minWidth: 160, | 25 minWidth: 160, |
| 33 minHeight: 100 | 26 minHeight: 100 |
| 34 }, | 27 }, |
| 35 function(createdWindow) { | 28 function(createdWindow) { |
| 36 // Stores the window for test purpose. | |
| 37 appWindowsForTest[title] = createdWindow; | |
| 38 | |
| 39 createdWindow.setIcon('images/200/icon.png'); | 29 createdWindow.setIcon('images/200/icon.png'); |
| 40 createdWindow.contentWindow.videoUrl = url; | 30 createdWindow.contentWindow.videoUrl = url; |
| 41 createdWindow.contentWindow.videoTitle = title; | 31 createdWindow.contentWindow.videoTitle = title; |
| 42 }.wrap()); | 32 }); |
| 43 } | 33 } |
| OLD | NEW |