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

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: Add missing dependency for extensions_renderer_resources target 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} origin
164 * @return {!originMojom.Origin}
165 */
166 function stringToMojoOrigin_(origin) {
167 var url = new URL(origin);
168 var mojoOrigin = {};
169 mojoOrigin.scheme = url.protocol.replace(':', '');
170 mojoOrigin.host = url.hostname;
171 var port = url.port ? Number.parseInt(url.port) : 0;
172 switch (mojoOrigin.scheme) {
173 case 'http':
174 mojoOrigin.port = port || 80;
175 break;
176 case 'https':
177 mojoOrigin.port = port || 443;
178 break;
179 default:
180 throw new Error('Scheme must be http or https');
181 }
182 return new originMojom.Origin(mojoOrigin);
183 }
184
146 /** 185 /**
147 * Parses the given route request Error object and converts it to the 186 * Parses the given route request Error object and converts it to the
148 * corresponding result code. 187 * corresponding result code.
149 * @param {!Error} error 188 * @param {!Error} error
150 * @return {!mediaRouterMojom.RouteRequestResultCode} 189 * @return {!mediaRouterMojom.RouteRequestResultCode}
151 */ 190 */
152 function getRouteRequestResultCode_(error) { 191 function getRouteRequestResultCode_(error) {
153 return error.errorCode ? error.errorCode : 192 return error.errorCode ? error.errorCode :
154 mediaRouterMojom.RouteRequestResultCode.UNKNOWN_ERROR; 193 mediaRouterMojom.RouteRequestResultCode.UNKNOWN_ERROR;
155 } 194 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 /** 286 /**
248 * Called by the provider manager when a sink list for a given source is 287 * Called by the provider manager when a sink list for a given source is
249 * updated. 288 * updated.
250 * @param {!string} sourceUrn 289 * @param {!string} sourceUrn
251 * @param {!Array<!MediaSink>} sinks 290 * @param {!Array<!MediaSink>} sinks
252 * @param {!Array<string>} origins 291 * @param {!Array<string>} origins
253 */ 292 */
254 MediaRouter.prototype.onSinksReceived = function(sourceUrn, sinks, 293 MediaRouter.prototype.onSinksReceived = function(sourceUrn, sinks,
255 origins) { 294 origins) {
256 this.service_.onSinksReceived(sourceUrn, sinks.map(sinkToMojo_), 295 this.service_.onSinksReceived(sourceUrn, sinks.map(sinkToMojo_),
257 origins); 296 origins.map(stringToMojoOrigin_));
258 }; 297 };
259 298
260 /** 299 /**
261 * Called by the provider manager when a sink is found to notify the MR of the 300 * 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 301 * 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 302 * update process, so this helps the MR identify the search result in the
264 * list. 303 * list.
265 * @param {string} pseudoSinkId ID of the pseudo sink that started the 304 * @param {string} pseudoSinkId ID of the pseudo sink that started the
266 * search. 305 * search.
267 * @param {string} sinkId ID of the newly-found sink. 306 * @param {string} sinkId ID of the newly-found sink.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 }; 604 };
566 605
567 /** 606 /**
568 * Requests that |sinkId| render the media referenced by |sourceUrn|. If the 607 * Requests that |sinkId| render the media referenced by |sourceUrn|. If the
569 * request is from the Presentation API, then origin and tabId will 608 * request is from the Presentation API, then origin and tabId will
570 * be populated. 609 * be populated.
571 * @param {!string} sourceUrn Media source to render. 610 * @param {!string} sourceUrn Media source to render.
572 * @param {!string} sinkId Media sink ID. 611 * @param {!string} sinkId Media sink ID.
573 * @param {!string} presentationId Presentation ID from the site 612 * @param {!string} presentationId Presentation ID from the site
574 * requesting presentation. TODO(mfoltz): Remove. 613 * requesting presentation. TODO(mfoltz): Remove.
575 * @param {!string} origin Origin of site requesting presentation. 614 * @param {!originMojom.Origin} origin Origin of site requesting presentation.
576 * @param {!number} tabId ID of tab requesting presentation. 615 * @param {!number} tabId ID of tab requesting presentation.
577 * @param {!TimeDelta} timeout If positive, the timeout duration for the 616 * @param {!TimeDelta} timeout If positive, the timeout duration for the
578 * request. Otherwise, the default duration will be used. 617 * request. Otherwise, the default duration will be used.
579 * @param {!boolean} incognito If true, the route is being requested by 618 * @param {!boolean} incognito If true, the route is being requested by
580 * an incognito profile. 619 * an incognito profile.
581 * @return {!Promise.<!Object>} A Promise resolving to an object describing 620 * @return {!Promise.<!Object>} A Promise resolving to an object describing
582 * the newly created media route, or rejecting with an error message on 621 * the newly created media route, or rejecting with an error message on
583 * failure. 622 * failure.
584 */ 623 */
585 MediaRouteProvider.prototype.createRoute = 624 MediaRouteProvider.prototype.createRoute =
586 function(sourceUrn, sinkId, presentationId, origin, tabId, 625 function(sourceUrn, sinkId, presentationId, origin, tabId,
587 timeout, incognito) { 626 timeout, incognito) {
588 this.handlers_.onBeforeInvokeHandler(); 627 this.handlers_.onBeforeInvokeHandler();
589 return this.handlers_.createRoute( 628 return this.handlers_.createRoute(
590 sourceUrn, sinkId, presentationId, origin, tabId, 629 sourceUrn, sinkId, presentationId, mojoOriginToString_(origin), tabId,
591 Math.floor(timeout.microseconds / 1000), incognito) 630 Math.floor(timeout.microseconds / 1000), incognito)
592 .then(function(route) { 631 .then(function(route) {
593 return toSuccessRouteResponse_(route); 632 return toSuccessRouteResponse_(route);
594 }, 633 },
595 function(err) { 634 function(err) {
596 return toErrorRouteResponse_(err); 635 return toErrorRouteResponse_(err);
597 }); 636 });
598 }; 637 };
599 638
600 /** 639 /**
601 * Handles a request via the Presentation API to join an existing route given 640 * Handles a request via the Presentation API to join an existing route given
602 * by |sourceUrn| and |presentationId|. |origin| and |tabId| are used for 641 * by |sourceUrn| and |presentationId|. |origin| and |tabId| are used for
603 * validating same-origin/tab scope. 642 * validating same-origin/tab scope.
604 * @param {!string} sourceUrn Media source to render. 643 * @param {!string} sourceUrn Media source to render.
605 * @param {!string} presentationId Presentation ID to join. 644 * @param {!string} presentationId Presentation ID to join.
606 * @param {!string} origin Origin of site requesting join. 645 * @param {!originMojom.Origin} origin Origin of site requesting join.
607 * @param {!number} tabId ID of tab requesting join. 646 * @param {!number} tabId ID of tab requesting join.
608 * @param {!TimeDelta} timeout If positive, the timeout duration for the 647 * @param {!TimeDelta} timeout If positive, the timeout duration for the
609 * request. Otherwise, the default duration will be used. 648 * request. Otherwise, the default duration will be used.
610 * @param {!boolean} incognito If true, the route is being requested by 649 * @param {!boolean} incognito If true, the route is being requested by
611 * an incognito profile. 650 * an incognito profile.
612 * @return {!Promise.<!Object>} A Promise resolving to an object describing 651 * @return {!Promise.<!Object>} A Promise resolving to an object describing
613 * the newly created media route, or rejecting with an error message on 652 * the newly created media route, or rejecting with an error message on
614 * failure. 653 * failure.
615 */ 654 */
616 MediaRouteProvider.prototype.joinRoute = 655 MediaRouteProvider.prototype.joinRoute =
617 function(sourceUrn, presentationId, origin, tabId, timeout, 656 function(sourceUrn, presentationId, origin, tabId, timeout,
618 incognito) { 657 incognito) {
619 this.handlers_.onBeforeInvokeHandler(); 658 this.handlers_.onBeforeInvokeHandler();
620 return this.handlers_.joinRoute( 659 return this.handlers_.joinRoute(
621 sourceUrn, presentationId, origin, tabId, 660 sourceUrn, presentationId, mojoOriginToString_(origin), tabId,
622 Math.floor(timeout.microseconds / 1000), incognito) 661 Math.floor(timeout.microseconds / 1000), incognito)
623 .then(function(route) { 662 .then(function(route) {
624 return toSuccessRouteResponse_(route); 663 return toSuccessRouteResponse_(route);
625 }, 664 },
626 function(err) { 665 function(err) {
627 return toErrorRouteResponse_(err); 666 return toErrorRouteResponse_(err);
628 }); 667 });
629 }; 668 };
630 669
631 /** 670 /**
632 * Handles a request via the Presentation API to join an existing route given 671 * Handles a request via the Presentation API to join an existing route given
633 * by |sourceUrn| and |routeId|. |origin| and |tabId| are used for 672 * by |sourceUrn| and |routeId|. |origin| and |tabId| are used for
634 * validating same-origin/tab scope. 673 * validating same-origin/tab scope.
635 * @param {!string} sourceUrn Media source to render. 674 * @param {!string} sourceUrn Media source to render.
636 * @param {!string} routeId Route ID to join. 675 * @param {!string} routeId Route ID to join.
637 * @param {!string} presentationId Presentation ID to join. 676 * @param {!string} presentationId Presentation ID to join.
638 * @param {!string} origin Origin of site requesting join. 677 * @param {!originMojom.Origin} origin Origin of site requesting join.
639 * @param {!number} tabId ID of tab requesting join. 678 * @param {!number} tabId ID of tab requesting join.
640 * @param {!TimeDelta} timeout If positive, the timeout duration for the 679 * @param {!TimeDelta} timeout If positive, the timeout duration for the
641 * request. Otherwise, the default duration will be used. 680 * request. Otherwise, the default duration will be used.
642 * @param {!boolean} incognito If true, the route is being requested by 681 * @param {!boolean} incognito If true, the route is being requested by
643 * an incognito profile. 682 * an incognito profile.
644 * @return {!Promise.<!Object>} A Promise resolving to an object describing 683 * @return {!Promise.<!Object>} A Promise resolving to an object describing
645 * the newly created media route, or rejecting with an error message on 684 * the newly created media route, or rejecting with an error message on
646 * failure. 685 * failure.
647 */ 686 */
648 MediaRouteProvider.prototype.connectRouteByRouteId = 687 MediaRouteProvider.prototype.connectRouteByRouteId =
649 function(sourceUrn, routeId, presentationId, origin, tabId, 688 function(sourceUrn, routeId, presentationId, origin, tabId,
650 timeout, incognito) { 689 timeout, incognito) {
651 this.handlers_.onBeforeInvokeHandler(); 690 this.handlers_.onBeforeInvokeHandler();
652 return this.handlers_.connectRouteByRouteId( 691 return this.handlers_.connectRouteByRouteId(
653 sourceUrn, routeId, presentationId, origin, tabId, 692 sourceUrn, routeId, presentationId, mojoOriginToString_(origin), tabId,
654 Math.floor(timeout.microseconds / 1000), incognito) 693 Math.floor(timeout.microseconds / 1000), incognito)
655 .then(function(route) { 694 .then(function(route) {
656 return toSuccessRouteResponse_(route); 695 return toSuccessRouteResponse_(route);
657 }, 696 },
658 function(err) { 697 function(err) {
659 return toErrorRouteResponse_(err); 698 return toErrorRouteResponse_(err);
660 }); 699 });
661 }; 700 };
662 701
663 /** 702 /**
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 return Promise.resolve({ 840 return Promise.resolve({
802 'sink_id': this.handlers_.searchSinks(sinkId, sourceUrn, searchCriteria) 841 'sink_id': this.handlers_.searchSinks(sinkId, sourceUrn, searchCriteria)
803 }); 842 });
804 }; 843 };
805 844
806 mediaRouter = new MediaRouter(new mediaRouterMojom.MediaRouterPtr( 845 mediaRouter = new MediaRouter(new mediaRouterMojom.MediaRouterPtr(
807 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name))); 846 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name)));
808 847
809 return mediaRouter; 848 return mediaRouter;
810 }); 849 });
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