| 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 that wraps low-level details of interacting with the client plugin. | 7 * Class that wraps low-level details of interacting with the client plugin. |
| 8 * | 8 * |
| 9 * This abstracts a <embed> element and controls the plugin which does | 9 * This abstracts a <embed> element and controls the plugin which does |
| 10 * the actual remoting work. It also handles differences between | 10 * the actual remoting work. It also handles differences between |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'native') { | 92 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'native') { |
| 93 window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500); | 93 window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500); |
| 94 } | 94 } |
| 95 | 95 |
| 96 this.hostDesktop_ = new remoting.ClientPlugin.HostDesktopImpl( | 96 this.hostDesktop_ = new remoting.ClientPlugin.HostDesktopImpl( |
| 97 this, this.postMessage_.bind(this)); | 97 this, this.postMessage_.bind(this)); |
| 98 | 98 |
| 99 /** @private {remoting.CredentialsProvider} */ | 99 /** @private {remoting.CredentialsProvider} */ |
| 100 this.credentials_ = null; | 100 this.credentials_ = null; |
| 101 |
| 102 /** @private {string} */ |
| 103 this.keyRemappings_ = ''; |
| 101 }; | 104 }; |
| 102 | 105 |
| 103 /** | 106 /** |
| 104 * Creates plugin element without adding it to a container. | 107 * Creates plugin element without adding it to a container. |
| 105 * | 108 * |
| 106 * @return {HTMLEmbedElement} Plugin element | 109 * @return {HTMLEmbedElement} Plugin element |
| 107 */ | 110 */ |
| 108 remoting.ClientPluginImpl.createPluginElement_ = function() { | 111 remoting.ClientPluginImpl.createPluginElement_ = function() { |
| 109 var plugin = | 112 var plugin = |
| 110 /** @type {HTMLEmbedElement} */ (document.createElement('embed')); | 113 /** @type {HTMLEmbedElement} */ (document.createElement('embed')); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 | 491 |
| 489 /** | 492 /** |
| 490 * Release all currently pressed keys. | 493 * Release all currently pressed keys. |
| 491 */ | 494 */ |
| 492 remoting.ClientPluginImpl.prototype.releaseAllKeys = function() { | 495 remoting.ClientPluginImpl.prototype.releaseAllKeys = function() { |
| 493 this.plugin_.postMessage(JSON.stringify( | 496 this.plugin_.postMessage(JSON.stringify( |
| 494 { method: 'releaseAllKeys', data: {} })); | 497 { method: 'releaseAllKeys', data: {} })); |
| 495 }; | 498 }; |
| 496 | 499 |
| 497 /** | 500 /** |
| 501 * Sets and stores the key remapping setting for the current host. |
| 502 * |
| 503 * @param {string} remappings Comma separated list of key remappings. |
| 504 */ |
| 505 remoting.ClientPluginImpl.prototype.setRemapKeys = |
| 506 function(remappings) { |
| 507 // Cancel any existing remappings and apply the new ones. |
| 508 this.applyRemapKeys_(this.keyRemappings_, false); |
| 509 this.applyRemapKeys_(remappings, true); |
| 510 this.keyRemappings_ = remappings; |
| 511 }; |
| 512 |
| 513 /** |
| 514 * Applies the configured key remappings to the session, or resets them. |
| 515 * |
| 516 * @param {string} remapKeys |
| 517 * @param {boolean} apply True to apply remappings, false to cancel them. |
| 518 * @private |
| 519 */ |
| 520 remoting.ClientPluginImpl.prototype.applyRemapKeys_ = |
| 521 function(remapKeys, apply) { |
| 522 if (remapKeys == '') { |
| 523 return; |
| 524 } |
| 525 |
| 526 var remappings = remapKeys.split(','); |
| 527 for (var i = 0; i < remappings.length; ++i) { |
| 528 var keyCodes = remappings[i].split('>'); |
| 529 if (keyCodes.length != 2) { |
| 530 console.log('bad remapKey: ' + remappings[i]); |
| 531 continue; |
| 532 } |
| 533 var fromKey = parseInt(keyCodes[0], 0); |
| 534 var toKey = parseInt(keyCodes[1], 0); |
| 535 if (!fromKey || !toKey) { |
| 536 console.log('bad remapKey code: ' + remappings[i]); |
| 537 continue; |
| 538 } |
| 539 if (apply) { |
| 540 console.log('remapKey 0x' + fromKey.toString(16) + |
| 541 '>0x' + toKey.toString(16)); |
| 542 this.remapKey(fromKey, toKey); |
| 543 } else { |
| 544 console.log('cancel remapKey 0x' + fromKey.toString(16)); |
| 545 this.remapKey(fromKey, fromKey); |
| 546 } |
| 547 } |
| 548 }; |
| 549 |
| 550 /** |
| 551 * Sends a key combination to the remoting host, by sending down events for |
| 552 * the given keys, followed by up events in reverse order. |
| 553 * |
| 554 * @param {Array<number>} keys Key codes to be sent. |
| 555 * @return {void} Nothing. |
| 556 */ |
| 557 remoting.ClientPluginImpl.prototype.injectKeyCombination = |
| 558 function(keys) { |
| 559 for (var i = 0; i < keys.length; i++) { |
| 560 this.injectKeyEvent(keys[i], true); |
| 561 } |
| 562 for (var i = 0; i < keys.length; i++) { |
| 563 this.injectKeyEvent(keys[i], false); |
| 564 } |
| 565 }; |
| 566 |
| 567 /** |
| 498 * Send a key event to the host. | 568 * Send a key event to the host. |
| 499 * | 569 * |
| 500 * @param {number} usbKeycode The USB-style code of the key to inject. | 570 * @param {number} usbKeycode The USB-style code of the key to inject. |
| 501 * @param {boolean} pressed True to inject a key press, False for a release. | 571 * @param {boolean} pressed True to inject a key press, False for a release. |
| 502 */ | 572 */ |
| 503 remoting.ClientPluginImpl.prototype.injectKeyEvent = | 573 remoting.ClientPluginImpl.prototype.injectKeyEvent = |
| 504 function(usbKeycode, pressed) { | 574 function(usbKeycode, pressed) { |
| 505 this.plugin_.postMessage(JSON.stringify( | 575 this.plugin_.postMessage(JSON.stringify( |
| 506 { method: 'injectKeyEvent', data: { | 576 { method: 'injectKeyEvent', data: { |
| 507 'usbKeycode': usbKeycode, | 577 'usbKeycode': usbKeycode, |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() { | 854 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() { |
| 785 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') { | 855 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') { |
| 786 return; | 856 return; |
| 787 } | 857 } |
| 788 | 858 |
| 789 var plugin = remoting.ClientPluginImpl.createPluginElement_(); | 859 var plugin = remoting.ClientPluginImpl.createPluginElement_(); |
| 790 plugin.addEventListener( | 860 plugin.addEventListener( |
| 791 'loadend', function() { document.body.removeChild(plugin); }, false); | 861 'loadend', function() { document.body.removeChild(plugin); }, false); |
| 792 document.body.appendChild(plugin); | 862 document.body.appendChild(plugin); |
| 793 }; | 863 }; |
| OLD | NEW |