OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 * Connect set-up state machine for Me2Me and IT2Me | 7 * Connect set-up state machine for Me2Me and IT2Me |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 /** | 100 /** |
101 * A timer that polls for an updated access token. | 101 * A timer that polls for an updated access token. |
102 * | 102 * |
103 * @type {number} | 103 * @type {number} |
104 * @private | 104 * @private |
105 */ | 105 */ |
106 this.wcsAccessTokenRefreshTimer_ = 0; | 106 this.wcsAccessTokenRefreshTimer_ = 0; |
107 | 107 |
108 /** | 108 /** |
| 109 * Function to interactively obtain the PIN from the user. |
| 110 * @param {function(string):void} onPinFetched Called when the PIN is fetched. |
| 111 * @private |
| 112 */ |
| 113 this.fetchPin_ = function(onPinFetched) {}; |
| 114 |
| 115 /** |
109 * Host 'name', as displayed in the client tool-bar. For a Me2Me connection, | 116 * Host 'name', as displayed in the client tool-bar. For a Me2Me connection, |
110 * this is the name of the host; for an IT2Me connection, it is the email | 117 * this is the name of the host; for an IT2Me connection, it is the email |
111 * address of the person sharing their computer. | 118 * address of the person sharing their computer. |
112 * | 119 * |
113 * @type {string} | 120 * @type {string} |
114 * @private | 121 * @private |
115 */ | 122 */ |
116 this.hostDisplayName_ = ''; | 123 this.hostDisplayName_ = ''; |
117 | 124 |
118 // Pre-load WCS to improve connection time. | 125 // Pre-load WCS to improve connection time. |
119 remoting.identity.callWithToken(this.loadWcs_.bind(this), this.onError_); | 126 remoting.identity.callWithToken(this.loadWcs_.bind(this), this.onError_); |
120 }; | 127 }; |
121 | 128 |
122 /** | 129 /** |
123 * Initiate a Me2Me connection. | 130 * Initiate a Me2Me connection. |
124 * | 131 * |
125 * @param {remoting.Host} host The Me2Me host to which to connect. | 132 * @param {remoting.Host} host The Me2Me host to which to connect. |
126 * @param {string} pin The PIN as entered by the user. | 133 * @param {function(function(string):void):void} fetchPin Function to |
| 134 * interactively obtain the PIN from the user. |
127 * @return {void} Nothing. | 135 * @return {void} Nothing. |
128 */ | 136 */ |
129 remoting.SessionConnector.prototype.connectMe2Me = function(host, pin) { | 137 remoting.SessionConnector.prototype.connectMe2Me = function(host, fetchPin) { |
130 this.hostId_ = host.hostId; | 138 this.hostId_ = host.hostId; |
131 this.hostJid_ = host.jabberId; | 139 this.hostJid_ = host.jabberId; |
132 this.passPhrase_ = pin; | 140 this.fetchPin_ = fetchPin; |
133 this.hostDisplayName_ = host.hostName; | 141 this.hostDisplayName_ = host.hostName; |
134 this.createSessionIfReady_(); | 142 this.createSessionIfReady_(); |
135 }; | 143 }; |
136 | 144 |
137 /** | 145 /** |
138 * Initiate an IT2Me connection. | 146 * Initiate an IT2Me connection. |
139 * | 147 * |
140 * @param {string} accessCode The access code as entered by the user. | 148 * @param {string} accessCode The access code as entered by the user. |
141 * @return {void} Nothing. | 149 * @return {void} Nothing. |
142 */ | 150 */ |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 * @return {void} Nothing. | 269 * @return {void} Nothing. |
262 * @private | 270 * @private |
263 */ | 271 */ |
264 remoting.SessionConnector.prototype.createSessionIfReady_ = function() { | 272 remoting.SessionConnector.prototype.createSessionIfReady_ = function() { |
265 if (!this.clientJid_ || !this.hostJid_) { | 273 if (!this.clientJid_ || !this.hostJid_) { |
266 return; | 274 return; |
267 } | 275 } |
268 | 276 |
269 var securityTypes = 'spake2_hmac,spake2_plain'; | 277 var securityTypes = 'spake2_hmac,spake2_plain'; |
270 this.clientSession_ = new remoting.ClientSession( | 278 this.clientSession_ = new remoting.ClientSession( |
271 this.hostJid_, this.clientJid_, this.hostPublicKey_, | 279 this.hostJid_, this.clientJid_, this.hostPublicKey_, this.passPhrase_, |
272 this.passPhrase_, securityTypes, this.hostId_, | 280 this.fetchPin_, securityTypes, this.hostId_, this.connectionMode_, |
273 this.connectionMode_, this.hostDisplayName_); | 281 this.hostDisplayName_); |
274 this.clientSession_.logHostOfflineErrors(!this.refreshHostJidIfOffline_); | 282 this.clientSession_.logHostOfflineErrors(!this.refreshHostJidIfOffline_); |
275 this.clientSession_.setOnStateChange(this.onStateChange_.bind(this)); | 283 this.clientSession_.setOnStateChange(this.onStateChange_.bind(this)); |
276 this.clientSession_.createPluginAndConnect(this.pluginParent_); | 284 this.clientSession_.createPluginAndConnect(this.pluginParent_); |
277 }; | 285 }; |
278 | 286 |
279 /** | 287 /** |
280 * Handle a change in the state of the client session prior to successful | 288 * Handle a change in the state of the client session prior to successful |
281 * connection (after connection, this class no longer handles state change | 289 * connection (after connection, this class no longer handles state change |
282 * events). Errors that occur while connecting either trigger a reconnect | 290 * events). Errors that occur while connecting either trigger a reconnect |
283 * or notify the onError handler. | 291 * or notify the onError handler. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 361 |
354 /** | 362 /** |
355 * @param {boolean} success True if the host list was successfully refreshed; | 363 * @param {boolean} success True if the host list was successfully refreshed; |
356 * false if an error occurred. | 364 * false if an error occurred. |
357 * @private | 365 * @private |
358 */ | 366 */ |
359 remoting.SessionConnector.prototype.onHostListRefresh_ = function(success) { | 367 remoting.SessionConnector.prototype.onHostListRefresh_ = function(success) { |
360 if (success) { | 368 if (success) { |
361 var host = remoting.hostList.getHostForId(this.hostId_); | 369 var host = remoting.hostList.getHostForId(this.hostId_); |
362 if (host) { | 370 if (host) { |
363 this.connectMe2Me(host, this.passPhrase_); | 371 this.connectMe2Me(host, this.fetchPin_); |
364 return; | 372 return; |
365 } | 373 } |
366 } | 374 } |
367 this.onError_(remoting.Error.HOST_IS_OFFLINE); | 375 this.onError_(remoting.Error.HOST_IS_OFFLINE); |
368 }; | 376 }; |
369 | 377 |
370 /** | 378 /** |
371 * Start a timer to periodically refresh the access token used by WCS. Access | 379 * Start a timer to periodically refresh the access token used by WCS. Access |
372 * tokens have a limited lifespan, and since the WCS driver runs in a sandbox, | 380 * tokens have a limited lifespan, and since the WCS driver runs in a sandbox, |
373 * it can't obtain a new one directly. | 381 * it can't obtain a new one directly. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 /** | 424 /** |
417 * Normalize the access code entered by the user. | 425 * Normalize the access code entered by the user. |
418 * | 426 * |
419 * @param {string} accessCode The access code, as entered by the user. | 427 * @param {string} accessCode The access code, as entered by the user. |
420 * @return {string} The normalized form of the code (whitespace removed). | 428 * @return {string} The normalized form of the code (whitespace removed). |
421 */ | 429 */ |
422 remoting.SessionConnector.prototype.normalizeAccessCode_ = | 430 remoting.SessionConnector.prototype.normalizeAccessCode_ = |
423 function(accessCode) { | 431 function(accessCode) { |
424 // Trim whitespace. | 432 // Trim whitespace. |
425 return accessCode.replace(/\s/g, ''); | 433 return accessCode.replace(/\s/g, ''); |
426 }; | 434 }; |
OLD | NEW |