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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 remoting.ClientSession.ConnectionError.NONE; | 221 remoting.ClientSession.ConnectionError.NONE; |
222 | 222 |
223 /** | 223 /** |
224 * The id of the client plugin | 224 * The id of the client plugin |
225 * | 225 * |
226 * @const | 226 * @const |
227 */ | 227 */ |
228 remoting.ClientSession.prototype.PLUGIN_ID = 'session-client-plugin'; | 228 remoting.ClientSession.prototype.PLUGIN_ID = 'session-client-plugin'; |
229 | 229 |
230 /** | 230 /** |
| 231 * Set of capabilities for which hasCapability_() can be used to test. |
| 232 * |
| 233 * @enum {string} |
| 234 */ |
| 235 remoting.ClientSession.Capability = { |
| 236 // When enabled this capability causes the client to send its screen |
| 237 // resolution to the host once connection has been established. See |
| 238 // this.plugin.notifyClientResolution(). |
| 239 SEND_INITIAL_RESOLUTION: 'sendInitialResolution' |
| 240 }; |
| 241 |
| 242 /** |
| 243 * The set of capabilities negotiated between the client and host. |
| 244 * @type {Array.<string>} |
| 245 * @private |
| 246 */ |
| 247 remoting.ClientSession.prototype.capabilities_ = null; |
| 248 |
| 249 /** |
| 250 * @param {remoting.ClientSession.Capability} capability The capability to test |
| 251 * for. |
| 252 * @return {boolean} True if the capability has been negotiated between |
| 253 * the client and host. |
| 254 * @private |
| 255 */ |
| 256 remoting.ClientSession.prototype.hasCapability_ = function(capability) { |
| 257 if (this.capabilities_ == null) |
| 258 return false; |
| 259 |
| 260 return this.capabilities_.indexOf(capability) > -1; |
| 261 }; |
| 262 |
| 263 /** |
231 * @param {Element} container The element to add the plugin to. | 264 * @param {Element} container The element to add the plugin to. |
232 * @param {string} id Id to use for the plugin element . | 265 * @param {string} id Id to use for the plugin element . |
233 * @return {remoting.ClientPlugin} Create plugin object for the locally | 266 * @return {remoting.ClientPlugin} Create plugin object for the locally |
234 * installed plugin. | 267 * installed plugin. |
235 */ | 268 */ |
236 remoting.ClientSession.prototype.createClientPlugin_ = function(container, id) { | 269 remoting.ClientSession.prototype.createClientPlugin_ = function(container, id) { |
237 var plugin = /** @type {remoting.ViewerPlugin} */ | 270 var plugin = /** @type {remoting.ViewerPlugin} */ |
238 document.createElement('embed'); | 271 document.createElement('embed'); |
239 | 272 |
240 plugin.id = id; | 273 plugin.id = id; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 this.plugin.onDebugMessageHandler = function(msg) { | 395 this.plugin.onDebugMessageHandler = function(msg) { |
363 console.log('plugin: ' + msg); | 396 console.log('plugin: ' + msg); |
364 }; | 397 }; |
365 | 398 |
366 this.plugin.onConnectionStatusUpdateHandler = | 399 this.plugin.onConnectionStatusUpdateHandler = |
367 this.onConnectionStatusUpdate_.bind(this); | 400 this.onConnectionStatusUpdate_.bind(this); |
368 this.plugin.onConnectionReadyHandler = | 401 this.plugin.onConnectionReadyHandler = |
369 this.onConnectionReady_.bind(this); | 402 this.onConnectionReady_.bind(this); |
370 this.plugin.onDesktopSizeUpdateHandler = | 403 this.plugin.onDesktopSizeUpdateHandler = |
371 this.onDesktopSizeChanged_.bind(this); | 404 this.onDesktopSizeChanged_.bind(this); |
| 405 this.plugin.onSetCapabilitiesHandler = |
| 406 this.onSetCapabilities_.bind(this); |
372 | 407 |
373 this.connectPluginToWcs_(); | 408 this.connectPluginToWcs_(); |
374 }; | 409 }; |
375 | 410 |
376 /** | 411 /** |
377 * Deletes the <embed> element from the container, without sending a | 412 * Deletes the <embed> element from the container, without sending a |
378 * session_terminate request. This is to be called when the session was | 413 * session_terminate request. This is to be called when the session was |
379 * disconnected by the Host. | 414 * disconnected by the Host. |
380 * | 415 * |
381 * @return {void} Nothing. | 416 * @return {void} Nothing. |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 */ | 789 */ |
755 remoting.ClientSession.prototype.onConnectionReady_ = function(ready) { | 790 remoting.ClientSession.prototype.onConnectionReady_ = function(ready) { |
756 if (!ready) { | 791 if (!ready) { |
757 this.plugin.element().classList.add("session-client-inactive"); | 792 this.plugin.element().classList.add("session-client-inactive"); |
758 } else { | 793 } else { |
759 this.plugin.element().classList.remove("session-client-inactive"); | 794 this.plugin.element().classList.remove("session-client-inactive"); |
760 } | 795 } |
761 } | 796 } |
762 | 797 |
763 /** | 798 /** |
| 799 * Called when the client-host capabilities negotiation is complete. |
| 800 * |
| 801 * @param {!Array.<string>} capabilities The set of capabilities negotiated |
| 802 * between the client and host. |
| 803 * @return {void} Nothing. |
| 804 * @private |
| 805 */ |
| 806 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { |
| 807 if (this.capabilities_ != null) { |
| 808 console.error('onSetCapabilities_() is called more than once'); |
| 809 return; |
| 810 } |
| 811 |
| 812 this.capabilities_ = capabilities; |
| 813 if (this.hasCapability_( |
| 814 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION)) { |
| 815 this.plugin.notifyClientResolution(window.innerWidth, |
| 816 window.innerHeight, |
| 817 window.devicePixelRatio); |
| 818 } |
| 819 }; |
| 820 |
| 821 /** |
764 * @private | 822 * @private |
765 * @param {remoting.ClientSession.State} newState The new state for the session. | 823 * @param {remoting.ClientSession.State} newState The new state for the session. |
766 * @return {void} Nothing. | 824 * @return {void} Nothing. |
767 */ | 825 */ |
768 remoting.ClientSession.prototype.setState_ = function(newState) { | 826 remoting.ClientSession.prototype.setState_ = function(newState) { |
769 var oldState = this.state; | 827 var oldState = this.state; |
770 this.state = newState; | 828 this.state = newState; |
771 var state = this.state; | 829 var state = this.state; |
772 if (oldState == remoting.ClientSession.State.CONNECTING) { | 830 if (oldState == remoting.ClientSession.State.CONNECTING) { |
773 if (this.state == remoting.ClientSession.State.CLOSED) { | 831 if (this.state == remoting.ClientSession.State.CLOSED) { |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 var lateAdjustment = 1 + (now - expected) / timeout; | 1188 var lateAdjustment = 1 + (now - expected) / timeout; |
1131 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { | 1189 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { |
1132 that.bumpScrollTimer_ = window.setTimeout( | 1190 that.bumpScrollTimer_ = window.setTimeout( |
1133 function() { repeatScroll(now + timeout); }, | 1191 function() { repeatScroll(now + timeout); }, |
1134 timeout); | 1192 timeout); |
1135 } | 1193 } |
1136 }; | 1194 }; |
1137 repeatScroll(new Date().getTime()); | 1195 repeatScroll(new Date().getTime()); |
1138 } | 1196 } |
1139 }; | 1197 }; |
OLD | NEW |