Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** @suppress {duplicate} */ | 5 /** @suppress {duplicate} */ |
| 6 var remoting = remoting || {}; | 6 var remoting = remoting || {}; |
| 7 | 7 |
| 8 (function() { | 8 (function() { |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 * Rejects with remoting.Error on failure. | 47 * Rejects with remoting.Error on failure. |
| 48 * @private | 48 * @private |
| 49 */ | 49 */ |
| 50 remoting.It2MeConnectFlow.prototype.connect_ = function(accessCode) { | 50 remoting.It2MeConnectFlow.prototype.connect_ = function(accessCode) { |
| 51 var that = this; | 51 var that = this; |
| 52 | 52 |
| 53 return this.verifyAccessCode_(accessCode).then(function() { | 53 return this.verifyAccessCode_(accessCode).then(function() { |
| 54 return remoting.identity.getToken(); | 54 return remoting.identity.getToken(); |
| 55 }).then(function(/** string */ token) { | 55 }).then(function(/** string */ token) { |
| 56 return that.getHostInfo_(token); | 56 return that.getHostInfo_(token); |
| 57 }).then(function(/** XMLHttpRequest */ xhr) { | 57 }).then(function(/** XMLHttpRequest */ xhr) { |
|
kelvinp
2015/03/17 01:32:46
You need to fix that as well.
John Williams
2015/03/17 17:39:38
God bless JSCompiler and its rigorous type system.
| |
| 58 return that.onHostInfo_(xhr); | 58 return that.onHostInfo_(xhr); |
| 59 }).then(function(/** remoting.Host */ host) { | 59 }).then(function(/** remoting.Host */ host) { |
| 60 that.sessionConnector_.connect( | 60 that.sessionConnector_.connect( |
| 61 remoting.DesktopConnectedView.Mode.IT2ME, | 61 remoting.DesktopConnectedView.Mode.IT2ME, |
| 62 host, | 62 host, |
| 63 new remoting.CredentialsProvider({ accessCode: that.passCode_ })); | 63 new remoting.CredentialsProvider({ accessCode: that.passCode_ })); |
| 64 }).catch(function(error) { | 64 }).catch(function(error) { |
| 65 return Promise.reject(/** remoting.Error */ error); | 65 return Promise.reject(/** remoting.Error */ error); |
| 66 }); | 66 }); |
| 67 }; | 67 }; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 81 this.hostId_ = normalizedAccessCode.substring(0, SUPPORT_ID_LENGTH); | 81 this.hostId_ = normalizedAccessCode.substring(0, SUPPORT_ID_LENGTH); |
| 82 this.passCode_ = normalizedAccessCode; | 82 this.passCode_ = normalizedAccessCode; |
| 83 | 83 |
| 84 return Promise.resolve(); | 84 return Promise.resolve(); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * Continues an IT2Me connection once an access token has been obtained. | 88 * Continues an IT2Me connection once an access token has been obtained. |
| 89 * | 89 * |
| 90 * @param {string} token An OAuth2 access token. | 90 * @param {string} token An OAuth2 access token. |
| 91 * @return {Promise<XMLHttpRequest>} | 91 * @return {Promise<remoting.Xhr.Response>} |
| 92 * @private | 92 * @private |
| 93 */ | 93 */ |
| 94 remoting.It2MeConnectFlow.prototype.getHostInfo_ = function(token) { | 94 remoting.It2MeConnectFlow.prototype.getHostInfo_ = function(token) { |
| 95 var that = this; | 95 var that = this; |
| 96 return new Promise(function(resolve) { | 96 return new remoting.Xhr({ |
| 97 remoting.xhr.start({ | 97 method: 'GET', |
| 98 method: 'GET', | 98 url: remoting.settings.DIRECTORY_API_BASE_URL + '/support-hosts/' + |
| 99 url: remoting.settings.DIRECTORY_API_BASE_URL + '/support-hosts/' + | 99 encodeURIComponent(that.hostId_), |
| 100 encodeURIComponent(that.hostId_), | 100 oauthToken: token |
| 101 onDone: resolve, | 101 }).start(); |
| 102 oauthToken: token | |
| 103 }); | |
| 104 }); | |
| 105 }; | 102 }; |
| 106 | 103 |
| 107 /** | 104 /** |
| 108 * Continues an IT2Me connection once the host JID has been looked up. | 105 * Continues an IT2Me connection once the host JID has been looked up. |
| 109 * | 106 * |
| 110 * @param {XMLHttpRequest} xhr The server response to the support-hosts query. | 107 * @param {XMLHttpRequest} xhr The server response to the support-hosts query. |
| 111 * @return {!Promise<!remoting.Host>} Rejects on error. | 108 * @return {!Promise<!remoting.Host>} Rejects on error. |
| 112 * @private | 109 * @private |
| 113 */ | 110 */ |
| 114 remoting.It2MeConnectFlow.prototype.onHostInfo_ = function(xhr) { | 111 remoting.It2MeConnectFlow.prototype.onHostInfo_ = function(xhr) { |
|
kelvinp
2015/03/17 01:32:46
This needed to be updated as well.
John Williams
2015/03/17 17:39:38
Done.
kelvinp
2015/03/17 22:06:20
I don't think it is done yet, probably need s/XMLH
John Williams
2015/03/18 20:07:23
Done.
| |
| 115 if (xhr.status == 200) { | 112 if (xhr.status == 200) { |
| 116 var response = /** @type {{data: {jabberId: string, publicKey: string}}} */ | 113 var response = /** @type {{data: {jabberId: string, publicKey: string}}} */ |
| 117 (base.jsonParseSafe(xhr.responseText)); | 114 (base.jsonParseSafe(xhr.responseText)); |
| 118 if (response && response.data && | 115 if (response && response.data && |
| 119 response.data.jabberId && response.data.publicKey) { | 116 response.data.jabberId && response.data.publicKey) { |
| 120 var host = new remoting.Host(); | 117 var host = new remoting.Host(); |
| 121 host.hostId = this.hostId_; | 118 host.hostId = this.hostId_; |
| 122 host.jabberId = response.data.jabberId; | 119 host.jabberId = response.data.jabberId; |
| 123 host.publicKey = response.data.publicKey; | 120 host.publicKey = response.data.publicKey; |
| 124 host.hostName = response.data.jabberId.split('/')[0]; | 121 host.hostName = response.data.jabberId.split('/')[0]; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 141 switch (error) { | 138 switch (error) { |
| 142 case 0: return new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE); | 139 case 0: return new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE); |
| 143 case 404: return new remoting.Error(remoting.Error.Tag.INVALID_ACCESS_CODE); | 140 case 404: return new remoting.Error(remoting.Error.Tag.INVALID_ACCESS_CODE); |
| 144 case 502: // No break | 141 case 502: // No break |
| 145 case 503: return new remoting.Error(remoting.Error.Tag.SERVICE_UNAVAILABLE); | 142 case 503: return new remoting.Error(remoting.Error.Tag.SERVICE_UNAVAILABLE); |
| 146 default: return remoting.Error.unexpected(); | 143 default: return remoting.Error.unexpected(); |
| 147 } | 144 } |
| 148 } | 145 } |
| 149 | 146 |
| 150 })(); | 147 })(); |
| OLD | NEW |