1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 * Discover the ID of installed cast extension.
11 function CastExtensionDiscoverer() {
15 * Tentatice IDs to try.
16 * @type {Array.<string>}
19 CastExtensionDiscoverer.CAST_EXTENSION_IDS = [
20 'boadgeojelhgndaghljhdicfkmllpafd', // release
21 'dliochdbjfkdbacpmhlcpmleaejidimm', // beta
22 'hfaagokkkhdbgiakmmlclaapfelnkoah',
23 'fmfcbgogabcbclcofgocippekhfcmgfj',
24 'enhhojjnijigcajfphajepfemndkmdlo'
28 * @param {function(string)} callback Callback called with the extension ID. The
29 * ID may be null if extension is not found.
31 CastExtensionDiscoverer.findInstalledExtension = function(callback) {
32 CastExtensionDiscoverer.findInstalledExtensionHelper_(0, callback);
36 * @param {number} index Current index which is tried to check.
37 * @param {function(string)} callback Callback function which will be called
38 * the extension is found.
41 CastExtensionDiscoverer.findInstalledExtensionHelper_ = function(index,
43 if (index === CastExtensionDiscoverer.CAST_EXTENSION_IDS.length) {
44 // no extension found.
49 CastExtensionDiscoverer.isExtensionInstalled_(
50 CastExtensionDiscoverer.CAST_EXTENSION_IDS[index],
53 callback(CastExtensionDiscoverer.CAST_EXTENSION_IDS[index]);
55 CastExtensionDiscoverer.findInstalledExtensionHelper_(index + 1,
62 * The result will be notified on |callback|. True if installed, false not.
63 * @param {string} extensionId Id to be checked.
64 * @param {function(boolean)} callback Callback to notify the result.
67 CastExtensionDiscoverer.isExtensionInstalled_ =
68 function(extensionId, callback) {
70 var xhr = new XMLHttpRequest();
71 var url = 'chrome-extension://' + extensionId + '/cast_sender.js';
72 xhr.open('GET', url, true);
73 xhr.onerror = function() { callback(false); };
74 /** @param {*} event */
75 xhr.onreadystatechange = function(event) {
76 if (xhr.readyState == 4 && xhr.status === 200) {
77 // Cast extension found.