OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var mediaRouter; | 5 var mediaRouter; |
6 | 6 |
7 define('media_router_bindings', [ | 7 define('media_router_bindings', [ |
8 'mojo/public/js/bindings', | |
9 'mojo/public/js/core', | |
10 'content/public/renderer/frame_interfaces', | 8 'content/public/renderer/frame_interfaces', |
11 'chrome/browser/media/router/mojo/media_router.mojom', | 9 'chrome/browser/media/router/mojo/media_router.mojom', |
12 'extensions/common/mojo/keep_alive.mojom', | 10 'extensions/common/mojo/keep_alive.mojom', |
13 'mojo/common/time.mojom', | 11 'mojo/common/time.mojom', |
14 'mojo/public/js/connection', | 12 'mojo/public/js/bindings', |
15 'mojo/public/js/router', | 13 ], function(frameInterfaces, |
16 ], function(bindings, | |
17 core, | |
18 frameInterfaces, | |
19 mediaRouterMojom, | 14 mediaRouterMojom, |
20 keepAliveMojom, | 15 keepAliveMojom, |
21 timeMojom, | 16 timeMojom, |
22 connector, | 17 bindings) { |
23 routerModule) { | |
24 'use strict'; | 18 'use strict'; |
25 | 19 |
26 /** | 20 /** |
27 * Converts a media sink to a MediaSink Mojo object. | 21 * Converts a media sink to a MediaSink Mojo object. |
28 * @param {!MediaSink} sink A media sink. | 22 * @param {!MediaSink} sink A media sink. |
29 * @return {!mediaRouterMojom.MediaSink} A Mojo MediaSink object. | 23 * @return {!mediaRouterMojom.MediaSink} A Mojo MediaSink object. |
30 */ | 24 */ |
31 function sinkToMojo_(sink) { | 25 function sinkToMojo_(sink) { |
32 return new mediaRouterMojom.MediaSink({ | 26 return new mediaRouterMojom.MediaSink({ |
33 'name': sink.friendlyName, | 27 'name': sink.friendlyName, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 function toErrorRouteResponse_(error) { | 174 function toErrorRouteResponse_(error) { |
181 return { | 175 return { |
182 error_text: error.message, | 176 error_text: error.message, |
183 result_code: getRouteRequestResultCode_(error) | 177 result_code: getRouteRequestResultCode_(error) |
184 }; | 178 }; |
185 } | 179 } |
186 | 180 |
187 /** | 181 /** |
188 * Creates a new MediaRouter. | 182 * Creates a new MediaRouter. |
189 * Converts a route struct to its Mojo form. | 183 * Converts a route struct to its Mojo form. |
190 * @param {!MediaRouterService} service | 184 * @param {!mediaRouterMojom.MediaRouterPtr} service |
191 * @constructor | 185 * @constructor |
192 */ | 186 */ |
193 function MediaRouter(service) { | 187 function MediaRouter(service) { |
194 /** | 188 /** |
195 * The Mojo service proxy. Allows extension code to call methods that reside | 189 * The Mojo service proxy. Allows extension code to call methods that reside |
196 * in the browser. | 190 * in the browser. |
197 * @type {!MediaRouterService} | 191 * @type {!mediaRouterMojom.MediaRouterPtr} |
198 */ | 192 */ |
199 this.service_ = service; | 193 this.service_ = service; |
200 | 194 |
201 /** | 195 /** |
202 * The provider manager service delegate. Its methods are called by the | 196 * The provider manager service delegate. Its methods are called by the |
203 * browser-resident Mojo service. | 197 * browser-resident Mojo service. |
204 * @type {!MediaRouter} | 198 * @type {!MediaRouter} |
205 */ | 199 */ |
206 this.mrpm_ = new MediaRouteProvider(this); | 200 this.mrpm_ = new MediaRouteProvider(this); |
207 | 201 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 /** | 274 /** |
281 * Called by the provider manager to keep the extension from suspending | 275 * Called by the provider manager to keep the extension from suspending |
282 * if it enters a state where suspension is undesirable (e.g. there is an | 276 * if it enters a state where suspension is undesirable (e.g. there is an |
283 * active MediaRoute.) | 277 * active MediaRoute.) |
284 * If keepAlive is true, the extension is kept alive. | 278 * If keepAlive is true, the extension is kept alive. |
285 * If keepAlive is false, the extension is allowed to suspend. | 279 * If keepAlive is false, the extension is allowed to suspend. |
286 * @param {boolean} keepAlive | 280 * @param {boolean} keepAlive |
287 */ | 281 */ |
288 MediaRouter.prototype.setKeepAlive = function(keepAlive) { | 282 MediaRouter.prototype.setKeepAlive = function(keepAlive) { |
289 if (keepAlive === false && this.keepAlive_) { | 283 if (keepAlive === false && this.keepAlive_) { |
290 this.keepAlive_.close(); | 284 this.keepAlive_.ptr.reset(); |
291 this.keepAlive_ = null; | 285 this.keepAlive_ = null; |
292 } else if (keepAlive === true && !this.keepAlive_) { | 286 } else if (keepAlive === true && !this.keepAlive_) { |
293 this.keepAlive_ = new routerModule.Router( | 287 this.keepAlive_ = new keepAliveMojom.KeepAlivePtr( |
294 frameInterfaces.getInterface(keepAliveMojom.KeepAlive.name)); | 288 frameInterfaces.getInterface(keepAliveMojom.KeepAlive.name)); |
295 } | 289 } |
296 }; | 290 }; |
297 | 291 |
298 /** | 292 /** |
299 * Called by the provider manager to send an issue from a media route | 293 * Called by the provider manager to send an issue from a media route |
300 * provider to the Media Router, to show the user. | 294 * provider to the Media Router, to show the user. |
301 * @param {!Object} issue The issue object. | 295 * @param {!Object} issue The issue object. |
302 */ | 296 */ |
303 MediaRouter.prototype.onIssue = function(issue) { | 297 MediaRouter.prototype.onIssue = function(issue) { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 }; | 485 }; |
492 | 486 |
493 /** | 487 /** |
494 * Routes calls from Media Router to the provider manager extension. | 488 * Routes calls from Media Router to the provider manager extension. |
495 * Registered with the MediaRouter stub. | 489 * Registered with the MediaRouter stub. |
496 * @param {!MediaRouter} MediaRouter proxy to call into the | 490 * @param {!MediaRouter} MediaRouter proxy to call into the |
497 * Media Router mojo interface. | 491 * Media Router mojo interface. |
498 * @constructor | 492 * @constructor |
499 */ | 493 */ |
500 function MediaRouteProvider(mediaRouter) { | 494 function MediaRouteProvider(mediaRouter) { |
501 mediaRouterMojom.MediaRouteProvider.stubClass.call(this); | |
502 | |
503 /** | 495 /** |
504 * Object containing JS callbacks into Provider Manager code. | 496 * Object containing JS callbacks into Provider Manager code. |
505 * @type {!MediaRouterHandlers} | 497 * @type {!MediaRouterHandlers} |
506 */ | 498 */ |
507 this.handlers_ = new MediaRouterHandlers(); | 499 this.handlers_ = new MediaRouterHandlers(); |
508 | 500 |
509 /** | 501 /** |
510 * Proxy class to the browser's Media Router Mojo service. | 502 * Proxy class to the browser's Media Router Mojo service. |
511 * @type {!MediaRouter} | 503 * @type {!MediaRouter} |
512 */ | 504 */ |
513 this.mediaRouter_ = mediaRouter; | 505 this.mediaRouter_ = mediaRouter; |
514 } | 506 } |
515 MediaRouteProvider.prototype = Object.create( | |
516 mediaRouterMojom.MediaRouteProvider.stubClass.prototype); | |
517 | 507 |
518 /* | 508 /* |
519 * Sets the callback handler used to invoke methods in the provider manager. | 509 * Sets the callback handler used to invoke methods in the provider manager. |
520 * | 510 * |
521 * @param {!MediaRouterHandlers} handlers | 511 * @param {!MediaRouterHandlers} handlers |
522 */ | 512 */ |
523 MediaRouteProvider.prototype.setHandlers = function(handlers) { | 513 MediaRouteProvider.prototype.setHandlers = function(handlers) { |
524 // TODO(mfoltz): Remove when component that supports this method is | 514 // TODO(mfoltz): Remove when component that supports this method is |
525 // rolled out to all Chrome channels in M56. | 515 // rolled out to all Chrome channels in M56. |
526 if (!handlers['onBeforeInvokeHandler']) | 516 if (!handlers['onBeforeInvokeHandler']) |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 // to be missing this API. | 796 // to be missing this API. |
807 if (!this.handlers_.searchSinks) { | 797 if (!this.handlers_.searchSinks) { |
808 return Promise.resolve({'sink_id': ''}); | 798 return Promise.resolve({'sink_id': ''}); |
809 } | 799 } |
810 this.handlers_.onBeforeInvokeHandler(); | 800 this.handlers_.onBeforeInvokeHandler(); |
811 return Promise.resolve({ | 801 return Promise.resolve({ |
812 'sink_id': this.handlers_.searchSinks(sinkId, sourceUrn, searchCriteria) | 802 'sink_id': this.handlers_.searchSinks(sinkId, sourceUrn, searchCriteria) |
813 }); | 803 }); |
814 }; | 804 }; |
815 | 805 |
816 mediaRouter = new MediaRouter(connector.bindHandleToProxy( | 806 mediaRouter = new MediaRouter(new mediaRouterMojom.MediaRouterPtr( |
817 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name), | 807 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name))); |
818 mediaRouterMojom.MediaRouter)); | |
819 | 808 |
820 return mediaRouter; | 809 return mediaRouter; |
821 }); | 810 }); |
OLD | NEW |