Commit 47e7b0d9 authored by yoshiki@chromium.org's avatar yoshiki@chromium.org

Video Player: Check Cast extension before launching cast feature

If the cast extension is not install, video player doesn't activate the cast-related feature.

BUG=399557
TEST=manually tested
R=fukino@chromium.org

Review URL: https://codereview.chromium.org/443083002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288003 0039d316-1c4b-4281-b951-d872f2087c98
parent afc7c3c9
// 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();
};
...@@ -15,10 +15,12 @@ window.__defineGetter__('localStorage', function() { return {}; }); ...@@ -15,10 +15,12 @@ window.__defineGetter__('localStorage', function() { return {}; });
var APPLICATION_ID = '214CC863'; var APPLICATION_ID = '214CC863';
util.addPageLoadHandler(function() { util.addPageLoadHandler(function() {
// TODO(yoshiki): Check if the Google Cast extension is installed or not. CastExtensionDiscoverer.findInstalledExtension(function(foundId) {
// If not installed, we should skip all cast-related functionality. if (foundId)
loadCastAPI(initializeApi);
loadCastAPI(initializeApi); else
console.info('No Google Cast extension is installed.');
});
}); });
/** /**
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
//<include src="../../file_manager/foreground/js/media/media_controls.js"/> //<include src="../../file_manager/foreground/js/media/media_controls.js"/>
//<include src="../../file_manager/foreground/js/media/mouse_inactivity_watcher.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/cast_video_element.js"/>
//<include src="cast/media_manager.js"/> //<include src="cast/media_manager.js"/>
//<include src="cast/caster.js"/> //<include src="cast/caster.js"/>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment