| 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 // TODO(yoshiki): Check if the Google Cast extension is installed or not. | 18 CastExtensionDiscoverer.findInstalledExtension(function(foundId) { |
| 19 // If not installed, we should skip all cast-related functionality. | 19 if (foundId) |
| 20 | 20 loadCastAPI(initializeApi); |
| 21 loadCastAPI(initializeApi); | 21 else |
| 22 console.info('No Google Cast extension is installed.'); |
| 23 }); |
| 22 }); | 24 }); |
| 23 | 25 |
| 24 /** | 26 /** |
| 25 * Executes the given callback after the cast extension is initialized. | 27 * Executes the given callback after the cast extension is initialized. |
| 26 * @param {function} callback Callback (executed asynchronously). | 28 * @param {function} callback Callback (executed asynchronously). |
| 27 * @param {boolean=} opt_secondTry Spericy try if it's second call after | 29 * @param {boolean=} opt_secondTry Spericy try if it's second call after |
| 28 * installation of Cast API extension. | 30 * installation of Cast API extension. |
| 29 */ | 31 */ |
| 30 function loadCastAPI(callback, opt_secondTry) { | 32 function loadCastAPI(callback, opt_secondTry) { |
| 31 var script = document.createElement('script'); | 33 var script = document.createElement('script'); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 123 } |
| 122 | 124 |
| 123 player.setCastList(receivers); | 125 player.setCastList(receivers); |
| 124 } else if (availability == chrome.cast.ReceiverAvailability.UNAVAILABLE) { | 126 } else if (availability == chrome.cast.ReceiverAvailability.UNAVAILABLE) { |
| 125 player.setCastList([]); | 127 player.setCastList([]); |
| 126 } else { | 128 } else { |
| 127 console.error('Unexpected response in onReceiver.', arguments); | 129 console.error('Unexpected response in onReceiver.', arguments); |
| 128 player.setCastList([]); | 130 player.setCastList([]); |
| 129 } | 131 } |
| 130 } | 132 } |
| OLD | NEW |