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 |
11 * establish connection. Specifically it: | 11 * establish connection. Specifically it: |
12 * - Delivers incoming/outgoing signaling messages, | 12 * - Delivers incoming/outgoing signaling messages, |
13 * - Adjusts plugin size and position when destop resolution changes, | 13 * - Adjusts plugin size and position when destop resolution changes, |
14 * | 14 * |
15 * This class should not access the plugin directly, instead it should | 15 * This class should not access the plugin directly, instead it should |
16 * do it through ClientPlugin class which abstracts plugin version | 16 * do it through ClientPlugin class which abstracts plugin version |
17 * differences. | 17 * differences. |
18 */ | 18 */ |
19 | 19 |
20 'use strict'; | 20 'use strict'; |
21 | 21 |
22 /** @suppress {duplicate} */ | 22 /** @suppress {duplicate} */ |
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} sharedSecret The access code for IT2Me or the PIN | 30 * @param {string} passPhrase The pre-determined pass phrase for connection. |
Jamie
2013/03/18 20:28:23
I think it's worth keeping the style of the origin
rmsousa
2013/03/18 21:58:01
Done.
| |
31 * for Me2Me. | 31 * @param {function(function(string): void): void} fetchPin Called |
32 * when a PIN needs to be obtained interactively. | |
Jamie
2013/03/18 20:28:23
I think we should be consistent with referring to
rmsousa
2013/03/18 21:58:01
I tried to differentiate between a user-generated
| |
32 * @param {string} authenticationMethods Comma-separated list of | 33 * @param {string} authenticationMethods Comma-separated list of |
33 * authentication methods the client should attempt to use. | 34 * authentication methods the client should attempt to use. |
34 * @param {string} hostId The host identifier for Me2Me, or empty for IT2Me. | 35 * @param {string} hostId The host identifier for Me2Me, or empty for IT2Me. |
35 * Mixed into authentication hashes for some authentication methods. | 36 * Mixed into authentication hashes for some authentication methods. |
36 * @param {remoting.ClientSession.Mode} mode The mode of this connection. | 37 * @param {remoting.ClientSession.Mode} mode The mode of this connection. |
37 * @constructor | 38 * @constructor |
38 */ | 39 */ |
39 remoting.ClientSession = function(hostJid, clientJid, | 40 remoting.ClientSession = function(hostJid, clientJid, |
40 hostPublicKey, sharedSecret, | 41 hostPublicKey, passPhrase, |
42 fetchPin, | |
Jamie
2013/03/18 20:28:23
Nit: I'm not sure what the intended line-break sch
rmsousa
2013/03/18 21:58:01
Done.
| |
41 authenticationMethods, hostId, mode) { | 43 authenticationMethods, hostId, mode) { |
42 this.state = remoting.ClientSession.State.CREATED; | 44 this.state = remoting.ClientSession.State.CREATED; |
43 | 45 |
44 this.hostJid = hostJid; | 46 this.hostJid = hostJid; |
45 this.clientJid = clientJid; | 47 this.clientJid = clientJid; |
46 this.hostPublicKey = hostPublicKey; | 48 this.hostPublicKey = hostPublicKey; |
47 this.sharedSecret = sharedSecret; | 49 this.passPhrase_ = passPhrase; |
50 this.fetchPin_ = fetchPin; | |
Jamie
2013/03/18 20:28:23
Please add @private annotations to these members.
rmsousa
2013/03/18 21:58:01
Done.
| |
48 this.authenticationMethods = authenticationMethods; | 51 this.authenticationMethods = authenticationMethods; |
49 this.hostId = hostId; | 52 this.hostId = hostId; |
50 /** @type {remoting.ClientSession.Mode} */ | 53 /** @type {remoting.ClientSession.Mode} */ |
51 this.mode = mode; | 54 this.mode = mode; |
52 this.sessionId = ''; | 55 this.sessionId = ''; |
53 /** @type {remoting.ClientPlugin} */ | 56 /** @type {remoting.ClientPlugin} */ |
54 this.plugin = null; | 57 this.plugin = null; |
55 /** @private */ | 58 /** @private */ |
56 this.shrinkToFit_ = true; | 59 this.shrinkToFit_ = true; |
57 /** @private */ | 60 /** @private */ |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 this.resizeToClient_ = /** @type {boolean} */ | 286 this.resizeToClient_ = /** @type {boolean} */ |
284 options[remoting.ClientSession.KEY_RESIZE_TO_CLIENT]; | 287 options[remoting.ClientSession.KEY_RESIZE_TO_CLIENT]; |
285 } | 288 } |
286 if (remoting.ClientSession.KEY_SHRINK_TO_FIT in options && | 289 if (remoting.ClientSession.KEY_SHRINK_TO_FIT in options && |
287 typeof(options[remoting.ClientSession.KEY_SHRINK_TO_FIT]) == | 290 typeof(options[remoting.ClientSession.KEY_SHRINK_TO_FIT]) == |
288 'boolean') { | 291 'boolean') { |
289 this.shrinkToFit_ = /** @type {boolean} */ | 292 this.shrinkToFit_ = /** @type {boolean} */ |
290 options[remoting.ClientSession.KEY_SHRINK_TO_FIT]; | 293 options[remoting.ClientSession.KEY_SHRINK_TO_FIT]; |
291 } | 294 } |
292 | 295 |
293 this.plugin.element().focus(); | |
294 | |
295 /** @param {boolean} result */ | 296 /** @param {boolean} result */ |
296 this.plugin.initialize(this.onPluginInitialized_.bind(this)); | 297 this.plugin.initialize(this.onPluginInitialized_.bind(this)); |
298 }; | |
299 | |
300 /** | |
301 * Constrains the focus to the plugin element. | |
Jamie
2013/03/18 20:28:23
Add @private
rmsousa
2013/03/18 21:58:01
Done.
| |
302 */ | |
303 remoting.ClientSession.prototype.setFocusHandlers_ = function() { | |
297 this.plugin.element().addEventListener( | 304 this.plugin.element().addEventListener( |
298 'focus', this.callPluginGotFocus_, false); | 305 'focus', this.callPluginGotFocus_, false); |
299 this.plugin.element().addEventListener( | 306 this.plugin.element().addEventListener( |
300 'blur', this.callPluginLostFocus_, false); | 307 'blur', this.callPluginLostFocus_, false); |
308 this.plugin.element().focus(); | |
301 }; | 309 }; |
302 | 310 |
303 /** | 311 /** |
304 * @param {boolean} initialized | 312 * @param {boolean} initialized |
305 */ | 313 */ |
306 remoting.ClientSession.prototype.onPluginInitialized_ = function(initialized) { | 314 remoting.ClientSession.prototype.onPluginInitialized_ = function(initialized) { |
307 if (!initialized) { | 315 if (!initialized) { |
308 console.error('ERROR: remoting plugin not loaded'); | 316 console.error('ERROR: remoting plugin not loaded'); |
309 this.plugin.cleanup(); | 317 this.plugin.cleanup(); |
310 delete this.plugin; | 318 delete this.plugin; |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 }; | 589 }; |
582 | 590 |
583 /** | 591 /** |
584 * Connects the plugin to WCS. | 592 * Connects the plugin to WCS. |
585 * | 593 * |
586 * @private | 594 * @private |
587 * @return {void} Nothing. | 595 * @return {void} Nothing. |
588 */ | 596 */ |
589 remoting.ClientSession.prototype.connectPluginToWcs_ = function() { | 597 remoting.ClientSession.prototype.connectPluginToWcs_ = function() { |
590 remoting.formatIq.setJids(this.clientJid, this.hostJid); | 598 remoting.formatIq.setJids(this.clientJid, this.hostJid); |
599 /** @type remoting.ClientPlugin */ | |
Jamie
2013/03/18 20:28:23
Brackets around the type, please.
rmsousa
2013/03/18 21:58:01
Done.
| |
591 var plugin = this.plugin; | 600 var plugin = this.plugin; |
592 var forwardIq = plugin.onIncomingIq.bind(plugin); | 601 var forwardIq = plugin.onIncomingIq.bind(plugin); |
593 /** @param {string} stanza The IQ stanza received. */ | 602 /** @param {string} stanza The IQ stanza received. */ |
594 var onIncomingIq = function(stanza) { | 603 var onIncomingIq = function(stanza) { |
595 // HACK: Remove 'x' prefix added to the id in sendIq_(). | 604 // HACK: Remove 'x' prefix added to the id in sendIq_(). |
596 try { | 605 try { |
597 var parser = new DOMParser(); | 606 var parser = new DOMParser(); |
598 var iqNode = parser.parseFromString(stanza, 'text/xml').firstChild; | 607 var iqNode = parser.parseFromString(stanza, 'text/xml').firstChild; |
599 var type = iqNode.getAttribute('type'); | 608 var type = iqNode.getAttribute('type'); |
600 var id = iqNode.getAttribute('id'); | 609 var id = iqNode.getAttribute('id'); |
601 if (type != 'set' && id.charAt(0) == 'x') { | 610 if (type != 'set' && id.charAt(0) == 'x') { |
602 iqNode.setAttribute('id', id.substr(1)); | 611 iqNode.setAttribute('id', id.substr(1)); |
603 stanza = (new XMLSerializer()).serializeToString(iqNode); | 612 stanza = (new XMLSerializer()).serializeToString(iqNode); |
604 } | 613 } |
605 } catch (err) { | 614 } catch (err) { |
606 // Pass message as is when it is malformed. | 615 // Pass message as is when it is malformed. |
607 } | 616 } |
608 | 617 |
609 console.log(remoting.timestamp(), | 618 console.log(remoting.timestamp(), |
610 remoting.formatIq.prettifyReceiveIq(stanza)); | 619 remoting.formatIq.prettifyReceiveIq(stanza)); |
611 forwardIq(stanza); | 620 forwardIq(stanza); |
612 } | 621 } |
613 remoting.wcsSandbox.setOnIq(onIncomingIq); | 622 remoting.wcsSandbox.setOnIq(onIncomingIq); |
Jamie
2013/03/18 20:28:23
Blank line here, please.
rmsousa
2013/03/18 21:58:01
Done.
| |
623 // Pass phrase was already supplied before connecting (It2Me case). | |
Jamie
2013/03/18 20:28:23
Can you move this comment inside the if, for consi
rmsousa
2013/03/18 21:58:01
Done.
| |
624 if (this.passPhrase_) { | |
625 this.connectToHost_(this.passPhrase_); | |
626 } else if (plugin.hasFeature( | |
627 remoting.ClientPlugin.Feature.USE_ASYNC_PIN_DIALOG)) { | |
628 // Plugin supports asynchronously asking for passphrase. | |
629 plugin.useAsyncPinDialog(); | |
630 /** @type remoting.ClientSession */ | |
631 var that = this; | |
632 var fetchPin = function() { | |
633 that.fetchPin_(plugin.onPinFetched.bind(plugin)); | |
634 }; | |
635 plugin.fetchPinHandler = fetchPin; | |
636 this.connectToHost_(''); | |
637 } else { | |
638 // Plugin doesn't support asynchronously asking for passphrase, ask now. | |
639 this.fetchPin_(this.connectToHost_.bind(this)); | |
640 } | |
641 }; | |
642 | |
643 /** | |
644 * Connects to the host. | |
645 * | |
646 * @private | |
Jamie
2013/03/18 20:28:23
Nit: We're pretty consistent about @private being
rmsousa
2013/03/18 21:58:01
Done.
| |
647 * @param {string} sharedSecret Shared secret for SPAKE negotiation. | |
648 * @return {void} Nothing. | |
649 */ | |
650 remoting.ClientSession.prototype.connectToHost_ = function(sharedSecret) { | |
614 this.plugin.connect(this.hostJid, this.hostPublicKey, this.clientJid, | 651 this.plugin.connect(this.hostJid, this.hostPublicKey, this.clientJid, |
615 this.sharedSecret, this.authenticationMethods, | 652 sharedSecret, this.authenticationMethods, |
616 this.hostId); | 653 this.hostId); |
617 }; | 654 }; |
618 | 655 |
619 /** | 656 /** |
620 * Callback that the plugin invokes to indicate that the connection | 657 * Callback that the plugin invokes to indicate that the connection |
621 * status has changed. | 658 * status has changed. |
622 * | 659 * |
623 * @private | 660 * @private |
624 * @param {number} status The plugin's status. | 661 * @param {number} status The plugin's status. |
625 * @param {number} error The plugin's error state, if any. | 662 * @param {number} error The plugin's error state, if any. |
626 */ | 663 */ |
627 remoting.ClientSession.prototype.onConnectionStatusUpdate_ = | 664 remoting.ClientSession.prototype.onConnectionStatusUpdate_ = |
628 function(status, error) { | 665 function(status, error) { |
629 if (status == remoting.ClientSession.State.CONNECTED) { | 666 if (status == remoting.ClientSession.State.CONNECTED) { |
667 this.setFocusHandlers_(); | |
630 this.onDesktopSizeChanged_(); | 668 this.onDesktopSizeChanged_(); |
631 if (this.resizeToClient_) { | 669 if (this.resizeToClient_) { |
632 this.plugin.notifyClientResolution(window.innerWidth, | 670 this.plugin.notifyClientResolution(window.innerWidth, |
633 window.innerHeight, | 671 window.innerHeight, |
634 window.devicePixelRatio); | 672 window.devicePixelRatio); |
635 } | 673 } |
636 } else if (status == remoting.ClientSession.State.FAILED) { | 674 } else if (status == remoting.ClientSession.State.FAILED) { |
637 this.error_ = /** @type {remoting.ClientSession.ConnectionError} */ (error); | 675 this.error_ = /** @type {remoting.ClientSession.ConnectionError} */ (error); |
638 } | 676 } |
639 this.setState_(/** @type {remoting.ClientSession.State} */ (status)); | 677 this.setState_(/** @type {remoting.ClientSession.State} */ (status)); |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 var lateAdjustment = 1 + (now - expected) / timeout; | 1059 var lateAdjustment = 1 + (now - expected) / timeout; |
1022 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { | 1060 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { |
1023 that.bumpScrollTimer_ = window.setTimeout( | 1061 that.bumpScrollTimer_ = window.setTimeout( |
1024 function() { repeatScroll(now + timeout); }, | 1062 function() { repeatScroll(now + timeout); }, |
1025 timeout); | 1063 timeout); |
1026 } | 1064 } |
1027 }; | 1065 }; |
1028 repeatScroll(new Date().getTime()); | 1066 repeatScroll(new Date().getTime()); |
1029 } | 1067 } |
1030 }; | 1068 }; |
OLD | NEW |