Chromium Code Reviews| Index: extensions/renderer/resources/media_router_bindings.js |
| diff --git a/extensions/renderer/resources/media_router_bindings.js b/extensions/renderer/resources/media_router_bindings.js |
| index 0373e0363e0e92375d7bf5ee5d1a4306d18261f1..f04abf6b03ec401ceb5552613c4607d32719f35d 100644 |
| --- a/extensions/renderer/resources/media_router_bindings.js |
| +++ b/extensions/renderer/resources/media_router_bindings.js |
| @@ -10,11 +10,13 @@ define('media_router_bindings', [ |
| 'extensions/common/mojo/keep_alive.mojom', |
| 'mojo/common/time.mojom', |
| 'mojo/public/js/bindings', |
| + 'url/mojo/origin.mojom', |
| ], function(frameInterfaces, |
| mediaRouterMojom, |
| keepAliveMojom, |
| timeMojom, |
| - bindings) { |
| + bindings, |
| + originMojom) { |
| 'use strict'; |
| /** |
| @@ -144,6 +146,46 @@ define('media_router_bindings', [ |
| } |
| /** |
| + * Converts Mojo origin to string. |
| + * @param {!originMojom.Origin} Mojo origin |
| + * @return {!string} |
| + */ |
| + function mojoOriginToString_(origin) { |
|
mark a. foltz
2017/02/02 23:05:08
Please file a crbug to remove this conversion once
steimel
2017/02/03 00:17:31
Done.
|
| + if (origin.unique) { |
| + return ''; |
| + } |
| + var serializedOrigin = origin.scheme + '://' + origin.host; |
|
mark a. foltz
2017/02/02 23:05:08
This could be a one liner with an ES6 template str
steimel
2017/02/03 00:17:31
Done.
|
| + if (origin.port) { |
| + serializedOrigin += ':' + origin.port; |
| + } |
| + serializedOrigin += '/'; |
| + return serializedOrigin; |
| + } |
| + |
| + /** |
| + * Converts string to Mojo origin. |
| + * @param {!string} string origin |
| + * @return {!originMojom.Origin} |
| + */ |
| + function stringToMojoOrigin_(string) { |
| + try { |
| + var url = new URL(string); |
|
mark a. foltz
2017/02/02 23:05:08
Is URL defined by the bindings for mojo URL?
steimel
2017/02/03 00:17:31
This is a native js URL object, not a mojo URL obj
|
| + } catch (err) { |
| + if (string !== '') { |
|
mark a. foltz
2017/02/02 23:05:08
Nit: I would put this check first, then attempt to
steimel
2017/02/03 00:17:31
Done.
|
| + console.error('Invalid URL: ' + string); |
| + } |
| + return new originMojom.Origin({ unique: true }); |
| + } |
| + var origin = new originMojom.Origin(); |
| + origin.scheme = url.protocol.replace(':', ''); |
| + origin.host = url.hostname; |
| + if (url.port) { |
| + origin.port = Number.parseInt(url.port); |
| + } |
| + return origin; |
| + } |
| + |
| + /** |
| * Parses the given route request Error object and converts it to the |
| * corresponding result code. |
| * @param {!Error} error |
| @@ -254,7 +296,7 @@ define('media_router_bindings', [ |
| MediaRouter.prototype.onSinksReceived = function(sourceUrn, sinks, |
| origins) { |
| this.service_.onSinksReceived(sourceUrn, sinks.map(sinkToMojo_), |
| - origins); |
| + origins.map(stringToMojoOrigin_)); |
| }; |
| /** |
| @@ -572,7 +614,7 @@ define('media_router_bindings', [ |
| * @param {!string} sinkId Media sink ID. |
| * @param {!string} presentationId Presentation ID from the site |
| * requesting presentation. TODO(mfoltz): Remove. |
| - * @param {!string} origin Origin of site requesting presentation. |
| + * @param {!originMojom.Origin} origin Origin of site requesting presentation. |
| * @param {!number} tabId ID of tab requesting presentation. |
| * @param {!TimeDelta} timeout If positive, the timeout duration for the |
| * request. Otherwise, the default duration will be used. |
| @@ -587,7 +629,7 @@ define('media_router_bindings', [ |
| timeout, incognito) { |
| this.handlers_.onBeforeInvokeHandler(); |
| return this.handlers_.createRoute( |
| - sourceUrn, sinkId, presentationId, origin, tabId, |
| + sourceUrn, sinkId, presentationId, mojoOriginToString_(origin), tabId, |
| Math.floor(timeout.microseconds / 1000), incognito) |
| .then(function(route) { |
| return toSuccessRouteResponse_(route); |
| @@ -603,7 +645,7 @@ define('media_router_bindings', [ |
| * validating same-origin/tab scope. |
| * @param {!string} sourceUrn Media source to render. |
| * @param {!string} presentationId Presentation ID to join. |
| - * @param {!string} origin Origin of site requesting join. |
| + * @param {!originMojom.Origin} origin Origin of site requesting join. |
| * @param {!number} tabId ID of tab requesting join. |
| * @param {!TimeDelta} timeout If positive, the timeout duration for the |
| * request. Otherwise, the default duration will be used. |
| @@ -618,7 +660,7 @@ define('media_router_bindings', [ |
| incognito) { |
| this.handlers_.onBeforeInvokeHandler(); |
| return this.handlers_.joinRoute( |
| - sourceUrn, presentationId, origin, tabId, |
| + sourceUrn, presentationId, mojoOriginToString_(origin), tabId, |
| Math.floor(timeout.microseconds / 1000), incognito) |
| .then(function(route) { |
| return toSuccessRouteResponse_(route); |
| @@ -635,7 +677,7 @@ define('media_router_bindings', [ |
| * @param {!string} sourceUrn Media source to render. |
| * @param {!string} routeId Route ID to join. |
| * @param {!string} presentationId Presentation ID to join. |
| - * @param {!string} origin Origin of site requesting join. |
| + * @param {!originMojom.Origin} origin Origin of site requesting join. |
| * @param {!number} tabId ID of tab requesting join. |
| * @param {!TimeDelta} timeout If positive, the timeout duration for the |
| * request. Otherwise, the default duration will be used. |
| @@ -650,7 +692,7 @@ define('media_router_bindings', [ |
| timeout, incognito) { |
| this.handlers_.onBeforeInvokeHandler(); |
| return this.handlers_.connectRouteByRouteId( |
| - sourceUrn, routeId, presentationId, origin, tabId, |
| + sourceUrn, routeId, presentationId, mojoOriginToString_(origin), tabId, |
| Math.floor(timeout.microseconds / 1000), incognito) |
| .then(function(route) { |
| return toSuccessRouteResponse_(route); |