Chromium Code Reviews| Index: remoting/webapp/client_session.js |
| diff --git a/remoting/webapp/client_session.js b/remoting/webapp/client_session.js |
| index 5284e53b66a36799f820b146ac6b5a0b8bda6f32..0a417e3e8f1d3565acea830164e787f361be6561 100644 |
| --- a/remoting/webapp/client_session.js |
| +++ b/remoting/webapp/client_session.js |
| @@ -228,6 +228,36 @@ remoting.ClientSession.prototype.error_ = |
| remoting.ClientSession.prototype.PLUGIN_ID = 'session-client-plugin'; |
| /** |
| + * Set of capabilities for which hasCapability_() can be used to test. |
| + * |
| + * @enum {string} |
| + */ |
| +remoting.ClientSession.Capability = { |
| + ALWAYS_RESIZE_TO_CLIENT: 'alwaysResizeToClient' |
| +}; |
| + |
| +/** |
| + * The set of capabilities negotiated between the client and host. |
| + * @type {!Array.<string>} |
|
Jamie
2013/04/15 22:14:11
You've declared this type as being never null, the
alexeypa (please no reviews)
2013/04/15 23:18:53
Done.
|
| + * @private |
| + */ |
| +remoting.ClientSession.prototype.capabilities_ = null; |
| + |
| +/** |
| + * @param {remoting.ClientSession.Capability} capability The capability to test |
| + * for. |
| + * @return {boolean} True if the capability has been negotiated between |
| + * the client and host. |
| + * @private |
| + */ |
| +remoting.ClientSession.prototype.hasCapability_ = function(capability) { |
| + if (this.capabilities_ == null) |
| + return false; |
| + |
| + return this.capabilities_.indexOf(capability) > -1; |
| +}; |
| + |
| +/** |
| * @param {Element} container The element to add the plugin to. |
| * @param {string} id Id to use for the plugin element . |
| * @return {remoting.ClientPlugin} Create plugin object for the locally |
| @@ -369,6 +399,8 @@ remoting.ClientSession.prototype.onPluginInitialized_ = function(initialized) { |
| this.onConnectionReady_.bind(this); |
| this.plugin.onDesktopSizeUpdateHandler = |
| this.onDesktopSizeChanged_.bind(this); |
| + this.plugin.onSetCapabilitiesHandler = |
| + this.onSetCapabilities_.bind(this); |
| this.connectPluginToWcs_(); |
| }; |
| @@ -561,6 +593,15 @@ remoting.ClientSession.prototype.onSetScreenMode_ = function(event) { |
| }; |
| /** |
| + * @return {boolean} True if resize-to-client is enabled. |
| + * @private |
| + */ |
| +remoting.ClientSession.prototype.isResizingToClient_ = function() { |
| + return this.resizeToClient_ || this.hasCapability_( |
| + remoting.ClientSession.Capability.ALWAYS_RESIZE_TO_CLIENT); |
| +} |
| + |
| +/** |
| * Set the shrink-to-fit and resize-to-client flags and save them if this is |
| * a Me2Me connection. |
| * |
| @@ -576,7 +617,7 @@ remoting.ClientSession.prototype.onSetScreenMode_ = function(event) { |
| */ |
| remoting.ClientSession.prototype.setScreenMode_ = |
| function(shrinkToFit, resizeToClient) { |
| - if (resizeToClient && !this.resizeToClient_) { |
| + if (resizeToClient && !this.isResizingToClient_()) { |
| this.plugin.notifyClientResolution(window.innerWidth, |
| window.innerHeight, |
| window.devicePixelRatio); |
| @@ -734,7 +775,7 @@ remoting.ClientSession.prototype.onConnectionStatusUpdate_ = |
| if (status == remoting.ClientSession.State.CONNECTED) { |
| this.setFocusHandlers_(); |
| this.onDesktopSizeChanged_(); |
| - if (this.resizeToClient_) { |
| + if (this.isResizingToClient_()) { |
| this.plugin.notifyClientResolution(window.innerWidth, |
| window.innerHeight, |
| window.devicePixelRatio); |
| @@ -761,6 +802,30 @@ remoting.ClientSession.prototype.onConnectionReady_ = function(ready) { |
| } |
| /** |
| + * This is a callback that gets called when the plugin report capabilities |
| + * negotiated with the host. |
| + * |
| + * @param {Array.<string>} capabilities The set of capabilities negotiated |
| + * between the client and host. |
| + * @return {void} Nothing. |
| + * @private |
| + */ |
| +remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { |
| + if (this.capabilities_ != null) { |
| + console.error('ERROR: onSetCapabilities_() is called more than once'); |
| + return; |
| + } |
| + |
| + this.capabilities_ = capabilities; |
| + if (this.isResizingToClient_()) { |
| + this.onDesktopSizeChanged_(); |
| + this.plugin.notifyClientResolution(window.innerWidth, |
| + window.innerHeight, |
| + window.devicePixelRatio); |
| + } |
| +}; |
| + |
| +/** |
| * @private |
| * @param {remoting.ClientSession.State} newState The new state for the session. |
| * @return {void} Nothing. |
| @@ -805,7 +870,7 @@ remoting.ClientSession.prototype.onResize = function() { |
| // Defer notifying the host of the change until the window stops resizing, to |
| // avoid overloading the control channel with notifications. |
| - if (this.resizeToClient_) { |
| + if (this.isResizingToClient_()) { |
| this.notifyClientResolutionTimer_ = window.setTimeout( |
| this.plugin.notifyClientResolution.bind(this.plugin, |
| window.innerWidth, |