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 70bc28ca472c1ec4a03de084520554570a9b9ee3..93196b112fec5e8aed2e0419032a6f22e2190262 100644 |
| --- a/ui/file_manager/video_player/js/cast/caster.js |
| +++ b/ui/file_manager/video_player/js/cast/caster.js |
| @@ -27,91 +27,58 @@ function initialize() { |
| if (window.loadMockCastExtensionForTest) { |
| // If the test flag is set, the mock extension for test will be laoded by |
| // the test script. Sets the handler to wait for loading. |
| - onLoadCastExtension(initializeApi); |
| + onLoadCastSDK(initializeApi); |
| return; |
| } |
| CastExtensionDiscoverer.findInstalledExtension(function(foundId) { |
| if (foundId) { |
| - loadCastAPI(initializeApi); |
| + loadCastSDK(foundId, initializeApi); |
| } else { |
| console.info('No Google Cast extension is installed.'); |
| - |
| - metrics.recordCastAPIExtensionStatus( |
| - metrics.CAST_API_EXTENSION_STATUS.SKIPPED); |
| } |
| }.wrap()); |
| } |
| /** |
| - * Loads the cast API extention. If not install, the extension is installed |
| - * in background before load. The cast API will load the cast SDK automatically. |
| - * The given callback is executes after the cast SDK extension is initialized. |
| + * Loads the Google Cast Sender SDK from the given cast extension. |
| + * The given callback is executes after the cast SDK is loaded. |
| * |
| + * @param {string} extensionId ID of the extension to be loaded. |
| * @param {function()} callback Callback (executed asynchronously). |
| - * @param {boolean=} opt_secondTry Specify true if it's the second call after |
| - * installation of Cast API extension. |
| */ |
| -function loadCastAPI(callback, opt_secondTry) { |
| +function loadCastSDK(extensionId, callback) { |
| var script = document.createElement('script'); |
| var onError = function() { |
| script.removeEventListener('error', onError); |
| document.body.removeChild(script); |
| - if (opt_secondTry) { |
| - metrics.recordCastAPIExtensionStatus( |
| - metrics.CAST_API_EXTENSION_STATUS.LOAD_FAILED); |
| - |
| - // Shows error message and exits if it's the 2nd try. |
| - console.error('Google Cast API extension load failed.'); |
| - return; |
| - } |
| + metrics.recordCastAPIExtensionStatus( |
|
yoshiki
2016/04/26 05:01:16
Please remove this as well. I think we can remove
fukino
2016/04/26 06:36:17
I removed all the metrics about CAST_API_EXTENSION
|
| + metrics.CAST_API_EXTENSION_STATUS.LOAD_FAILED); |
| - // Installs the Google Cast API extension and retry loading. |
| - chrome.webstoreWidgetPrivate.installWebstoreItem( |
| - 'mafeflapfdfljijmlienjedomfjfmhpd', |
| - true, // Don't use installation prompt. |
| - function() { |
| - if (chrome.runtime.lastError) { |
| - metrics.recordCastAPIExtensionStatus( |
| - metrics.CAST_API_EXTENSION_STATUS.INSTALLATION_FAILED); |
| - |
| - console.error('Google Cast API extension installation error.', |
| - chrome.runtime.lastError.message); |
| - return; |
| - } |
| - |
| - console.info('Google Cast API extension installed.'); |
| - |
| - // Loads API again. |
| - setTimeout(loadCastAPI.bind(null, callback, true), 0); |
| - }.wrap()); |
| + console.error('Google Cast API extension load failed.'); |
| }.wrap(); |
| - // Trys to load the cast API extention which is defined in manifest.json. |
| - script.src = '_modules/mafeflapfdfljijmlienjedomfjfmhpd/cast_sender.js'; |
| + // Load the Cast Sender SDK provided by the given Cast extension. |
| + window.chrome['cast'] = window.chrome['cast'] || {}; |
| + window.chrome['cast']['extensionId'] = extensionId; |
|
yoshiki
2016/04/26 05:04:30
I can't file the usage of this? Is this necessary?
fukino
2016/04/26 06:36:17
Added a comment.
Legacy cast extension relies on t
|
| + script.src = 'chrome-extension://' + extensionId + '/cast_sender.js'; |
| script.addEventListener('error', onError); |
| script.addEventListener( |
|
yoshiki
2016/04/26 05:01:16
nit: no need for new line?
fukino
2016/04/26 06:36:17
Done.
|
| - 'load', onLoadCastExtension.bind(null, callback, opt_secondTry)); |
| + 'load', onLoadCastSDK.bind(null, callback)); |
| document.body.appendChild(script); |
| } |
| /** |
| - * Loads the cast sdk extension. |
| - * @param {function()} callback Callback (executed asynchronously). |
| - * @param {boolean=} opt_installationOccured True if the extension is just |
| - * installed in this window. False or null if it's already installed. |
| + * Handles load event of Cast SDK and make sure the Cast API is available. |
| + * @param {function()} callback Callback which is called when the Caset Sender |
| + * API is ready for use. |
| */ |
| -function onLoadCastExtension(callback, opt_installationOccured) { |
| +function onLoadCastSDK(callback) { |
| var executeCallback = function() { |
| - if (opt_installationOccured) { |
| - metrics.recordCastAPIExtensionStatus( |
| - metrics.CAST_API_EXTENSION_STATUS.INSTALLED_AND_LOADED); |
| - } else { |
| - metrics.recordCastAPIExtensionStatus( |
| - metrics.CAST_API_EXTENSION_STATUS.LOADED); |
| - } |
| + metrics.recordCastAPIExtensionStatus( |
|
yoshiki
2016/04/26 05:01:16
ditto
fukino
2016/04/26 06:36:17
Done.
|
| + metrics.CAST_API_EXTENSION_STATUS.LOADED); |
| setTimeout(callback, 0); // Runs asynchronously. |
| }; |