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

Side by Side 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: throw error instead of returning unique origin Created 3 years, 10 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 | « extensions/renderer/resources/extensions_renderer_resources.grd ('k') | 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_router.mojom', 9 'chrome/browser/media/router/mojo/media_router.mojom',
10 'extensions/common/mojo/keep_alive.mojom', 10 'extensions/common/mojo/keep_alive.mojom',
11 'mojo/common/time.mojom', 11 'mojo/common/time.mojom',
12 'mojo/public/js/bindings', 12 'mojo/public/js/bindings',
13 'url/mojo/origin.mojom',
13 ], function(frameInterfaces, 14 ], function(frameInterfaces,
14 mediaRouterMojom, 15 mediaRouterMojom,
15 keepAliveMojom, 16 keepAliveMojom,
16 timeMojom, 17 timeMojom,
17 bindings) { 18 bindings,
19 originMojom) {
18 'use strict'; 20 'use strict';
19 21
20 /** 22 /**
21 * Converts a media sink to a MediaSink Mojo object. 23 * Converts a media sink to a MediaSink Mojo object.
22 * @param {!MediaSink} sink A media sink. 24 * @param {!MediaSink} sink A media sink.
23 * @return {!mediaRouterMojom.MediaSink} A Mojo MediaSink object. 25 * @return {!mediaRouterMojom.MediaSink} A Mojo MediaSink object.
24 */ 26 */
25 function sinkToMojo_(sink) { 27 function sinkToMojo_(sink) {
26 return new mediaRouterMojom.MediaSink({ 28 return new mediaRouterMojom.MediaSink({
27 'name': sink.friendlyName, 29 'name': sink.friendlyName,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 return PresentationConnectionCloseReason.CLOSED; 138 return PresentationConnectionCloseReason.CLOSED;
137 case 'went_away': 139 case 'went_away':
138 return PresentationConnectionCloseReason.WENT_AWAY; 140 return PresentationConnectionCloseReason.WENT_AWAY;
139 default: 141 default:
140 console.error('Unknown presentation connection close reason : ' + 142 console.error('Unknown presentation connection close reason : ' +
141 reason); 143 reason);
142 return PresentationConnectionCloseReason.CONNECTION_ERROR; 144 return PresentationConnectionCloseReason.CONNECTION_ERROR;
143 } 145 }
144 } 146 }
145 147
148 // TODO(crbug.com/688177): remove this conversion.
149 /**
150 * Converts Mojo origin to string.
151 * @param {!originMojom.Origin} Mojo origin
152 * @return {string}
153 */
154 function mojoOriginToString_(origin) {
155 return origin.unique ? '' :
156 `${origin.scheme}:\/\/${origin.host}` +
157 `${origin.port ? `:${origin.port}` : ''}/`
158 }
159
160 // TODO(crbug.com/688177): remove this conversion.
161 /**
162 * Converts string to Mojo origin.
163 * @param {string} string origin
mark a. foltz 2017/02/04 01:44:29 Nit: name this e.g. origin so as not to conflict w
steimel 2017/02/06 23:01:37 Done.
164 * @return {!originMojom.Origin}
165 */
166 function stringToMojoOrigin_(string) {
167 var url = new URL(string);
168 var origin = new originMojom.Origin();
169 origin.scheme = url.protocol.replace(':', '');
170 origin.host = url.hostname;
171 if (url.port) {
172 origin.port = Number.parseInt(url.port);
173 }
174 return origin;
175 }
176
146 /** 177 /**
147 * Parses the given route request Error object and converts it to the 178 * Parses the given route request Error object and converts it to the
148 * corresponding result code. 179 * corresponding result code.
149 * @param {!Error} error 180 * @param {!Error} error
150 * @return {!mediaRouterMojom.RouteRequestResultCode} 181 * @return {!mediaRouterMojom.RouteRequestResultCode}
151 */ 182 */
152 function getRouteRequestResultCode_(error) { 183 function getRouteRequestResultCode_(error) {
153 return error.errorCode ? error.errorCode : 184 return error.errorCode ? error.errorCode :
154 mediaRouterMojom.RouteRequestResultCode.UNKNOWN_ERROR; 185 mediaRouterMojom.RouteRequestResultCode.UNKNOWN_ERROR;
155 } 186 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 /** 278 /**
248 * Called by the provider manager when a sink list for a given source is 279 * Called by the provider manager when a sink list for a given source is
249 * updated. 280 * updated.
250 * @param {!string} sourceUrn 281 * @param {!string} sourceUrn
251 * @param {!Array<!MediaSink>} sinks 282 * @param {!Array<!MediaSink>} sinks
252 * @param {!Array<string>} origins 283 * @param {!Array<string>} origins
253 */ 284 */
254 MediaRouter.prototype.onSinksReceived = function(sourceUrn, sinks, 285 MediaRouter.prototype.onSinksReceived = function(sourceUrn, sinks,
255 origins) { 286 origins) {
256 this.service_.onSinksReceived(sourceUrn, sinks.map(sinkToMojo_), 287 this.service_.onSinksReceived(sourceUrn, sinks.map(sinkToMojo_),
257 origins); 288 origins.map(stringToMojoOrigin_));
258 }; 289 };
259 290
260 /** 291 /**
261 * Called by the provider manager when a sink is found to notify the MR of the 292 * Called by the provider manager when a sink is found to notify the MR of the
262 * sink's ID. The actual sink will be returned through the normal sink list 293 * sink's ID. The actual sink will be returned through the normal sink list
263 * update process, so this helps the MR identify the search result in the 294 * update process, so this helps the MR identify the search result in the
264 * list. 295 * list.
265 * @param {string} pseudoSinkId ID of the pseudo sink that started the 296 * @param {string} pseudoSinkId ID of the pseudo sink that started the
266 * search. 297 * search.
267 * @param {string} sinkId ID of the newly-found sink. 298 * @param {string} sinkId ID of the newly-found sink.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 }; 596 };
566 597
567 /** 598 /**
568 * Requests that |sinkId| render the media referenced by |sourceUrn|. If the 599 * Requests that |sinkId| render the media referenced by |sourceUrn|. If the
569 * request is from the Presentation API, then origin and tabId will 600 * request is from the Presentation API, then origin and tabId will
570 * be populated. 601 * be populated.
571 * @param {!string} sourceUrn Media source to render. 602 * @param {!string} sourceUrn Media source to render.
572 * @param {!string} sinkId Media sink ID. 603 * @param {!string} sinkId Media sink ID.
573 * @param {!string} presentationId Presentation ID from the site 604 * @param {!string} presentationId Presentation ID from the site
574 * requesting presentation. TODO(mfoltz): Remove. 605 * requesting presentation. TODO(mfoltz): Remove.
575 * @param {!string} origin Origin of site requesting presentation. 606 * @param {!originMojom.Origin} origin Origin of site requesting presentation.
576 * @param {!number} tabId ID of tab requesting presentation. 607 * @param {!number} tabId ID of tab requesting presentation.
577 * @param {!TimeDelta} timeout If positive, the timeout duration for the 608 * @param {!TimeDelta} timeout If positive, the timeout duration for the
578 * request. Otherwise, the default duration will be used. 609 * request. Otherwise, the default duration will be used.
579 * @param {!boolean} incognito If true, the route is being requested by 610 * @param {!boolean} incognito If true, the route is being requested by
580 * an incognito profile. 611 * an incognito profile.
581 * @return {!Promise.<!Object>} A Promise resolving to an object describing 612 * @return {!Promise.<!Object>} A Promise resolving to an object describing
582 * the newly created media route, or rejecting with an error message on 613 * the newly created media route, or rejecting with an error message on
583 * failure. 614 * failure.
584 */ 615 */
585 MediaRouteProvider.prototype.createRoute = 616 MediaRouteProvider.prototype.createRoute =
586 function(sourceUrn, sinkId, presentationId, origin, tabId, 617 function(sourceUrn, sinkId, presentationId, origin, tabId,
587 timeout, incognito) { 618 timeout, incognito) {
588 this.handlers_.onBeforeInvokeHandler(); 619 this.handlers_.onBeforeInvokeHandler();
589 return this.handlers_.createRoute( 620 return this.handlers_.createRoute(
590 sourceUrn, sinkId, presentationId, origin, tabId, 621 sourceUrn, sinkId, presentationId, mojoOriginToString_(origin), tabId,
591 Math.floor(timeout.microseconds / 1000), incognito) 622 Math.floor(timeout.microseconds / 1000), incognito)
592 .then(function(route) { 623 .then(function(route) {
593 return toSuccessRouteResponse_(route); 624 return toSuccessRouteResponse_(route);
594 }, 625 },
595 function(err) { 626 function(err) {
596 return toErrorRouteResponse_(err); 627 return toErrorRouteResponse_(err);
597 }); 628 });
598 }; 629 };
599 630
600 /** 631 /**
601 * Handles a request via the Presentation API to join an existing route given 632 * Handles a request via the Presentation API to join an existing route given
602 * by |sourceUrn| and |presentationId|. |origin| and |tabId| are used for 633 * by |sourceUrn| and |presentationId|. |origin| and |tabId| are used for
603 * validating same-origin/tab scope. 634 * validating same-origin/tab scope.
604 * @param {!string} sourceUrn Media source to render. 635 * @param {!string} sourceUrn Media source to render.
605 * @param {!string} presentationId Presentation ID to join. 636 * @param {!string} presentationId Presentation ID to join.
606 * @param {!string} origin Origin of site requesting join. 637 * @param {!originMojom.Origin} origin Origin of site requesting join.
607 * @param {!number} tabId ID of tab requesting join. 638 * @param {!number} tabId ID of tab requesting join.
608 * @param {!TimeDelta} timeout If positive, the timeout duration for the 639 * @param {!TimeDelta} timeout If positive, the timeout duration for the
609 * request. Otherwise, the default duration will be used. 640 * request. Otherwise, the default duration will be used.
610 * @param {!boolean} incognito If true, the route is being requested by 641 * @param {!boolean} incognito If true, the route is being requested by
611 * an incognito profile. 642 * an incognito profile.
612 * @return {!Promise.<!Object>} A Promise resolving to an object describing 643 * @return {!Promise.<!Object>} A Promise resolving to an object describing
613 * the newly created media route, or rejecting with an error message on 644 * the newly created media route, or rejecting with an error message on
614 * failure. 645 * failure.
615 */ 646 */
616 MediaRouteProvider.prototype.joinRoute = 647 MediaRouteProvider.prototype.joinRoute =
617 function(sourceUrn, presentationId, origin, tabId, timeout, 648 function(sourceUrn, presentationId, origin, tabId, timeout,
618 incognito) { 649 incognito) {
619 this.handlers_.onBeforeInvokeHandler(); 650 this.handlers_.onBeforeInvokeHandler();
620 return this.handlers_.joinRoute( 651 return this.handlers_.joinRoute(
621 sourceUrn, presentationId, origin, tabId, 652 sourceUrn, presentationId, mojoOriginToString_(origin), tabId,
622 Math.floor(timeout.microseconds / 1000), incognito) 653 Math.floor(timeout.microseconds / 1000), incognito)
623 .then(function(route) { 654 .then(function(route) {
624 return toSuccessRouteResponse_(route); 655 return toSuccessRouteResponse_(route);
625 }, 656 },
626 function(err) { 657 function(err) {
627 return toErrorRouteResponse_(err); 658 return toErrorRouteResponse_(err);
628 }); 659 });
629 }; 660 };
630 661
631 /** 662 /**
632 * Handles a request via the Presentation API to join an existing route given 663 * Handles a request via the Presentation API to join an existing route given
633 * by |sourceUrn| and |routeId|. |origin| and |tabId| are used for 664 * by |sourceUrn| and |routeId|. |origin| and |tabId| are used for
634 * validating same-origin/tab scope. 665 * validating same-origin/tab scope.
635 * @param {!string} sourceUrn Media source to render. 666 * @param {!string} sourceUrn Media source to render.
636 * @param {!string} routeId Route ID to join. 667 * @param {!string} routeId Route ID to join.
637 * @param {!string} presentationId Presentation ID to join. 668 * @param {!string} presentationId Presentation ID to join.
638 * @param {!string} origin Origin of site requesting join. 669 * @param {!originMojom.Origin} origin Origin of site requesting join.
639 * @param {!number} tabId ID of tab requesting join. 670 * @param {!number} tabId ID of tab requesting join.
640 * @param {!TimeDelta} timeout If positive, the timeout duration for the 671 * @param {!TimeDelta} timeout If positive, the timeout duration for the
641 * request. Otherwise, the default duration will be used. 672 * request. Otherwise, the default duration will be used.
642 * @param {!boolean} incognito If true, the route is being requested by 673 * @param {!boolean} incognito If true, the route is being requested by
643 * an incognito profile. 674 * an incognito profile.
644 * @return {!Promise.<!Object>} A Promise resolving to an object describing 675 * @return {!Promise.<!Object>} A Promise resolving to an object describing
645 * the newly created media route, or rejecting with an error message on 676 * the newly created media route, or rejecting with an error message on
646 * failure. 677 * failure.
647 */ 678 */
648 MediaRouteProvider.prototype.connectRouteByRouteId = 679 MediaRouteProvider.prototype.connectRouteByRouteId =
649 function(sourceUrn, routeId, presentationId, origin, tabId, 680 function(sourceUrn, routeId, presentationId, origin, tabId,
650 timeout, incognito) { 681 timeout, incognito) {
651 this.handlers_.onBeforeInvokeHandler(); 682 this.handlers_.onBeforeInvokeHandler();
652 return this.handlers_.connectRouteByRouteId( 683 return this.handlers_.connectRouteByRouteId(
653 sourceUrn, routeId, presentationId, origin, tabId, 684 sourceUrn, routeId, presentationId, mojoOriginToString_(origin), tabId,
654 Math.floor(timeout.microseconds / 1000), incognito) 685 Math.floor(timeout.microseconds / 1000), incognito)
655 .then(function(route) { 686 .then(function(route) {
656 return toSuccessRouteResponse_(route); 687 return toSuccessRouteResponse_(route);
657 }, 688 },
658 function(err) { 689 function(err) {
659 return toErrorRouteResponse_(err); 690 return toErrorRouteResponse_(err);
660 }); 691 });
661 }; 692 };
662 693
663 /** 694 /**
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 return Promise.resolve({ 832 return Promise.resolve({
802 'sink_id': this.handlers_.searchSinks(sinkId, sourceUrn, searchCriteria) 833 'sink_id': this.handlers_.searchSinks(sinkId, sourceUrn, searchCriteria)
803 }); 834 });
804 }; 835 };
805 836
806 mediaRouter = new MediaRouter(new mediaRouterMojom.MediaRouterPtr( 837 mediaRouter = new MediaRouter(new mediaRouterMojom.MediaRouterPtr(
807 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name))); 838 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name)));
808 839
809 return mediaRouter; 840 return mediaRouter;
810 }); 841 });
OLDNEW
« 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