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..c906935ef939348b40318a7e6d16579f465e3128 100644 |
| --- a/ui/file_manager/video_player/js/cast/caster.js |
| +++ b/ui/file_manager/video_player/js/cast/caster.js |
| @@ -33,7 +33,7 @@ function initialize() { |
| CastExtensionDiscoverer.findInstalledExtension(function(foundId) { |
| if (foundId) { |
| - loadCastAPI(initializeApi); |
| + loadCastAPI(foundId, initializeApi); |
| } else { |
| console.info('No Google Cast extension is installed.'); |
| @@ -44,74 +44,45 @@ function initialize() { |
| } |
| /** |
| - * 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 cast API extention. |
| + * The cast API will load the cast SDK automatically. The given callback is |
|
yoshiki
2016/04/26 03:02:52
nit: update the comment.
fukino
2016/04/26 03:59:07
Done.
|
| + * executes after the cast SDK extension is initialized. |
| * |
| + * @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 loadCastAPI(extensionId, callback) { |
|
yoshiki
2016/04/26 03:02:52
Please rename this, since now this loads the googl
fukino
2016/04/26 03:59:08
Done.
I renamed it to loadCastSDK(), as it loads G
|
| 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; |
| - } |
| - |
| - // 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; |
| - } |
| + metrics.recordCastAPIExtensionStatus( |
| + metrics.CAST_API_EXTENSION_STATUS.LOAD_FAILED); |
| - console.info('Google Cast API extension installed.'); |
| - |
| - // Loads API again. |
| - setTimeout(loadCastAPI.bind(null, callback, true), 0); |
| - }.wrap()); |
| - }.wrap(); |
| + // Shows error message and exits if it's the 2nd try. |
|
yoshiki
2016/04/26 03:02:52
nit: please update the comment.
fukino
2016/04/26 03:59:07
Removed this comment.
|
| + console.error('Google Cast API extension load failed.'); |
| + } |
|
yoshiki
2016/04/26 03:02:52
nit: need .wrap() for consistency?
yoshiki
2016/04/26 03:02:52
nit: semicolon.
fukino
2016/04/26 03:59:07
Done.
fukino
2016/04/26 03:59:07
Done.
|
| // Trys to load the cast API extention which is defined in manifest.json. |
|
yoshiki
2016/04/26 03:02:52
nit: please fix the comment
fukino
2016/04/26 03:59:07
Done.
|
| - script.src = '_modules/mafeflapfdfljijmlienjedomfjfmhpd/cast_sender.js'; |
| + window.chrome['cast'] = window.chrome['cast'] || {}; |
| + window.chrome['cast']['extensionId'] = extensionId; |
| + script.src = 'chrome-extension://' + extensionId + '/cast_sender.js'; |
| script.addEventListener('error', onError); |
| script.addEventListener( |
| - 'load', onLoadCastExtension.bind(null, callback, opt_secondTry)); |
| + 'load', onLoadCastExtension.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. |
| */ |
| -function onLoadCastExtension(callback, opt_installationOccured) { |
| +function onLoadCastExtension(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( |
| + metrics.CAST_API_EXTENSION_STATUS.LOADED); |
| setTimeout(callback, 0); // Runs asynchronously. |
| }; |