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 mediaRouterObserver; | 5 var mediaRouterObserver; |
6 | 6 |
7 define('media_router_bindings', [ | 7 define('media_router_bindings', [ |
8 'mojo/public/js/bindings', | 8 'mojo/public/js/bindings', |
9 'mojo/public/js/core', | 9 'mojo/public/js/core', |
10 'content/public/renderer/service_provider', | 10 'content/public/renderer/service_provider', |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 * @type {function(string)} | 297 * @type {function(string)} |
298 */ | 298 */ |
299 this.startObservingMediaSinks = null; | 299 this.startObservingMediaSinks = null; |
300 | 300 |
301 /** | 301 /** |
302 * @type {function(string)} | 302 * @type {function(string)} |
303 */ | 303 */ |
304 this.stopObservingMediaSinks = null; | 304 this.stopObservingMediaSinks = null; |
305 | 305 |
306 /** | 306 /** |
307 * @type {function(string, string, string)} | 307 * @type {function(string, string)} |
308 */ | 308 */ |
309 this.postMessage = null; | 309 this.sendMessage = null; |
310 | 310 |
311 /** | 311 /** |
312 * @type {function()} | 312 * @type {function()} |
313 */ | 313 */ |
314 this.startObservingMediaRoutes = null; | 314 this.startObservingMediaRoutes = null; |
315 | 315 |
316 /** | 316 /** |
317 * @type {function()} | 317 * @type {function()} |
318 */ | 318 */ |
319 this.stopObservingMediaRoutes = null; | 319 this.stopObservingMediaRoutes = null; |
(...skipping 26 matching lines...) Expand all Loading... | |
346 * Sets the callback handler used to invoke methods in the provider manager. | 346 * Sets the callback handler used to invoke methods in the provider manager. |
347 * | 347 * |
348 * TODO(mfoltz): Rename to something more explicit? | 348 * TODO(mfoltz): Rename to something more explicit? |
349 * @param {!MediaRouterHandlers} handlers | 349 * @param {!MediaRouterHandlers} handlers |
350 */ | 350 */ |
351 MediaRouter.prototype.setHandlers = function(handlers) { | 351 MediaRouter.prototype.setHandlers = function(handlers) { |
352 this.handlers_ = handlers; | 352 this.handlers_ = handlers; |
353 var requiredHandlers = [ | 353 var requiredHandlers = [ |
354 'stopObservingMediaRoutes', | 354 'stopObservingMediaRoutes', |
355 'startObservingMediaRoutes', | 355 'startObservingMediaRoutes', |
356 'postMessage', | 356 'sendMessage', |
357 'closeRoute', | 357 'closeRoute', |
358 'joinRoute', | 358 'joinRoute', |
359 'createRoute', | 359 'createRoute', |
360 'stopObservingMediaSinks', | 360 'stopObservingMediaSinks', |
361 'startObservingMediaRoutes' | 361 'startObservingMediaRoutes' |
362 ]; | 362 ]; |
363 requiredHandlers.forEach(function(nextHandler) { | 363 requiredHandlers.forEach(function(nextHandler) { |
364 if (!handlers.hasOwnProperty(nextHandler)) { | 364 if (!handlers.hasOwnProperty(nextHandler)) { |
365 console.error(nextHandler + ' handler not registered.'); | 365 console.error(nextHandler + ' handler not registered.'); |
366 } | 366 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 * @param {!string} routeId | 441 * @param {!string} routeId |
442 */ | 442 */ |
443 MediaRouter.prototype.closeRoute = function(routeId) { | 443 MediaRouter.prototype.closeRoute = function(routeId) { |
444 this.handlers_.closeRoute(routeId); | 444 this.handlers_.closeRoute(routeId); |
445 }; | 445 }; |
446 | 446 |
447 /** | 447 /** |
448 * Posts a message to the route designated by |routeId|. | 448 * Posts a message to the route designated by |routeId|. |
449 * @param {!string} routeId | 449 * @param {!string} routeId |
450 * @param {!string} message | 450 * @param {!string} message |
451 * @param {string} extraInfoJson | 451 * @return {!Promise.<boolean>} Resolved with true if the message was sent, |
452 * or false on failure. | |
Ken Rockot(use gerrit already)
2015/06/11 21:22:04
super nitty style nit: should indent 4 spaces from
haibinlu
2015/06/11 22:46:23
Done.
| |
452 */ | 453 */ |
453 MediaRouter.prototype.postMessage = function( | 454 MediaRouter.prototype.sendMessage = function( |
mark a. foltz
2015/06/11 18:48:33
It seems odd that the Promise should be resolved h
Ken Rockot(use gerrit already)
2015/06/11 21:22:04
I agree. A Promise resolving/rejecting is effectiv
haibinlu
2015/06/11 22:46:23
For mojo method that returns a value, mojo genera
| |
454 routeId, message, extraInfoJson) { | 455 routeId, message) { |
455 // TODO(mfoltz): Remove extraInfoJson if no longer needed. | 456 this.handlers_.sendMessage(routeId, message) |
456 this.handlers_.postMessage(routeId, message, JSON.parse(extraInfoJson)); | 457 .then(function() { |
458 return true; | |
459 }, function() { | |
460 return false; | |
461 }); | |
457 }; | 462 }; |
458 | 463 |
459 /** | 464 /** |
460 * Requests that the provider manager start sending information about active | 465 * Requests that the provider manager start sending information about active |
461 * media routes to the Media Router. | 466 * media routes to the Media Router. |
462 */ | 467 */ |
463 MediaRouter.prototype.startObservingMediaRoutes = function() { | 468 MediaRouter.prototype.startObservingMediaRoutes = function() { |
464 this.handlers_.startObservingMediaRoutes(); | 469 this.handlers_.startObservingMediaRoutes(); |
465 }; | 470 }; |
466 | 471 |
467 /** | 472 /** |
468 * Requests that the provider manager stop sending information about active | 473 * Requests that the provider manager stop sending information about active |
469 * media routes to the Media Router. | 474 * media routes to the Media Router. |
470 */ | 475 */ |
471 MediaRouter.prototype.stopObservingMediaRoutes = function() { | 476 MediaRouter.prototype.stopObservingMediaRoutes = function() { |
472 this.handlers_.stopObservingMediaRoutes(); | 477 this.handlers_.stopObservingMediaRoutes(); |
473 }; | 478 }; |
474 | 479 |
475 mediaRouterObserver = new MediaRouterObserver(connector.bindHandleToProxy( | 480 mediaRouterObserver = new MediaRouterObserver(connector.bindHandleToProxy( |
476 serviceProvider.connectToService( | 481 serviceProvider.connectToService( |
477 mediaRouterMojom.MediaRouterObserver.name), | 482 mediaRouterMojom.MediaRouterObserver.name), |
478 mediaRouterMojom.MediaRouterObserver)); | 483 mediaRouterMojom.MediaRouterObserver)); |
479 | 484 |
480 return mediaRouterObserver; | 485 return mediaRouterObserver; |
481 }); | 486 }); |
482 | 487 |
OLD | NEW |