Chromium Code Reviews| Index: remoting/webapp/host_controller.js |
| diff --git a/remoting/webapp/host_controller.js b/remoting/webapp/host_controller.js |
| index 34278ac73b44788a03b17a99de7f3ffe3754346b..d278826501e0a9dbca74af2c2bf19abb8aa73a32 100644 |
| --- a/remoting/webapp/host_controller.js |
| +++ b/remoting/webapp/host_controller.js |
| @@ -173,8 +173,8 @@ remoting.HostController.prototype.start = function(hostPin, consent, onDone, |
| * @param {string} refreshToken |
| * @param {string} hostSecretHash |
| */ |
| - function startHostWithHash(hostName, publicKey, privateKey, |
| - xmppLogin, refreshToken, hostSecretHash) { |
| + function startHostWithHash(hostName, publicKey, privateKey, xmppLogin, |
| + refreshToken, clientJid, hostSecretHash) { |
| var hostConfig = { |
| xmpp_login: xmppLogin, |
| oauth_refresh_token: refreshToken, |
| @@ -183,9 +183,13 @@ remoting.HostController.prototype.start = function(hostPin, consent, onDone, |
| host_secret_hash: hostSecretHash, |
| private_key: privateKey |
| }; |
| - var hostOwner = remoting.identity.getCachedEmail(); |
| + var hostOwner = clientJid; |
| + var hostOwnerEmail = remoting.identity.getCachedEmail(); |
| if (hostOwner != xmppLogin) { |
| hostConfig['host_owner'] = hostOwner; |
| + if (hostOwnerEmail != hostOwner) { |
| + hostConfig['host_owner_email'] = hostOwnerEmail; |
| + } |
| } |
| that.hostDaemonFacade_.startDaemon( |
| hostConfig, consent, onStarted.bind(null, hostName, publicKey), |
| @@ -199,12 +203,12 @@ remoting.HostController.prototype.start = function(hostPin, consent, onDone, |
| * @param {string} email |
| * @param {string} refreshToken |
| */ |
| - function onServiceAccountCredentials( |
| - hostName, publicKey, privateKey, email, refreshToken) { |
| + function onClientBaseJid( |
| + hostName, publicKey, privateKey, email, refreshToken, clientBaseJid) { |
| that.hostDaemonFacade_.getPinHash( |
| newHostId, hostPin, |
| - startHostWithHash.bind( |
| - null, hostName, publicKey, privateKey, email, refreshToken), |
| + startHostWithHash.bind(null, hostName, publicKey, privateKey, |
| + email, refreshToken, clientBaseJid), |
| onError); |
| } |
| @@ -212,6 +216,21 @@ remoting.HostController.prototype.start = function(hostPin, consent, onDone, |
| * @param {string} hostName |
| * @param {string} publicKey |
| * @param {string} privateKey |
| + * @param {string} email |
| + * @param {string} refreshToken |
| + */ |
| + function onServiceAccountCredentials( |
| + hostName, publicKey, privateKey, email, refreshToken) { |
| + that.getClientBaseJid_( |
| + onClientBaseJid.bind( |
| + null, hostName, publicKey, privateKey, email, refreshToken), |
| + onStartError); |
| + } |
| + |
| + /** |
| + * @param {string} hostName |
| + * @param {string} publicKey |
| + * @param {string} privateKey |
| * @param {XMLHttpRequest} xhr |
| */ |
| function onRegistered( |
| @@ -499,5 +518,53 @@ remoting.HostController.prototype.clearPairedClients = function( |
| this.hostDaemonFacade_.clearPairedClients(onDone, onError); |
| }; |
| +/** |
| + * @private |
|
Sergey Ulanov
2014/09/27 01:46:02
add comment here to explain what it is used for.
|
| + * @param {function(string): void} onSuccess |
| + * @param {function(remoting.Error): void} onError |
| + */ |
| +remoting.HostController.prototype.getClientBaseJid_ = function( |
| + onSuccess, onError) { |
| + // Find out the client JID that should be allowed to connect to this host. |
| + var signalStrategy = null; |
| + |
| + var onState = function(state) { |
| + switch (state) { |
| + case remoting.SignalStrategy.State.CONNECTED: |
| + var jid = signalStrategy.getJid().split('/')[0].toLowerCase(); |
| + base.dispose(signalStrategy); |
| + signalStrategy = null; |
| + onSuccess(jid); |
| + break; |
| + |
| + case remoting.SignalStrategy.State.FAILED: |
| + var error = signalStrategy.getError(); |
| + base.dispose(signalStrategy); |
| + signalStrategy = null; |
| + onError(error); |
| + break; |
| + } |
| + }; |
| + |
| + signalStrategy = remoting.SignalStrategy.create(onState); |
| + |
| + /** @param {string} token */ |
| + function connectSignalingWithToken(token) { |
| + remoting.identity.getEmail( |
| + connectSignalingWithTokenAndEmail.bind(null, token), onError); |
| + } |
| + |
| + /** |
| + * @param {string} token |
| + * @param {string} email |
| + */ |
| + function connectSignalingWithTokenAndEmail(token, email) { |
| + signalStrategy.connect( |
| + remoting.settings.XMPP_SERVER_ADDRESS, email, token); |
| + } |
| + |
| + remoting.identity.callWithToken(connectSignalingWithToken, onError); |
| +} |
| + |
| /** @type {remoting.HostController} */ |
| remoting.hostController = null; |