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

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
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.textContent));
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 27 matching lines...) Expand all
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(new remoting.Error( 151 that.handleError(new remoting.Error(
152 remoting.Error.Tag.SERVICE_UNAVAILABLE)); 152 remoting.Error.Tag.SERVICE_UNAVAILABLE));
153 } 153 }
154 } else { 154 } else {
155 console.error('Invalid "runApplication" response from server.'); 155 console.error('Invalid "runApplication" response from server.');
156 // TODO(garykac) Start using remoting.Error.fromHttpStatus once it has 156 // TODO(garykac) Start using remoting.Error.fromHttpStatus once it has
157 // been updated to properly report 'unknown' errors (rather than 157 // been updated to properly report 'unknown' errors (rather than
158 // reporting them as AUTHENTICATION_FAILED). 158 // reporting them as AUTHENTICATION_FAILED).
159 if (xhr.status == 0) { 159 if (xhrResponse.status == 0) {
160 that.handleError(new remoting.Error( 160 that.handleError(new remoting.Error(
161 remoting.Error.Tag.NETWORK_FAILURE)); 161 remoting.Error.Tag.NETWORK_FAILURE));
162 } else if (xhr.status == 401) { 162 } else if (xhrResponse.status == 401) {
163 that.handleError(new remoting.Error( 163 that.handleError(new remoting.Error(
164 remoting.Error.Tag.AUTHENTICATION_FAILED)); 164 remoting.Error.Tag.AUTHENTICATION_FAILED));
165 } else if (xhr.status == 403) { 165 } else if (xhrResponse.status == 403) {
166 that.handleError(new remoting.Error( 166 that.handleError(new remoting.Error(
167 remoting.Error.Tag.APP_NOT_AUTHORIZED)); 167 remoting.Error.Tag.APP_NOT_AUTHORIZED));
168 } else if (xhr.status == 502 || xhr.status == 503) { 168 } else if (xhrResponse.status == 502 || xhrResponse.status == 503) {
169 that.handleError(new remoting.Error( 169 that.handleError(new remoting.Error(
170 remoting.Error.Tag.SERVICE_UNAVAILABLE)); 170 remoting.Error.Tag.SERVICE_UNAVAILABLE));
171 } else { 171 } else {
172 that.handleError(remoting.Error.unexpected()); 172 that.handleError(remoting.Error.unexpected());
173 } 173 }
174 } 174 }
175 }; 175 };
176 176
177 remoting.xhr.start({ 177 new remoting.Xhr({
178 method: 'POST', 178 method: 'POST',
179 url: that.runApplicationUrl(), 179 url: that.runApplicationUrl(),
180 onDone: parseAppHostResponse,
181 oauthToken: token 180 oauthToken: token
182 }); 181 }).start().then(parseAppHostResponse);
183 }; 182 };
184 183
185 /** 184 /**
186 * 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()
187 * 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.
188 * 187 *
189 * @param {!remoting.Error} error The failure reason. 188 * @param {!remoting.Error} error The failure reason.
190 */ 189 */
191 remoting.AppRemoting.prototype.signInFailed = function(error) { 190 remoting.AppRemoting.prototype.signInFailed = function(error) {
192 this.handleError(error); 191 this.handleError(error);
193 }; 192 };
194 193
195 /** 194 /**
196 * @return {string} Application product name to be used in UI. 195 * @return {string} Application product name to be used in UI.
197 */ 196 */
198 remoting.AppRemoting.prototype.getApplicationName = function() { 197 remoting.AppRemoting.prototype.getApplicationName = function() {
199 var manifest = chrome.runtime.getManifest(); 198 var manifest = chrome.runtime.getManifest();
200 return manifest.name; 199 // XXX return manifest.name;
kelvinp 2015/03/17 01:32:46 what does //XXX stands for?
John Williams 2015/03/17 17:39:38 "Don't commit this." Oops. I was testing to see if
kelvinp 2015/03/17 22:06:20 Acknowledged.
201 }; 200 };
202 201
203 /** @return {string} */ 202 /** @return {string} */
204 remoting.AppRemoting.prototype.runApplicationUrl = function() { 203 remoting.AppRemoting.prototype.runApplicationUrl = function() {
205 return remoting.settings.APP_REMOTING_API_BASE_URL + '/applications/' + 204 return remoting.settings.APP_REMOTING_API_BASE_URL + '/applications/' +
206 remoting.settings.getAppRemotingApplicationId() + '/run'; 205 remoting.settings.getAppRemotingApplicationId() + '/run';
207 }; 206 };
208 207
209 /** 208 /**
210 * @return {string} The default remap keys for the current platform. 209 * @return {string} The default remap keys for the current platform.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 * Called when an error needs to be displayed to the user. 333 * Called when an error needs to be displayed to the user.
335 * 334 *
336 * @param {!remoting.Error} error The error to be localized and displayed. 335 * @param {!remoting.Error} error The error to be localized and displayed.
337 * @return {void} Nothing. 336 * @return {void} Nothing.
338 */ 337 */
339 remoting.AppRemoting.prototype.handleError = function(error) { 338 remoting.AppRemoting.prototype.handleError = function(error) {
340 console.error('Connection failed: ' + error.toString()); 339 console.error('Connection failed: ' + error.toString());
341 remoting.LoadingWindow.close(); 340 remoting.LoadingWindow.close();
342 remoting.MessageWindow.showErrorMessage( 341 remoting.MessageWindow.showErrorMessage(
343 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), 342 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'),
344 chrome.i18n.getMessage(/** @type {string} */ (error.tag))); 343 chrome.i18n.getMessage(error.getTag()));
345 }; 344 };
346 345
347 /** 346 /**
348 * Close the loading window before exiting. 347 * Close the loading window before exiting.
349 */ 348 */
350 remoting.AppRemoting.prototype.handleExit = function() { 349 remoting.AppRemoting.prototype.handleExit = function() {
351 remoting.LoadingWindow.close(); 350 remoting.LoadingWindow.close();
352 }; 351 };
OLDNEW
« no previous file with comments | « no previous file | remoting/webapp/app_remoting/js/feedback_consent.js » ('j') | remoting/webapp/crd/js/it2me_connect_flow.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698