Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 'use strict'; | |
| 6 | |
| 7 /** | |
| 8 * The instance of cast api. | |
| 9 * @type {cast.ExtensionApi} | |
| 10 */ | |
| 11 var castApi = null; | |
| 12 | |
| 13 /** | |
| 14 * @type {string} | |
|
fukino
2014/07/11 04:35:50
nit: @const
| |
| 15 */ | |
| 16 var CAST_COMMAND_LINE_FLAG = 'enable-video-player-chromecast-support'; | |
| 17 | |
| 18 chrome.commandLinePrivate.hasSwitch(CAST_COMMAND_LINE_FLAG, function(result) { | |
| 19 if (!result) | |
| 20 return; | |
| 21 | |
| 22 CastExtensionDiscoverer.findInstalledExtension(onCastExtensionFound); | |
| 23 }); | |
| 24 | |
| 25 function onCastExtensionFound(extensionId) { | |
| 26 if (!extensionId) { | |
| 27 console.info('Cast extention is not found.'); | |
| 28 return; | |
| 29 } | |
| 30 | |
| 31 var api = document.createElement('script'); | |
| 32 api.src = 'chrome-extension://' + extensionId + '/api_script.js'; | |
| 33 api.onload = function() { | |
| 34 initializeCast(extensionId); | |
| 35 }; | |
| 36 api.onerror = function() { | |
| 37 console.error('api_script.js load failed.'); | |
| 38 }; | |
| 39 document.body.appendChild(api); | |
| 40 }; | |
| 41 | |
| 42 function initializeCast(extensionId) { | |
| 43 loadCastExtensionApi(); | |
| 44 | |
| 45 castApi = new cast.ExtensionApi(extensionId); | |
| 46 castApi.addReceiverListener('ChromeCast', onReceiverUpdate); | |
| 47 } | |
| 48 | |
| 49 function onReceiverUpdate(receivers) { | |
| 50 player.setCastList(receivers); | |
| 51 } | |
| OLD | NEW |