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.
6 * Discover the ID of installed cast extension.
10 function CastExtensionDiscoverer() {}
13 * Tentatice IDs to try.
14 * @type {!Array.<string>}
17 CastExtensionDiscoverer.CAST_EXTENSION_IDS = [
18 'boadgeojelhgndaghljhdicfkmllpafd', // release
19 'dliochdbjfkdbacpmhlcpmleaejidimm', // beta
20 'hfaagokkkhdbgiakmmlclaapfelnkoah',
21 'fmfcbgogabcbclcofgocippekhfcmgfj',
22 'enhhojjnijigcajfphajepfemndkmdlo'
26 * @param {function(?string)} callback Callback called with the extension ID.
27 * The ID may be null if extension is not found.
29 CastExtensionDiscoverer.findInstalledExtension = function(callback) {
30 CastExtensionDiscoverer.findInstalledExtensionHelper_(0, callback);
34 * @param {number} index Current index which is tried to check.
35 * @param {function(?string)} callback Callback function which will be called
36 * the extension is found.
39 CastExtensionDiscoverer.findInstalledExtensionHelper_ = function(index,
41 if (index === CastExtensionDiscoverer.CAST_EXTENSION_IDS.length) {
42 // no extension found.
47 CastExtensionDiscoverer.isExtensionInstalled_(
48 CastExtensionDiscoverer.CAST_EXTENSION_IDS[index],
51 callback(CastExtensionDiscoverer.CAST_EXTENSION_IDS[index]);
53 CastExtensionDiscoverer.findInstalledExtensionHelper_(index + 1,
60 * The result will be notified on |callback|. True if installed, false not.
61 * @param {string} extensionId Id to be checked.
62 * @param {function(boolean)} callback Callback to notify the result.
65 CastExtensionDiscoverer.isExtensionInstalled_ =
66 function(extensionId, callback) {
68 var xhr = new XMLHttpRequest();
69 var url = 'chrome-extension://' + extensionId + '/cast_sender.js';
70 xhr.open('GET', url, true);
71 xhr.onerror = function() { callback(false); };
72 /** @param {*} event */
73 xhr.onreadystatechange = function(event) {
74 if (xhr.readyState == 4 && xhr.status === 200) {
75 // Cast extension found.