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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 that.getClientBaseJid_( | 227 that.getClientBaseJid_( |
228 onClientBaseJid.bind( | 228 onClientBaseJid.bind( |
229 null, hostName, publicKey, privateKey, email, refreshToken), | 229 null, hostName, publicKey, privateKey, email, refreshToken), |
230 onStartError); | 230 onStartError); |
231 } | 231 } |
232 | 232 |
233 /** | 233 /** |
234 * @param {string} hostName | 234 * @param {string} hostName |
235 * @param {string} publicKey | 235 * @param {string} publicKey |
236 * @param {string} privateKey | 236 * @param {string} privateKey |
237 * @param {XMLHttpRequest} xhr | 237 * @param {remoting.Xhr.Response} xhrr |
238 */ | 238 */ |
239 function onRegistered( | 239 function onRegistered( |
240 hostName, publicKey, privateKey, xhr) { | 240 hostName, publicKey, privateKey, xhrr) { |
241 var success = (xhr.status == 200); | 241 var success = (xhrr.status == 200); |
242 | 242 |
243 if (success) { | 243 if (success) { |
244 var result = base.jsonParseSafe(xhr.responseText); | 244 var result = base.jsonParseSafe(xhrr.responseText); |
245 if ('data' in result && 'authorizationCode' in result['data']) { | 245 if ('data' in result && 'authorizationCode' in result['data']) { |
246 that.hostDaemonFacade_.getCredentialsFromAuthCode( | 246 that.hostDaemonFacade_.getCredentialsFromAuthCode( |
247 result['data']['authorizationCode'], | 247 result['data']['authorizationCode'], |
248 onServiceAccountCredentials.bind( | 248 onServiceAccountCredentials.bind( |
249 null, hostName, publicKey, privateKey), | 249 null, hostName, publicKey, privateKey), |
250 onError); | 250 onError); |
251 } else { | 251 } else { |
252 // No authorization code returned, use regular user credential flow. | 252 // No authorization code returned, use regular user credential flow. |
253 remoting.identity.getEmail().then( | 253 remoting.identity.getEmail().then( |
254 function(/** string */ email) { | 254 function(/** string */ email) { |
255 that.hostDaemonFacade_.getPinHash( | 255 that.hostDaemonFacade_.getPinHash( |
256 newHostId, hostPin, startHostWithHash.bind( | 256 newHostId, hostPin, startHostWithHash.bind( |
257 null, hostName, publicKey, privateKey, | 257 null, hostName, publicKey, privateKey, |
258 email, remoting.oauth2.getRefreshToken(), email), | 258 email, remoting.oauth2.getRefreshToken(), email), |
259 onError); | 259 onError); |
260 }); | 260 }); |
261 } | 261 } |
262 } else { | 262 } else { |
263 console.log('Failed to register the host. Status: ' + xhr.status + | 263 console.log('Failed to register the host. Status: ' + xhrr.status + |
264 ' response: ' + xhr.responseText); | 264 ' response: ' + xhrr.responseText); |
265 onError(remoting.Error.REGISTRATION_FAILED); | 265 onError(remoting.Error.REGISTRATION_FAILED); |
266 } | 266 } |
267 } | 267 } |
268 | 268 |
269 /** | 269 /** |
270 * @param {string} hostName | 270 * @param {string} hostName |
271 * @param {string} privateKey | 271 * @param {string} privateKey |
272 * @param {string} publicKey | 272 * @param {string} publicKey |
273 * @param {?string} hostClientId | 273 * @param {?string} hostClientId |
274 * @param {string} oauthToken | 274 * @param {string} oauthToken |
275 */ | 275 */ |
276 function doRegisterHost( | 276 function doRegisterHost( |
277 hostName, privateKey, publicKey, hostClientId, oauthToken) { | 277 hostName, privateKey, publicKey, hostClientId, oauthToken) { |
278 var newHostDetails = { data: { | 278 var newHostDetails = { data: { |
279 hostId: newHostId, | 279 hostId: newHostId, |
280 hostName: hostName, | 280 hostName: hostName, |
281 publicKey: publicKey | 281 publicKey: publicKey |
282 } }; | 282 } }; |
283 | 283 |
284 remoting.xhr.start({ | 284 new remoting.Xhr({ |
285 method: 'POST', | 285 method: 'POST', |
286 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts', | 286 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts', |
287 urlParams: { | 287 urlParams: { |
288 hostClientId: hostClientId | 288 hostClientId: hostClientId |
289 }, | 289 }, |
290 onDone: onRegistered.bind(null, hostName, publicKey, privateKey), | |
291 jsonContent: newHostDetails, | 290 jsonContent: newHostDetails, |
292 oauthToken: oauthToken | 291 oauthToken: oauthToken |
293 }); | 292 }).then(onRegistered.bind(null, hostName, publicKey, privateKey)); |
294 } | 293 } |
295 | 294 |
296 /** | 295 /** |
297 * @param {string} hostName | 296 * @param {string} hostName |
298 * @param {string} privateKey | 297 * @param {string} privateKey |
299 * @param {string} publicKey | 298 * @param {string} publicKey |
300 * @param {string} hostClientId | 299 * @param {string} hostClientId |
301 */ | 300 */ |
302 function onHostClientId( | 301 function onHostClientId( |
303 hostName, privateKey, publicKey, hostClientId) { | 302 hostName, privateKey, publicKey, hostClientId) { |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 signalStrategy.connect( | 567 signalStrategy.connect( |
569 remoting.settings.XMPP_SERVER_FOR_CLIENT, email, token); | 568 remoting.settings.XMPP_SERVER_FOR_CLIENT, email, token); |
570 } | 569 } |
571 | 570 |
572 remoting.identity.getToken().then( | 571 remoting.identity.getToken().then( |
573 connectSignalingWithToken, remoting.Error.handler(onError)); | 572 connectSignalingWithToken, remoting.Error.handler(onError)); |
574 }; | 573 }; |
575 | 574 |
576 /** @type {remoting.HostController} */ | 575 /** @type {remoting.HostController} */ |
577 remoting.hostController = null; | 576 remoting.hostController = null; |
OLD | NEW |