| 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 12 matching lines...) Expand all Loading... |
| 23 var remoting = remoting || {}; | 23 var remoting = remoting || {}; |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * @param {string} hostJid The jid of the host to connect to. | 26 * @param {string} hostJid The jid of the host to connect to. |
| 27 * @param {string} clientJid The jid of the WCS client. | 27 * @param {string} clientJid The jid of the WCS client. |
| 28 * @param {string} hostPublicKey The base64 encoded version of the host's | 28 * @param {string} hostPublicKey The base64 encoded version of the host's |
| 29 * public key. | 29 * public key. |
| 30 * @param {string} accessCode The IT2Me access code. Blank for Me2Me. | 30 * @param {string} accessCode The IT2Me access code. Blank for Me2Me. |
| 31 * @param {function(function(string): void): void} fetchPin Called by Me2Me | 31 * @param {function(function(string): void): void} fetchPin Called by Me2Me |
| 32 * connections when a PIN needs to be obtained interactively. | 32 * connections when a PIN needs to be obtained interactively. |
| 33 * @param {function(string, string, function(string, string): void): void} |
| 34 * fetchThirdPartyToken Called by Me2Me connections when a third party |
| 35 * authentication token must be obtained. |
| 33 * @param {string} authenticationMethods Comma-separated list of | 36 * @param {string} authenticationMethods Comma-separated list of |
| 34 * authentication methods the client should attempt to use. | 37 * authentication methods the client should attempt to use. |
| 35 * @param {string} hostId The host identifier for Me2Me, or empty for IT2Me. | 38 * @param {string} hostId The host identifier for Me2Me, or empty for IT2Me. |
| 36 * Mixed into authentication hashes for some authentication methods. | 39 * Mixed into authentication hashes for some authentication methods. |
| 37 * @param {remoting.ClientSession.Mode} mode The mode of this connection. | 40 * @param {remoting.ClientSession.Mode} mode The mode of this connection. |
| 38 * @param {string} hostDisplayName The name of the host for display purposes. | 41 * @param {string} hostDisplayName The name of the host for display purposes. |
| 39 * @constructor | 42 * @constructor |
| 40 */ | 43 */ |
| 41 remoting.ClientSession = function(hostJid, clientJid, hostPublicKey, accessCode, | 44 remoting.ClientSession = function(hostJid, clientJid, hostPublicKey, accessCode, |
| 42 fetchPin, authenticationMethods, hostId, | 45 fetchPin, fetchThirdPartyToken, |
| 46 authenticationMethods, hostId, |
| 43 mode, hostDisplayName) { | 47 mode, hostDisplayName) { |
| 44 this.state = remoting.ClientSession.State.CREATED; | 48 this.state = remoting.ClientSession.State.CREATED; |
| 45 | 49 |
| 46 this.hostJid = hostJid; | 50 this.hostJid = hostJid; |
| 47 this.clientJid = clientJid; | 51 this.clientJid = clientJid; |
| 48 this.hostPublicKey = hostPublicKey; | 52 this.hostPublicKey = hostPublicKey; |
| 49 /** @private */ | 53 /** @private */ |
| 50 this.accessCode_ = accessCode; | 54 this.accessCode_ = accessCode; |
| 51 /** @private */ | 55 /** @private */ |
| 52 this.fetchPin_ = fetchPin; | 56 this.fetchPin_ = fetchPin; |
| 57 /** @private */ |
| 58 this.fetchThirdPartyToken_ = fetchThirdPartyToken; |
| 53 this.authenticationMethods = authenticationMethods; | 59 this.authenticationMethods = authenticationMethods; |
| 54 this.hostId = hostId; | 60 this.hostId = hostId; |
| 55 /** @type {string} */ | 61 /** @type {string} */ |
| 56 this.hostDisplayName = hostDisplayName; | 62 this.hostDisplayName = hostDisplayName; |
| 57 /** @type {remoting.ClientSession.Mode} */ | 63 /** @type {remoting.ClientSession.Mode} */ |
| 58 this.mode = mode; | 64 this.mode = mode; |
| 59 this.sessionId = ''; | 65 this.sessionId = ''; |
| 60 /** @type {remoting.ClientPlugin} */ | 66 /** @type {remoting.ClientPlugin} */ |
| 61 this.plugin = null; | 67 this.plugin = null; |
| 62 /** @private */ | 68 /** @private */ |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 }; | 403 }; |
| 398 | 404 |
| 399 this.plugin.onConnectionStatusUpdateHandler = | 405 this.plugin.onConnectionStatusUpdateHandler = |
| 400 this.onConnectionStatusUpdate_.bind(this); | 406 this.onConnectionStatusUpdate_.bind(this); |
| 401 this.plugin.onConnectionReadyHandler = | 407 this.plugin.onConnectionReadyHandler = |
| 402 this.onConnectionReady_.bind(this); | 408 this.onConnectionReady_.bind(this); |
| 403 this.plugin.onDesktopSizeUpdateHandler = | 409 this.plugin.onDesktopSizeUpdateHandler = |
| 404 this.onDesktopSizeChanged_.bind(this); | 410 this.onDesktopSizeChanged_.bind(this); |
| 405 this.plugin.onSetCapabilitiesHandler = | 411 this.plugin.onSetCapabilitiesHandler = |
| 406 this.onSetCapabilities_.bind(this); | 412 this.onSetCapabilities_.bind(this); |
| 407 | |
| 408 this.connectPluginToWcs_(); | 413 this.connectPluginToWcs_(); |
| 409 }; | 414 }; |
| 410 | 415 |
| 411 /** | 416 /** |
| 412 * Deletes the <embed> element from the container, without sending a | 417 * Deletes the <embed> element from the container, without sending a |
| 413 * session_terminate request. This is to be called when the session was | 418 * session_terminate request. This is to be called when the session was |
| 414 * disconnected by the Host. | 419 * disconnected by the Host. |
| 415 * | 420 * |
| 416 * @return {void} Nothing. | 421 * @return {void} Nothing. |
| 417 */ | 422 */ |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 } catch (err) { | 719 } catch (err) { |
| 715 // Pass message as is when it is malformed. | 720 // Pass message as is when it is malformed. |
| 716 } | 721 } |
| 717 | 722 |
| 718 console.log(remoting.timestamp(), | 723 console.log(remoting.timestamp(), |
| 719 remoting.formatIq.prettifyReceiveIq(stanza)); | 724 remoting.formatIq.prettifyReceiveIq(stanza)); |
| 720 forwardIq(stanza); | 725 forwardIq(stanza); |
| 721 }; | 726 }; |
| 722 remoting.wcsSandbox.setOnIq(onIncomingIq); | 727 remoting.wcsSandbox.setOnIq(onIncomingIq); |
| 723 | 728 |
| 729 /** @type remoting.ClientSession */ |
| 730 var that = this; |
| 731 if (plugin.hasFeature(remoting.ClientPlugin.Feature.THIRD_PARTY_AUTH)) { |
| 732 /** @type{function(string, string, string): void} */ |
| 733 var fetchThirdPartyToken = function(tokenUrl, hostPublicKey, scope) { |
| 734 that.fetchThirdPartyToken_( |
| 735 tokenUrl, hostPublicKey, scope, |
| 736 plugin.onThirdPartyTokenFetched.bind(plugin)); |
| 737 }; |
| 738 plugin.fetchThirdPartyTokenHandler = fetchThirdPartyToken; |
| 739 } |
| 724 if (this.accessCode_) { | 740 if (this.accessCode_) { |
| 725 // Shared secret was already supplied before connecting (It2Me case). | 741 // Shared secret was already supplied before connecting (It2Me case). |
| 726 this.connectToHost_(this.accessCode_); | 742 this.connectToHost_(this.accessCode_); |
| 727 | |
| 728 } else if (plugin.hasFeature( | 743 } else if (plugin.hasFeature( |
| 729 remoting.ClientPlugin.Feature.ASYNC_PIN)) { | 744 remoting.ClientPlugin.Feature.ASYNC_PIN)) { |
| 730 // Plugin supports asynchronously asking for the PIN. | 745 // Plugin supports asynchronously asking for the PIN. |
| 731 plugin.useAsyncPinDialog(); | 746 plugin.useAsyncPinDialog(); |
| 732 /** @type remoting.ClientSession */ | |
| 733 var that = this; | |
| 734 var fetchPin = function() { | 747 var fetchPin = function() { |
| 735 that.fetchPin_(plugin.onPinFetched.bind(plugin)); | 748 that.fetchPin_(plugin.onPinFetched.bind(plugin)); |
| 736 }; | 749 }; |
| 737 plugin.fetchPinHandler = fetchPin; | 750 plugin.fetchPinHandler = fetchPin; |
| 738 this.connectToHost_(''); | 751 this.connectToHost_(''); |
| 739 | |
| 740 } else { | 752 } else { |
| 741 // Plugin doesn't support asynchronously asking for the PIN, ask now. | 753 // Plugin doesn't support asynchronously asking for the PIN, ask now. |
| 742 this.fetchPin_(this.connectToHost_.bind(this)); | 754 this.fetchPin_(this.connectToHost_.bind(this)); |
| 743 } | 755 } |
| 744 }; | 756 }; |
| 745 | 757 |
| 746 /** | 758 /** |
| 747 * Connects to the host. | 759 * Connects to the host. |
| 748 * | 760 * |
| 749 * @param {string} sharedSecret Shared secret for SPAKE negotiation. | 761 * @param {string} sharedSecret Shared secret for SPAKE negotiation. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 * | 798 * |
| 787 * @private | 799 * @private |
| 788 * @param {boolean} ready True if the connection is ready. | 800 * @param {boolean} ready True if the connection is ready. |
| 789 */ | 801 */ |
| 790 remoting.ClientSession.prototype.onConnectionReady_ = function(ready) { | 802 remoting.ClientSession.prototype.onConnectionReady_ = function(ready) { |
| 791 if (!ready) { | 803 if (!ready) { |
| 792 this.plugin.element().classList.add("session-client-inactive"); | 804 this.plugin.element().classList.add("session-client-inactive"); |
| 793 } else { | 805 } else { |
| 794 this.plugin.element().classList.remove("session-client-inactive"); | 806 this.plugin.element().classList.remove("session-client-inactive"); |
| 795 } | 807 } |
| 796 } | 808 }; |
| 797 | 809 |
| 798 /** | 810 /** |
| 799 * Called when the client-host capabilities negotiation is complete. | 811 * Called when the client-host capabilities negotiation is complete. |
| 800 * | 812 * |
| 801 * @param {!Array.<string>} capabilities The set of capabilities negotiated | 813 * @param {!Array.<string>} capabilities The set of capabilities negotiated |
| 802 * between the client and host. | 814 * between the client and host. |
| 803 * @return {void} Nothing. | 815 * @return {void} Nothing. |
| 804 * @private | 816 * @private |
| 805 */ | 817 */ |
| 806 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { | 818 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 var lateAdjustment = 1 + (now - expected) / timeout; | 1200 var lateAdjustment = 1 + (now - expected) / timeout; |
| 1189 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { | 1201 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { |
| 1190 that.bumpScrollTimer_ = window.setTimeout( | 1202 that.bumpScrollTimer_ = window.setTimeout( |
| 1191 function() { repeatScroll(now + timeout); }, | 1203 function() { repeatScroll(now + timeout); }, |
| 1192 timeout); | 1204 timeout); |
| 1193 } | 1205 } |
| 1194 }; | 1206 }; |
| 1195 repeatScroll(new Date().getTime()); | 1207 repeatScroll(new Date().getTime()); |
| 1196 } | 1208 } |
| 1197 }; | 1209 }; |
| OLD | NEW |