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

Side by Side Diff: extensions/renderer/resources/media_router_bindings.js

Issue 2779203003: [Media Router] Export Mojom definitions in media_router_bindings.js. (Closed)
Patch Set: backwards compatible Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'content/public/renderer/frame_interfaces', 8 'content/public/renderer/frame_interfaces',
9 'chrome/browser/media/router/mojo/media_controller.mojom',
9 'chrome/browser/media/router/mojo/media_router.mojom', 10 'chrome/browser/media/router/mojo/media_router.mojom',
11 'chrome/browser/media/router/mojo/media_status.mojom',
10 'extensions/common/mojo/keep_alive.mojom', 12 'extensions/common/mojo/keep_alive.mojom',
11 'mojo/common/time.mojom', 13 'mojo/common/time.mojom',
12 'mojo/public/js/bindings', 14 'mojo/public/js/bindings',
15 'net/interfaces/ip_address.mojom',
13 'url/mojo/origin.mojom', 16 'url/mojo/origin.mojom',
17 'url/mojo/url.mojom',
14 ], function(frameInterfaces, 18 ], function(frameInterfaces,
19 mediaControllerMojom,
15 mediaRouterMojom, 20 mediaRouterMojom,
21 mediaStatusMojom,
16 keepAliveMojom, 22 keepAliveMojom,
17 timeMojom, 23 timeMojom,
18 bindings, 24 bindings,
19 originMojom) { 25 ipAddressMojom,
26 originMojom,
27 urlMojom) {
20 'use strict'; 28 'use strict';
21 29
22 /** 30 /**
23 * Converts a media sink to a MediaSink Mojo object. 31 * Converts a media sink to a MediaSink Mojo object.
24 * @param {!MediaSink} sink A media sink. 32 * @param {!MediaSink} sink A media sink.
25 * @return {!mediaRouterMojom.MediaSink} A Mojo MediaSink object. 33 * @return {!mediaRouterMojom.MediaSink} A Mojo MediaSink object.
26 */ 34 */
27 function sinkToMojo_(sink) { 35 function sinkToMojo_(sink) {
28 return new mediaRouterMojom.MediaSink({ 36 return new mediaRouterMojom.MediaSink({
29 'name': sink.friendlyName, 37 'name': sink.friendlyName,
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 * The bindings to bind the service delegate to the Mojo interface. 257 * The bindings to bind the service delegate to the Mojo interface.
250 * Object must remain in scope for the lifetime of the connection to 258 * Object must remain in scope for the lifetime of the connection to
251 * prevent the connection from closing automatically. 259 * prevent the connection from closing automatically.
252 * @type {!bindings.Binding} 260 * @type {!bindings.Binding}
253 */ 261 */
254 this.mediaRouteProviderBinding_ = new bindings.Binding( 262 this.mediaRouteProviderBinding_ = new bindings.Binding(
255 mediaRouterMojom.MediaRouteProvider, this.mrpm_); 263 mediaRouterMojom.MediaRouteProvider, this.mrpm_);
256 } 264 }
257 265
258 /** 266 /**
267 * Returns definitions of Mojo core and generated Mojom classes that can be
268 * used directly by the component.
269 * @return {!Object}
270 * TODO(imcheng): We should export these along with MediaRouter. This requires
271 * us to modify the component to handle multiple exports. When that logic is
272 * baked in for a couple of milestones, we should be able to remove this
273 * method.
274 */
275 MediaRouter.prototype.getMojoExports = function() {
276 return {
277 Binding: bindings.Binding,
278 DialMediaSink: mediaRouterMojom.DialMediaSink,
279 CastMediaSink: mediaRouterMojom.CastMediaSink,
280 IPAddress: ipAddressMojom.IPAddress,
281 InterfacePtrController: bindings.InterfacePtrController,
282 InterfaceRequest: bindings.InterfaceRequest,
283 MediaController: mediaControllerMojom.MediaController,
284 MediaStatus: mediaStatusMojom.MediaStatus,
285 MediaStatusObserverPtr: mediaStatusMojom.MediaStatusObserverPtr,
286 Sink: mediaRouterMojom.MediaSink,
287 SinkExtraData: mediaRouterMojom.MediaSinkExtraData,
288 Url: urlMojom.Url,
289 };
290 };
291
292 /**
259 * Registers the Media Router Provider Manager with the Media Router. 293 * Registers the Media Router Provider Manager with the Media Router.
260 * @return {!Promise<string>} Instance ID for the Media Router. 294 * @return {!Promise<string>} Instance ID for the Media Router.
261 */ 295 */
262 MediaRouter.prototype.start = function() { 296 MediaRouter.prototype.start = function() {
263 return this.service_.registerMediaRouteProvider( 297 return this.service_.registerMediaRouteProvider(
264 this.mediaRouteProviderBinding_.createInterfacePtrAndBind()).then( 298 this.mediaRouteProviderBinding_.createInterfacePtrAndBind()).then(
265 function(result) { 299 function(result) {
266 return result.instance_id; 300 return result.instance_id;
267 }.bind(this)); 301 }.bind(this));
268 } 302 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 * @type {function()} 545 * @type {function()}
512 */ 546 */
513 this.enableMdnsDiscovery = null; 547 this.enableMdnsDiscovery = null;
514 548
515 /** 549 /**
516 * @type {function()} 550 * @type {function()}
517 */ 551 */
518 this.updateMediaSinks = null; 552 this.updateMediaSinks = null;
519 553
520 /** 554 /**
521 * @type {function(!string, !string, !SinkSearchCriteria): !string} 555 * @type {function(string, string, !SinkSearchCriteria): string}
522 */ 556 */
523 this.searchSinks = null; 557 this.searchSinks = null;
558
559 /**
560 * @type {function(string, !bindings.InterfaceRequest): !Promise<boolean>}
561 */
562 this.createMediaRouteController = null;
563
564 /**
565 * @type {function(string, !mediaStatusMojom.MediaStatusObserverPtr)}
566 */
567 this.setMediaRouteStatusObserver = null;
524 }; 568 };
525 569
526 /** 570 /**
527 * Routes calls from Media Router to the provider manager extension. 571 * Routes calls from Media Router to the provider manager extension.
528 * Registered with the MediaRouter stub. 572 * Registered with the MediaRouter stub.
529 * @param {!MediaRouter} MediaRouter proxy to call into the 573 * @param {!MediaRouter} MediaRouter proxy to call into the
530 * Media Router mojo interface. 574 * Media Router mojo interface.
531 * @constructor 575 * @constructor
532 */ 576 */
533 function MediaRouteProvider(mediaRouter) { 577 function MediaRouteProvider(mediaRouter) {
534 /** 578 /**
535 * Object containing JS callbacks into Provider Manager code. 579 * Object containing JS callbacks into Provider Manager code.
536 * @type {!MediaRouterHandlers} 580 * @type {!MediaRouterHandlers}
537 */ 581 */
538 this.handlers_ = new MediaRouterHandlers(); 582 this.handlers_ = new MediaRouterHandlers();
539 583
540 /** 584 /**
541 * Proxy class to the browser's Media Router Mojo service. 585 * Proxy class to the browser's Media Router Mojo service.
542 * @type {!MediaRouter} 586 * @type {!MediaRouter}
543 */ 587 */
544 this.mediaRouter_ = mediaRouter; 588 this.mediaRouter_ = mediaRouter;
545 } 589 }
546 590
547 /* 591 /*
548 * Sets the callback handler used to invoke methods in the provider manager. 592 * Sets the callback handler used to invoke methods in the provider manager.
549 * 593 *
550 * @param {!MediaRouterHandlers} handlers 594 * @param {!MediaRouterHandlers} handlers
551 */ 595 */
552 MediaRouteProvider.prototype.setHandlers = function(handlers) { 596 MediaRouteProvider.prototype.setHandlers = function(handlers) {
553 // TODO(mfoltz): Remove when component that supports this method is 597 // TODO(mfoltz): Remove when component that supports this method is
mark a. foltz 2017/03/30 23:21:05 We should do a pass through these bindings and rem
554 // rolled out to all Chrome channels in M56. 598 // rolled out to all Chrome channels in M56.
555 if (!handlers['onBeforeInvokeHandler']) 599 if (!handlers['onBeforeInvokeHandler'])
556 handlers['onBeforeInvokeHandler'] = () => {}; 600 handlers['onBeforeInvokeHandler'] = () => {};
557 this.handlers_ = handlers; 601 this.handlers_ = handlers;
558 var requiredHandlers = [ 602 var requiredHandlers = [
559 'stopObservingMediaRoutes', 603 'stopObservingMediaRoutes',
560 'startObservingMediaRoutes', 604 'startObservingMediaRoutes',
561 'sendRouteMessage', 605 'sendRouteMessage',
562 'sendRouteBinaryMessage', 606 'sendRouteBinaryMessage',
563 'startListeningForRouteMessages', 607 'startListeningForRouteMessages',
564 'stopListeningForRouteMessages', 608 'stopListeningForRouteMessages',
565 'detachRoute', 609 'detachRoute',
566 'terminateRoute', 610 'terminateRoute',
567 'joinRoute', 611 'joinRoute',
568 'createRoute', 612 'createRoute',
569 'stopObservingMediaSinks', 613 'stopObservingMediaSinks',
570 'startObservingMediaRoutes', 614 'startObservingMediaRoutes',
571 'connectRouteByRouteId', 615 'connectRouteByRouteId',
572 'enableMdnsDiscovery', 616 'enableMdnsDiscovery',
573 'updateMediaSinks', 617 'updateMediaSinks',
574 'searchSinks', 618 'searchSinks',
619 'createMediaRouteController',
620 'setMediaRouteStatusObserver',
575 'onBeforeInvokeHandler' 621 'onBeforeInvokeHandler'
576 ]; 622 ];
577 requiredHandlers.forEach(function(nextHandler) { 623 requiredHandlers.forEach(function(nextHandler) {
578 if (handlers[nextHandler] === undefined) { 624 if (handlers[nextHandler] === undefined) {
579 console.error(nextHandler + ' handler not registered.'); 625 console.error(nextHandler + ' handler not registered.');
580 } 626 }
581 }); 627 });
582 } 628 }
583 629
584 /** 630 /**
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 // to be missing this API. 881 // to be missing this API.
836 if (!this.handlers_.searchSinks) { 882 if (!this.handlers_.searchSinks) {
837 return Promise.resolve({'sink_id': ''}); 883 return Promise.resolve({'sink_id': ''});
838 } 884 }
839 this.handlers_.onBeforeInvokeHandler(); 885 this.handlers_.onBeforeInvokeHandler();
840 return Promise.resolve({ 886 return Promise.resolve({
841 'sink_id': this.handlers_.searchSinks(sinkId, sourceUrn, searchCriteria) 887 'sink_id': this.handlers_.searchSinks(sinkId, sourceUrn, searchCriteria)
842 }); 888 });
843 }; 889 };
844 890
891
892 /**
893 * Creates a controller for the given route and binds the given
894 * InterfaceRequest to it.
895 * @param {string} routeId
896 * @param {!bindings.InterfaceRequest} controllerRequest
897 * @return {!Promise<!{success: boolean}>} Resolves to true if a controller
898 * is created. Resolves to false if a controller cannot be created, or if
899 * the controller is already bound.
900 */
901 MediaRouteProvider.prototype.createMediaRouteController = function(
902 routeId, controllerRequest) {
903 // TODO(imcheng): Remove this check when M59 is in stable.
904 if (!this.handlers_.createMediaRouteController) {
905 return Promise.resolve({success: false});
906 }
907
908 this.handlers_.onBeforeInvokeHandler();
909 this.handlers_.createMediaRouteController(routeId, controllerRequest)
910 .then(controller => {success: true},
911 e => {success: false});
912 }
913
914 /**
915 * Sets the MediaStatus oberver for a given route. MediaStatus updates are
916 * notified via the given observer interface.
917 * @param {string} routeId
918 * @param {!mediaStatusMojom.MediaStatusObserverPtr} observer
919 */
920 MediaRouteProvider.prototype.setMediaRouteStatusObserver = function(
921 routeId, observer) {
922 // TODO(imcheng): Remove this check when M59 is in stable.
923 if (!this.handlers_.setMediaRouteStatusObserver) {
924 return;
925 }
926 this.handlers_.onBeforeInvokeHandler();
927 this.handlers_.setMediaRouteStatusObserver(routeId, observer);
928 };
929
845 mediaRouter = new MediaRouter(new mediaRouterMojom.MediaRouterPtr( 930 mediaRouter = new MediaRouter(new mediaRouterMojom.MediaRouterPtr(
846 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name))); 931 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name)));
847 932
848 return mediaRouter; 933 return mediaRouter;
849 }); 934 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698