| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * This class implements the functionality that is specific to application | 7 * This class implements the functionality that is specific to application |
| 8 * remoting ("AppRemoting" or AR). | 8 * remoting ("AppRemoting" or AR). |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 * | 97 * |
| 98 * @param {remoting.SessionConnector} connector | 98 * @param {remoting.SessionConnector} connector |
| 99 * @param {string} token An OAuth access token. The delegate should not cache | 99 * @param {string} token An OAuth access token. The delegate should not cache |
| 100 * this token, but can assume that it will remain valid during application | 100 * this token, but can assume that it will remain valid during application |
| 101 * start-up. | 101 * start-up. |
| 102 */ | 102 */ |
| 103 remoting.AppRemoting.prototype.start = function(connector, token) { | 103 remoting.AppRemoting.prototype.start = function(connector, token) { |
| 104 /** @type {remoting.AppRemoting} */ | 104 /** @type {remoting.AppRemoting} */ |
| 105 var that = this; | 105 var that = this; |
| 106 | 106 |
| 107 /** @param {XMLHttpRequest} xhr */ | 107 /** @param {!remoting.Xhr.Response} xhrResponse */ |
| 108 var parseAppHostResponse = function(xhr) { | 108 var parseAppHostResponse = function(xhrResponse) { |
| 109 if (xhr.status == 200) { | 109 if (xhrResponse.status == 200) { |
| 110 var response = /** @type {remoting.AppRemoting.AppHostResponse} */ | 110 var response = /** @type {remoting.AppRemoting.AppHostResponse} */ |
| 111 (base.jsonParseSafe(xhr.responseText)); | 111 (base.jsonParseSafe(xhrResponse.getText())); |
| 112 if (response && | 112 if (response && |
| 113 response.status && | 113 response.status && |
| 114 response.status == 'done' && | 114 response.status == 'done' && |
| 115 response.hostJid && | 115 response.hostJid && |
| 116 response.authorizationCode && | 116 response.authorizationCode && |
| 117 response.sharedSecret && | 117 response.sharedSecret && |
| 118 response.host && | 118 response.host && |
| 119 response.host.hostId) { | 119 response.host.hostId) { |
| 120 var hostJid = response.hostJid; | 120 var hostJid = response.hostJid; |
| 121 that.contextMenu_.setHostId(response.host.hostId); | 121 that.contextMenu_.setHostId(response.host.hostId); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 141 */ | 141 */ |
| 142 var fetchThirdPartyToken = function( | 142 var fetchThirdPartyToken = function( |
| 143 tokenUrl, hostPublicKey, scope, onThirdPartyTokenFetched) { | 143 tokenUrl, hostPublicKey, scope, onThirdPartyTokenFetched) { |
| 144 // Use the authentication tokens returned by the app-remoting server. | 144 // Use the authentication tokens returned by the app-remoting server. |
| 145 onThirdPartyTokenFetched(host['authorizationCode'], | 145 onThirdPartyTokenFetched(host['authorizationCode'], |
| 146 host['sharedSecret']); | 146 host['sharedSecret']); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 connector.connectMe2App(host, fetchThirdPartyToken); | 149 connector.connectMe2App(host, fetchThirdPartyToken); |
| 150 } else if (response && response.status == 'pending') { | 150 } else if (response && response.status == 'pending') { |
| 151 that.handleError(remoting.Error.SERVICE_UNAVAILABLE); | 151 that.handleError(new remoting.Error( |
| 152 remoting.Error.Tag.SERVICE_UNAVAILABLE)); |
| 152 } | 153 } |
| 153 } else { | 154 } else { |
| 154 console.error('Invalid "runApplication" response from server.'); | 155 console.error('Invalid "runApplication" response from server.'); |
| 155 // TODO(garykac) Start using remoting.Error.fromHttpStatus once it has | 156 // TODO(garykac) Start using remoting.Error.fromHttpStatus once it has |
| 156 // been updated to properly report 'unknown' errors (rather than | 157 // been updated to properly report 'unknown' errors (rather than |
| 157 // reporting them as AUTHENTICATION_FAILED). | 158 // reporting them as AUTHENTICATION_FAILED). |
| 158 if (xhr.status == 0) { | 159 if (xhrResponse.status == 0) { |
| 159 that.handleError(remoting.Error.NETWORK_FAILURE); | 160 that.handleError(new remoting.Error( |
| 160 } else if (xhr.status == 401) { | 161 remoting.Error.Tag.NETWORK_FAILURE)); |
| 161 that.handleError(remoting.Error.AUTHENTICATION_FAILED); | 162 } else if (xhrResponse.status == 401) { |
| 162 } else if (xhr.status == 403) { | 163 that.handleError(new remoting.Error( |
| 163 that.handleError(remoting.Error.APP_NOT_AUTHORIZED); | 164 remoting.Error.Tag.AUTHENTICATION_FAILED)); |
| 164 } else if (xhr.status == 502 || xhr.status == 503) { | 165 } else if (xhrResponse.status == 403) { |
| 165 that.handleError(remoting.Error.SERVICE_UNAVAILABLE); | 166 that.handleError(new remoting.Error( |
| 167 remoting.Error.Tag.APP_NOT_AUTHORIZED)); |
| 168 } else if (xhrResponse.status == 502 || xhrResponse.status == 503) { |
| 169 that.handleError(new remoting.Error( |
| 170 remoting.Error.Tag.SERVICE_UNAVAILABLE)); |
| 166 } else { | 171 } else { |
| 167 that.handleError(remoting.Error.UNEXPECTED); | 172 that.handleError(remoting.Error.unexpected()); |
| 168 } | 173 } |
| 169 } | 174 } |
| 170 }; | 175 }; |
| 171 | 176 |
| 172 remoting.xhr.start({ | 177 new remoting.Xhr({ |
| 173 method: 'POST', | 178 method: 'POST', |
| 174 url: that.runApplicationUrl(), | 179 url: that.runApplicationUrl(), |
| 175 onDone: parseAppHostResponse, | |
| 176 oauthToken: token | 180 oauthToken: token |
| 177 }); | 181 }).start().then(parseAppHostResponse); |
| 178 }; | 182 }; |
| 179 | 183 |
| 180 /** | 184 /** |
| 181 * Report an authentication error to the user. This is called in lieu of start() | 185 * Report an authentication error to the user. This is called in lieu of start() |
| 182 * if the user cannot be authenticated or if they decline the app permissions. | 186 * if the user cannot be authenticated or if they decline the app permissions. |
| 183 * | 187 * |
| 184 * @param {!remoting.Error} error The failure reason. | 188 * @param {!remoting.Error} error The failure reason. |
| 185 */ | 189 */ |
| 186 remoting.AppRemoting.prototype.signInFailed = function(error) { | 190 remoting.AppRemoting.prototype.signInFailed = function(error) { |
| 187 this.handleError(error); | 191 this.handleError(error); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 return false; | 329 return false; |
| 326 }; | 330 }; |
| 327 | 331 |
| 328 /** | 332 /** |
| 329 * Called when an error needs to be displayed to the user. | 333 * Called when an error needs to be displayed to the user. |
| 330 * | 334 * |
| 331 * @param {!remoting.Error} error The error to be localized and displayed. | 335 * @param {!remoting.Error} error The error to be localized and displayed. |
| 332 * @return {void} Nothing. | 336 * @return {void} Nothing. |
| 333 */ | 337 */ |
| 334 remoting.AppRemoting.prototype.handleError = function(error) { | 338 remoting.AppRemoting.prototype.handleError = function(error) { |
| 335 console.error('Connection failed: ' + error.tag); | 339 console.error('Connection failed: ' + error.toString()); |
| 336 remoting.LoadingWindow.close(); | 340 remoting.LoadingWindow.close(); |
| 337 remoting.MessageWindow.showErrorMessage( | 341 remoting.MessageWindow.showErrorMessage( |
| 338 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), | 342 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), |
| 339 chrome.i18n.getMessage(/** @type {string} */ (error.tag))); | 343 chrome.i18n.getMessage(error.getTag())); |
| 340 }; | 344 }; |
| 341 | 345 |
| 342 /** | 346 /** |
| 343 * Close the loading window before exiting. | 347 * Close the loading window before exiting. |
| 344 */ | 348 */ |
| 345 remoting.AppRemoting.prototype.handleExit = function() { | 349 remoting.AppRemoting.prototype.handleExit = function() { |
| 346 remoting.LoadingWindow.close(); | 350 remoting.LoadingWindow.close(); |
| 347 }; | 351 }; |
| OLD | NEW |