OLD | NEW |
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 'mojo/public/js/bindings', |
| 9 'mojo/public/js/core', |
8 'content/public/renderer/frame_interfaces', | 10 'content/public/renderer/frame_interfaces', |
9 'chrome/browser/media/router/mojo/media_router.mojom', | 11 'chrome/browser/media/router/mojo/media_router.mojom', |
10 'extensions/common/mojo/keep_alive.mojom', | 12 'extensions/common/mojo/keep_alive.mojom', |
11 'mojo/common/time.mojom', | 13 'mojo/common/time.mojom', |
12 'mojo/public/js/bindings', | 14 'mojo/public/js/connection', |
13 ], function(frameInterfaces, | 15 'mojo/public/js/router', |
| 16 ], function(bindings, |
| 17 core, |
| 18 frameInterfaces, |
14 mediaRouterMojom, | 19 mediaRouterMojom, |
15 keepAliveMojom, | 20 keepAliveMojom, |
16 timeMojom, | 21 timeMojom, |
17 bindings) { | 22 connector, |
| 23 routerModule) { |
18 'use strict'; | 24 'use strict'; |
19 | 25 |
20 /** | 26 /** |
21 * Converts a media sink to a MediaSink Mojo object. | 27 * Converts a media sink to a MediaSink Mojo object. |
22 * @param {!MediaSink} sink A media sink. | 28 * @param {!MediaSink} sink A media sink. |
23 * @return {!mediaRouterMojom.MediaSink} A Mojo MediaSink object. | 29 * @return {!mediaRouterMojom.MediaSink} A Mojo MediaSink object. |
24 */ | 30 */ |
25 function sinkToMojo_(sink) { | 31 function sinkToMojo_(sink) { |
26 return new mediaRouterMojom.MediaSink({ | 32 return new mediaRouterMojom.MediaSink({ |
27 'name': sink.friendlyName, | 33 'name': sink.friendlyName, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 function toErrorRouteResponse_(error) { | 180 function toErrorRouteResponse_(error) { |
175 return { | 181 return { |
176 error_text: error.message, | 182 error_text: error.message, |
177 result_code: getRouteRequestResultCode_(error) | 183 result_code: getRouteRequestResultCode_(error) |
178 }; | 184 }; |
179 } | 185 } |
180 | 186 |
181 /** | 187 /** |
182 * Creates a new MediaRouter. | 188 * Creates a new MediaRouter. |
183 * Converts a route struct to its Mojo form. | 189 * Converts a route struct to its Mojo form. |
184 * @param {!mediaRouterMojom.MediaRouterPtr} service | 190 * @param {!MediaRouterService} service |
185 * @constructor | 191 * @constructor |
186 */ | 192 */ |
187 function MediaRouter(service) { | 193 function MediaRouter(service) { |
188 /** | 194 /** |
189 * The Mojo service proxy. Allows extension code to call methods that reside | 195 * The Mojo service proxy. Allows extension code to call methods that reside |
190 * in the browser. | 196 * in the browser. |
191 * @type {!mediaRouterMojom.MediaRouterPtr} | 197 * @type {!MediaRouterService} |
192 */ | 198 */ |
193 this.service_ = service; | 199 this.service_ = service; |
194 | 200 |
195 /** | 201 /** |
196 * The provider manager service delegate. Its methods are called by the | 202 * The provider manager service delegate. Its methods are called by the |
197 * browser-resident Mojo service. | 203 * browser-resident Mojo service. |
198 * @type {!MediaRouter} | 204 * @type {!MediaRouter} |
199 */ | 205 */ |
200 this.mrpm_ = new MediaRouteProvider(this); | 206 this.mrpm_ = new MediaRouteProvider(this); |
201 | 207 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 /** | 280 /** |
275 * Called by the provider manager to keep the extension from suspending | 281 * Called by the provider manager to keep the extension from suspending |
276 * if it enters a state where suspension is undesirable (e.g. there is an | 282 * if it enters a state where suspension is undesirable (e.g. there is an |
277 * active MediaRoute.) | 283 * active MediaRoute.) |
278 * If keepAlive is true, the extension is kept alive. | 284 * If keepAlive is true, the extension is kept alive. |
279 * If keepAlive is false, the extension is allowed to suspend. | 285 * If keepAlive is false, the extension is allowed to suspend. |
280 * @param {boolean} keepAlive | 286 * @param {boolean} keepAlive |
281 */ | 287 */ |
282 MediaRouter.prototype.setKeepAlive = function(keepAlive) { | 288 MediaRouter.prototype.setKeepAlive = function(keepAlive) { |
283 if (keepAlive === false && this.keepAlive_) { | 289 if (keepAlive === false && this.keepAlive_) { |
284 this.keepAlive_.ptr.reset(); | 290 this.keepAlive_.close(); |
285 this.keepAlive_ = null; | 291 this.keepAlive_ = null; |
286 } else if (keepAlive === true && !this.keepAlive_) { | 292 } else if (keepAlive === true && !this.keepAlive_) { |
287 this.keepAlive_ = new keepAliveMojom.KeepAlivePtr( | 293 this.keepAlive_ = new routerModule.Router( |
288 frameInterfaces.getInterface(keepAliveMojom.KeepAlive.name)); | 294 frameInterfaces.getInterface(keepAliveMojom.KeepAlive.name)); |
289 } | 295 } |
290 }; | 296 }; |
291 | 297 |
292 /** | 298 /** |
293 * Called by the provider manager to send an issue from a media route | 299 * Called by the provider manager to send an issue from a media route |
294 * provider to the Media Router, to show the user. | 300 * provider to the Media Router, to show the user. |
295 * @param {!Object} issue The issue object. | 301 * @param {!Object} issue The issue object. |
296 */ | 302 */ |
297 MediaRouter.prototype.onIssue = function(issue) { | 303 MediaRouter.prototype.onIssue = function(issue) { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 }; | 491 }; |
486 | 492 |
487 /** | 493 /** |
488 * Routes calls from Media Router to the provider manager extension. | 494 * Routes calls from Media Router to the provider manager extension. |
489 * Registered with the MediaRouter stub. | 495 * Registered with the MediaRouter stub. |
490 * @param {!MediaRouter} MediaRouter proxy to call into the | 496 * @param {!MediaRouter} MediaRouter proxy to call into the |
491 * Media Router mojo interface. | 497 * Media Router mojo interface. |
492 * @constructor | 498 * @constructor |
493 */ | 499 */ |
494 function MediaRouteProvider(mediaRouter) { | 500 function MediaRouteProvider(mediaRouter) { |
| 501 mediaRouterMojom.MediaRouteProvider.stubClass.call(this); |
| 502 |
495 /** | 503 /** |
496 * Object containing JS callbacks into Provider Manager code. | 504 * Object containing JS callbacks into Provider Manager code. |
497 * @type {!MediaRouterHandlers} | 505 * @type {!MediaRouterHandlers} |
498 */ | 506 */ |
499 this.handlers_ = new MediaRouterHandlers(); | 507 this.handlers_ = new MediaRouterHandlers(); |
500 | 508 |
501 /** | 509 /** |
502 * Proxy class to the browser's Media Router Mojo service. | 510 * Proxy class to the browser's Media Router Mojo service. |
503 * @type {!MediaRouter} | 511 * @type {!MediaRouter} |
504 */ | 512 */ |
505 this.mediaRouter_ = mediaRouter; | 513 this.mediaRouter_ = mediaRouter; |
506 } | 514 } |
| 515 MediaRouteProvider.prototype = Object.create( |
| 516 mediaRouterMojom.MediaRouteProvider.stubClass.prototype); |
507 | 517 |
508 /* | 518 /* |
509 * Sets the callback handler used to invoke methods in the provider manager. | 519 * Sets the callback handler used to invoke methods in the provider manager. |
510 * | 520 * |
511 * @param {!MediaRouterHandlers} handlers | 521 * @param {!MediaRouterHandlers} handlers |
512 */ | 522 */ |
513 MediaRouteProvider.prototype.setHandlers = function(handlers) { | 523 MediaRouteProvider.prototype.setHandlers = function(handlers) { |
514 // TODO(mfoltz): Remove when component that supports this method is | 524 // TODO(mfoltz): Remove when component that supports this method is |
515 // rolled out to all Chrome channels in M56. | 525 // rolled out to all Chrome channels in M56. |
516 if (!handlers['onBeforeInvokeHandler']) | 526 if (!handlers['onBeforeInvokeHandler']) |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 // to be missing this API. | 806 // to be missing this API. |
797 if (!this.handlers_.searchSinks) { | 807 if (!this.handlers_.searchSinks) { |
798 return Promise.resolve({'sink_id': ''}); | 808 return Promise.resolve({'sink_id': ''}); |
799 } | 809 } |
800 this.handlers_.onBeforeInvokeHandler(); | 810 this.handlers_.onBeforeInvokeHandler(); |
801 return Promise.resolve({ | 811 return Promise.resolve({ |
802 'sink_id': this.handlers_.searchSinks(sinkId, sourceUrn, searchCriteria) | 812 'sink_id': this.handlers_.searchSinks(sinkId, sourceUrn, searchCriteria) |
803 }); | 813 }); |
804 }; | 814 }; |
805 | 815 |
806 mediaRouter = new MediaRouter(new mediaRouterMojom.MediaRouterPtr( | 816 mediaRouter = new MediaRouter(connector.bindHandleToProxy( |
807 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name))); | 817 frameInterfaces.getInterface(mediaRouterMojom.MediaRouter.name), |
| 818 mediaRouterMojom.MediaRouter)); |
808 | 819 |
809 return mediaRouter; | 820 return mediaRouter; |
810 }); | 821 }); |
OLD | NEW |