Skip to content

Commit

Permalink
[Chromoting] Refactor remapKeys and Capabilities into DesktopRemoting.
Browse files Browse the repository at this point in the history
This cl removes the hard-coded values from ClientSession and ClientPlugin
and moves them into Application.Delegate.

NOTRY=True
BUG=

Review URL: https://codereview.chromium.org/727363004

Cr-Commit-Position: refs/heads/master@{#307353}
  • Loading branch information
garykac authored and Commit bot committed Dec 8, 2014
1 parent c93ba53 commit 4339def
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 44 deletions.
15 changes: 14 additions & 1 deletion remoting/webapp/base/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ remoting.Application.prototype.getSessionConnector = function() {
document.getElementById('video-container'),
this.onConnected.bind(this),
this.onError.bind(this),
this.onExtensionMessage.bind(this));
this.onExtensionMessage.bind(this),
this.delegate_.getRequiredCapabilities(),
this.delegate_.getDefaultRemapKeys());
}
return this.session_connector_;
};
Expand All @@ -138,6 +140,17 @@ remoting.Application.Delegate = function() {};
*/
remoting.Application.Delegate.prototype.init = function() {};

/**
* @return {string} The default remap keys for the current platform.
*/
remoting.Application.Delegate.prototype.getDefaultRemapKeys = function() {};

/**
* @return {Array.<string>} A list of |ClientSession.Capability|s required
* by this application.
*/
remoting.Application.Delegate.prototype.getRequiredCapabilities = function() {};

/**
* Called when a new session has been connected.
*
Expand Down
3 changes: 2 additions & 1 deletion remoting/webapp/crd/js/client_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,11 @@ remoting.ClientPluginFactory = function() {};
* @param {function(string, string):boolean} onExtensionMessage The handler for
* protocol extension messages. Returns true if a message is recognized;
* false otherwise.
* @param {Array.<string>} requiredCapabilities
* @return {remoting.ClientPlugin} A new client plugin instance.
*/
remoting.ClientPluginFactory.prototype.createPlugin =
function(container, onExtensionMessage) {};
function(container, onExtensionMessage, requiredCapabilities) {};

