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 SEND_INITIAL_RESOLUTION: 'sendInitialResolution' | |
Jamie
2013/04/15 23:40:23
These capabilities should be commented somewhere.
alexeypa (please no reviews)
2013/04/15 23:56:31
Done.
| |
237 }; | |
238 | |
239 /** | |
240 * The set of capabilities negotiated between the client and host. | |
241 * @type {Array.<string>} | |
242 * @private | |
243 */ | |
244 remoting.ClientSession.prototype.capabilities_ = null; | |
245 | |
246 /** | |
247 * @param {remoting.ClientSession.Capability} capability The capability to test | |
248 * for. | |
249 * @return {boolean} True if the capability has been negotiated between | |
250 * the client and host. | |
251 * @private | |
252 */ | |
253 remoting.ClientSession.prototype.hasCapability_ = function(capability) { | |
254 if (this.capabilities_ == null) | |
255 return false; | |
256 | |
257 return this.capabilities_.indexOf(capability) > -1; | |
258 }; | |
259 | |
260 /** | |
231 * @param {Element} container The element to add the plugin to. | 261 * @param {Element} container The element to add the plugin to. |
232 * @param {string} id Id to use for the plugin element . | 262 * @param {string} id Id to use for the plugin element . |
233 * @return {remoting.ClientPlugin} Create plugin object for the locally | 263 * @return {remoting.ClientPlugin} Create plugin object for the locally |
234 * installed plugin. | 264 * installed plugin. |
235 */ | 265 */ |
236 remoting.ClientSession.prototype.createClientPlugin_ = function(container, id) { | 266 remoting.ClientSession.prototype.createClientPlugin_ = function(container, id) { |
237 var plugin = /** @type {remoting.ViewerPlugin} */ | 267 var plugin = /** @type {remoting.ViewerPlugin} */ |
238 document.createElement('embed'); | 268 document.createElement('embed'); |
239 | 269 |
240 plugin.id = id; | 270 plugin.id = id; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 this.plugin.onDebugMessageHandler = function(msg) { | 392 this.plugin.onDebugMessageHandler = function(msg) { |
363 console.log('plugin: ' + msg); | 393 console.log('plugin: ' + msg); |
364 }; | 394 }; |
365 | 395 |
366 this.plugin.onConnectionStatusUpdateHandler = | 396 this.plugin.onConnectionStatusUpdateHandler = |
367 this.onConnectionStatusUpdate_.bind(this); | 397 this.onConnectionStatusUpdate_.bind(this); |
368 this.plugin.onConnectionReadyHandler = | 398 this.plugin.onConnectionReadyHandler = |
369 this.onConnectionReady_.bind(this); | 399 this.onConnectionReady_.bind(this); |
370 this.plugin.onDesktopSizeUpdateHandler = | 400 this.plugin.onDesktopSizeUpdateHandler = |
371 this.onDesktopSizeChanged_.bind(this); | 401 this.onDesktopSizeChanged_.bind(this); |
402 this.plugin.onSetCapabilitiesHandler = | |
403 this.onSetCapabilities_.bind(this); | |
372 | 404 |
373 this.connectPluginToWcs_(); | 405 this.connectPluginToWcs_(); |
374 }; | 406 }; |
375 | 407 |
376 /** | 408 /** |
377 * Deletes the <embed> element from the container, without sending a | 409 * Deletes the <embed> element from the container, without sending a |
378 * session_terminate request. This is to be called when the session was | 410 * session_terminate request. This is to be called when the session was |
379 * disconnected by the Host. | 411 * disconnected by the Host. |
380 * | 412 * |
381 * @return {void} Nothing. | 413 * @return {void} Nothing. |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 */ | 786 */ |
755 remoting.ClientSession.prototype.onConnectionReady_ = function(ready) { | 787 remoting.ClientSession.prototype.onConnectionReady_ = function(ready) { |
756 if (!ready) { | 788 if (!ready) { |
757 this.plugin.element().classList.add("session-client-inactive"); | 789 this.plugin.element().classList.add("session-client-inactive"); |
758 } else { | 790 } else { |
759 this.plugin.element().classList.remove("session-client-inactive"); | 791 this.plugin.element().classList.remove("session-client-inactive"); |
760 } | 792 } |
761 } | 793 } |
762 | 794 |
763 /** | 795 /** |
796 * This is a callback that gets called when the plugin report capabilities | |
797 * negotiated with the host. | |
Jamie
2013/04/15 23:40:23
This could be more simply phrased: "Called when th
alexeypa (please no reviews)
2013/04/15 23:56:31
Done.
| |
798 * | |
799 * @param {!Array.<string>} capabilities The set of capabilities negotiated | |
800 * between the client and host. | |
801 * @return {void} Nothing. | |
802 * @private | |
803 */ | |
804 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { | |
805 if (this.capabilities_ != null) { | |
806 console.error('ERROR: onSetCapabilities_() is called more than once'); | |
Jamie
2013/04/15 23:40:23
Nit: No need for ERROR--the console shows errors i
alexeypa (please no reviews)
2013/04/15 23:56:31
Done.
| |
807 return; | |
808 } | |
809 | |
810 this.capabilities_ = capabilities; | |
811 if (this.hasCapability_( | |
812 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION)) { | |
813 this.plugin.notifyClientResolution(window.innerWidth, | |
814 window.innerHeight, | |
815 window.devicePixelRatio); | |
816 } | |
817 }; | |
818 | |
819 /** | |
764 * @private | 820 * @private |
765 * @param {remoting.ClientSession.State} newState The new state for the session. | 821 * @param {remoting.ClientSession.State} newState The new state for the session. |
766 * @return {void} Nothing. | 822 * @return {void} Nothing. |
767 */ | 823 */ |
768 remoting.ClientSession.prototype.setState_ = function(newState) { | 824 remoting.ClientSession.prototype.setState_ = function(newState) { |
769 var oldState = this.state; | 825 var oldState = this.state; |
770 this.state = newState; | 826 this.state = newState; |
771 var state = this.state; | 827 var state = this.state; |
772 if (oldState == remoting.ClientSession.State.CONNECTING) { | 828 if (oldState == remoting.ClientSession.State.CONNECTING) { |
773 if (this.state == remoting.ClientSession.State.CLOSED) { | 829 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; | 1186 var lateAdjustment = 1 + (now - expected) / timeout; |
1131 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { | 1187 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { |
1132 that.bumpScrollTimer_ = window.setTimeout( | 1188 that.bumpScrollTimer_ = window.setTimeout( |
1133 function() { repeatScroll(now + timeout); }, | 1189 function() { repeatScroll(now + timeout); }, |
1134 timeout); | 1190 timeout); |
1135 } | 1191 } |
1136 }; | 1192 }; |
1137 repeatScroll(new Date().getTime()); | 1193 repeatScroll(new Date().getTime()); |
1138 } | 1194 } |
1139 }; | 1195 }; |
OLD | NEW |