Chromium Code Reviews| 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'; |
|
hirono
2014/08/26 05:59:01
How about overriding the path of chrome cat API fo
yoshiki
2014/08/26 06:11:02
That's not good because here this doesn't the load
hirono
2014/08/26 06:33:24
Cannot we load the mock API instead of the SDK loa
| |
| 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 cast sdk extension. | |
| 82 * @param {function} callback Callback (executed asynchronously). | |
|
hirono
2014/08/26 05:59:01
nit: Please add type annotation to the function.
yoshiki
2014/08/26 06:11:02
Done.
| |
| 83 */ | |
| 84 function onLoadCastExtension(callback) { | |
| 85 if(!chrome.cast || !chrome.cast.isAvailable) { | |
| 86 var checkTimer = setTimeout(function() { | |
| 87 console.error('Either "Google Cast API" or "Google Cast" extension ' + | |
| 88 'seems not to be installed?'); | |
| 89 }.wrap(), 5000); | |
| 90 | |
| 91 window['__onGCastApiAvailable'] = function(loaded, errorInfo) { | |
| 92 clearTimeout(checkTimer); | |
| 93 | |
| 94 if (loaded) | |
| 95 callback(); | |
| 96 else | |
| 97 console.error('Google Cast extension load failed.', errorInfo); | |
| 98 }.wrap(); | |
| 99 } else { | |
| 100 setTimeout(callback); // Runs asynchronously. | |
| 101 } | |
| 102 }; | |
| 103 | |
| 104 /** | |
| 96 * Initialize Cast API. | 105 * Initialize Cast API. |
| 97 */ | 106 */ |
| 98 function initializeApi() { | 107 function initializeApi() { |
| 99 var onSession = function() { | 108 var onSession = function() { |
| 100 // TODO(yoshiki): Implement this. | 109 // TODO(yoshiki): Implement this. |
| 101 }; | 110 }; |
| 102 | 111 |
| 103 var onInitSuccess = function() { | 112 var onInitSuccess = function() { |
| 104 // TODO(yoshiki): Implement this. | 113 // TODO(yoshiki): Implement this. |
| 105 }; | 114 }; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 130 } | 139 } |
| 131 | 140 |
| 132 player.setCastList(receivers); | 141 player.setCastList(receivers); |
| 133 } else if (availability == chrome.cast.ReceiverAvailability.UNAVAILABLE) { | 142 } else if (availability == chrome.cast.ReceiverAvailability.UNAVAILABLE) { |
| 134 player.setCastList([]); | 143 player.setCastList([]); |
| 135 } else { | 144 } else { |
| 136 console.error('Unexpected response in onReceiver.', arguments); | 145 console.error('Unexpected response in onReceiver.', arguments); |
| 137 player.setCastList([]); | 146 player.setCastList([]); |
| 138 } | 147 } |
| 139 } | 148 } |
| OLD | NEW |