Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: remoting/webapp/app_remoting/js/app_remoting.js

Issue 1003433002: Updated remoting.xhr API to use promises. Removed access to the native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@spy-promise
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | remoting/webapp/app_remoting/js/feedback_consent.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 * 98 *
99 * @param {remoting.SessionConnector} connector 99 * @param {remoting.SessionConnector} connector
100 * @param {string} token An OAuth access token. The delegate should not cache 100 * @param {string} token An OAuth access token. The delegate should not cache
101 * this token, but can assume that it will remain valid during application 101 * this token, but can assume that it will remain valid during application
102 * start-up. 102 * start-up.
103 */ 103 */
104 remoting.AppRemoting.prototype.start = function(connector, token) { 104 remoting.AppRemoting.prototype.start = function(connector, token) {
105 /** @type {remoting.AppRemoting} */ 105 /** @type {remoting.AppRemoting} */
106 var that = this; 106 var that = this;
107 107
108 /** @param {XMLHttpRequest} xhr */ 108 /** @param {!remoting.Xhr.Response} xhrResponse */
109 var parseAppHostResponse = function(xhr) { 109 var parseAppHostResponse = function(xhrResponse) {
110 if (xhr.status == 200) { 110 if (xhrResponse.status == 200) {
111 var response = /** @type {remoting.AppRemoting.AppHostResponse} */ 111 var response = /** @type {remoting.AppRemoting.AppHostResponse} */
112 (base.jsonParseSafe(xhr.responseText)); 112 (base.jsonParseSafe(xhrResponse.getText()));
113 if (response && 113 if (response &&
114 response.status && 114 response.status &&
115 response.status == 'done' && 115 response.status == 'done' &&
116 response.hostJid && 116 response.hostJid &&
117 response.authorizationCode && 117 response.authorizationCode &&
118 response.sharedSecret && 118 response.sharedSecret &&
119 response.host && 119 response.host &&
120 response.host.hostId) { 120 response.host.hostId) {
121 var hostJid = response.hostJid; 121 var hostJid = response.hostJid;
122 that.contextMenu_.setHostId(response.host.hostId); 122 that.contextMenu_.setHostId(response.host.hostId);
(...skipping 27 matching lines...) Expand all
150 connector.connectMe2App(host, fetchThirdPartyToken); 150 connector.connectMe2App(host, fetchThirdPartyToken);
151 } else if (response && response.status == 'pending') { 151 } else if (response && response.status == 'pending') {
152 that.handleError(new remoting.Error( 152 that.handleError(new remoting.Error(
153 remoting.Error.Tag.SERVICE_UNAVAILABLE)); 153 remoting.Error.Tag.SERVICE_UNAVAILABLE));
154 } 154 }
155 } else { 155 } else {
156 console.error('Invalid "runApplication" response from server.'); 156 console.error('Invalid "runApplication" response from server.');
157 // TODO(garykac) Start using remoting.Error.fromHttpStatus once it has 157 // TODO(garykac) Start using remoting.Error.fromHttpStatus once it has
158 // been updated to properly report 'unknown' errors (rather than 158 // been updated to properly report 'unknown' errors (rather than
159 // reporting them as AUTHENTICATION_FAILED). 159 // reporting them as AUTHENTICATION_FAILED).
160 if (xhr.status == 0) { 160 if (xhrResponse.status == 0) {
161 that.handleError(new remoting.Error( 161 that.handleError(new remoting.Error(
162 remoting.Error.Tag.NETWORK_FAILURE)); 162 remoting.Error.Tag.NETWORK_FAILURE));
163 } else if (xhr.status == 401) { 163 } else if (xhrResponse.status == 401) {
164 that.handleError(new remoting.Error( 164 that.handleError(new remoting.Error(
165 remoting.Error.Tag.AUTHENTICATION_FAILED)); 165 remoting.Error.Tag.AUTHENTICATION_FAILED));
166 } else if (xhr.status == 403) { 166 } else if (xhrResponse.status == 403) {
167 that.handleError(new remoting.Error( 167 that.handleError(new remoting.Error(
168 remoting.Error.Tag.APP_NOT_AUTHORIZED)); 168 remoting.Error.Tag.APP_NOT_AUTHORIZED));
169 } else if (xhr.status == 502 || xhr.status == 503) { 169 } else if (xhrResponse.status == 502 || xhrResponse.status == 503) {
170 that.handleError(new remoting.Error( 170 that.handleError(new remoting.Error(
171 remoting.Error.Tag.SERVICE_UNAVAILABLE)); 171 remoting.Error.Tag.SERVICE_UNAVAILABLE));
172 } else { 172 } else {
173 that.handleError(remoting.Error.unexpected()); 173 that.handleError(remoting.Error.unexpected());
174 } 174 }
175 } 175 }
176 }; 176 };
177 177
178 remoting.xhr.start({ 178 new remoting.Xhr({
179 method: 'POST', 179 method: 'POST',
180 url: that.runApplicationUrl(), 180 url: that.runApplicationUrl(),
181 onDone: parseAppHostResponse,
182 oauthToken: token 181 oauthToken: token
183 }); 182 }).start().then(parseAppHostResponse);
184 }; 183 };
185 184
186 /** 185 /**
187 * Report an authentication error to the user. This is called in lieu of start() 186 * Report an authentication error to the user. This is called in lieu of start()
188 * if the user cannot be authenticated or if they decline the app permissions. 187 * if the user cannot be authenticated or if they decline the app permissions.
189 * 188 *
190 * @param {!remoting.Error} error The failure reason. 189 * @param {!remoting.Error} error The failure reason.
191 */ 190 */
192 remoting.AppRemoting.prototype.signInFailed = function(error) { 191 remoting.AppRemoting.prototype.signInFailed = function(error) {
193 this.handleError(error); 192 this.handleError(error);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), 333 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'),
335 chrome.i18n.getMessage(error.getTag())); 334 chrome.i18n.getMessage(error.getTag()));
336 }; 335 };
337 336
338 /** 337 /**
339 * Close the loading window before exiting. 338 * Close the loading window before exiting.
340 */ 339 */
341 remoting.AppRemoting.prototype.handleExit = function() { 340 remoting.AppRemoting.prototype.handleExit = function() {
342 remoting.LoadingWindow.close(); 341 remoting.LoadingWindow.close();
343 }; 342 };
OLDNEW
« no previous file with comments | « no previous file | remoting/webapp/app_remoting/js/feedback_consent.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698