Chromium Code Reviews| Index: ui/file_manager/video_player/js/cast/caster.js |
| diff --git a/ui/file_manager/video_player/js/cast/caster.js b/ui/file_manager/video_player/js/cast/caster.js |
| index e349f03bf7965db772d6d9868fcf140490d917d0..e81ab6618c1513a4a680a4d235d476a65000bc68 100644 |
| --- a/ui/file_manager/video_player/js/cast/caster.js |
| +++ b/ui/file_manager/video_player/js/cast/caster.js |
| @@ -22,6 +22,11 @@ util.addPageLoadHandler(function() { |
| * Starts initialization of cast-related feature. |
| */ |
| function initialize() { |
| + if (window.loadMockCastExtensionForTest) { |
| + onLoadCastExtension(initializeApi); |
| + return; |
| + } |
| + |
| CastExtensionDiscoverer.findInstalledExtension(function(foundId) { |
| if (foundId) |
| loadCastAPI(initializeApi); |
| @@ -66,33 +71,37 @@ function loadCastAPI(callback, opt_secondTry) { |
| }.wrap()); |
| }.wrap(); |
| - var onLoad = function() { |
| - if(!chrome.cast || !chrome.cast.isAvailable) { |
| - var checkTimer = setTimeout(function() { |
| - console.error('Either "Google Cast API" or "Google Cast" extension ' + |
| - 'seems not to be installed?'); |
| - }.wrap(), 5000); |
| - |
| - window['__onGCastApiAvailable'] = function(loaded, errorInfo) { |
| - clearTimeout(checkTimer); |
| - |
| - if (loaded) |
| - callback(); |
| - else |
| - console.error('Google Cast extension load failed.', errorInfo); |
| - }.wrap(); |
| - } else { |
| - setTimeout(callback); // Runs asynchronously. |
| - } |
| - }.wrap(); |
| - |
| 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
|
| script.addEventListener('error', onError); |
| - script.addEventListener('load', onLoad); |
| + script.addEventListener('load', onLoadCastExtension.bind(null, callback)); |
| document.body.appendChild(script); |
| } |
| /** |
| + * Loads the cast sdk extension. |
| + * @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.
|
| + */ |
| +function onLoadCastExtension(callback) { |
| + if(!chrome.cast || !chrome.cast.isAvailable) { |
| + var checkTimer = setTimeout(function() { |
| + console.error('Either "Google Cast API" or "Google Cast" extension ' + |
| + 'seems not to be installed?'); |
| + }.wrap(), 5000); |
| + |
| + window['__onGCastApiAvailable'] = function(loaded, errorInfo) { |
| + clearTimeout(checkTimer); |
| + |
| + if (loaded) |
| + callback(); |
| + else |
| + console.error('Google Cast extension load failed.', errorInfo); |
| + }.wrap(); |
| + } else { |
| + setTimeout(callback); // Runs asynchronously. |
| + } |
| +}; |
| + |
| +/** |
| * Initialize Cast API. |
| */ |
| function initializeApi() { |