OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Class handling creation and teardown of a remoting client session. | 7 * Class handling creation and teardown of a remoting client session. |
8 * | 8 * |
9 * The ClientSession class controls lifetime of the client plugin | 9 * The ClientSession class controls lifetime of the client plugin |
10 * object and provides the plugin with the functionality it needs to | 10 * object and provides the plugin with the functionality it needs to |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 remoting.ClientSession.STATS_KEY_DECODE_LATENCY = 'decodeLatency'; | 349 remoting.ClientSession.STATS_KEY_DECODE_LATENCY = 'decodeLatency'; |
350 remoting.ClientSession.STATS_KEY_RENDER_LATENCY = 'renderLatency'; | 350 remoting.ClientSession.STATS_KEY_RENDER_LATENCY = 'renderLatency'; |
351 remoting.ClientSession.STATS_KEY_ROUNDTRIP_LATENCY = 'roundtripLatency'; | 351 remoting.ClientSession.STATS_KEY_ROUNDTRIP_LATENCY = 'roundtripLatency'; |
352 | 352 |
353 // Keys for per-host settings. | 353 // Keys for per-host settings. |
354 remoting.ClientSession.KEY_REMAP_KEYS = 'remapKeys'; | 354 remoting.ClientSession.KEY_REMAP_KEYS = 'remapKeys'; |
355 remoting.ClientSession.KEY_RESIZE_TO_CLIENT = 'resizeToClient'; | 355 remoting.ClientSession.KEY_RESIZE_TO_CLIENT = 'resizeToClient'; |
356 remoting.ClientSession.KEY_SHRINK_TO_FIT = 'shrinkToFit'; | 356 remoting.ClientSession.KEY_SHRINK_TO_FIT = 'shrinkToFit'; |
357 | 357 |
358 /** | 358 /** |
359 * The id of the client plugin | |
360 * | |
361 * @const | |
362 */ | |
363 remoting.ClientSession.prototype.PLUGIN_ID = 'session-client-plugin'; | |
364 | |
365 /** | |
366 * Set of capabilities for which hasCapability_() can be used to test. | 359 * Set of capabilities for which hasCapability_() can be used to test. |
367 * | 360 * |
368 * @enum {string} | 361 * @enum {string} |
369 */ | 362 */ |
370 remoting.ClientSession.Capability = { | 363 remoting.ClientSession.Capability = { |
371 // When enabled this capability causes the client to send its screen | 364 // When enabled this capability causes the client to send its screen |
372 // resolution to the host once connection has been established. See | 365 // resolution to the host once connection has been established. See |
373 // this.plugin_.notifyClientResolution(). | 366 // this.plugin_.notifyClientResolution(). |
374 SEND_INITIAL_RESOLUTION: 'sendInitialResolution', | 367 SEND_INITIAL_RESOLUTION: 'sendInitialResolution', |
375 RATE_LIMIT_RESIZE_REQUESTS: 'rateLimitResizeRequests', | 368 RATE_LIMIT_RESIZE_REQUESTS: 'rateLimitResizeRequests', |
(...skipping 15 matching lines...) Expand all Loading... |
391 * @private | 384 * @private |
392 */ | 385 */ |
393 remoting.ClientSession.prototype.hasCapability_ = function(capability) { | 386 remoting.ClientSession.prototype.hasCapability_ = function(capability) { |
394 if (this.capabilities_ == null) | 387 if (this.capabilities_ == null) |
395 return false; | 388 return false; |
396 | 389 |
397 return this.capabilities_.indexOf(capability) > -1; | 390 return this.capabilities_.indexOf(capability) > -1; |
398 }; | 391 }; |
399 | 392 |
400 /** | 393 /** |
401 * @param {string} id Id to use for the plugin element . | |
402 * @param {function(string, string):boolean} onExtensionMessage The handler for | |
403 * protocol extension messages. Returns true if a message is recognized; | |
404 * false otherwise. | |
405 * @return {remoting.ClientPlugin} Create plugin object for the locally | |
406 * installed plugin. | |
407 */ | |
408 remoting.ClientSession.prototype.createClientPlugin_ = | |
409 function(id, onExtensionMessage) { | |
410 var plugin = /** @type {remoting.ViewerPlugin} */ | |
411 document.createElement('embed'); | |
412 | |
413 plugin.id = id; | |
414 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'pnacl') { | |
415 plugin.src = 'remoting_client_pnacl.nmf'; | |
416 plugin.type = 'application/x-pnacl'; | |
417 } else if (remoting.settings.CLIENT_PLUGIN_TYPE == 'nacl') { | |
418 plugin.src = 'remoting_client_nacl.nmf'; | |
419 plugin.type = 'application/x-nacl'; | |
420 } else { | |
421 plugin.src = 'about://none'; | |
422 plugin.type = 'application/vnd.chromium.remoting-viewer'; | |
423 } | |
424 | |
425 plugin.width = 0; | |
426 plugin.height = 0; | |
427 plugin.tabIndex = 0; // Required, otherwise focus() doesn't work. | |
428 this.container_.querySelector('.client-plugin-container').appendChild(plugin); | |
429 | |
430 return new remoting.ClientPlugin(plugin, onExtensionMessage); | |
431 }; | |
432 | |
433 /** | |
434 * Callback function called when the plugin element gets focus. | 394 * Callback function called when the plugin element gets focus. |
435 */ | 395 */ |
436 remoting.ClientSession.prototype.pluginGotFocus_ = function() { | 396 remoting.ClientSession.prototype.pluginGotFocus_ = function() { |
437 remoting.clipboard.initiateToHost(); | 397 remoting.clipboard.initiateToHost(); |
438 }; | 398 }; |
439 | 399 |
440 /** | 400 /** |
441 * Callback function called when the plugin element loses focus. | 401 * Callback function called when the plugin element loses focus. |
442 */ | 402 */ |
443 remoting.ClientSession.prototype.pluginLostFocus_ = function() { | 403 remoting.ClientSession.prototype.pluginLostFocus_ = function() { |
444 if (this.plugin_) { | 404 if (this.plugin_) { |
445 // Release all keys to prevent them becoming 'stuck down' on the host. | 405 // Release all keys to prevent them becoming 'stuck down' on the host. |
446 this.plugin_.releaseAllKeys(); | 406 this.plugin_.releaseAllKeys(); |
447 if (this.plugin_.element()) { | 407 if (this.plugin_.element()) { |
448 // Focus should stay on the element, not (for example) the toolbar. | 408 // Focus should stay on the element, not (for example) the toolbar. |
449 // Due to crbug.com/246335, we can't restore the focus immediately, | 409 // Due to crbug.com/246335, we can't restore the focus immediately, |
450 // otherwise the plugin gets confused about whether or not it has focus. | 410 // otherwise the plugin gets confused about whether or not it has focus. |
451 window.setTimeout( | 411 window.setTimeout( |
452 this.plugin_.element().focus.bind(this.plugin_.element()), | 412 this.plugin_.element().focus.bind(this.plugin_.element()), 0); |
453 0); | |
454 } | 413 } |
455 } | 414 } |
456 }; | 415 }; |
457 | 416 |
458 /** | 417 /** |
459 * Adds <embed> element to |container| and readies the sesion object. | 418 * Adds <embed> element to |container| and readies the sesion object. |
460 * | 419 * |
461 * @param {function(string, string):boolean} onExtensionMessage The handler for | 420 * @param {function(string, string):boolean} onExtensionMessage The handler for |
462 * protocol extension messages. Returns true if a message is recognized; | 421 * protocol extension messages. Returns true if a message is recognized; |
463 * false otherwise. | 422 * false otherwise. |
464 */ | 423 */ |
465 remoting.ClientSession.prototype.createPluginAndConnect = | 424 remoting.ClientSession.prototype.createPluginAndConnect = |
466 function(onExtensionMessage) { | 425 function(onExtensionMessage) { |
467 this.plugin_ = this.createClientPlugin_(this.PLUGIN_ID, onExtensionMessage); | 426 this.plugin_ = new remoting.ClientPlugin( |
| 427 this.container_.querySelector('.client-plugin-container'), |
| 428 onExtensionMessage); |
468 remoting.HostSettings.load(this.hostId_, | 429 remoting.HostSettings.load(this.hostId_, |
469 this.onHostSettingsLoaded_.bind(this)); | 430 this.onHostSettingsLoaded_.bind(this)); |
470 }; | 431 }; |
471 | 432 |
472 /** | 433 /** |
473 * @param {Object.<string>} options The current options for the host, or {} | 434 * @param {Object.<string>} options The current options for the host, or {} |
474 * if this client has no saved settings for the host. | 435 * if this client has no saved settings for the host. |
475 * @private | 436 * @private |
476 */ | 437 */ |
477 remoting.ClientSession.prototype.onHostSettingsLoaded_ = function(options) { | 438 remoting.ClientSession.prototype.onHostSettingsLoaded_ = function(options) { |
(...skipping 30 matching lines...) Expand all Loading... |
508 this.plugin_.element().addEventListener( | 469 this.plugin_.element().addEventListener( |
509 'blur', this.callPluginLostFocus_, false); | 470 'blur', this.callPluginLostFocus_, false); |
510 this.plugin_.element().focus(); | 471 this.plugin_.element().focus(); |
511 }; | 472 }; |
512 | 473 |
513 /** | 474 /** |
514 * @param {remoting.Error} error | 475 * @param {remoting.Error} error |
515 */ | 476 */ |
516 remoting.ClientSession.prototype.resetWithError_ = function(error) { | 477 remoting.ClientSession.prototype.resetWithError_ = function(error) { |
517 this.plugin_.cleanup(); | 478 this.plugin_.cleanup(); |
518 delete this.plugin_; | 479 this.plugin_ = null; |
519 this.error_ = error; | 480 this.error_ = error; |
520 this.setState_(remoting.ClientSession.State.FAILED); | 481 this.setState_(remoting.ClientSession.State.FAILED); |
521 } | 482 } |
522 | 483 |
523 /** | 484 /** |
524 * @param {boolean} initialized | 485 * @param {boolean} initialized |
525 */ | 486 */ |
526 remoting.ClientSession.prototype.onPluginInitialized_ = function(initialized) { | 487 remoting.ClientSession.prototype.onPluginInitialized_ = function(initialized) { |
527 if (!initialized) { | 488 if (!initialized) { |
528 console.error('ERROR: remoting plugin not loaded'); | 489 console.error('ERROR: remoting plugin not loaded'); |
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1571 * @return {{top: number, left:number}} The top-left corner of the plugin. | 1532 * @return {{top: number, left:number}} The top-left corner of the plugin. |
1572 */ | 1533 */ |
1573 remoting.ClientSession.prototype.getPluginPositionForTesting = function() { | 1534 remoting.ClientSession.prototype.getPluginPositionForTesting = function() { |
1574 var plugin = this.plugin_.element(); | 1535 var plugin = this.plugin_.element(); |
1575 var style = plugin.style; | 1536 var style = plugin.style; |
1576 return { | 1537 return { |
1577 top: parseFloat(style.marginTop), | 1538 top: parseFloat(style.marginTop), |
1578 left: parseFloat(style.marginLeft) | 1539 left: parseFloat(style.marginLeft) |
1579 }; | 1540 }; |
1580 }; | 1541 }; |
OLD | NEW |