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 onStartError(remoting.Error.UNEXPECTED); | 164 onStartError(remoting.Error.UNEXPECTED); |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 /** | 168 /** |
169 * @param {string} hostName | 169 * @param {string} hostName |
170 * @param {string} publicKey | 170 * @param {string} publicKey |
171 * @param {string} privateKey | 171 * @param {string} privateKey |
172 * @param {string} xmppLogin | 172 * @param {string} xmppLogin |
173 * @param {string} refreshToken | 173 * @param {string} refreshToken |
| 174 * @param {string} clientBaseJid |
174 * @param {string} hostSecretHash | 175 * @param {string} hostSecretHash |
175 */ | 176 */ |
176 function startHostWithHash(hostName, publicKey, privateKey, | 177 function startHostWithHash(hostName, publicKey, privateKey, xmppLogin, |
177 xmppLogin, refreshToken, hostSecretHash) { | 178 refreshToken, clientBaseJid, hostSecretHash) { |
178 var hostConfig = { | 179 var hostConfig = { |
179 xmpp_login: xmppLogin, | 180 xmpp_login: xmppLogin, |
180 oauth_refresh_token: refreshToken, | 181 oauth_refresh_token: refreshToken, |
181 host_id: newHostId, | 182 host_id: newHostId, |
182 host_name: hostName, | 183 host_name: hostName, |
183 host_secret_hash: hostSecretHash, | 184 host_secret_hash: hostSecretHash, |
184 private_key: privateKey | 185 private_key: privateKey |
185 }; | 186 }; |
186 var hostOwner = remoting.identity.getCachedEmail(); | 187 var hostOwner = clientBaseJid; |
| 188 var hostOwnerEmail = remoting.identity.getCachedEmail(); |
187 if (hostOwner != xmppLogin) { | 189 if (hostOwner != xmppLogin) { |
188 hostConfig['host_owner'] = hostOwner; | 190 hostConfig['host_owner'] = hostOwner; |
| 191 if (hostOwnerEmail != hostOwner) { |
| 192 hostConfig['host_owner_email'] = hostOwnerEmail; |
| 193 } |
189 } | 194 } |
190 that.hostDaemonFacade_.startDaemon( | 195 that.hostDaemonFacade_.startDaemon( |
191 hostConfig, consent, onStarted.bind(null, hostName, publicKey), | 196 hostConfig, consent, onStarted.bind(null, hostName, publicKey), |
192 onStartError); | 197 onStartError); |
193 } | 198 } |
194 | 199 |
195 /** | 200 /** |
196 * @param {string} hostName | 201 * @param {string} hostName |
197 * @param {string} publicKey | 202 * @param {string} publicKey |
198 * @param {string} privateKey | 203 * @param {string} privateKey |
199 * @param {string} email | 204 * @param {string} email |
200 * @param {string} refreshToken | 205 * @param {string} refreshToken |
| 206 * @param {string} clientBaseJid |
201 */ | 207 */ |
202 function onServiceAccountCredentials( | 208 function onClientBaseJid( |
203 hostName, publicKey, privateKey, email, refreshToken) { | 209 hostName, publicKey, privateKey, email, refreshToken, clientBaseJid) { |
204 that.hostDaemonFacade_.getPinHash( | 210 that.hostDaemonFacade_.getPinHash( |
205 newHostId, hostPin, | 211 newHostId, hostPin, |
206 startHostWithHash.bind( | 212 startHostWithHash.bind(null, hostName, publicKey, privateKey, |
207 null, hostName, publicKey, privateKey, email, refreshToken), | 213 email, refreshToken, clientBaseJid), |
208 onError); | 214 onError); |
209 } | 215 } |
210 | 216 |
211 /** | 217 /** |
212 * @param {string} hostName | 218 * @param {string} hostName |
213 * @param {string} publicKey | 219 * @param {string} publicKey |
214 * @param {string} privateKey | 220 * @param {string} privateKey |
| 221 * @param {string} email |
| 222 * @param {string} refreshToken |
| 223 */ |
| 224 function onServiceAccountCredentials( |
| 225 hostName, publicKey, privateKey, email, refreshToken) { |
| 226 that.getClientBaseJid_( |
| 227 onClientBaseJid.bind( |
| 228 null, hostName, publicKey, privateKey, email, refreshToken), |
| 229 onStartError); |
| 230 } |
| 231 |
| 232 /** |
| 233 * @param {string} hostName |
| 234 * @param {string} publicKey |
| 235 * @param {string} privateKey |
215 * @param {XMLHttpRequest} xhr | 236 * @param {XMLHttpRequest} xhr |
216 */ | 237 */ |
217 function onRegistered( | 238 function onRegistered( |
218 hostName, publicKey, privateKey, xhr) { | 239 hostName, publicKey, privateKey, xhr) { |
219 var success = (xhr.status == 200); | 240 var success = (xhr.status == 200); |
220 | 241 |
221 if (success) { | 242 if (success) { |
222 var result = jsonParseSafe(xhr.responseText); | 243 var result = jsonParseSafe(xhr.responseText); |
223 if ('data' in result && 'authorizationCode' in result['data']) { | 244 if ('data' in result && 'authorizationCode' in result['data']) { |
224 that.hostDaemonFacade_.getCredentialsFromAuthCode( | 245 that.hostDaemonFacade_.getCredentialsFromAuthCode( |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 * | 513 * |
493 * @param {function():void} onDone Completion callback. | 514 * @param {function():void} onDone Completion callback. |
494 * @param {function(remoting.Error):void} onError Error callback. | 515 * @param {function(remoting.Error):void} onError Error callback. |
495 * @return {void} | 516 * @return {void} |
496 */ | 517 */ |
497 remoting.HostController.prototype.clearPairedClients = function( | 518 remoting.HostController.prototype.clearPairedClients = function( |
498 onDone, onError) { | 519 onDone, onError) { |
499 this.hostDaemonFacade_.clearPairedClients(onDone, onError); | 520 this.hostDaemonFacade_.clearPairedClients(onDone, onError); |
500 }; | 521 }; |
501 | 522 |
| 523 /** |
| 524 * Gets the host owner's base JID, used by the host for client authorization. |
| 525 * In most cases this is the same as the owner's email address, but for |
| 526 * non-Gmail accounts, it may be different. |
| 527 * |
| 528 * @private |
| 529 * @param {function(string): void} onSuccess |
| 530 * @param {function(remoting.Error): void} onError |
| 531 */ |
| 532 remoting.HostController.prototype.getClientBaseJid_ = function( |
| 533 onSuccess, onError) { |
| 534 var signalStrategy = null; |
| 535 |
| 536 var onState = function(state) { |
| 537 switch (state) { |
| 538 case remoting.SignalStrategy.State.CONNECTED: |
| 539 var jid = signalStrategy.getJid().split('/')[0].toLowerCase(); |
| 540 base.dispose(signalStrategy); |
| 541 signalStrategy = null; |
| 542 onSuccess(jid); |
| 543 break; |
| 544 |
| 545 case remoting.SignalStrategy.State.FAILED: |
| 546 var error = signalStrategy.getError(); |
| 547 base.dispose(signalStrategy); |
| 548 signalStrategy = null; |
| 549 onError(error); |
| 550 break; |
| 551 } |
| 552 }; |
| 553 |
| 554 signalStrategy = remoting.SignalStrategy.create(onState); |
| 555 |
| 556 /** @param {string} token */ |
| 557 function connectSignalingWithToken(token) { |
| 558 remoting.identity.getEmail( |
| 559 connectSignalingWithTokenAndEmail.bind(null, token), onError); |
| 560 } |
| 561 |
| 562 /** |
| 563 * @param {string} token |
| 564 * @param {string} email |
| 565 */ |
| 566 function connectSignalingWithTokenAndEmail(token, email) { |
| 567 signalStrategy.connect( |
| 568 remoting.settings.XMPP_SERVER_ADDRESS, email, token); |
| 569 } |
| 570 |
| 571 remoting.identity.callWithToken(connectSignalingWithToken, onError); |
| 572 }; |
| 573 |
502 /** @type {remoting.HostController} */ | 574 /** @type {remoting.HostController} */ |
503 remoting.hostController = null; | 575 remoting.hostController = null; |
OLD | NEW |