summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/file_manager/video_player/js/cast/cast_extension_discoverer.js83
-rw-r--r--ui/file_manager/video_player/js/cast/caster.js10
-rw-r--r--ui/file_manager/video_player/js/video_player_scripts.js1
3 files changed, 90 insertions, 4 deletions
diff --git a/ui/file_manager/video_player/js/cast/cast_extension_discoverer.js b/ui/file_manager/video_player/js/cast/cast_extension_discoverer.js
new file mode 100644
index 0000000..e980e4a
--- /dev/null
+++ b/ui/file_manager/video_player/js/cast/cast_extension_discoverer.js
@@ -0,0 +1,83 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+'use strict';
+
+/**
+ * Discover the ID of installed cast extesnion.
+ * @constructor
+ */
+function CastExtensionDiscoverer() {
+}
+
+/**
+ * Tentatice IDs to try.
+ * @type {Array.<string>}
+ * @const
+ */
+CastExtensionDiscoverer.CAST_EXTENSION_IDS = [
+ 'boadgeojelhgndaghljhdicfkmllpafd', // release
+ 'dliochdbjfkdbacpmhlcpmleaejidimm', // beta
+ 'hfaagokkkhdbgiakmmlclaapfelnkoah',
+ 'fmfcbgogabcbclcofgocippekhfcmgfj',
+ 'enhhojjnijigcajfphajepfemndkmdlo'
+];
+
+/**
+ * @param {function(string)} callback Callback called with the extension ID. The
+ * ID may be null if extension is not found.
+ */
+CastExtensionDiscoverer.findInstalledExtension = function(callback) {
+ CastExtensionDiscoverer.findInstalledExtensionHelper_(0, callback);
+};
+
+/**
+ * @param {number} index Current index which is tried to check.
+ * @param {function(string)} callback Callback function which will be called
+ * the extension is found.
+ * @private
+ */
+CastExtensionDiscoverer.findInstalledExtensionHelper_ = function(index,
+ callback) {
+ if (index === CastExtensionDiscoverer.CAST_EXTENSION_IDS.length) {
+ // no extension found.
+ callback(null);
+ return;
+ }
+
+ CastExtensionDiscoverer.isExtensionInstalled_(
+ CastExtensionDiscoverer.CAST_EXTENSION_IDS[index],
+ function(installed) {
+ if (installed) {
+ callback(CastExtensionDiscoverer.CAST_EXTENSION_IDS[index]);
+ } else {
+ CastExtensionDiscoverer.findInstalledExtensionHelper_(index + 1,
+ callback);
+ }
+ });
+};
+
+/**
+ * The result will be notified on |callback|. True if installed, false not.
+ * @param {string} extensionId Id to be checked.
+ * @param {function(boolean)} callback Callback to notify the result.
+ * @private
+ */
+CastExtensionDiscoverer.isExtensionInstalled_ =
+ function(extensionId, callback) {
+
+ var xhr = new XMLHttpRequest();
+ var url = 'chrome-extension://' + extensionId + '/cast_sender.js';
+ xhr.open('GET', url, true);
+ xhr.onerror = function() { callback(false); };
+ xhr.onreadystatechange =
+ /** @param {*} response */
+ function(event) {
+ if (xhr.readyState == 4 && xhr.status === 200) {
+ // Cast extension found.
+ callback(true);
+ }
+ }.wrap(this);
+ xhr.send();
+};
diff --git a/ui/file_manager/video_player/js/cast/caster.js b/ui/file_manager/video_player/js/cast/caster.js
index 9ccc528..4b5cd5c 100644
--- a/ui/file_manager/video_player/js/cast/caster.js
+++ b/ui/file_manager/video_player/js/cast/caster.js
@@ -15,10 +15,12 @@ window.__defineGetter__('localStorage', function() { return {}; });
var APPLICATION_ID = '214CC863';
util.addPageLoadHandler(function() {
- // TODO(yoshiki): Check if the Google Cast extension is installed or not.
- // If not installed, we should skip all cast-related functionality.
-
- loadCastAPI(initializeApi);
+ CastExtensionDiscoverer.findInstalledExtension(function(foundId) {
+ if (foundId)
+ loadCastAPI(initializeApi);
+ else
+ console.info('No Google Cast extension is installed.');
+ });
});
/**
diff --git a/ui/file_manager/video_player/js/video_player_scripts.js b/ui/file_manager/video_player/js/video_player_scripts.js
index 61e80f3..7e95190 100644
--- a/ui/file_manager/video_player/js/video_player_scripts.js
+++ b/ui/file_manager/video_player/js/video_player_scripts.js
@@ -32,6 +32,7 @@
//<include src="../../file_manager/foreground/js/media/media_controls.js"/>
//<include src="../../file_manager/foreground/js/media/mouse_inactivity_watcher.js"/>
+//<include src="cast/cast_extension_discoverer.js"/>
//<include src="cast/cast_video_element.js"/>
//<include src="cast/media_manager.js"/>
//<include src="cast/caster.js"/>