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

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

Issue 2485313002: [Media Router] Remove obsolete code and bindings. (Closed)
Patch Set: Respond to imcheng@ comments Created 4 years, 1 month 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 'mojo/public/js/bindings', 8 'mojo/public/js/bindings',
9 'mojo/public/js/core', 9 'mojo/public/js/core',
10 'content/public/renderer/frame_interfaces', 10 'content/public/renderer/frame_interfaces',
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 */ 258 */
259 MediaRouter.prototype.getKeepAlive = function() { 259 MediaRouter.prototype.getKeepAlive = function() {
260 return this.keepAlive_ != null; 260 return this.keepAlive_ != null;
261 }; 261 };
262 262
263 /** 263 /**
264 * Called by the provider manager when a sink list for a given source is 264 * Called by the provider manager when a sink list for a given source is
265 * updated. 265 * updated.
266 * @param {!string} sourceUrn 266 * @param {!string} sourceUrn
267 * @param {!Array<!MediaSink>} sinks 267 * @param {!Array<!MediaSink>} sinks
268 * @param {Array<string>=} opt_origins 268 * @param {!Array<string>} origins
269 */ 269 */
270 MediaRouter.prototype.onSinksReceived = function(sourceUrn, sinks, 270 MediaRouter.prototype.onSinksReceived = function(sourceUrn, sinks,
271 opt_origins) { 271 origins) {
272 // TODO(imcheng): Make origins required in M52+.
273 this.service_.onSinksReceived(sourceUrn, sinks.map(sinkToMojo_), 272 this.service_.onSinksReceived(sourceUrn, sinks.map(sinkToMojo_),
274 opt_origins || []); 273 origins);
275 }; 274 };
276 275
277 /** 276 /**
278 * Called by the provider manager when a sink is found to notify the MR of the 277 * Called by the provider manager when a sink is found to notify the MR of the
279 * sink's ID. The actual sink will be returned through the normal sink list 278 * sink's ID. The actual sink will be returned through the normal sink list
280 * update process, so this helps the MR identify the search result in the 279 * update process, so this helps the MR identify the search result in the
281 * list. 280 * list.
282 * @param {string} pseudoSinkId ID of the pseudo sink that started the 281 * @param {string} pseudoSinkId ID of the pseudo sink that started the
283 * search. 282 * search.
284 * @param {string} sinkId ID of the newly-found sink. 283 * @param {string} sinkId ID of the newly-found sink.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 'secondary_actions': secondaryActions, 349 'secondary_actions': secondaryActions,
351 'help_page_id': issue.helpPageId, 350 'help_page_id': issue.helpPageId,
352 'is_blocking': issue.isBlocking 351 'is_blocking': issue.isBlocking
353 })); 352 }));
354 }; 353 };
355 354
356 /** 355 /**
357 * Called by the provider manager when the set of active routes 356 * Called by the provider manager when the set of active routes
358 * has been updated. 357 * has been updated.
359 * @param {!Array<MediaRoute>} routes The active set of media routes. 358 * @param {!Array<MediaRoute>} routes The active set of media routes.
360 * @param {string=} opt_sourceUrn The sourceUrn associated with this route 359 * @param {string=} sourceUrn The sourceUrn associated with this route
361 * query. This parameter is optional and can be empty. 360 * query.
362 * @param {Array<string>=} opt_joinableRouteIds The active set of joinable 361 * @param {Array<string>=} joinableRouteIds The active set of joinable
363 * media routes. This parameter is optional and can be empty. 362 * media routes.
364 */ 363 */
365 MediaRouter.prototype.onRoutesUpdated = 364 MediaRouter.prototype.onRoutesUpdated =
366 function(routes, opt_sourceUrn, opt_joinableRouteIds) { 365 function(routes, sourceUrn = '', joinableRouteIds = []) {
367 // TODO(boetger): This check allows backward compatibility with the Cast SDK
368 // and can be removed when the Cast SDK is updated.
369 if (typeof(opt_sourceUrn) != 'string') {
370 opt_sourceUrn = '';
371 }
372
373 this.service_.onRoutesUpdated( 366 this.service_.onRoutesUpdated(
374 routes.map(routeToMojo_), 367 routes.map(routeToMojo_),
375 opt_sourceUrn || '', 368 sourceUrn,
376 opt_joinableRouteIds || []); 369 joinableRouteIds);
377 }; 370 };
378 371
379 /** 372 /**
380 * Called by the provider manager when sink availability has been updated. 373 * Called by the provider manager when sink availability has been updated.
381 * @param {!mediaRouterMojom.MediaRouter.SinkAvailability} availability 374 * @param {!mediaRouterMojom.MediaRouter.SinkAvailability} availability
382 * The new sink availability. 375 * The new sink availability.
383 */ 376 */
384 MediaRouter.prototype.onSinkAvailabilityUpdated = function(availability) { 377 MediaRouter.prototype.onSinkAvailabilityUpdated = function(availability) {
385 this.service_.onSinkAvailabilityUpdated(availability); 378 this.service_.onSinkAvailabilityUpdated(availability);
386 }; 379 };
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 * @type {function(string, string): Promise} 448 * @type {function(string, string): Promise}
456 */ 449 */
457 this.sendRouteMessage = null; 450 this.sendRouteMessage = null;
458 451
459 /** 452 /**
460 * @type {function(string, Uint8Array): Promise} 453 * @type {function(string, Uint8Array): Promise}
461 */ 454 */
462 this.sendRouteBinaryMessage = null; 455 this.sendRouteBinaryMessage = null;
463 456
464 /** 457 /**
465 * TODO(imcheng): Remove in M55 (crbug.com/626395).
466 * @type {function(string):
467 * Promise.<{messages: Array.<RouteMessage>, error: boolean}>}
468 */
469 this.listenForRouteMessages = null;
470
471 /**
472 * @type {function(string)} 458 * @type {function(string)}
473 */ 459 */
474 this.startListeningForRouteMessages = null; 460 this.startListeningForRouteMessages = null;
475 461
476 /** 462 /**
477 * @type {function(string)} 463 * @type {function(string)}
478 */ 464 */
479 this.stopListeningForRouteMessages = null; 465 this.stopListeningForRouteMessages = null;
480 466
481 /** 467 /**
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 682
697 /** 683 /**
698 * Terminates the route specified by |routeId|. 684 * Terminates the route specified by |routeId|.
699 * @param {!string} routeId 685 * @param {!string} routeId
700 * @return {!Promise<!Object>} A Promise resolving to an object describing 686 * @return {!Promise<!Object>} A Promise resolving to an object describing
701 * the result of the terminate operation, or rejecting with an error 687 * the result of the terminate operation, or rejecting with an error
702 * message and code if the operation failed. 688 * message and code if the operation failed.
703 */ 689 */
704 MediaRouteProvider.prototype.terminateRoute = function(routeId) { 690 MediaRouteProvider.prototype.terminateRoute = function(routeId) {
705 this.handlers_.onBeforeInvokeHandler(); 691 this.handlers_.onBeforeInvokeHandler();
706 // TODO(crbug.com/627967): Remove code path that doesn't expect a Promise 692 return this.handlers_.terminateRoute(routeId).then(
707 // in M56. 693 () => ({result_code: mediaRouterMojom.RouteRequestResultCode.OK}),
708 var maybePromise = this.handlers_.terminateRoute(routeId); 694 (err) => toErrorRouteResponse_(err));
709 var successResult = {
710 result_code: mediaRouterMojom.RouteRequestResultCode.OK
711 };
712 if (maybePromise) {
713 return maybePromise.then(
714 function() { return successResult; },
715 function(err) { return toErrorRouteResponse_(err); }
716 );
717 } else {
718 return Promise.resolve(successResult);
719 }
720 }; 695 };
721 696
722 /** 697 /**
723 * Posts a message to the route designated by |routeId|. 698 * Posts a message to the route designated by |routeId|.
724 * @param {!string} routeId 699 * @param {!string} routeId
725 * @param {!string} message 700 * @param {!string} message
726 * @return {!Promise.<boolean>} Resolved with true if the message was sent, 701 * @return {!Promise.<boolean>} Resolved with true if the message was sent,
727 * or false on failure. 702 * or false on failure.
728 */ 703 */
729 MediaRouteProvider.prototype.sendRouteMessage = function( 704 MediaRouteProvider.prototype.sendRouteMessage = function(
(...skipping 25 matching lines...) Expand all
755 }); 730 });
756 }; 731 };
757 732
758 /** 733 /**
759 * Listen for messages from a route. 734 * Listen for messages from a route.
760 * @param {!string} routeId 735 * @param {!string} routeId
761 */ 736 */
762 MediaRouteProvider.prototype.startListeningForRouteMessages = function( 737 MediaRouteProvider.prototype.startListeningForRouteMessages = function(
763 routeId) { 738 routeId) {
764 this.handlers_.onBeforeInvokeHandler(); 739 this.handlers_.onBeforeInvokeHandler();
765 if (this.handlers_.startListeningForRouteMessages) { 740 this.handlers_.startListeningForRouteMessages(routeId);
766 this.handlers_.startListeningForRouteMessages(routeId);
767 } else {
768 // Old API.
769 this.listenForRouteMessagesOld(routeId);
770 }
771 };
772
773
774 /**
775 * A hack to adapt new MR messaging API to old extension messaging API.
776 * TODO(imcheng): Remove in M55 (crbug.com/626395).
777 * @param {!string} routeId
778 */
779 MediaRouteProvider.prototype.listenForRouteMessagesOld = function(routeId) {
780 this.handlers_.onBeforeInvokeHandler();
781 this.handlers_.listenForRouteMessages(routeId)
782 .then(function(messages) {
783 // If messages is empty, then stopListeningForRouteMessages has been
784 // called. We don't need to send it back to MR.
785 if (messages.length > 0) {
786 // Send the messages back to MR, and listen for next batch of
787 // messages.
788 this.mediaRouter_.onRouteMessagesReceived(routeId, messages);
789 this.listenForRouteMessagesOld(routeId);
790 }
791 }.bind(this), function() {
792 // Ignore rejections.
793 }.bind(this));
794 }; 741 };
795 742
796 /** 743 /**
797 * @param {!string} routeId 744 * @param {!string} routeId
798 */ 745 */
799 MediaRouteProvider.prototype.stopListeningForRouteMessages = function( 746 MediaRouteProvider.prototype.stopListeningForRouteMessages = function(
800 routeId) { 747 routeId) {
801 this.handlers_.onBeforeInvokeHandler(); 748 this.handlers_.onBeforeInvokeHandler();
802 this.handlers_.stopListeningForRouteMessages(routeId); 749 this.handlers_.stopListeningForRouteMessages(routeId);
803 }; 750 };
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 'sink_id': this.handlers_.searchSinks(sinkId, sourceUrn, searchCriteria) 822 'sink_id': this.handlers_.searchSinks(sinkId, sourceUrn, searchCriteria)
876 }); 823 });
877 }; 824 };
878 825
879 mediaRouter = new MediaRouter(connector.bindHandleToProxy( 826 mediaRouter = new MediaRouter(connector.bindHandleToProxy(
880 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name), 827 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name),
881 mediaRouterMojom.MediaRouter)); 828 mediaRouterMojom.MediaRouter));
882 829
883 return mediaRouter; 830 return mediaRouter;
884 }); 831 });
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