| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 */ | 111 */ |
| 112 this.clientSession_ = null; | 112 this.clientSession_ = null; |
| 113 | 113 |
| 114 /** | 114 /** |
| 115 * @type {XMLHttpRequest} | 115 * @type {XMLHttpRequest} |
| 116 * @private | 116 * @private |
| 117 */ | 117 */ |
| 118 this.pendingXhr_ = null; | 118 this.pendingXhr_ = null; |
| 119 | 119 |
| 120 /** | 120 /** |
| 121 * Function to interactively obtain the PIN from the user. | 121 * @type {function(function(string):void): void} |
| 122 * @type {function(function(string):void):void} | |
| 123 * @private | 122 * @private |
| 124 */ | 123 */ |
| 125 this.fetchPin_ = function(onPinFetched) {}; | 124 this.fetchPin_ = function(onPinFetched) {}; |
| 126 | 125 |
| 127 /** | 126 /** |
| 127 * @type {function(string, string, function(string, string):void): void} |
| 128 * @private |
| 129 */ |
| 130 this.fetchThirdPartyToken_ = function( |
| 131 tokenUrl, scope, onThirdPartyTokenFetched) {}; |
| 132 |
| 133 /** |
| 128 * Host 'name', as displayed in the client tool-bar. For a Me2Me connection, | 134 * Host 'name', as displayed in the client tool-bar. For a Me2Me connection, |
| 129 * this is the name of the host; for an IT2Me connection, it is the email | 135 * this is the name of the host; for an IT2Me connection, it is the email |
| 130 * address of the person sharing their computer. | 136 * address of the person sharing their computer. |
| 131 * | 137 * |
| 132 * @type {string} | 138 * @type {string} |
| 133 * @private | 139 * @private |
| 134 */ | 140 */ |
| 135 this.hostDisplayName_ = ''; | 141 this.hostDisplayName_ = ''; |
| 136 }; | 142 }; |
| 137 | 143 |
| 138 /** | 144 /** |
| 139 * Initiate a Me2Me connection. | 145 * Initiate a Me2Me connection. |
| 140 * | 146 * |
| 141 * @param {remoting.Host} host The Me2Me host to which to connect. | 147 * @param {remoting.Host} host The Me2Me host to which to connect. |
| 142 * @param {function(function(string):void):void} fetchPin Function to | 148 * @param {function(function(string):void):void} fetchPin Function to |
| 143 * interactively obtain the PIN from the user. | 149 * interactively obtain the PIN from the user. |
| 150 * @param {function(string, string, function(string, string): void): void} |
| 151 * fetchThirdPartyToken Function to obtain a token from a third party |
| 152 * authenticaiton server. |
| 144 * @return {void} Nothing. | 153 * @return {void} Nothing. |
| 145 */ | 154 */ |
| 146 remoting.SessionConnector.prototype.connectMe2Me = function(host, fetchPin) { | 155 remoting.SessionConnector.prototype.connectMe2Me = function( |
| 156 host, fetchPin, fetchThirdPartyToken) { |
| 147 // Cancel any existing connect operation. | 157 // Cancel any existing connect operation. |
| 148 this.cancel(); | 158 this.cancel(); |
| 149 | 159 |
| 150 this.hostId_ = host.hostId; | 160 this.hostId_ = host.hostId; |
| 151 this.hostJid_ = host.jabberId; | 161 this.hostJid_ = host.jabberId; |
| 162 this.hostPublicKey_ = host.publicKey; |
| 152 this.fetchPin_ = fetchPin; | 163 this.fetchPin_ = fetchPin; |
| 164 this.fetchThirdPartyToken_ = fetchThirdPartyToken; |
| 153 this.hostDisplayName_ = host.hostName; | 165 this.hostDisplayName_ = host.hostName; |
| 154 this.connectionMode_ = remoting.ClientSession.Mode.ME2ME; | 166 this.connectionMode_ = remoting.ClientSession.Mode.ME2ME; |
| 155 this.createSessionIfReady_(); | 167 this.createSessionIfReady_(); |
| 156 }; | 168 }; |
| 157 | 169 |
| 158 /** | 170 /** |
| 159 * Initiate an IT2Me connection. | 171 * Initiate an IT2Me connection. |
| 160 * | 172 * |
| 161 * @param {string} accessCode The access code as entered by the user. | 173 * @param {string} accessCode The access code as entered by the user. |
| 162 * @return {void} Nothing. | 174 * @return {void} Nothing. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 * If both the client and host JIDs are available, create a session and connect. | 304 * If both the client and host JIDs are available, create a session and connect. |
| 293 * | 305 * |
| 294 * @return {void} Nothing. | 306 * @return {void} Nothing. |
| 295 * @private | 307 * @private |
| 296 */ | 308 */ |
| 297 remoting.SessionConnector.prototype.createSessionIfReady_ = function() { | 309 remoting.SessionConnector.prototype.createSessionIfReady_ = function() { |
| 298 if (!this.clientJid_ || !this.hostJid_) { | 310 if (!this.clientJid_ || !this.hostJid_) { |
| 299 return; | 311 return; |
| 300 } | 312 } |
| 301 | 313 |
| 302 var securityTypes = 'spake2_hmac,spake2_plain'; | 314 var securityTypes = 'third_party,spake2_hmac,spake2_plain'; |
| 303 this.clientSession_ = new remoting.ClientSession( | 315 this.clientSession_ = new remoting.ClientSession( |
| 304 this.hostJid_, this.clientJid_, this.hostPublicKey_, this.passPhrase_, | 316 this.hostJid_, this.clientJid_, this.hostPublicKey_, this.passPhrase_, |
| 305 this.fetchPin_, securityTypes, this.hostId_, this.connectionMode_, | 317 this.fetchPin_, this.fetchThirdPartyToken_, securityTypes, this.hostId_, |
| 306 this.hostDisplayName_); | 318 this.connectionMode_, this.hostDisplayName_); |
| 307 this.clientSession_.logHostOfflineErrors(!this.refreshHostJidIfOffline_); | 319 this.clientSession_.logHostOfflineErrors(!this.refreshHostJidIfOffline_); |
| 308 this.clientSession_.setOnStateChange(this.onStateChange_.bind(this)); | 320 this.clientSession_.setOnStateChange(this.onStateChange_.bind(this)); |
| 309 this.clientSession_.createPluginAndConnect(this.pluginParent_); | 321 this.clientSession_.createPluginAndConnect(this.pluginParent_); |
| 310 }; | 322 }; |
| 311 | 323 |
| 312 /** | 324 /** |
| 313 * Handle a change in the state of the client session prior to successful | 325 * Handle a change in the state of the client session prior to successful |
| 314 * connection (after connection, this class no longer handles state change | 326 * connection (after connection, this class no longer handles state change |
| 315 * events). Errors that occur while connecting either trigger a reconnect | 327 * events). Errors that occur while connecting either trigger a reconnect |
| 316 * or notify the onError handler. | 328 * or notify the onError handler. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 398 |
| 387 /** | 399 /** |
| 388 * @param {boolean} success True if the host list was successfully refreshed; | 400 * @param {boolean} success True if the host list was successfully refreshed; |
| 389 * false if an error occurred. | 401 * false if an error occurred. |
| 390 * @private | 402 * @private |
| 391 */ | 403 */ |
| 392 remoting.SessionConnector.prototype.onHostListRefresh_ = function(success) { | 404 remoting.SessionConnector.prototype.onHostListRefresh_ = function(success) { |
| 393 if (success) { | 405 if (success) { |
| 394 var host = remoting.hostList.getHostForId(this.hostId_); | 406 var host = remoting.hostList.getHostForId(this.hostId_); |
| 395 if (host) { | 407 if (host) { |
| 396 this.connectMe2Me(host, this.fetchPin_); | 408 this.connectMe2Me(host, this.fetchPin_, this.fetchThirdPartyToken_); |
| 397 return; | 409 return; |
| 398 } | 410 } |
| 399 } | 411 } |
| 400 this.onError_(remoting.Error.HOST_IS_OFFLINE); | 412 this.onError_(remoting.Error.HOST_IS_OFFLINE); |
| 401 }; | 413 }; |
| 402 | 414 |
| 403 /** | 415 /** |
| 404 * Start a timer to periodically refresh the access token used by WCS. Access | 416 * Start a timer to periodically refresh the access token used by WCS. Access |
| 405 * tokens have a limited lifespan, and since the WCS driver runs in a sandbox, | 417 * tokens have a limited lifespan, and since the WCS driver runs in a sandbox, |
| 406 * it can't obtain a new one directly. | 418 * it can't obtain a new one directly. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 * Normalize the access code entered by the user. | 462 * Normalize the access code entered by the user. |
| 451 * | 463 * |
| 452 * @param {string} accessCode The access code, as entered by the user. | 464 * @param {string} accessCode The access code, as entered by the user. |
| 453 * @return {string} The normalized form of the code (whitespace removed). | 465 * @return {string} The normalized form of the code (whitespace removed). |
| 454 */ | 466 */ |
| 455 remoting.SessionConnector.prototype.normalizeAccessCode_ = | 467 remoting.SessionConnector.prototype.normalizeAccessCode_ = |
| 456 function(accessCode) { | 468 function(accessCode) { |
| 457 // Trim whitespace. | 469 // Trim whitespace. |
| 458 return accessCode.replace(/\s/g, ''); | 470 return accessCode.replace(/\s/g, ''); |
| 459 }; | 471 }; |
| OLD | NEW |