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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9543d7eda7c4a3921d9b4d33416049c38079b4e5 |
| --- /dev/null |
| +++ b/ui/file_manager/video_player/js/cast/caster.js |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +'use strict'; |
| + |
| +/** |
| + * The instance of cast api. |
| + * @type {cast.ExtensionApi} |
| + */ |
| +var castApi = null; |
| + |
| +/** |
| + * @type {string} |
|
fukino
2014/07/11 04:35:50
nit: @const
|
| + */ |
| +var CAST_COMMAND_LINE_FLAG = 'enable-video-player-chromecast-support'; |
| + |
| +chrome.commandLinePrivate.hasSwitch(CAST_COMMAND_LINE_FLAG, function(result) { |
| + if (!result) |
| + return; |
| + |
| + CastExtensionDiscoverer.findInstalledExtension(onCastExtensionFound); |
| +}); |
| + |
| +function onCastExtensionFound(extensionId) { |
| + if (!extensionId) { |
| + console.info('Cast extention is not found.'); |
| + return; |
| + } |
| + |
| + var api = document.createElement('script'); |
| + api.src = 'chrome-extension://' + extensionId + '/api_script.js'; |
| + api.onload = function() { |
| + initializeCast(extensionId); |
| + }; |
| + api.onerror = function() { |
| + console.error('api_script.js load failed.'); |
| + }; |
| + document.body.appendChild(api); |
| +}; |
| + |
| +function initializeCast(extensionId) { |
| + loadCastExtensionApi(); |
| + |
| + castApi = new cast.ExtensionApi(extensionId); |
| + castApi.addReceiverListener('ChromeCast', onReceiverUpdate); |
| +} |
| + |
| +function onReceiverUpdate(receivers) { |
| + player.setCastList(receivers); |
| +} |