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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 refreshToken, clientBaseJid, hostSecretHash) { | 177 refreshToken, clientBaseJid, hostSecretHash) { |
178 var hostConfig = { | 178 var hostConfig = { |
179 xmpp_login: xmppLogin, | 179 xmpp_login: xmppLogin, |
180 oauth_refresh_token: refreshToken, | 180 oauth_refresh_token: refreshToken, |
181 host_id: newHostId, | 181 host_id: newHostId, |
182 host_name: hostName, | 182 host_name: hostName, |
183 host_secret_hash: hostSecretHash, | 183 host_secret_hash: hostSecretHash, |
184 private_key: privateKey | 184 private_key: privateKey |
185 }; | 185 }; |
186 var hostOwner = clientBaseJid; | 186 var hostOwner = clientBaseJid; |
187 var hostOwnerEmail = remoting.identity.getCachedEmail(); | 187 remoting.identity.getEmail().then( |
188 if (hostOwner != xmppLogin) { | 188 function(/** string */ hostOwnerEmail) { |
189 hostConfig['host_owner'] = hostOwner; | 189 if (hostOwner != xmppLogin) { |
190 if (hostOwnerEmail != hostOwner) { | 190 hostConfig['host_owner'] = hostOwner; |
191 hostConfig['host_owner_email'] = hostOwnerEmail; | 191 if (hostOwnerEmail != hostOwner) { |
192 } | 192 hostConfig['host_owner_email'] = hostOwnerEmail; |
193 } | 193 } |
194 that.hostDaemonFacade_.startDaemon( | 194 } |
195 hostConfig, consent, onStarted.bind(null, hostName, publicKey), | 195 that.hostDaemonFacade_.startDaemon( |
196 onStartError); | 196 hostConfig, consent, onStarted.bind(null, hostName, publicKey), |
| 197 onStartError); |
| 198 }); |
197 } | 199 } |
198 | 200 |
199 /** | 201 /** |
200 * @param {string} hostName | 202 * @param {string} hostName |
201 * @param {string} publicKey | 203 * @param {string} publicKey |
202 * @param {string} privateKey | 204 * @param {string} privateKey |
203 * @param {string} email | 205 * @param {string} email |
204 * @param {string} refreshToken | 206 * @param {string} refreshToken |
205 * @param {string} clientBaseJid | 207 * @param {string} clientBaseJid |
206 */ | 208 */ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 if (success) { | 243 if (success) { |
242 var result = base.jsonParseSafe(xhr.responseText); | 244 var result = base.jsonParseSafe(xhr.responseText); |
243 if ('data' in result && 'authorizationCode' in result['data']) { | 245 if ('data' in result && 'authorizationCode' in result['data']) { |
244 that.hostDaemonFacade_.getCredentialsFromAuthCode( | 246 that.hostDaemonFacade_.getCredentialsFromAuthCode( |
245 result['data']['authorizationCode'], | 247 result['data']['authorizationCode'], |
246 onServiceAccountCredentials.bind( | 248 onServiceAccountCredentials.bind( |
247 null, hostName, publicKey, privateKey), | 249 null, hostName, publicKey, privateKey), |
248 onError); | 250 onError); |
249 } else { | 251 } else { |
250 // No authorization code returned, use regular user credential flow. | 252 // No authorization code returned, use regular user credential flow. |
251 that.hostDaemonFacade_.getPinHash( | 253 remoting.identity.getEmail().then( |
252 newHostId, hostPin, startHostWithHash.bind( | 254 function(/** string */ email) { |
253 null, hostName, publicKey, privateKey, | 255 that.hostDaemonFacade_.getPinHash( |
254 remoting.identity.getCachedEmail(), | 256 newHostId, hostPin, startHostWithHash.bind( |
255 remoting.oauth2.getRefreshToken(), | 257 null, hostName, publicKey, privateKey, |
256 remoting.identity.getCachedEmail()), | 258 email, remoting.oauth2.getRefreshToken(), email), |
257 onError); | 259 onError); |
| 260 }); |
258 } | 261 } |
259 } else { | 262 } else { |
260 console.log('Failed to register the host. Status: ' + xhr.status + | 263 console.log('Failed to register the host. Status: ' + xhr.status + |
261 ' response: ' + xhr.responseText); | 264 ' response: ' + xhr.responseText); |
262 onError(remoting.Error.REGISTRATION_FAILED); | 265 onError(remoting.Error.REGISTRATION_FAILED); |
263 } | 266 } |
264 } | 267 } |
265 | 268 |
266 /** | 269 /** |
267 * @param {string} hostName | 270 * @param {string} hostName |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 signalStrategy.connect( | 568 signalStrategy.connect( |
566 remoting.settings.XMPP_SERVER_FOR_CLIENT, email, token); | 569 remoting.settings.XMPP_SERVER_FOR_CLIENT, email, token); |
567 } | 570 } |
568 | 571 |
569 remoting.identity.getToken().then( | 572 remoting.identity.getToken().then( |
570 connectSignalingWithToken, remoting.Error.handler(onError)); | 573 connectSignalingWithToken, remoting.Error.handler(onError)); |
571 }; | 574 }; |
572 | 575 |
573 /** @type {remoting.HostController} */ | 576 /** @type {remoting.HostController} */ |
574 remoting.hostController = null; | 577 remoting.hostController = null; |
OLD | NEW |