Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3179)

Unified Diff: ui/file_manager/video_player/js/cast/caster.js

Issue 437593006: Video Player: Install the cast API extension if it is not installed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 79214a88b699a9161a1e01efd2520ff2f499ac89..c12947d548c2e831072941e6518d3b25a4c10e95 100644
--- a/ui/file_manager/video_player/js/cast/caster.js
+++ b/ui/file_manager/video_player/js/cast/caster.js
@@ -24,31 +24,72 @@ chrome.commandLinePrivate.hasSwitch(CAST_COMMAND_LINE_FLAG, function(result) {
if (!result)
return;
- ensureLoad(initializeApi);
+ // TODO(yoshiki): Check if the Google Cast extension is installed or not.
+ // If not installed, we should skip all cast-related functionality.
+
+ loadCastAPI(initializeApi);
});
/**
* Executes the given callback after the cast extension is initialized.
* @param {function} callback Callback (executed asynchronously).
+ * @param {boolean=} opt_secondTry Spericy try if it's second call after
+ * installation of Cast API extension.
*/
-function ensureLoad(callback) {
- if(!chrome.cast || !chrome.cast.isAvailable) {
- var checkTimer = setTimeout(function() {
- console.error('Either "Google Cast API" or "Google Cast" extension ' +
- 'seems not to be installed?');
- }, 5000);
-
- window['__onGCastApiAvailable'] = function(loaded, errorInfo) {
- if (loaded) {
- callback();
+function loadCastAPI(callback, opt_secondTry) {
+ var script = document.createElement('script');
+
+ var onError = function() {
+ script.removeEventListener('error', onError);
+ document.body.removeChild(script);
+
+ if (opt_secondTry) {
+ // 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.fileBrowserPrivate.installWebstoreItem(
+ 'mafeflapfdfljijmlienjedomfjfmhpd',
+ true, // Don't use installation prompt.
+ function() {
+ if (chrome.runtime.lastError) {
+ 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));
+ }.wrap());
+ }.wrap();
+
+ var onLoad = function() {
+ if(!chrome.cast || !chrome.cast.isAvailable) {
+ var checkTimer = setTimeout(function() {
+ console.error('Either "Google Cast API" or "Google Cast" extension ' +
+ 'seems not to be installed?');
+ }.wrap(), 5000);
+
+ window['__onGCastApiAvailable'] = function(loaded, errorInfo) {
clearTimeout(checkTimer);
- } else {
- console.error(errorInfo);
- }
+
+ if (loaded)
+ callback();
+ else
+ console.error('Google Cast exntnsion load failed.', errorInfo);
+ }.wrap();
+ } else {
+ setTimeout(callback); // Runs asynchronously.
}
- } else {
- setTimeout(callback); // Runs asynchronously.
- }
+ }.wrap();
+
+ script.src = '_modules/mafeflapfdfljijmlienjedomfjfmhpd/cast_sender.js';
+ script.addEventListener('error', onError);
+ script.addEventListener('load', onLoad);
+ document.body.appendChild(script);
}
/**
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/app_installer.js ('k') | ui/file_manager/video_player/video_player.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698