summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorkelvinp <kelvinp@chromium.org>2015-03-19 13:21:35 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-19 20:22:05 +0000
commit06408c1d57d6521cc1acebccbdb4972d2a26ae41 (patch)
tree38e67e4a0af7544866df6b2d358be57f944fd748 /remoting
parenta8190bfa85ddd4a2f86b5dde62ccdad80b631fd9 (diff)
downloadchromium_src-06408c1d57d6521cc1acebccbdb4972d2a26ae41.zip
chromium_src-06408c1d57d6521cc1acebccbdb4972d2a26ae41.tar.gz
chromium_src-06408c1d57d6521cc1acebccbdb4972d2a26ae41.tar.bz2
[Webapp Refactor] Move key injection related functionality into the plugin layer.
This CL moves key injection logic setRemapKey() and injectKeyCombination() into the plugin layer. With this change, we no longer need to pass the default remap keys from the ApplicationDelegate through the SessionConnector to the DesktopConnectedView in order to setup a key remapping. Instead, we can simply call plugin.setRemapKeys('a->b,b->c') on the delegate. BUG=465878 Review URL: https://codereview.chromium.org/1022473004 Cr-Commit-Position: refs/heads/master@{#321419}
Diffstat (limited to 'remoting')
-rw-r--r--remoting/webapp/app_remoting/js/app_remoting.js21
-rw-r--r--remoting/webapp/base/js/application.js8
-rw-r--r--remoting/webapp/crd/js/client_plugin.js16
-rw-r--r--remoting/webapp/crd/js/client_plugin_impl.js70
-rw-r--r--remoting/webapp/crd/js/desktop_connected_view.js87
-rw-r--r--remoting/webapp/crd/js/desktop_remoting.js22
-rw-r--r--remoting/webapp/crd/js/session_connector.js4
-rw-r--r--remoting/webapp/crd/js/session_connector_impl.js15
8 files changed, 108 insertions, 135 deletions
diff --git a/remoting/webapp/app_remoting/js/app_remoting.js b/remoting/webapp/app_remoting/js/app_remoting.js
index f6b46a6..3754111 100644
--- a/remoting/webapp/app_remoting/js/app_remoting.js
+++ b/remoting/webapp/app_remoting/js/app_remoting.js
@@ -211,18 +211,6 @@ remoting.AppRemoting.prototype.runApplicationUrl = function() {
};
/**
- * @return {string} The default remap keys for the current platform.
- */
-remoting.AppRemoting.prototype.getDefaultRemapKeys = function() {
- // Map Cmd to Ctrl on Mac since hosts typically use Ctrl for keyboard
- // shortcuts, but we want them to act as natively as possible.
- if (remoting.platformIsMac()) {
- return '0x0700e3>0x0700e0,0x0700e7>0x0700e4';
- }
- return '';
-};
-
-/**
* Called when a new session has been connected.
*
* @param {remoting.ConnectionInfo} connectionInfo
@@ -249,8 +237,13 @@ remoting.AppRemoting.prototype.handleConnected = function(connectionInfo) {
// TODO(kelvinp): Move all app remoting specific logic into
// remoting.AppRemotingView.
this.connectedView_ = new remoting.DesktopConnectedView(
- document.getElementById('client-container'), connectionInfo,
- this.getDefaultRemapKeys());
+ document.getElementById('client-container'), connectionInfo);
+
+ // Map Cmd to Ctrl on Mac since hosts typically use Ctrl for keyboard
+ // shortcuts, but we want them to act as natively as possible.
+ if (remoting.platformIsMac()) {
+ connectionInfo.plugin().setRemapKeys('0x0700e3>0x0700e0,0x0700e7>0x0700e4');
+ }
};
/**
diff --git a/remoting/webapp/base/js/application.js b/remoting/webapp/base/js/application.js
index 3141ec9..7289b0e 100644
--- a/remoting/webapp/base/js/application.js
+++ b/remoting/webapp/base/js/application.js
@@ -180,8 +180,7 @@ remoting.Application.prototype.getSessionConnector = function() {
this.onConnected.bind(this),
this.onError.bind(this),
this.onConnectionFailed.bind(this),
- this.appCapabilities_,
- this.delegate_.getDefaultRemapKeys());
+ this.appCapabilities_);
}
return this.sessionConnector_;
};
@@ -267,11 +266,6 @@ remoting.Application.Delegate.prototype.signInFailed = function(error) {};
remoting.Application.Delegate.prototype.getApplicationName = function() {};
/**
- * @return {string} The default remap keys for the current platform.
- */
-remoting.Application.Delegate.prototype.getDefaultRemapKeys = function() {};
-
-/**
* Called when a new session has been connected.
*
* @param {remoting.ConnectionInfo} connectionInfo
diff --git a/remoting/webapp/crd/js/client_plugin.js b/remoting/webapp/crd/js/client_plugin.js
index 66b9fd3..325117f 100644
--- a/remoting/webapp/crd/js/client_plugin.js
+++ b/remoting/webapp/crd/js/client_plugin.js
@@ -49,6 +49,22 @@ remoting.ClientPlugin.prototype.injectKeyEvent =
function(key, down) {};
/**
+ * Sends a key combination to the host, by sending down events for
+ * the given keys, followed by up events in reverse order.
+ *
+ * @param {Array<number>} keys Key codes to be sent.
+ * @return {void} Nothing.
+ */
+remoting.ClientPlugin.prototype.injectKeyCombination = function(keys) {};
+
+/**
+ * Sets and stores the key remapping setting for the current host.
+ *
+ * @param {string} remappings Comma separated list of key remappings.
+ */
+remoting.ClientPlugin.prototype.setRemapKeys = function(remappings) {};
+
+/**
* @param {number} from
* @param {number} to
*/
diff --git a/remoting/webapp/crd/js/client_plugin_impl.js b/remoting/webapp/crd/js/client_plugin_impl.js
index a0de1e3..3560e7b 100644
--- a/remoting/webapp/crd/js/client_plugin_impl.js
+++ b/remoting/webapp/crd/js/client_plugin_impl.js
@@ -98,6 +98,9 @@ remoting.ClientPluginImpl = function(container,
/** @private {remoting.CredentialsProvider} */
this.credentials_ = null;
+
+ /** @private {string} */
+ this.keyRemappings_ = '';
};
/**
@@ -497,6 +500,73 @@ remoting.ClientPluginImpl.prototype.releaseAllKeys = function() {
};
/**
+ * Sets and stores the key remapping setting for the current host.
+ *
+ * @param {string} remappings Comma separated list of key remappings.
+ */
+remoting.ClientPluginImpl.prototype.setRemapKeys =
+ function(remappings) {
+ // Cancel any existing remappings and apply the new ones.
+ this.applyRemapKeys_(this.keyRemappings_, false);
+ this.applyRemapKeys_(remappings, true);
+ this.keyRemappings_ = remappings;
+};
+
+/**
+ * Applies the configured key remappings to the session, or resets them.
+ *
+ * @param {string} remapKeys
+ * @param {boolean} apply True to apply remappings, false to cancel them.
+ * @private
+ */
+remoting.ClientPluginImpl.prototype.applyRemapKeys_ =
+ function(remapKeys, apply) {
+ if (remapKeys == '') {
+ return;
+ }
+
+ var remappings = remapKeys.split(',');
+ for (var i = 0; i < remappings.length; ++i) {
+ var keyCodes = remappings[i].split('>');
+ if (keyCodes.length != 2) {
+ console.log('bad remapKey: ' + remappings[i]);
+ continue;
+ }
+ var fromKey = parseInt(keyCodes[0], 0);
+ var toKey = parseInt(keyCodes[1], 0);
+ if (!fromKey || !toKey) {
+ console.log('bad remapKey code: ' + remappings[i]);
+ continue;
+ }
+ if (apply) {
+ console.log('remapKey 0x' + fromKey.toString(16) +
+ '>0x' + toKey.toString(16));
+ this.remapKey(fromKey, toKey);
+ } else {
+ console.log('cancel remapKey 0x' + fromKey.toString(16));
+ this.remapKey(fromKey, fromKey);
+ }
+ }
+};
+
+/**
+ * Sends a key combination to the remoting host, by sending down events for
+ * the given keys, followed by up events in reverse order.
+ *
+ * @param {Array<number>} keys Key codes to be sent.
+ * @return {void} Nothing.
+ */
+remoting.ClientPluginImpl.prototype.injectKeyCombination =
+ function(keys) {
+ for (var i = 0; i < keys.length; i++) {
+ this.injectKeyEvent(keys[i], true);
+ }
+ for (var i = 0; i < keys.length; i++) {
+ this.injectKeyEvent(keys[i], false);
+ }
+};
+
+/**
* Send a key event to the host.
*
* @param {number} usbKeycode The USB-style code of the key to inject.
diff --git a/remoting/webapp/crd/js/desktop_connected_view.js b/remoting/webapp/crd/js/desktop_connected_view.js
index f1baf13..af4a3fb 100644
--- a/remoting/webapp/crd/js/desktop_connected_view.js
+++ b/remoting/webapp/crd/js/desktop_connected_view.js
@@ -15,14 +15,11 @@ var remoting = remoting || {};
/**
* @param {HTMLElement} container
* @param {remoting.ConnectionInfo} connectionInfo
- * @param {string} defaultRemapKeys The default set of remap keys, to use
- * when the client doesn't define any.
* @constructor
* @extends {base.EventSourceImpl}
* @implements {base.Disposable}
*/
-remoting.DesktopConnectedView = function(container, connectionInfo,
- defaultRemapKeys) {
+remoting.DesktopConnectedView = function(container, connectionInfo) {
/** @private {HTMLElement} */
this.container_ = container;
@@ -39,9 +36,6 @@ remoting.DesktopConnectedView = function(container, connectionInfo,
/** @private */
this.mode_ = connectionInfo.mode();
- /** @private {string} */
- this.defaultRemapKeys_ = defaultRemapKeys;
-
/** @private {remoting.DesktopViewport} */
this.viewport_ = null;
@@ -156,11 +150,6 @@ remoting.DesktopConnectedView.prototype.initPlugin_ = function() {
sendCadElement.hidden = true;
}
- // Apply customized key remappings if the plugin supports remapKeys.
- if (this.plugin_.hasFeature(remoting.ClientPlugin.Feature.REMAP_KEY)) {
- this.applyRemapKeys_(true);
- }
-
if (this.session_.hasCapability(
remoting.ClientSession.Capability.VIDEO_RECORDER)) {
this.videoFrameRecorder_ = new remoting.VideoFrameRecorder(this.plugin_);
@@ -254,83 +243,13 @@ remoting.DesktopConnectedView.prototype.onFullScreenChanged_ = function (
};
/**
- * Sets and stores the key remapping setting for the current host.
- *
- * @param {string} remappings Comma separated list of key remappings.
- */
-remoting.DesktopConnectedView.prototype.setRemapKeys = function(remappings) {
- // Cancel any existing remappings and apply the new ones.
- this.applyRemapKeys_(false);
- this.host_.options.remapKeys = remappings;
- this.applyRemapKeys_(true);
-
- // Save the new remapping setting.
- this.host_.options.save();
-};
-
-/**
- * Applies the configured key remappings to the session, or resets them.
- *
- * @param {boolean} apply True to apply remappings, false to cancel them.
- */
-remoting.DesktopConnectedView.prototype.applyRemapKeys_ = function(apply) {
- var remapKeys = this.host_.options.remapKeys;
- if (remapKeys == '') {
- remapKeys = this.defaultRemapKeys_;
- if (remapKeys == '') {
- return;
- }
- }
-
- var remappings = remapKeys.split(',');
- for (var i = 0; i < remappings.length; ++i) {
- var keyCodes = remappings[i].split('>');
- if (keyCodes.length != 2) {
- console.log('bad remapKey: ' + remappings[i]);
- continue;
- }
- var fromKey = parseInt(keyCodes[0], 0);
- var toKey = parseInt(keyCodes[1], 0);
- if (!fromKey || !toKey) {
- console.log('bad remapKey code: ' + remappings[i]);
- continue;
- }
- if (apply) {
- console.log('remapKey 0x' + fromKey.toString(16) +
- '>0x' + toKey.toString(16));
- this.plugin_.remapKey(fromKey, toKey);
- } else {
- console.log('cancel remapKey 0x' + fromKey.toString(16));
- this.plugin_.remapKey(fromKey, fromKey);
- }
- }
-};
-
-/**
- * Sends a key combination to the remoting client, by sending down events for
- * the given keys, followed by up events in reverse order.
- *
- * @param {Array<number>} keys Key codes to be sent.
- * @return {void} Nothing.
- * @private
- */
-remoting.DesktopConnectedView.prototype.sendKeyCombination_ = function(keys) {
- for (var i = 0; i < keys.length; i++) {
- this.plugin_.injectKeyEvent(keys[i], true);
- }
- for (var i = 0; i < keys.length; i++) {
- this.plugin_.injectKeyEvent(keys[i], false);
- }
-};
-
-/**
* Sends a Ctrl-Alt-Del sequence to the remoting client.
*
* @return {void} Nothing.
*/
remoting.DesktopConnectedView.prototype.sendCtrlAltDel = function() {
console.log('Sending Ctrl-Alt-Del.');
- this.sendKeyCombination_([0x0700e0, 0x0700e2, 0x07004c]);
+ this.plugin_.injectKeyCombination([0x0700e0, 0x0700e2, 0x07004c]);
};
/**
@@ -340,7 +259,7 @@ remoting.DesktopConnectedView.prototype.sendCtrlAltDel = function() {
*/
remoting.DesktopConnectedView.prototype.sendPrintScreen = function() {
console.log('Sending Print Screen.');
- this.sendKeyCombination_([0x070046]);
+ this.plugin_.injectKeyCombination([0x070046]);
};
/**
diff --git a/remoting/webapp/crd/js/desktop_remoting.js b/remoting/webapp/crd/js/desktop_remoting.js
index 9b7e24e..0f727f0 100644
--- a/remoting/webapp/crd/js/desktop_remoting.js
+++ b/remoting/webapp/crd/js/desktop_remoting.js
@@ -156,19 +156,6 @@ remoting.DesktopRemoting.prototype.getApplicationName = function() {
};
/**
- * @return {string} The default remap keys for the current platform.
- */
-remoting.DesktopRemoting.prototype.getDefaultRemapKeys = function() {
- var remapKeys = '';
- // By default, under ChromeOS, remap the right Control key to the right
- // Win / Cmd key.
- if (remoting.platformIsChromeOS()) {
- remapKeys = '0x0700e4>0x0700e7';
- }
- return remapKeys;
-};
-
-/**
* Called when a new session has been connected.
*
* @param {remoting.ConnectionInfo} connectionInfo
@@ -198,8 +185,13 @@ remoting.DesktopRemoting.prototype.handleConnected = function(connectionInfo) {
}
this.connectedView_ = new remoting.DesktopConnectedView(
- document.getElementById('client-container'), connectionInfo,
- this.getDefaultRemapKeys());
+ document.getElementById('client-container'), connectionInfo);
+
+ // By default, under ChromeOS, remap the right Control key to the right
+ // Win / Cmd key.
+ if (remoting.platformIsChromeOS()) {
+ connectionInfo.plugin().setRemapKeys('0x0700e4>0x0700e7');
+ }
if (connectionInfo.mode() === remoting.DesktopConnectedView.Mode.ME2ME) {
var sessionConnector = remoting.app.getSessionConnector();
diff --git a/remoting/webapp/crd/js/session_connector.js b/remoting/webapp/crd/js/session_connector.js
index 2d35a78..467648e 100644
--- a/remoting/webapp/crd/js/session_connector.js
+++ b/remoting/webapp/crd/js/session_connector.js
@@ -129,13 +129,11 @@ remoting.SessionConnectorFactory = function() {};
* the connection fails.
* @param {Array<string>} requiredCapabilities Connector capabilities
* required by this application.
- * @param {string} defaultRemapKeys The default set of key mappings to use
- * in the client session.
* @return {remoting.SessionConnector}
*/
remoting.SessionConnectorFactory.prototype.createConnector =
function(clientContainer, onConnected, onError,
- onConnectionFailed, requiredCapabilities, defaultRemapKeys) {};
+ onConnectionFailed, requiredCapabilities) {};
/**
* @type {remoting.SessionConnectorFactory}
diff --git a/remoting/webapp/crd/js/session_connector_impl.js b/remoting/webapp/crd/js/session_connector_impl.js
index 9e3f67c..427d6a3 100644
--- a/remoting/webapp/crd/js/session_connector_impl.js
+++ b/remoting/webapp/crd/js/session_connector_impl.js
@@ -28,15 +28,12 @@ remoting.clientSession = null;
* the connection fails.
* @param {Array<string>} requiredCapabilities Connector capabilities
* required by this application.
- * @param {string} defaultRemapKeys The default set of key mappings for the
- * client session to use.
* @constructor
* @implements {remoting.SessionConnector}
*/
remoting.SessionConnectorImpl = function(clientContainer, onConnected, onError,
onConnectionFailed,
- requiredCapabilities,
- defaultRemapKeys) {
+ requiredCapabilities) {
/** @private {HTMLElement} */
this.clientContainer_ = clientContainer;
@@ -52,9 +49,6 @@ remoting.SessionConnectorImpl = function(clientContainer, onConnected, onError,
/** @private {Array<string>} */
this.requiredCapabilities_ = requiredCapabilities;
- /** @private {string} */
- this.defaultRemapKeys_ = defaultRemapKeys;
-
/** @private {remoting.DesktopConnectedView.Mode} */
this.connectionMode_ = remoting.DesktopConnectedView.Mode.ME2ME;
@@ -555,16 +549,13 @@ remoting.DefaultSessionConnectorFactory = function() {};
* the connection fails.
* @param {Array<string>} requiredCapabilities Connector capabilities
* required by this application.
- * @param {string} defaultRemapKeys The default set of key mappings to use
- * in the client session.
* @return {remoting.SessionConnector}
*/
remoting.DefaultSessionConnectorFactory.prototype.createConnector =
function(clientContainer, onConnected, onError,
- onConnectionFailed, requiredCapabilities, defaultRemapKeys) {
+ onConnectionFailed, requiredCapabilities) {
return new remoting.SessionConnectorImpl(clientContainer, onConnected,
onError,
onConnectionFailed,
- requiredCapabilities,
- defaultRemapKeys);
+ requiredCapabilities);
};