| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 this.plugin.onDebugMessageHandler = function(msg) { | 368 this.plugin.onDebugMessageHandler = function(msg) { |
| 363 console.log('plugin: ' + msg); | 369 console.log('plugin: ' + msg); |
| 364 }; | 370 }; |
| 365 | 371 |
| 366 this.plugin.onConnectionStatusUpdateHandler = | 372 this.plugin.onConnectionStatusUpdateHandler = |
| 367 this.onConnectionStatusUpdate_.bind(this); | 373 this.onConnectionStatusUpdate_.bind(this); |
| 368 this.plugin.onConnectionReadyHandler = | 374 this.plugin.onConnectionReadyHandler = |
| 369 this.onConnectionReady_.bind(this); | 375 this.onConnectionReady_.bind(this); |
| 370 this.plugin.onDesktopSizeUpdateHandler = | 376 this.plugin.onDesktopSizeUpdateHandler = |
| 371 this.onDesktopSizeChanged_.bind(this); | 377 this.onDesktopSizeChanged_.bind(this); |
| 372 | |
| 373 this.connectPluginToWcs_(); | 378 this.connectPluginToWcs_(); |
| 374 }; | 379 }; |
| 375 | 380 |
| 376 /** | 381 /** |
| 377 * Deletes the <embed> element from the container, without sending a | 382 * Deletes the <embed> element from the container, without sending a |
| 378 * session_terminate request. This is to be called when the session was | 383 * session_terminate request. This is to be called when the session was |
| 379 * disconnected by the Host. | 384 * disconnected by the Host. |
| 380 * | 385 * |
| 381 * @return {void} Nothing. | 386 * @return {void} Nothing. |
| 382 */ | 387 */ |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 } catch (err) { | 684 } catch (err) { |
| 680 // Pass message as is when it is malformed. | 685 // Pass message as is when it is malformed. |
| 681 } | 686 } |
| 682 | 687 |
| 683 console.log(remoting.timestamp(), | 688 console.log(remoting.timestamp(), |
| 684 remoting.formatIq.prettifyReceiveIq(stanza)); | 689 remoting.formatIq.prettifyReceiveIq(stanza)); |
| 685 forwardIq(stanza); | 690 forwardIq(stanza); |
| 686 }; | 691 }; |
| 687 remoting.wcsSandbox.setOnIq(onIncomingIq); | 692 remoting.wcsSandbox.setOnIq(onIncomingIq); |
| 688 | 693 |
| 694 /** @type remoting.ClientSession */ |
| 695 var that = this; |
| 696 if (plugin.hasFeature(remoting.ClientPlugin.Feature.THIRD_PARTY_AUTH)) { |
| 697 /** @type{function(string, string): void} */ |
| 698 var fetchThirdPartyToken = function(tokenUrl, scope) { |
| 699 that.fetchThirdPartyToken_( |
| 700 tokenUrl, scope, plugin.onThirdPartyTokenFetched.bind(plugin)); |
| 701 }; |
| 702 plugin.fetchThirdPartyTokenHandler = fetchThirdPartyToken; |
| 703 } |
| 689 if (this.accessCode_) { | 704 if (this.accessCode_) { |
| 690 // Shared secret was already supplied before connecting (It2Me case). | 705 // Shared secret was already supplied before connecting (It2Me case). |
| 691 this.connectToHost_(this.accessCode_); | 706 this.connectToHost_(this.accessCode_); |
| 692 | |
| 693 } else if (plugin.hasFeature( | 707 } else if (plugin.hasFeature( |
| 694 remoting.ClientPlugin.Feature.ASYNC_PIN)) { | 708 remoting.ClientPlugin.Feature.ASYNC_PIN)) { |
| 695 // Plugin supports asynchronously asking for the PIN. | 709 // Plugin supports asynchronously asking for the PIN. |
| 696 plugin.useAsyncPinDialog(); | 710 plugin.useAsyncPinDialog(); |
| 697 /** @type remoting.ClientSession */ | |
| 698 var that = this; | |
| 699 var fetchPin = function() { | 711 var fetchPin = function() { |
| 700 that.fetchPin_(plugin.onPinFetched.bind(plugin)); | 712 that.fetchPin_(plugin.onPinFetched.bind(plugin)); |
| 701 }; | 713 }; |
| 702 plugin.fetchPinHandler = fetchPin; | 714 plugin.fetchPinHandler = fetchPin; |
| 703 this.connectToHost_(''); | 715 this.connectToHost_(''); |
| 704 | |
| 705 } else { | 716 } else { |
| 706 // Plugin doesn't support asynchronously asking for the PIN, ask now. | 717 // Plugin doesn't support asynchronously asking for the PIN, ask now. |
| 707 this.fetchPin_(this.connectToHost_.bind(this)); | 718 this.fetchPin_(this.connectToHost_.bind(this)); |
| 708 } | 719 } |
| 709 }; | 720 }; |
| 710 | 721 |
| 711 /** | 722 /** |
| 712 * Connects to the host. | 723 * Connects to the host. |
| 713 * | 724 * |
| 714 * @param {string} sharedSecret Shared secret for SPAKE negotiation. | 725 * @param {string} sharedSecret Shared secret for SPAKE negotiation. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 * | 762 * |
| 752 * @private | 763 * @private |
| 753 * @param {boolean} ready True if the connection is ready. | 764 * @param {boolean} ready True if the connection is ready. |
| 754 */ | 765 */ |
| 755 remoting.ClientSession.prototype.onConnectionReady_ = function(ready) { | 766 remoting.ClientSession.prototype.onConnectionReady_ = function(ready) { |
| 756 if (!ready) { | 767 if (!ready) { |
| 757 this.plugin.element().classList.add("session-client-inactive"); | 768 this.plugin.element().classList.add("session-client-inactive"); |
| 758 } else { | 769 } else { |
| 759 this.plugin.element().classList.remove("session-client-inactive"); | 770 this.plugin.element().classList.remove("session-client-inactive"); |
| 760 } | 771 } |
| 761 } | 772 }; |
| 762 | 773 |
| 763 /** | 774 /** |
| 764 * @private | 775 * @private |
| 765 * @param {remoting.ClientSession.State} newState The new state for the session. | 776 * @param {remoting.ClientSession.State} newState The new state for the session. |
| 766 * @return {void} Nothing. | 777 * @return {void} Nothing. |
| 767 */ | 778 */ |
| 768 remoting.ClientSession.prototype.setState_ = function(newState) { | 779 remoting.ClientSession.prototype.setState_ = function(newState) { |
| 769 var oldState = this.state; | 780 var oldState = this.state; |
| 770 this.state = newState; | 781 this.state = newState; |
| 771 var state = this.state; | 782 var state = this.state; |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 var lateAdjustment = 1 + (now - expected) / timeout; | 1141 var lateAdjustment = 1 + (now - expected) / timeout; |
| 1131 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { | 1142 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { |
| 1132 that.bumpScrollTimer_ = window.setTimeout( | 1143 that.bumpScrollTimer_ = window.setTimeout( |
| 1133 function() { repeatScroll(now + timeout); }, | 1144 function() { repeatScroll(now + timeout); }, |
| 1134 timeout); | 1145 timeout); |
| 1135 } | 1146 } |
| 1136 }; | 1147 }; |
| 1137 repeatScroll(new Date().getTime()); | 1148 repeatScroll(new Date().getTime()); |
| 1138 } | 1149 } |
| 1139 }; | 1150 }; |
| OLD | NEW |