/**
* Preload the plugin to make instantiation faster when the user tries
Expand Down
42 changes: 16 additions & 26 deletions remoting/webapp/crd/js/client_plugin_impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@ var remoting = remoting || {};
* @param {function(string, string):boolean} onExtensionMessage The handler for
* protocol extension messages. Returns true if a message is recognized;
* false otherwise.
* @param {Array.<string>} requiredCapabilities The set of capabilties that the
* session must support for this application.
* @constructor
* @implements {remoting.ClientPlugin}
*/
remoting.ClientPluginImpl = function(container, onExtensionMessage) {
remoting.ClientPluginImpl = function(container, onExtensionMessage,
requiredCapabilities) {
this.plugin_ = remoting.ClientPluginImpl.createPluginElement_();
this.plugin_.id = 'session-client-plugin';
container.appendChild(this.plugin_);

this.onExtensionMessage_ = onExtensionMessage;
/**
* @type {Array.<string>}
* @private
*/
this.requiredCapabilities_ = requiredCapabilities;

/** @private */
this.desktopWidth_ = 0;
Expand Down Expand Up @@ -376,33 +384,13 @@ remoting.ClientPluginImpl.prototype.handleMessageMethod_ = function(message) {
supportedCapabilities =
tokenize(getStringAttr(message.data, 'supportedCapabilities'));
}

// At the moment the webapp does not recognize any of
// 'requestedCapabilities' capabilities (so they all should be disabled)
// and do not care about any of 'supportedCapabilities' capabilities (so
// they all can be enabled).
this.capabilities_ = supportedCapabilities;

// Let the host know that the webapp can be requested to always send
// the client's dimensions.
this.capabilities_.push(
remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION);

// Let the host know that we're interested in knowing whether or not
// it rate-limits desktop-resize requests.
this.capabilities_.push(
remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS);

// Let the host know that we can use the video framerecording extension.
this.capabilities_.push(
remoting.ClientSession.Capability.VIDEO_RECORDER);

// Let the host know that we can support casting of the screen.
// TODO(aiguha): Add this capability based on a gyp/command-line flag,
// rather than by default.
this.capabilities_.push(
remoting.ClientSession.Capability.CAST);

// All the required capabilities (specified by the app) are added to this.
this.capabilities_ = supportedCapabilities.concat(
this.requiredCapabilities_);
} else if (this.pluginApiVersion_ >= 6) {
this.pluginApiFeatures_ = ['highQualityScaling', 'injectKeyEvent'];
} else {
Expand Down Expand Up @@ -1003,11 +991,13 @@ remoting.DefaultClientPluginFactory = function() {};
/**
* @param {Element} container
* @param {function(string, string):boolean} onExtensionMessage
* @param {Array.<string>} requiredCapabilities
* @return {remoting.ClientPlugin}
*/
remoting.DefaultClientPluginFactory.prototype.createPlugin =
function(container, onExtensionMessage) {
return new remoting.ClientPluginImpl(container, onExtensionMessage);
function(container, onExtensionMessage, requiredCapabilities) {
return new remoting.ClientPluginImpl(container, onExtensionMessage,
requiredCapabilities);
};

remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() {
Expand Down
32 changes: 22 additions & 10 deletions remoting/webapp/crd/js/client_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ remoting.enableMouseLock = false;
* pairing id for this client, as issued by the host.
* @param {string} clientPairedSecret For paired Me2Me connections, the
* paired secret for this client, as issued by the host.
* @param {string} defaultRemapKeys The default set of remap keys, to use
* when the client doesn't define any.
* @constructor
* @extends {base.EventSource}
*/
remoting.ClientSession = function(signalStrategy, container, hostDisplayName,
accessCode, fetchPin, fetchThirdPartyToken,
authenticationMethods, hostId, hostJid,
hostPublicKey, mode, clientPairingId,
clientPairedSecret) {
clientPairedSecret, defaultRemapKeys) {
/** @private */
this.state_ = remoting.ClientSession.State.CREATED;

Expand Down Expand Up @@ -105,6 +107,9 @@ remoting.ClientSession = function(signalStrategy, container, hostDisplayName,
this.clientPairingId_ = clientPairingId;
/** @private */
this.clientPairedSecret_ = clientPairedSecret;
/** @private */
this.defaultRemapKeys_ = defaultRemapKeys;

/** @private */
this.sessionId_ = '';
/** @type {remoting.ClientPlugin}
Expand Down Expand Up @@ -370,8 +375,16 @@ remoting.ClientSession.Capability = {
// resolution to the host once connection has been established. See
// this.plugin_.notifyClientResolution().
SEND_INITIAL_RESOLUTION: 'sendInitialResolution',

// Let the host know that we're interested in knowing whether or not it
// rate limits desktop-resize requests.
RATE_LIMIT_RESIZE_REQUESTS: 'rateLimitResizeRequests',

// Indicates that the client supports the video frame-recording extension.
VIDEO_RECORDER: 'videoRecorder',

// Indicates that the client supports 'cast'ing the video stream to a
// cast-enabled device.
CAST: 'casting'
};

Expand Down Expand Up @@ -426,12 +439,14 @@ remoting.ClientSession.prototype.pluginLostFocus_ = function() {
* @param {function(string, string):boolean} onExtensionMessage The handler for
* protocol extension messages. Returns true if a message is recognized;
* false otherwise.
* @param {Array.<string>} requiredCapabilities A list of capabilities
* required by this application.
*/
remoting.ClientSession.prototype.createPluginAndConnect =
function(onExtensionMessage) {
function(onExtensionMessage, requiredCapabilities) {
this.plugin_ = remoting.ClientPlugin.factory.createPlugin(
this.container_.querySelector('.client-plugin-container'),
onExtensionMessage);
onExtensionMessage, requiredCapabilities);
remoting.HostSettings.load(this.hostId_,
this.onHostSettingsLoaded_.bind(this));
};
Expand Down Expand Up @@ -749,15 +764,12 @@ remoting.ClientSession.prototype.setRemapKeys = function(remappings) {
* @param {boolean} apply True to apply remappings, false to cancel them.
*/
remoting.ClientSession.prototype.applyRemapKeys_ = function(apply) {
// By default, under ChromeOS, remap the right Control key to the right
// Win / Cmd key.
var remapKeys = this.remapKeys_;
if (remapKeys == '' && remoting.platformIsChromeOS()) {
remapKeys = '0x0700e4>0x0700e7';
}

if (remapKeys == '') {
return;
remapKeys = this.defaultRemapKeys_;
if (remapKeys == '') {
return;
}
}

var remappings = remapKeys.split(',');
Expand Down
28 changes: 28 additions & 0 deletions remoting/webapp/crd/js/desktop_remoting.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,34 @@ remoting.DesktopRemoting.prototype.init = function() {
remoting.ClientPlugin.factory.preloadPlugin();
}

/**
* @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;
};

/**
* @return {Array.<string>} A list of |ClientSession.Capability|s required
* by this application.
*/
remoting.DesktopRemoting.prototype.getRequiredCapabilities = function() {
return [
remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION,
remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS,
remoting.ClientSession.Capability.VIDEO_RECORDER,
// TODO(aiguha): Add this capability based on a gyp/command-line flag,
// rather than by default.
remoting.ClientSession.Capability.CAST
];
};

/**
* @param {remoting.ClientSession} clientSession
*/
Expand Down
7 changes: 6 additions & 1 deletion remoting/webapp/crd/js/session_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,18 @@ remoting.SessionConnectorFactory = function() {};
* @param {function(string, string):boolean} onExtensionMessage The handler for
* protocol extension messages. Returns true if a message is recognized;
* false otherwise.
* @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 =
// TODO(garykac): Can onExtensionMessage be removed from here? It's only
// needed to pass to the ClientSession. Investigate why ClientSession
// needs this.
function(clientContainer, onConnected, onError, onExtensionMessage) {};
function(clientContainer, onConnected, onError, onExtensionMessage,
requiredCapabilities, defaultRemapKeys) {};

/**
* @type {remoting.SessionConnectorFactory}
Expand Down
37 changes: 32 additions & 5 deletions remoting/webapp/crd/js/session_connector_impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ var remoting = remoting || {};
* @param {function(string, string):boolean} onExtensionMessage The handler for
* protocol extension messages. Returns true if a message is recognized;
* false otherwise.
* @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,
onExtensionMessage) {
onExtensionMessage,
requiredCapabilities,
defaultRemapKeys) {
/**
* @type {HTMLElement}
* @private
Expand All @@ -49,6 +55,18 @@ remoting.SessionConnectorImpl = function(clientContainer, onConnected, onError,
*/
this.onExtensionMessage_ = onExtensionMessage;

/**
* @type {Array.<string>}
* @private
*/
this.requiredCapabilities_ = requiredCapabilities;

/**
* @type {string}
* @private
*/
this.defaultRemapKeys_ = defaultRemapKeys;

/**
* @type {string}
* @private
Expand Down Expand Up @@ -448,12 +466,14 @@ remoting.SessionConnectorImpl.prototype.createSession_ = function() {
this.signalStrategy_, this.clientContainer_, this.hostDisplayName_,
this.passPhrase_, this.fetchPin_, this.fetchThirdPartyToken_,
authenticationMethods, this.hostId_, this.hostJid_, this.hostPublicKey_,
this.connectionMode_, this.clientPairingId_, this.clientPairedSecret_);
this.connectionMode_, this.clientPairingId_, this.clientPairedSecret_,
this.defaultRemapKeys_);
this.clientSession_.logHostOfflineErrors(!this.refreshHostJidIfOffline_);
this.clientSession_.addEventListener(
remoting.ClientSession.Events.stateChanged,
this.bound_.onStateChange);
this.clientSession_.createPluginAndConnect(this.onExtensionMessage_);
this.clientSession_.createPluginAndConnect(this.onExtensionMessage_,
this.requiredCapabilities_);
};

/**
Expand Down Expand Up @@ -596,9 +616,16 @@ remoting.DefaultSessionConnectorFactory = function() {
* @param {function(string, string):boolean} onExtensionMessage The handler for
* protocol extension messages. Returns true if a message is recognized;
* false otherwise.
* @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.
*/
remoting.DefaultSessionConnectorFactory.prototype.createConnector =
function(clientContainer, onConnected, onError, onExtensionMessage) {
function(clientContainer, onConnected, onError, onExtensionMessage,
requiredCapabilities, defaultRemapKeys) {
return new remoting.SessionConnectorImpl(clientContainer, onConnected,
onError, onExtensionMessage);
onError, onExtensionMessage,
requiredCapabilities,
defaultRemapKeys);
};

0 comments on commit 4339def

Please sign in to comment.