Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: ui/file_manager/video_player/js/cast/cast_extension_discoverer.js

Issue 381073003: Video Player: Add a cast menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 cofgocippekhfcmgfj - / Copyright 2014 The Chromium Authors. All rights reserved.
fukino 2014/07/11 04:35:50 seems leading dust?
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.
39 */
40 CastExtensionDiscoverer.findInstalledExtensionHelper_ = function(index,
41 callback) {
42 if (index == CastExtensionDiscoverer.CAST_EXTENSION_IDS.length) {
fukino 2014/07/11 04:35:50 nit: seems '===' can be used
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.
64 */
65 CastExtensionDiscoverer.isExtensionInstalled_ =
66 function(extensionId, callback) {
67
68 var responseCallback =
69 /** @param {*} response */
70 function(response) {
71 if (chrome.runtime.lastError || response === false) {
72 // An error occurred while sending the message.
73 callback(false);
74 } else {
75 // Cast extension found.
76 callback(true);
77 }
78 }.wrap(this);
79
80 chrome.runtime.sendMessage(extensionId, {}, responseCallback);
81 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698