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 // This hack prevents a bug on the cast extension. | 7 // This hack prevents a bug on the cast extension. |
8 // TODO(yoshiki): Remove this once the cast extension supports Chrome apps. | 8 // TODO(yoshiki): Remove this once the cast extension supports Chrome apps. |
9 // Although localStorage in Chrome app is not supported, but it's used in the | 9 // Although localStorage in Chrome app is not supported, but it's used in the |
10 // cast extension. This line prevents an exception on using localStorage. | 10 // cast extension. This line prevents an exception on using localStorage. |
11 window.__defineGetter__('localStorage', function() { return {}; }); | 11 window.__defineGetter__('localStorage', function() { return {}; }); |
12 | 12 |
13 // THIS IS A TEST APP. | 13 // THIS IS A TEST APP. |
14 // TODO(yoshiki): Fix this before launch. | 14 // TODO(yoshiki): Fix this before launch. |
15 var APPLICATION_ID = '214CC863'; | 15 var APPLICATION_ID = '214CC863'; |
16 | 16 |
17 util.addPageLoadHandler(function() { | 17 util.addPageLoadHandler(function() { |
18 initialize(); | 18 initialize(); |
19 }.wrap()); | 19 }.wrap()); |
20 | 20 |
21 /** | 21 /** |
22 * Starts initialization of cast-related feature. | 22 * Starts initialization of cast-related feature. |
23 */ | 23 */ |
24 function initialize() { | 24 function initialize() { |
25 if (window.loadMockCastExtensionForTest) { | |
26 onLoadCastExtension(initializeApi); | |
27 return; | |
28 } | |
29 | |
25 CastExtensionDiscoverer.findInstalledExtension(function(foundId) { | 30 CastExtensionDiscoverer.findInstalledExtension(function(foundId) { |
26 if (foundId) | 31 if (foundId) |
27 loadCastAPI(initializeApi); | 32 loadCastAPI(initializeApi); |
28 else | 33 else |
29 console.info('No Google Cast extension is installed.'); | 34 console.info('No Google Cast extension is installed.'); |
30 }.wrap()); | 35 }.wrap()); |
31 } | 36 } |
32 | 37 |
33 /** | 38 /** |
34 * Executes the given callback after the cast extension is initialized. | 39 * Executes the given callback after the cast extension is initialized. |
(...skipping 24 matching lines...) Expand all Loading... | |
59 chrome.runtime.lastError.message); | 64 chrome.runtime.lastError.message); |
60 return; | 65 return; |
61 } | 66 } |
62 | 67 |
63 console.info('Google Cast API extension installed.'); | 68 console.info('Google Cast API extension installed.'); |
64 // Loads API again. | 69 // Loads API again. |
65 setTimeout(loadCastAPI.bind(null, callback, true)); | 70 setTimeout(loadCastAPI.bind(null, callback, true)); |
66 }.wrap()); | 71 }.wrap()); |
67 }.wrap(); | 72 }.wrap(); |
68 | 73 |
69 var onLoad = function() { | |
70 if(!chrome.cast || !chrome.cast.isAvailable) { | |
71 var checkTimer = setTimeout(function() { | |
72 console.error('Either "Google Cast API" or "Google Cast" extension ' + | |
73 'seems not to be installed?'); | |
74 }.wrap(), 5000); | |
75 | |
76 window['__onGCastApiAvailable'] = function(loaded, errorInfo) { | |
77 clearTimeout(checkTimer); | |
78 | |
79 if (loaded) | |
80 callback(); | |
81 else | |
82 console.error('Google Cast extension load failed.', errorInfo); | |
83 }.wrap(); | |
84 } else { | |
85 setTimeout(callback); // Runs asynchronously. | |
86 } | |
87 }.wrap(); | |
88 | |
89 script.src = '_modules/mafeflapfdfljijmlienjedomfjfmhpd/cast_sender.js'; | 74 script.src = '_modules/mafeflapfdfljijmlienjedomfjfmhpd/cast_sender.js'; |
90 script.addEventListener('error', onError); | 75 script.addEventListener('error', onError); |
91 script.addEventListener('load', onLoad); | 76 script.addEventListener('load', onLoadCastExtension.bind(null, callback)); |
92 document.body.appendChild(script); | 77 document.body.appendChild(script); |
93 } | 78 } |
94 | 79 |
95 /** | 80 /** |
81 * Loads the mock cast extension. | |
82 * @param {function} callback Callback (executed asynchronously). | |
83 */ | |
84 function loadMockCastAPI(callback) { | |
hirono
2014/08/26 00:56:58
Is the function used?
yoshiki
2014/08/26 05:31:24
It was used. Removed.
| |
85 var script = document.createElement('script'); | |
86 script.src = window.mockCastExtensionLoaderForTest ; | |
87 script.addEventListener('error', function() { | |
88 chrome.test.failed(''); | |
89 }); | |
90 script.addEventListener('load', onLoadCastExtension.bind(null, callback)); | |
91 document.body.appendChild(script); | |
92 } | |
93 | |
94 /** | |
95 * Loads the cast sdk extension. | |
96 * @param {function} callback Callback (executed asynchronously). | |
97 */ | |
98 function onLoadCastExtension(callback) { | |
99 if(!chrome.cast || !chrome.cast.isAvailable) { | |
100 var checkTimer = setTimeout(function() { | |
101 console.error('Either "Google Cast API" or "Google Cast" extension ' + | |
102 'seems not to be installed?'); | |
103 }.wrap(), 5000); | |
104 | |
105 window['__onGCastApiAvailable'] = function(loaded, errorInfo) { | |
106 clearTimeout(checkTimer); | |
107 | |
108 if (loaded) | |
109 callback(); | |
110 else | |
111 console.error('Google Cast extension load failed.', errorInfo); | |
112 }.wrap(); | |
113 } else { | |
114 setTimeout(callback); // Runs asynchronously. | |
115 } | |
116 }; | |
117 | |
118 /** | |
96 * Initialize Cast API. | 119 * Initialize Cast API. |
97 */ | 120 */ |
98 function initializeApi() { | 121 function initializeApi() { |
99 var onSession = function() { | 122 var onSession = function() { |
100 // TODO(yoshiki): Implement this. | 123 // TODO(yoshiki): Implement this. |
101 }; | 124 }; |
102 | 125 |
103 var onInitSuccess = function() { | 126 var onInitSuccess = function() { |
104 // TODO(yoshiki): Implement this. | 127 // TODO(yoshiki): Implement this. |
105 }; | 128 }; |
(...skipping 24 matching lines...) Expand all Loading... | |
130 } | 153 } |
131 | 154 |
132 player.setCastList(receivers); | 155 player.setCastList(receivers); |
133 } else if (availability == chrome.cast.ReceiverAvailability.UNAVAILABLE) { | 156 } else if (availability == chrome.cast.ReceiverAvailability.UNAVAILABLE) { |
134 player.setCastList([]); | 157 player.setCastList([]); |
135 } else { | 158 } else { |
136 console.error('Unexpected response in onReceiver.', arguments); | 159 console.error('Unexpected response in onReceiver.', arguments); |
137 player.setCastList([]); | 160 player.setCastList([]); |
138 } | 161 } |
139 } | 162 } |
OLD | NEW |