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

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

Issue 381073003: Video Player: Add a cast menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed the comment 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 // 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 /**
6 * Defines the cast.ExtensionApi class. This class inherits cast.Api and must
7 * be decraled after the parent is loaded. So we introduce this method to
8 * decrale it with delay.
9 */
10 function loadCastExtensionApi() {
11 if (!cast) {
12 console.error('"cast" namespace is not defined.');
13 return;
14 }
15
16 /**
17 * @constructor
18 * @param {string} castExtensionId Extension ID of cast extension.
19 * @extends {cast.Api}
20 */
21 cast.ExtensionApi = function(castExtensionId) {
22 this.castExtensionId_ = castExtensionId;
23 cast.Client.clientId_ = chrome.runtime.id;
24
25 cast.Api.call(this);
26 };
27
28 cast.ExtensionApi.prototype.__proto__ = cast.Api.prototype;
29
30 /**
31 * @override
32 */
33 cast.ExtensionApi.prototype.init = function() {
34 chrome.runtime.onMessageExternal.addListener(
35 this.onMessageExternal_.bind(this));
36 this.sendRequest(cast.AppRequestType.REGISTER_CLIENT, {});
37 cast.isAvailable = true;
38 };
39
40 /**
41 * @override
42 */
43 cast.ExtensionApi.prototype.onDisconnect = function() {};
44
45 /**
46 * @override
47 */
48 cast.ExtensionApi.prototype.sendRequest = function(requestType, request) {
49 if (!this.castExtensionId_)
50 return null;
51
52 var appRequest = new cast.Message(cast.Client.getClientId(),
53 cast.NAME, cast.Client.getNextSeq(), requestType, request);
54
55 // Use response callback for message ACK to detect extension unload.
56 var responseCallback = function() {
57 if (chrome.runtime.lastError) {
58 // Unregister the cast extension.
59 this.castExtensionId_ = '';
60 cast.isAvailable = false;
61 this.onDisconnect();
62 }
63 }.bind(this);
64
65 chrome.runtime.sendMessage(this.castExtensionId_,
66 appRequest,
67 responseCallback);
68 return appRequest;
69 };
70
71 /**
72 * @param {string} message
73 * @param {function(boolean)} sender
74 * @param {function(boolean)} sendResponse
75 * @private
76 */
77 cast.ExtensionApi.prototype.onMessageExternal_ = function(message,
78 sender, sendResponse) {
79 if (!this.castExtensionId_ || sender.id != this.castExtensionId_)
80 return;
81
82 // No content.
83 if (!message)
84 return;
85
86 this.processCastMessage(/** @type {cast.Message} */(message));
87 };
88 }
OLDNEW
« no previous file with comments | « ui/file_manager/video_player/js/cast/caster.js ('k') | ui/file_manager/video_player/js/video_player.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698