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

Side by Side Diff: chrome/renderer/resources/extensions/media_router_bindings.js

Issue 2869723004: [Media Router] Export origin mojom definition to the extension. (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | 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 'chrome/common/media_router/mojo/media_controller.mojom', 8 'chrome/common/media_router/mojo/media_controller.mojom',
9 'chrome/common/media_router/mojo/media_router.mojom', 9 'chrome/common/media_router/mojo/media_router.mojom',
10 'chrome/common/media_router/mojo/media_status.mojom', 10 'chrome/common/media_router/mojo/media_status.mojom',
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 return PresentationConnectionCloseReason.CLOSED; 148 return PresentationConnectionCloseReason.CLOSED;
149 case 'went_away': 149 case 'went_away':
150 return PresentationConnectionCloseReason.WENT_AWAY; 150 return PresentationConnectionCloseReason.WENT_AWAY;
151 default: 151 default:
152 console.error('Unknown presentation connection close reason : ' + 152 console.error('Unknown presentation connection close reason : ' +
153 reason); 153 reason);
154 return PresentationConnectionCloseReason.CONNECTION_ERROR; 154 return PresentationConnectionCloseReason.CONNECTION_ERROR;
155 } 155 }
156 } 156 }
157 157
158 // TODO(crbug.com/688177): remove this conversion. 158 // TODO(crbug.com/688177): remove this conversion when M60 is in stable.
159 /**
160 * Converts Mojo origin to string.
161 * @param {!originMojom.Origin} Mojo origin
162 * @return {string}
163 */
164 function mojoOriginToString_(origin) {
165 return origin.unique ? '' :
166 `${origin.scheme}:\/\/${origin.host}` +
167 `${origin.port ? `:${origin.port}` : ''}/`
168 }
169
170 // TODO(crbug.com/688177): remove this conversion.
171 /** 159 /**
172 * Converts string to Mojo origin. 160 * Converts string to Mojo origin.
173 * @param {string} origin 161 * @param {string|!originMojom.Origin} origin
174 * @return {!originMojom.Origin} 162 * @return {!originMojom.Origin}
175 */ 163 */
176 function stringToMojoOrigin_(origin) { 164 function stringToMojoOrigin_(origin) {
177 var url = new URL(origin); 165 if (origin instanceof originMojom.Origin) {
178 var mojoOrigin = {}; 166 return origin;
167 }
168 const url = new URL(origin);
169 const mojoOrigin = {};
179 mojoOrigin.scheme = url.protocol.replace(':', ''); 170 mojoOrigin.scheme = url.protocol.replace(':', '');
180 mojoOrigin.host = url.hostname; 171 mojoOrigin.host = url.hostname;
181 var port = url.port ? Number.parseInt(url.port) : 0; 172 var port = url.port ? Number.parseInt(url.port) : 0;
182 switch (mojoOrigin.scheme) { 173 switch (mojoOrigin.scheme) {
183 case 'http': 174 case 'http':
184 mojoOrigin.port = port || 80; 175 mojoOrigin.port = port || 80;
185 break; 176 break;
186 case 'https': 177 case 'https':
187 mojoOrigin.port = port || 443; 178 mojoOrigin.port = port || 443;
188 break; 179 break;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 return { 269 return {
279 Binding: bindings.Binding, 270 Binding: bindings.Binding,
280 DialMediaSink: mediaRouterMojom.DialMediaSink, 271 DialMediaSink: mediaRouterMojom.DialMediaSink,
281 CastMediaSink: mediaRouterMojom.CastMediaSink, 272 CastMediaSink: mediaRouterMojom.CastMediaSink,
282 IPAddress: ipAddressMojom.IPAddress, 273 IPAddress: ipAddressMojom.IPAddress,
283 InterfacePtrController: bindings.InterfacePtrController, 274 InterfacePtrController: bindings.InterfacePtrController,
284 InterfaceRequest: bindings.InterfaceRequest, 275 InterfaceRequest: bindings.InterfaceRequest,
285 MediaController: mediaControllerMojom.MediaController, 276 MediaController: mediaControllerMojom.MediaController,
286 MediaStatus: mediaStatusMojom.MediaStatus, 277 MediaStatus: mediaStatusMojom.MediaStatus,
287 MediaStatusObserverPtr: mediaStatusMojom.MediaStatusObserverPtr, 278 MediaStatusObserverPtr: mediaStatusMojom.MediaStatusObserverPtr,
279 Origin: originMojom.Origin,
288 Sink: mediaRouterMojom.MediaSink, 280 Sink: mediaRouterMojom.MediaSink,
289 SinkExtraData: mediaRouterMojom.MediaSinkExtraData, 281 SinkExtraData: mediaRouterMojom.MediaSinkExtraData,
290 TimeDelta: timeMojom.TimeDelta, 282 TimeDelta: timeMojom.TimeDelta,
291 Url: urlMojom.Url, 283 Url: urlMojom.Url,
292 }; 284 };
293 }; 285 };
294 286
295 /** 287 /**
296 * Registers the Media Router Provider Manager with the Media Router. 288 * Registers the Media Router Provider Manager with the Media Router.
297 * @return {!Promise<string>} Instance ID for the Media Router. 289 * @return {!Promise<string>} Instance ID for the Media Router.
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 * an incognito profile. 661 * an incognito profile.
670 * @return {!Promise.<!Object>} A Promise resolving to an object describing 662 * @return {!Promise.<!Object>} A Promise resolving to an object describing
671 * the newly created media route, or rejecting with an error message on 663 * the newly created media route, or rejecting with an error message on
672 * failure. 664 * failure.
673 */ 665 */
674 MediaRouteProvider.prototype.createRoute = 666 MediaRouteProvider.prototype.createRoute =
675 function(sourceUrn, sinkId, presentationId, origin, tabId, 667 function(sourceUrn, sinkId, presentationId, origin, tabId,
676 timeout, incognito) { 668 timeout, incognito) {
677 this.handlers_.onBeforeInvokeHandler(); 669 this.handlers_.onBeforeInvokeHandler();
678 return this.handlers_.createRoute( 670 return this.handlers_.createRoute(
679 sourceUrn, sinkId, presentationId, mojoOriginToString_(origin), tabId, 671 sourceUrn, sinkId, presentationId, origin, tabId,
680 Math.floor(timeout.microseconds / 1000), incognito) 672 Math.floor(timeout.microseconds / 1000), incognito)
681 .then(function(route) { 673 .then(function(route) {
682 return toSuccessRouteResponse_(route); 674 return toSuccessRouteResponse_(route);
683 }, 675 },
684 function(err) { 676 function(err) {
685 return toErrorRouteResponse_(err); 677 return toErrorRouteResponse_(err);
686 }); 678 });
687 }; 679 };
688 680
689 /** 681 /**
(...skipping 10 matching lines...) Expand all
700 * an incognito profile. 692 * an incognito profile.
701 * @return {!Promise.<!Object>} A Promise resolving to an object describing 693 * @return {!Promise.<!Object>} A Promise resolving to an object describing
702 * the newly created media route, or rejecting with an error message on 694 * the newly created media route, or rejecting with an error message on
703 * failure. 695 * failure.
704 */ 696 */
705 MediaRouteProvider.prototype.joinRoute = 697 MediaRouteProvider.prototype.joinRoute =
706 function(sourceUrn, presentationId, origin, tabId, timeout, 698 function(sourceUrn, presentationId, origin, tabId, timeout,
707 incognito) { 699 incognito) {
708 this.handlers_.onBeforeInvokeHandler(); 700 this.handlers_.onBeforeInvokeHandler();
709 return this.handlers_.joinRoute( 701 return this.handlers_.joinRoute(
710 sourceUrn, presentationId, mojoOriginToString_(origin), tabId, 702 sourceUrn, presentationId, origin, tabId,
711 Math.floor(timeout.microseconds / 1000), incognito) 703 Math.floor(timeout.microseconds / 1000), incognito)
712 .then(function(route) { 704 .then(function(route) {
713 return toSuccessRouteResponse_(route); 705 return toSuccessRouteResponse_(route);
714 }, 706 },
715 function(err) { 707 function(err) {
716 return toErrorRouteResponse_(err); 708 return toErrorRouteResponse_(err);
717 }); 709 });
718 }; 710 };
719 711
720 /** 712 /**
(...skipping 11 matching lines...) Expand all
732 * an incognito profile. 724 * an incognito profile.
733 * @return {!Promise.<!Object>} A Promise resolving to an object describing 725 * @return {!Promise.<!Object>} A Promise resolving to an object describing
734 * the newly created media route, or rejecting with an error message on 726 * the newly created media route, or rejecting with an error message on
735 * failure. 727 * failure.
736 */ 728 */
737 MediaRouteProvider.prototype.connectRouteByRouteId = 729 MediaRouteProvider.prototype.connectRouteByRouteId =
738 function(sourceUrn, routeId, presentationId, origin, tabId, 730 function(sourceUrn, routeId, presentationId, origin, tabId,
739 timeout, incognito) { 731 timeout, incognito) {
740 this.handlers_.onBeforeInvokeHandler(); 732 this.handlers_.onBeforeInvokeHandler();
741 return this.handlers_.connectRouteByRouteId( 733 return this.handlers_.connectRouteByRouteId(
742 sourceUrn, routeId, presentationId, mojoOriginToString_(origin), tabId, 734 sourceUrn, routeId, presentationId, origin, tabId,
743 Math.floor(timeout.microseconds / 1000), incognito) 735 Math.floor(timeout.microseconds / 1000), incognito)
744 .then(function(route) { 736 .then(function(route) {
745 return toSuccessRouteResponse_(route); 737 return toSuccessRouteResponse_(route);
746 }, 738 },
747 function(err) { 739 function(err) {
748 return toErrorRouteResponse_(err); 740 return toErrorRouteResponse_(err);
749 }); 741 });
750 }; 742 };
751 743
752 /** 744 /**
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 return this.handlers_ 926 return this.handlers_
935 .createMediaRouteController(routeId, controllerRequest, observer) 927 .createMediaRouteController(routeId, controllerRequest, observer)
936 .then(() => ({success: true}), e => ({success: false})); 928 .then(() => ({success: true}), e => ({success: false}));
937 }; 929 };
938 930
939 mediaRouter = new MediaRouter(new mediaRouterMojom.MediaRouterPtr( 931 mediaRouter = new MediaRouter(new mediaRouterMojom.MediaRouterPtr(
940 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name))); 932 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name)));
941 933
942 return mediaRouter; 934 return mediaRouter;
943 }); 935 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698