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 ALWAYS_RESIZE_TO_CLIENT: 'alwaysResizeToClient' | |
237 }; | |
238 | |
239 /** | |
240 * The set of capabilities negotiated between the client and host. | |
241 * @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.
| |
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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 if (event.target == this.shrinkToFitButton_) { | 586 if (event.target == this.shrinkToFitButton_) { |
555 shrinkToFit = !shrinkToFit; | 587 shrinkToFit = !shrinkToFit; |
556 } | 588 } |
557 if (event.target == this.resizeToClientButton_) { | 589 if (event.target == this.resizeToClientButton_) { |
558 resizeToClient = !resizeToClient; | 590 resizeToClient = !resizeToClient; |
559 } | 591 } |
560 this.setScreenMode_(shrinkToFit, resizeToClient); | 592 this.setScreenMode_(shrinkToFit, resizeToClient); |
561 }; | 593 }; |
562 | 594 |
563 /** | 595 /** |
596 * @return {boolean} True if resize-to-client is enabled. | |
597 * @private | |
598 */ | |
599 remoting.ClientSession.prototype.isResizingToClient_ = function() { | |
600 return this.resizeToClient_ || this.hasCapability_( | |
601 remoting.ClientSession.Capability.ALWAYS_RESIZE_TO_CLIENT); | |
602 } | |
603 | |
604 /** | |
564 * Set the shrink-to-fit and resize-to-client flags and save them if this is | 605 * Set the shrink-to-fit and resize-to-client flags and save them if this is |
565 * a Me2Me connection. | 606 * a Me2Me connection. |
566 * | 607 * |
567 * @param {boolean} shrinkToFit True if the remote desktop should be scaled | 608 * @param {boolean} shrinkToFit True if the remote desktop should be scaled |
568 * down if it is larger than the client window; false if scroll-bars | 609 * down if it is larger than the client window; false if scroll-bars |
569 * should be added in this case. | 610 * should be added in this case. |
570 * @param {boolean} resizeToClient True if window resizes should cause the | 611 * @param {boolean} resizeToClient True if window resizes should cause the |
571 * host to attempt to resize its desktop to match the client window size; | 612 * host to attempt to resize its desktop to match the client window size; |
572 * false to disable this behaviour for subsequent window resizes--the | 613 * false to disable this behaviour for subsequent window resizes--the |
573 * current host desktop size is not restored in this case. | 614 * current host desktop size is not restored in this case. |
574 * @return {void} Nothing. | 615 * @return {void} Nothing. |
575 * @private | 616 * @private |
576 */ | 617 */ |
577 remoting.ClientSession.prototype.setScreenMode_ = | 618 remoting.ClientSession.prototype.setScreenMode_ = |
578 function(shrinkToFit, resizeToClient) { | 619 function(shrinkToFit, resizeToClient) { |
579 if (resizeToClient && !this.resizeToClient_) { | 620 if (resizeToClient && !this.isResizingToClient_()) { |
580 this.plugin.notifyClientResolution(window.innerWidth, | 621 this.plugin.notifyClientResolution(window.innerWidth, |
581 window.innerHeight, | 622 window.innerHeight, |
582 window.devicePixelRatio); | 623 window.devicePixelRatio); |
583 } | 624 } |
584 | 625 |
585 // If enabling shrink, reset bump-scroll offsets. | 626 // If enabling shrink, reset bump-scroll offsets. |
586 var needsScrollReset = shrinkToFit && !this.shrinkToFit_; | 627 var needsScrollReset = shrinkToFit && !this.shrinkToFit_; |
587 | 628 |
588 this.shrinkToFit_ = shrinkToFit; | 629 this.shrinkToFit_ = shrinkToFit; |
589 this.resizeToClient_ = resizeToClient; | 630 this.resizeToClient_ = resizeToClient; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
727 * | 768 * |
728 * @private | 769 * @private |
729 * @param {number} status The plugin's status. | 770 * @param {number} status The plugin's status. |
730 * @param {number} error The plugin's error state, if any. | 771 * @param {number} error The plugin's error state, if any. |
731 */ | 772 */ |
732 remoting.ClientSession.prototype.onConnectionStatusUpdate_ = | 773 remoting.ClientSession.prototype.onConnectionStatusUpdate_ = |
733 function(status, error) { | 774 function(status, error) { |
734 if (status == remoting.ClientSession.State.CONNECTED) { | 775 if (status == remoting.ClientSession.State.CONNECTED) { |
735 this.setFocusHandlers_(); | 776 this.setFocusHandlers_(); |
736 this.onDesktopSizeChanged_(); | 777 this.onDesktopSizeChanged_(); |
737 if (this.resizeToClient_) { | 778 if (this.isResizingToClient_()) { |
738 this.plugin.notifyClientResolution(window.innerWidth, | 779 this.plugin.notifyClientResolution(window.innerWidth, |
739 window.innerHeight, | 780 window.innerHeight, |
740 window.devicePixelRatio); | 781 window.devicePixelRatio); |
741 } | 782 } |
742 } else if (status == remoting.ClientSession.State.FAILED) { | 783 } else if (status == remoting.ClientSession.State.FAILED) { |
743 this.error_ = /** @type {remoting.ClientSession.ConnectionError} */ (error); | 784 this.error_ = /** @type {remoting.ClientSession.ConnectionError} */ (error); |
744 } | 785 } |
745 this.setState_(/** @type {remoting.ClientSession.State} */ (status)); | 786 this.setState_(/** @type {remoting.ClientSession.State} */ (status)); |
746 }; | 787 }; |
747 | 788 |
748 /** | 789 /** |
749 * Callback that the plugin invokes to indicate when the connection is | 790 * Callback that the plugin invokes to indicate when the connection is |
750 * ready. | 791 * ready. |
751 * | 792 * |
752 * @private | 793 * @private |
753 * @param {boolean} ready True if the connection is ready. | 794 * @param {boolean} ready True if the connection is ready. |
754 */ | 795 */ |
755 remoting.ClientSession.prototype.onConnectionReady_ = function(ready) { | 796 remoting.ClientSession.prototype.onConnectionReady_ = function(ready) { |
756 if (!ready) { | 797 if (!ready) { |
757 this.plugin.element().classList.add("session-client-inactive"); | 798 this.plugin.element().classList.add("session-client-inactive"); |
758 } else { | 799 } else { |
759 this.plugin.element().classList.remove("session-client-inactive"); | 800 this.plugin.element().classList.remove("session-client-inactive"); |
760 } | 801 } |
761 } | 802 } |
762 | 803 |
763 /** | 804 /** |
805 * This is a callback that gets called when the plugin report capabilities | |
806 * negotiated with the host. | |
807 * | |
808 * @param {Array.<string>} capabilities The set of capabilities negotiated | |
809 * between the client and host. | |
810 * @return {void} Nothing. | |
811 * @private | |
812 */ | |
813 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { | |
814 if (this.capabilities_ != null) { | |
815 console.error('ERROR: onSetCapabilities_() is called more than once'); | |
816 return; | |
817 } | |
818 | |
819 this.capabilities_ = capabilities; | |
820 if (this.isResizingToClient_()) { | |
821 this.onDesktopSizeChanged_(); | |
822 this.plugin.notifyClientResolution(window.innerWidth, | |
823 window.innerHeight, | |
824 window.devicePixelRatio); | |
825 } | |
826 }; | |
827 | |
828 /** | |
764 * @private | 829 * @private |
765 * @param {remoting.ClientSession.State} newState The new state for the session. | 830 * @param {remoting.ClientSession.State} newState The new state for the session. |
766 * @return {void} Nothing. | 831 * @return {void} Nothing. |
767 */ | 832 */ |
768 remoting.ClientSession.prototype.setState_ = function(newState) { | 833 remoting.ClientSession.prototype.setState_ = function(newState) { |
769 var oldState = this.state; | 834 var oldState = this.state; |
770 this.state = newState; | 835 this.state = newState; |
771 var state = this.state; | 836 var state = this.state; |
772 if (oldState == remoting.ClientSession.State.CONNECTING) { | 837 if (oldState == remoting.ClientSession.State.CONNECTING) { |
773 if (this.state == remoting.ClientSession.State.CLOSED) { | 838 if (this.state == remoting.ClientSession.State.CLOSED) { |
(...skipping 24 matching lines...) Expand all Loading... | |
798 remoting.ClientSession.prototype.onResize = function() { | 863 remoting.ClientSession.prototype.onResize = function() { |
799 this.updateDimensions(); | 864 this.updateDimensions(); |
800 | 865 |
801 if (this.notifyClientResolutionTimer_) { | 866 if (this.notifyClientResolutionTimer_) { |
802 window.clearTimeout(this.notifyClientResolutionTimer_); | 867 window.clearTimeout(this.notifyClientResolutionTimer_); |
803 this.notifyClientResolutionTimer_ = null; | 868 this.notifyClientResolutionTimer_ = null; |
804 } | 869 } |
805 | 870 |
806 // Defer notifying the host of the change until the window stops resizing, to | 871 // Defer notifying the host of the change until the window stops resizing, to |
807 // avoid overloading the control channel with notifications. | 872 // avoid overloading the control channel with notifications. |
808 if (this.resizeToClient_) { | 873 if (this.isResizingToClient_()) { |
809 this.notifyClientResolutionTimer_ = window.setTimeout( | 874 this.notifyClientResolutionTimer_ = window.setTimeout( |
810 this.plugin.notifyClientResolution.bind(this.plugin, | 875 this.plugin.notifyClientResolution.bind(this.plugin, |
811 window.innerWidth, | 876 window.innerWidth, |
812 window.innerHeight, | 877 window.innerHeight, |
813 window.devicePixelRatio), | 878 window.devicePixelRatio), |
814 1000); | 879 1000); |
815 } | 880 } |
816 | 881 |
817 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize | 882 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize |
818 // the new window area. | 883 // the new window area. |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1130 var lateAdjustment = 1 + (now - expected) / timeout; | 1195 var lateAdjustment = 1 + (now - expected) / timeout; |
1131 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { | 1196 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { |
1132 that.bumpScrollTimer_ = window.setTimeout( | 1197 that.bumpScrollTimer_ = window.setTimeout( |
1133 function() { repeatScroll(now + timeout); }, | 1198 function() { repeatScroll(now + timeout); }, |
1134 timeout); | 1199 timeout); |
1135 } | 1200 } |
1136 }; | 1201 }; |
1137 repeatScroll(new Date().getTime()); | 1202 repeatScroll(new Date().getTime()); |
1138 } | 1203 } |
1139 }; | 1204 }; |
OLD | NEW |