| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 */ | 97 */ |
| 98 this.pendingXhr_ = null; | 98 this.pendingXhr_ = null; |
| 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 * @type {number} | 102 * @type {number} |
| 103 * @private | 103 * @private |
| 104 */ | 104 */ |
| 105 this.wcsAccessTokenRefreshTimer_ = 0; | 105 this.wcsAccessTokenRefreshTimer_ = 0; |
| 106 | 106 |
| 107 /** |
| 108 * Function to interactively obtain the PIN from the user. |
| 109 * @param {function(string):void} onPinFetched Called when the PIN is fetched. |
| 110 * @private |
| 111 */ |
| 112 this.fetchPin_ = function(onPinFetched) {}; |
| 113 |
| 107 // Pre-load WCS to improve connection time. | 114 // Pre-load WCS to improve connection time. |
| 108 remoting.identity.callWithToken(this.loadWcs_.bind(this), this.onError_); | 115 remoting.identity.callWithToken(this.loadWcs_.bind(this), this.onError_); |
| 109 }; | 116 }; |
| 110 | 117 |
| 111 /** | 118 /** |
| 112 * Initiate a Me2Me connection. | 119 * Initiate a Me2Me connection. |
| 113 * | 120 * |
| 114 * @param {remoting.Host} host The Me2Me host to which to connect. | 121 * @param {remoting.Host} host The Me2Me host to which to connect. |
| 115 * @param {string} pin The PIN as entered by the user. | 122 * @param {function(function(string):void):void} fetchPin Function to |
| 123 * interactively obtain the PIN from the user. |
| 116 * @return {void} Nothing. | 124 * @return {void} Nothing. |
| 117 */ | 125 */ |
| 118 remoting.SessionConnector.prototype.connectMe2Me = function(host, pin) { | 126 remoting.SessionConnector.prototype.connectMe2Me = function(host, fetchPin) { |
| 119 this.hostId_ = host.hostId; | 127 this.hostId_ = host.hostId; |
| 120 this.hostJid_ = host.jabberId; | 128 this.hostJid_ = host.jabberId; |
| 121 this.passPhrase_ = pin; | 129 this.fetchPin_ = fetchPin; |
| 122 this.createSessionIfReady_(); | 130 this.createSessionIfReady_(); |
| 123 }; | 131 }; |
| 124 | 132 |
| 125 /** | 133 /** |
| 126 * Initiate an IT2Me connection. | 134 * Initiate an IT2Me connection. |
| 127 * | 135 * |
| 128 * @param {string} accessCode The access code as entered by the user. | 136 * @param {string} accessCode The access code as entered by the user. |
| 129 * @return {void} Nothing. | 137 * @return {void} Nothing. |
| 130 */ | 138 */ |
| 131 remoting.SessionConnector.prototype.connectIT2Me = function(accessCode) { | 139 remoting.SessionConnector.prototype.connectIT2Me = function(accessCode) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 * @return {void} Nothing. | 256 * @return {void} Nothing. |
| 249 * @private | 257 * @private |
| 250 */ | 258 */ |
| 251 remoting.SessionConnector.prototype.createSessionIfReady_ = function() { | 259 remoting.SessionConnector.prototype.createSessionIfReady_ = function() { |
| 252 if (!this.clientJid_ || !this.hostJid_) { | 260 if (!this.clientJid_ || !this.hostJid_) { |
| 253 return; | 261 return; |
| 254 } | 262 } |
| 255 | 263 |
| 256 var securityTypes = 'spake2_hmac,spake2_plain'; | 264 var securityTypes = 'spake2_hmac,spake2_plain'; |
| 257 this.clientSession_ = new remoting.ClientSession( | 265 this.clientSession_ = new remoting.ClientSession( |
| 258 this.hostJid_, this.clientJid_, this.hostPublicKey_, | 266 this.hostJid_, this.clientJid_, this.hostPublicKey_, this.passPhrase_, |
| 259 this.passPhrase_, securityTypes, this.hostId_, | 267 this.fetchPin_, securityTypes, this.hostId_, this.connectionMode_); |
| 260 this.connectionMode_); | |
| 261 this.clientSession_.logHostOfflineErrors(!this.refreshHostJidIfOffline_); | 268 this.clientSession_.logHostOfflineErrors(!this.refreshHostJidIfOffline_); |
| 262 this.clientSession_.setOnStateChange(this.onStateChange_.bind(this)); | 269 this.clientSession_.setOnStateChange(this.onStateChange_.bind(this)); |
| 263 this.clientSession_.createPluginAndConnect(this.pluginParent_); | 270 this.clientSession_.createPluginAndConnect(this.pluginParent_); |
| 264 }; | 271 }; |
| 265 | 272 |
| 266 /** | 273 /** |
| 267 * Handle a change in the state of the client session prior to successful | 274 * Handle a change in the state of the client session prior to successful |
| 268 * connection (after connection, this class no longer handles state change | 275 * connection (after connection, this class no longer handles state change |
| 269 * events). Errors that occur while connecting either trigger a reconnect | 276 * events). Errors that occur while connecting either trigger a reconnect |
| 270 * or notify the onError handler. | 277 * or notify the onError handler. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 347 |
| 341 /** | 348 /** |
| 342 * @param {boolean} success True if the host list was successfully refreshed; | 349 * @param {boolean} success True if the host list was successfully refreshed; |
| 343 * false if an error occurred. | 350 * false if an error occurred. |
| 344 * @private | 351 * @private |
| 345 */ | 352 */ |
| 346 remoting.SessionConnector.prototype.onHostListRefresh_ = function(success) { | 353 remoting.SessionConnector.prototype.onHostListRefresh_ = function(success) { |
| 347 if (success) { | 354 if (success) { |
| 348 var host = remoting.hostList.getHostForId(this.hostId_); | 355 var host = remoting.hostList.getHostForId(this.hostId_); |
| 349 if (host) { | 356 if (host) { |
| 350 this.connectMe2Me(host, this.passPhrase_); | 357 this.connectMe2Me(host, this.fetchPin_); |
| 351 return; | 358 return; |
| 352 } | 359 } |
| 353 } | 360 } |
| 354 this.onError_(remoting.Error.HOST_IS_OFFLINE); | 361 this.onError_(remoting.Error.HOST_IS_OFFLINE); |
| 355 }; | 362 }; |
| 356 | 363 |
| 357 /** | 364 /** |
| 358 * Start a timer to periodically refresh the access token used by WCS. Access | 365 * Start a timer to periodically refresh the access token used by WCS. Access |
| 359 * tokens have a limited lifespan, and since the WCS driver runs in a sandbox, | 366 * tokens have a limited lifespan, and since the WCS driver runs in a sandbox, |
| 360 * it can't obtain a new one directly. | 367 * it can't obtain a new one directly. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 /** | 410 /** |
| 404 * Normalize the access code entered by the user. | 411 * Normalize the access code entered by the user. |
| 405 * | 412 * |
| 406 * @param {string} accessCode The access code, as entered by the user. | 413 * @param {string} accessCode The access code, as entered by the user. |
| 407 * @return {string} The normalized form of the code (whitespace removed). | 414 * @return {string} The normalized form of the code (whitespace removed). |
| 408 */ | 415 */ |
| 409 remoting.SessionConnector.prototype.normalizeAccessCode_ = | 416 remoting.SessionConnector.prototype.normalizeAccessCode_ = |
| 410 function(accessCode) { | 417 function(accessCode) { |
| 411 // Trim whitespace. | 418 // Trim whitespace. |
| 412 return accessCode.replace(/\s/g, ''); | 419 return accessCode.replace(/\s/g, ''); |
| 413 }; | 420 }; |
| OLD | NEW |