Chromium Code Reviews| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
| 8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
| 9 | 9 |
| 10 /** @constructor */ | 10 /** @constructor */ |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 } | 164 } |
| 165 }); | 165 }); |
| 166 var newHostId = base.generateUuid(); | 166 var newHostId = base.generateUuid(); |
| 167 var pinHashPromise = this.hostDaemonFacade_.getPinHash(newHostId, hostPin); | 167 var pinHashPromise = this.hostDaemonFacade_.getPinHash(newHostId, hostPin); |
| 168 | 168 |
| 169 /** @type {boolean} */ | 169 /** @type {boolean} */ |
| 170 var hostRegistered = false; | 170 var hostRegistered = false; |
| 171 | 171 |
| 172 // Register the host and extract an optional auth code from the host | 172 // Register the host and extract an optional auth code from the host |
| 173 // response. The absence of an auth code is represented by an empty | 173 // response. The absence of an auth code is represented by an empty |
| 174 // string. | 174 // string. |
|
Jamie
2015/04/27 23:24:24
Is this comment still correct?
John Williams
2015/04/28 20:27:40
Fixed.
| |
| 175 /** @type {!Promise<string>} */ | 175 /** @type {!Promise<remoting.HostListApi.RegisterResult>} */ |
| 176 var authCodePromise = Promise.all([ | 176 var regResultPromise = Promise.all([ |
| 177 hostClientIdPromise, | 177 hostClientIdPromise, |
| 178 hostNamePromise, | 178 hostNamePromise, |
| 179 keyPairPromise | 179 keyPairPromise |
| 180 ]).then(function(/** Array */ a) { | 180 ]).then(function(/** Array */ a) { |
| 181 var hostClientId = /** @type {string} */ (a[0]); | 181 var hostClientId = /** @type {string} */ (a[0]); |
| 182 var hostName = /** @type {string} */ (a[1]); | 182 var hostName = /** @type {string} */ (a[1]); |
| 183 var keyPair = /** @type {remoting.KeyPair} */ (a[2]); | 183 var keyPair = /** @type {remoting.KeyPair} */ (a[2]); |
| 184 | 184 |
| 185 return remoting.HostListApi.getInstance().register( | 185 return remoting.HostListApi.getInstance().register( |
| 186 newHostId, hostName, keyPair.publicKey, hostClientId); | 186 newHostId, hostName, keyPair.publicKey, hostClientId); |
| 187 }).then(function(/** string */ result) { | 187 }).then(function(/** remoting.HostListApi.RegisterResult */ result) { |
| 188 hostRegistered = true; | 188 hostRegistered = true; |
| 189 return result; | 189 return result; |
| 190 }); | 190 }); |
| 191 | 191 |
| 192 // Get XMPP creditials. | 192 // Get XMPP creditials. |
| 193 var xmppCredsPromise = authCodePromise.then(function(authCode) { | 193 var xmppCredsPromise = regResultPromise.then(function(regResult) { |
| 194 if (authCode) { | 194 if (regResult.authCode && regResult.email) { |
| 195 // Use auth code and email supplied by GCD. | |
| 196 return that.hostDaemonFacade_.getRefreshTokenFromAuthCode( | |
| 197 regResult.authCode).then(function(token) { | |
| 198 return { | |
| 199 userEmail: regResult.email, | |
| 200 refreshToken: token | |
| 201 }; | |
| 202 }); | |
| 203 } else if (regResult.authCode) { | |
| 195 // Use auth code supplied by Chromoting registry. | 204 // Use auth code supplied by Chromoting registry. |
| 196 return that.hostDaemonFacade_.getCredentialsFromAuthCode(authCode); | 205 return that.hostDaemonFacade_.getCredentialsFromAuthCode( |
| 206 regResult.authCode); | |
| 197 } else { | 207 } else { |
| 198 // No authorization code returned, use regular Chrome | 208 // No authorization code returned, use regular Chrome |
| 199 // identity credential flow. | 209 // identity credential flow. |
| 200 return remoting.identity.getEmail().then(function(/** string */ email) { | 210 return remoting.identity.getEmail().then(function(/** string */ email) { |
| 201 return { | 211 return { |
| 202 userEmail: email, | 212 userEmail: email, |
| 203 refreshToken: remoting.oauth2.getRefreshToken() | 213 refreshToken: remoting.oauth2.getRefreshToken() |
|
Jamie
2015/04/27 23:24:24
remoting.oauth2 is null for v2, so I think this sh
John Williams
2015/04/28 20:27:40
Done.
| |
| 204 }; | 214 }; |
| 205 }); | 215 }); |
| 206 } | 216 } |
| 207 }); | 217 }); |
| 208 | 218 |
| 209 // Get as JID to use as the host owner. | 219 // Get as JID to use as the host owner. |
| 210 var hostOwnerPromise = authCodePromise.then(function(authCode) { | 220 var hostOwnerPromise = regResultPromise.then(function(regResult) { |
| 211 if (authCode) { | 221 if (regResult.authCode && !regResult.email) { |
|
Jamie
2015/04/27 23:24:24
This doesn't look right. You're never using regRes
John Williams
2015/04/28 20:27:40
Done.
| |
| 212 return that.getClientBaseJid_(); | 222 return that.getClientBaseJid_(); |
| 213 } else { | 223 } else { |
| 214 return remoting.identity.getEmail(); | 224 return remoting.identity.getEmail(); |
| 215 } | 225 } |
| 216 }); | 226 }); |
| 217 | 227 |
| 218 // Build an initial host configuration. | 228 // Build an initial host configuration. |
| 219 /** @type {!Promise<!Object>} */ | 229 /** @type {!Promise<!Object>} */ |
| 220 var hostConfigNoOwnerPromise = Promise.all([ | 230 var hostConfigNoOwnerPromise = Promise.all([ |
| 221 hostNamePromise, | 231 hostNamePromise, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 235 host_secret_hash: hostSecretHash, | 245 host_secret_hash: hostSecretHash, |
| 236 private_key: keyPair.privateKey | 246 private_key: keyPair.privateKey |
| 237 }; | 247 }; |
| 238 }); | 248 }); |
| 239 | 249 |
| 240 // Add host_owner and host_owner_email fields to the host config if | 250 // Add host_owner and host_owner_email fields to the host config if |
| 241 // necessary. This promise resolves to the same value as | 251 // necessary. This promise resolves to the same value as |
| 242 // hostConfigNoOwnerPromise, with not until the extra fields are | 252 // hostConfigNoOwnerPromise, with not until the extra fields are |
| 243 // either added or determined to be redundant. | 253 // either added or determined to be redundant. |
| 244 /** @type {!Promise<!Object>} */ | 254 /** @type {!Promise<!Object>} */ |
| 245 var hostConfigWithOwnerPromise = Promise.all([ | 255 var hostConfigWithOwnerPromise = Promise.all([ |
|
John Williams
2015/04/28 20:27:40
I merged this with the function above since I real
| |
| 246 hostConfigNoOwnerPromise, | 256 hostConfigNoOwnerPromise, |
| 247 hostOwnerPromise, | 257 hostOwnerPromise, |
| 248 remoting.identity.getEmail(), | 258 remoting.identity.getEmail(), |
| 249 xmppCredsPromise | 259 xmppCredsPromise |
| 250 ]).then(function(/** Array */ a) { | 260 ]).then(function(/** Array */ a) { |
| 251 var hostConfig = /** @type {!Object} */ (a[0]); | 261 var hostConfig = /** @type {!Object} */ (a[0]); |
| 252 var hostOwner = /** @type {string} */ (a[1]); | 262 var hostOwner = /** @type {string} */ (a[1]); |
| 253 var hostOwnerEmail = /** @type {string} */ (a[2]); | 263 var hostOwnerEmail = /** @type {string} */ (a[2]); |
| 254 var xmppCreds = /** @type {remoting.XmppCredentials} */ (a[3]); | 264 var xmppCreds = /** @type {remoting.XmppCredentials} */ (a[3]); |
| 255 if (hostOwner != xmppCreds.userEmail) { | 265 if (hostOwner != xmppCreds.userEmail) { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 emailPromise.then(function(/** string */ email) { | 517 emailPromise.then(function(/** string */ email) { |
| 508 signalStrategy.connect(remoting.settings.XMPP_SERVER, email, token); | 518 signalStrategy.connect(remoting.settings.XMPP_SERVER, email, token); |
| 509 }); | 519 }); |
| 510 }); | 520 }); |
| 511 | 521 |
| 512 return result; | 522 return result; |
| 513 }; | 523 }; |
| 514 | 524 |
| 515 /** @type {remoting.HostController} */ | 525 /** @type {remoting.HostController} */ |
| 516 remoting.hostController = null; | 526 remoting.hostController = null; |
| OLD | NEW |