Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 'use strict'; | |
| 6 | |
| 7 /** | |
| 8 * Discover the ID of installed cast extesnion. | |
| 9 * @constructor | |
| 10 */ | |
| 11 function CastExtensionDiscoverer() { | |
| 12 } | |
| 13 | |
| 14 /** | |
| 15 * Tentatice IDs to try. | |
| 16 * @type {Array.<string>} | |
| 17 * @const | |
| 18 */ | |
| 19 CastExtensionDiscoverer.CAST_EXTENSION_IDS = [ | |
| 20 'boadgeojelhgndaghljhdicfkmllpafd', // release | |
| 21 'dliochdbjfkdbacpmhlcpmleaejidimm', // beta | |
| 22 'hfaagokkkhdbgiakmmlclaapfelnkoah', | |
| 23 'fmfcbgogabcbclcofgocippekhfcmgfj', | |
| 24 'enhhojjnijigcajfphajepfemndkmdlo' | |
| 25 ]; | |
| 26 | |
| 27 /** | |
| 28 * @param {function(string)} callback Callback called with the extension ID. The | |
| 29 * ID may be null if extension is not found. | |
| 30 */ | |
| 31 CastExtensionDiscoverer.findInstalledExtension = function(callback) { | |
| 32 CastExtensionDiscoverer.findInstalledExtensionHelper_(0, callback); | |
| 33 }; | |
| 34 | |
| 35 /** | |
| 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. | |
|
fukino
2014/08/07 00:35:04
nit: @private
yoshiki
2014/08/07 06:33:46
Done.
| |
| 39 */ | |
| 40 CastExtensionDiscoverer.findInstalledExtensionHelper_ = function(index, | |
| 41 callback) { | |
| 42 if (index === CastExtensionDiscoverer.CAST_EXTENSION_IDS.length) { | |
| 43 // no extension found. | |
| 44 callback(null); | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 CastExtensionDiscoverer.isExtensionInstalled_( | |
| 49 CastExtensionDiscoverer.CAST_EXTENSION_IDS[index], | |
| 50 function(installed) { | |
| 51 if (installed) { | |
| 52 callback(CastExtensionDiscoverer.CAST_EXTENSION_IDS[index]); | |
| 53 } else { | |
| 54 CastExtensionDiscoverer.findInstalledExtensionHelper_(index + 1, | |
| 55 callback); | |
| 56 } | |
| 57 }); | |
| 58 }; | |
| 59 | |
| 60 /** | |
| 61 * The result will be notified on |callback|. True if installed, false not. | |
| 62 * @param {string} extensionId Id to be checked. | |
| 63 * @param {function(boolean)} callback Callback to notify the result. | |
|
fukino
2014/08/07 00:35:04
nit: @private
yoshiki
2014/08/07 06:33:46
Done.
| |
| 64 */ | |
| 65 CastExtensionDiscoverer.isExtensionInstalled_ = | |
| 66 function(extensionId, callback) { | |
| 67 | |
| 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 xhr.onreadystatechange = | |
| 73 /** @param {*} response */ | |
| 74 function(event) { | |
| 75 if (xhr.readyState == 4 && xhr.status === 200) { | |
| 76 // Cast extension found. | |
| 77 callback(true); | |
| 78 } | |
| 79 }.wrap(this); | |
| 80 xhr.send(); | |
| 81 }; | |
| OLD | NEW |