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

Unified Diff: extensions/renderer/resources/media_router_bindings.js

Issue 2627463003: Convert MediaRouter mojom apis to intake url::Origin objects instead of strings (Closed)
Patch Set: mfoltz comments Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/resources/extensions_renderer_resources.grd ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..dda4d0e7042d8656964690023c1ab9270cf327c0 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';
/**
@@ -143,6 +145,43 @@ define('media_router_bindings', [
}
}
+ // TODO(crbug.com/688177): remove this conversion.
+ /**
+ * Converts Mojo origin to string.
+ * @param {!originMojom.Origin} Mojo origin
+ * @return {!string}
imcheng 2017/02/03 18:58:01 No need for ! on string, as it is a primitive
steimel 2017/02/03 22:38:36 Done.
+ */
+ function mojoOriginToString_(origin) {
+ return origin.unique ? '' :
+ `${origin.scheme}:\/\/${origin.host}` +
+ `${origin.port ? `:${origin.port}` : ''}/`
mark a. foltz 2017/02/03 17:52:39 Prefer String.valueOf() for orign.port, versus emb
steimel 2017/02/03 22:38:36 Discussed offline and leaving as-is
+ }
+
+ // TODO(crbug.com/688177): remove this conversion.
+ /**
+ * Converts string to Mojo origin.
+ * @param {!string} string origin
imcheng 2017/02/03 18:58:02 {string}
steimel 2017/02/03 22:38:36 Done.
+ * @return {!originMojom.Origin}
+ */
+ function stringToMojoOrigin_(string) {
+ if (string === '') {
+ return new originMojom.Origin({ unique: true });
imcheng 2017/02/03 18:58:01 Should probably throw new Error in this case?
mark a. foltz 2017/02/03 19:05:13 In general there should be a way to represent uniq
steimel 2017/02/03 22:38:36 Discussed offline. Allowing it to error instead of
+ }
+ try {
+ var url = new URL(string);
+ } catch (err) {
+ console.error('Invalid URL: ' + string);
+ return new originMojom.Origin({ unique: true });
mark a. foltz 2017/02/03 17:52:39 I don't think invalid origins should silently map
imcheng 2017/02/03 18:58:02 Yes. In our case the list of origins returned to b
steimel 2017/02/03 22:38:36 Done.
+ }
+ 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.
@@ -254,7 +293,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 +611,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 +626,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 +642,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 +657,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 +674,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 +689,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);
« no previous file with comments | « extensions/renderer/resources/extensions_renderer_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698