From ed10e96f38114815495521e730d5cf29aed9f9b6 Mon Sep 17 00:00:00 2001 From: imcheng Date: Mon, 22 Feb 2016 22:34:44 -0800 Subject: [MediaRouter] Plumb PresentationConnectionClose from MR to Blink. Added some follow up plumbing in Blink for close reason, as well as to send the new event via a new method in PresentationConnection. Added plumbing in PresentationDispatcher and PresentationServiceImpl. Added a new class to hold the (state change, close) callbacks in content public API which will be used by PresentationServiceImpl and MR. Changed existing MR API to take the new callbacks object. Added new MediaRouterMojoImpl API to be notified of presentation connection close. Added plumbing in media_router_bindings.js TODO: add tests BUG=579360,574233,574234 Review URL: https://codereview.chromium.org/1701143002 Cr-Commit-Position: refs/heads/master@{#376935} --- .../renderer/resources/media_router_bindings.js | 39 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'extensions/renderer') diff --git a/extensions/renderer/resources/media_router_bindings.js b/extensions/renderer/resources/media_router_bindings.js index 0ad0ae8..0b0bee0 100644 --- a/extensions/renderer/resources/media_router_bindings.js +++ b/extensions/renderer/resources/media_router_bindings.js @@ -123,6 +123,28 @@ define('media_router_bindings', [ } /** + * Converts presentation connection close reason to Mojo enum value. + * @param {!string} reason + * @return {!mediaRouterMojom.MediaRouter.PresentationConnectionCloseReason} + */ + function presentationConnectionCloseReasonToMojo_(reason) { + var PresentationConnectionCloseReason = + mediaRouterMojom.MediaRouter.PresentationConnectionCloseReason; + switch (state) { + case 'error': + return PresentationConnectionCloseReason.CONNECTION_ERROR; + case 'closed': + return PresentationConnectionCloseReason.CLOSED; + case 'went_away': + return PresentationConnectionCloseReason.WENT_AWAY; + default: + console.error('Unknown presentation connection close reason : ' + + reason); + return PresentationConnectionCloseReason.CONNECTION_ERROR; + } + } + + /** * Parses the given route request Error object and converts it to the * corresponding result code. * @param {!Error} error @@ -351,8 +373,8 @@ define('media_router_bindings', [ /** * Called by the provider manager when the state of a presentation connected * to a route has changed. - * @param {!string} routeId - * @param {!string} state + * @param {string} routeId + * @param {string} state */ MediaRouter.prototype.onPresentationConnectionStateChanged = function(routeId, state) { @@ -361,6 +383,19 @@ define('media_router_bindings', [ }; /** + * Called by the provider manager when the state of a presentation connected + * to a route has closed. + * @param {string} routeId + * @param {string} reason + * @param {string} message + */ + MediaRouter.prototype.onPresentationConnectionClosed = + function(routeId, reason, message) { + this.service_.onPresentationConnectionClosed( + routeId, presentationConnectionCloseReasonToMojo_(state), message); + }; + + /** * Object containing callbacks set by the provider manager. * * @constructor -- cgit v1.1