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

Side by Side Diff: remoting/webapp/crd/js/it2me_helpee_channel.js

Issue 955283002: Converted remoting.Error from an enum to a class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Requested changes. 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 * 7 *
8 * It2MeHelpeeChannel relays messages between the Hangouts web page (Hangouts) 8 * It2MeHelpeeChannel relays messages between the Hangouts web page (Hangouts)
9 * and the It2Me Native Messaging Host (It2MeHost) for the helpee (the Hangouts 9 * and the It2Me Native Messaging Host (It2MeHost) for the helpee (the Hangouts
10 * participant who is receiving remoting assistance). 10 * participant who is receiving remoting assistance).
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 this.handleDownloadHost_(message); 181 this.handleDownloadHost_(message);
182 return true; 182 return true;
183 case MessageTypes.CONNECT: 183 case MessageTypes.CONNECT:
184 this.handleConnect_(message); 184 this.handleConnect_(message);
185 return true; 185 return true;
186 case MessageTypes.DISCONNECT: 186 case MessageTypes.DISCONNECT:
187 this.dispose(); 187 this.dispose();
188 return true; 188 return true;
189 } 189 }
190 throw new Error('Unsupported message method=' + message.method); 190 throw new Error('Unsupported message method=' + message.method);
191 } catch(/** @type {Error} */ error) { 191 } catch(/** @type {!Error} */ error) {
192 this.sendErrorResponse_(message, error.message); 192 this.sendErrorResponse_(message, error);
193 } 193 }
194 return false; 194 return false;
195 }; 195 };
196 196
197 /** 197 /**
198 * Queries the |hostInstaller| for the installation status. 198 * Queries the |hostInstaller| for the installation status.
199 * 199 *
200 * @param {{method:string, data:Object<string,*>}} message 200 * @param {{method:string, data:Object<string,*>}} message
201 * @private 201 * @private
202 */ 202 */
(...skipping 17 matching lines...) Expand all
220 ); 220 );
221 }; 221 };
222 222
223 /** 223 /**
224 * @param {{method:string, data:Object<string,*>}} message 224 * @param {{method:string, data:Object<string,*>}} message
225 * @private 225 * @private
226 */ 226 */
227 remoting.It2MeHelpeeChannel.prototype.handleDownloadHost_ = function(message) { 227 remoting.It2MeHelpeeChannel.prototype.handleDownloadHost_ = function(message) {
228 try { 228 try {
229 this.hostInstaller_.download(); 229 this.hostInstaller_.download();
230 } catch (/** @type {*} */ e) { 230 } catch (/** @type {!Error} */ error) {
231 var error = /** @type {Error} */ (e); 231 this.sendErrorResponse_(message, error);
232 this.sendErrorResponse_(message, error.message);
233 } 232 }
234 }; 233 };
235 234
236 /** 235 /**
237 * Disconnect the session if the |hangoutPort| gets disconnected. 236 * Disconnect the session if the |hangoutPort| gets disconnected.
238 * @private 237 * @private
239 */ 238 */
240 remoting.It2MeHelpeeChannel.prototype.onHangoutDisconnect_ = function() { 239 remoting.It2MeHelpeeChannel.prototype.onHangoutDisconnect_ = function() {
241 this.dispose(); 240 this.dispose();
242 }; 241 };
(...skipping 14 matching lines...) Expand all
257 } 256 }
258 257
259 var that = this; 258 var that = this;
260 this.showConfirmDialog_(bounds) 259 this.showConfirmDialog_(bounds)
261 .then(this.initializeHost_.bind(this)) 260 .then(this.initializeHost_.bind(this))
262 .then(this.fetchOAuthToken_.bind(this)) 261 .then(this.fetchOAuthToken_.bind(this))
263 .then(this.fetchEmail_.bind(this)) 262 .then(this.fetchEmail_.bind(this))
264 /** @param {{email:string, token:string}|Promise} result */ 263 /** @param {{email:string, token:string}|Promise} result */
265 .then(function(result) { 264 .then(function(result) {
266 that.connectToHost_(result.email, result.token); 265 that.connectToHost_(result.email, result.token);
267 /** @param {*} reason */ 266 }).catch(function(/** !Error */ reason) {
Jamie 2015/03/02 18:28:10 Missing @type? Also, I thought we had problems wi
John Williams 2015/03/02 22:01:37 Yeah, it's fixed now, and the abbreviates type syn
268 }).catch(function(reason) { 267 that.sendErrorResponse_(message, reason);
269 that.sendErrorResponse_(message, /** @type {Error} */ (reason));
270 that.dispose(); 268 that.dispose();
271 }); 269 });
272 }; 270 };
273 271
274 /** 272 /**
275 * Prompts the user before starting the It2Me Native Messaging Host. This 273 * Prompts the user before starting the It2Me Native Messaging Host. This
276 * ensures that even if Hangouts is compromised, an attacker cannot start the 274 * ensures that even if Hangouts is compromised, an attacker cannot start the
277 * host without explicit user confirmation. 275 * host without explicit user confirmation.
278 * 276 *
279 * @param {Bounds} bounds Bounds of the hangout window 277 * @param {Bounds} bounds Bounds of the hangout window
(...skipping 21 matching lines...) Expand all
301 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_MESSAGE_2'); 299 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_MESSAGE_2');
302 var message2 = l10n.getTranslationOrError( 300 var message2 = l10n.getTranslationOrError(
303 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_MESSAGE_3'); 301 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_MESSAGE_3');
304 var message = base.escapeHTML(messageHeader) + '\n' + 302 var message = base.escapeHTML(messageHeader) + '\n' +
305 '- ' + base.escapeHTML(message1) + '\n' + 303 '- ' + base.escapeHTML(message1) + '\n' +
306 '- ' + base.escapeHTML(message2) + '\n'; 304 '- ' + base.escapeHTML(message2) + '\n';
307 305
308 if(window.confirm(message)) { 306 if(window.confirm(message)) {
309 return Promise.resolve(); 307 return Promise.resolve();
310 } else { 308 } else {
311 return Promise.reject(new Error(remoting.Error.CANCELLED)); 309 return Promise.reject(remoting.Error.CANCELLED);
312 } 310 }
313 }; 311 };
314 312
315 /** 313 /**
316 * @param {Bounds} bounds the bounds of the Hangouts Window. If set, the 314 * @param {Bounds} bounds the bounds of the Hangouts Window. If set, the
317 * confirm dialog will be centered within |bounds|. 315 * confirm dialog will be centered within |bounds|.
318 * @return {Promise} A promise that will resolve if the user accepts remote 316 * @return {Promise} A promise that will resolve if the user accepts remote
319 * assistance or reject otherwise. 317 * assistance or reject otherwise.
320 * @private 318 * @private
321 */ 319 */
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 353
356 /** 354 /**
357 * @return {!Promise<string>} Promise that resolves with the OAuth token as the 355 * @return {!Promise<string>} Promise that resolves with the OAuth token as the
358 * value. 356 * value.
359 */ 357 */
360 remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() { 358 remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() {
361 if (base.isAppsV2()) { 359 if (base.isAppsV2()) {
362 return remoting.identity.getToken(); 360 return remoting.identity.getToken();
363 } else { 361 } else {
364 var onError = function(/** * */ error) { 362 var onError = function(/** * */ error) {
365 if (error === remoting.Error.NOT_AUTHENTICATED) { 363 if (error instanceof remoting.Error &&
364 /** @type {!remoting.Error} */ (error).tag ===
365 remoting.Error.Tag.NOT_AUTHENTICATED) {
366 return new Promise(function(resolve, reject) { 366 return new Promise(function(resolve, reject) {
367 remoting.oauth2.doAuthRedirect(function() { 367 remoting.oauth2.doAuthRedirect(function() {
368 remoting.identity.getToken().then(resolve); 368 remoting.identity.getToken().then(resolve);
369 }); 369 });
370 }); 370 });
371 } 371 }
372 throw Error(remoting.Error.NOT_AUTHENTICATED); 372 throw remoting.Error.NOT_AUTHENTICATED;
373 }; 373 };
374 return /** @type {!Promise<string>} */ ( 374 return /** @type {!Promise<string>} */ (
375 remoting.identity.getToken().catch(onError)); 375 remoting.identity.getToken().catch(onError));
376 } 376 }
377 }; 377 };
378 378
379 /** 379 /**
380 * @param {string|Promise} token 380 * @param {string|Promise} token
381 * @return {Promise} Promise that resolves with the access token and the email 381 * @return {Promise} Promise that resolves with the access token and the email
382 * of the user. 382 * of the user.
(...skipping 23 matching lines...) Expand all
406 this.onHostStateChanged_.bind(this), 406 this.onHostStateChanged_.bind(this),
407 base.doNothing, // Ignore |onNatPolicyChanged|. 407 base.doNothing, // Ignore |onNatPolicyChanged|.
408 console.log.bind(console), // Forward logDebugInfo to console.log. 408 console.log.bind(console), // Forward logDebugInfo to console.log.
409 remoting.settings.XMPP_SERVER_FOR_IT2ME_HOST, 409 remoting.settings.XMPP_SERVER_FOR_IT2ME_HOST,
410 remoting.settings.XMPP_SERVER_USE_TLS, 410 remoting.settings.XMPP_SERVER_USE_TLS,
411 remoting.settings.DIRECTORY_BOT_JID, 411 remoting.settings.DIRECTORY_BOT_JID,
412 this.onHostConnectError_); 412 this.onHostConnectError_);
413 }; 413 };
414 414
415 /** 415 /**
416 * @param {remoting.Error} error 416 * @param {!remoting.Error} error
417 * @private 417 * @private
418 */ 418 */
419 remoting.It2MeHelpeeChannel.prototype.onHostConnectError_ = function(error) { 419 remoting.It2MeHelpeeChannel.prototype.onHostConnectError_ = function(error) {
420 this.sendErrorResponse_(null, error); 420 this.sendErrorResponse_(null, error);
421 }; 421 };
422 422
423 /** 423 /**
424 * @param {remoting.HostSession.State} state 424 * @param {remoting.HostSession.State} state
425 * @private 425 * @private
426 */ 426 */
(...skipping 23 matching lines...) Expand all
450 case HostState.INVALID_DOMAIN_ERROR: 450 case HostState.INVALID_DOMAIN_ERROR:
451 this.sendErrorResponse_(null, remoting.Error.INVALID_HOST_DOMAIN); 451 this.sendErrorResponse_(null, remoting.Error.INVALID_HOST_DOMAIN);
452 break; 452 break;
453 default: 453 default:
454 // It is safe to ignore other state changes. 454 // It is safe to ignore other state changes.
455 } 455 }
456 }; 456 };
457 457
458 /** 458 /**
459 * @param {?{method:string, data:Object<string,*>}} incomingMessage 459 * @param {?{method:string, data:Object<string,*>}} incomingMessage
460 * @param {string|Error} error 460 * @param {!remoting.Error|!Error} error
461 * @private 461 * @private
462 */ 462 */
463 remoting.It2MeHelpeeChannel.prototype.sendErrorResponse_ = 463 remoting.It2MeHelpeeChannel.prototype.sendErrorResponse_ =
464 function(incomingMessage, error) { 464 function(incomingMessage, error) {
465 /** @type {string} */
466 var errorMessage;
467
465 if (error instanceof Error) { 468 if (error instanceof Error) {
466 error = error.message; 469 errorMessage = error.message;
470 } else {
471 errorMessage = error.tag;
467 } 472 }
468 473
469 console.error('Error responding to message method:' + 474 console.error('Error responding to message method:' +
470 (incomingMessage ? incomingMessage.method : 'null') + 475 (incomingMessage ? incomingMessage.method : 'null') +
471 ' error:' + error); 476 ' error:' + errorMessage);
472 this.hangoutPort_.postMessage({ 477 this.hangoutPort_.postMessage({
473 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.ERROR, 478 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.ERROR,
474 message: error, 479 message: errorMessage,
475 request: incomingMessage 480 request: incomingMessage
476 }); 481 });
477 }; 482 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698