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

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

Issue 552403004: Interfaceify ClientPlugin in preparation for mocking it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Interfaceify more classes. Created 6 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 * Connect set-up state machine for Me2Me and IT2Me 7 * Connect set-up state machine for Me2Me and IT2Me
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
11 11
12 /** @suppress {duplicate} */ 12 /** @suppress {duplicate} */
13 var remoting = remoting || {}; 13 var remoting = remoting || {};
14 14
15 /** 15 /**
16 * @param {HTMLElement} clientContainer Container element for the client view. 16 * @param {HTMLElement} clientContainer Container element for the client view.
17 * @param {function(remoting.ClientSession):void} onConnected Callback on 17 * @param {function(remoting.ClientSession):void} onConnected Callback on
18 * success. 18 * success.
19 * @param {function(remoting.Error):void} onError Callback on error. 19 * @param {function(remoting.Error):void} onError Callback on error.
20 * @param {function(string, string):boolean} onExtensionMessage The handler for 20 * @param {function(string, string):boolean} onExtensionMessage The handler for
21 * protocol extension messages. Returns true if a message is recognized; 21 * protocol extension messages. Returns true if a message is recognized;
22 * false otherwise. 22 * false otherwise.
23 * @constructor 23 * @constructor
24 * @implements {remoting.SessionConnectorInterface}
24 */ 25 */
25 remoting.SessionConnector = function(clientContainer, onConnected, onError, 26 remoting.SessionConnector = function(clientContainer, onConnected, onError,
26 onExtensionMessage) { 27 onExtensionMessage) {
27 /** 28 /**
28 * @type {HTMLElement} 29 * @type {HTMLElement}
29 * @private 30 * @private
30 */ 31 */
31 this.clientContainer_ = clientContainer; 32 this.clientContainer_ = clientContainer;
32 33
33 /** 34 /**
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // Initialize/declare per-connection state. 83 // Initialize/declare per-connection state.
83 this.reset(); 84 this.reset();
84 }; 85 };
85 86
86 /** 87 /**
87 * Reset the per-connection state so that the object can be re-used for a 88 * Reset the per-connection state so that the object can be re-used for a
88 * second connection. Note the none of the shared WCS state is reset. 89 * second connection. Note the none of the shared WCS state is reset.
89 */ 90 */
90 remoting.SessionConnector.prototype.reset = function() { 91 remoting.SessionConnector.prototype.reset = function() {
91 /** 92 /**
92 * Set to true to indicate that the user requested pairing when entering
93 * their PIN for a Me2Me connection.
94 *
95 * @type {boolean}
96 */
97 this.pairingRequested = false;
98
99 /**
100 * String used to identify the host to which to connect. For IT2Me, this is 93 * String used to identify the host to which to connect. For IT2Me, this is
101 * the first 7 digits of the access code; for Me2Me it is the host identifier. 94 * the first 7 digits of the access code; for Me2Me it is the host identifier.
102 * 95 *
103 * @type {string} 96 * @type {string}
104 * @private 97 * @private
105 */ 98 */
106 this.hostId_ = ''; 99 this.hostId_ = '';
107 100
108 /** 101 /**
109 * For paired connections, the client id of this device, issued by the host. 102 * For paired connections, the client id of this device, issued by the host.
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 if (host && host.data && host.data.jabberId && host.data.publicKey) { 426 if (host && host.data && host.data.jabberId && host.data.publicKey) {
434 this.hostJid_ = host.data.jabberId; 427 this.hostJid_ = host.data.jabberId;
435 this.hostPublicKey_ = host.data.publicKey; 428 this.hostPublicKey_ = host.data.publicKey;
436 this.hostDisplayName_ = this.hostJid_.split('/')[0]; 429 this.hostDisplayName_ = this.hostJid_.split('/')[0];
437 this.createSession_(); 430 this.createSession_();
438 return; 431 return;
439 } else { 432 } else {
440 console.error('Invalid "support-hosts" response from server.'); 433 console.error('Invalid "support-hosts" response from server.');
441 } 434 }
442 } else { 435 } else {
443 this.onError_(this.translateSupportHostsError(xhr.status)); 436 this.onError_(this.translateSupportHostsError_(xhr.status));
444 } 437 }
445 }; 438 };
446 439
447 /** 440 /**
448 * Creates ClientSession object. 441 * Creates ClientSession object.
449 */ 442 */
450 remoting.SessionConnector.prototype.createSession_ = function() { 443 remoting.SessionConnector.prototype.createSession_ = function() {
451 // In some circumstances, the WCS <iframe> can get reloaded, which results 444 // In some circumstances, the WCS <iframe> can get reloaded, which results
452 // in a new clientJid and a new callback. In this case, remove the old 445 // in a new clientJid and a new callback. In this case, remove the old
453 // client plugin before instantiating a new one. 446 // client plugin before instantiating a new one.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 } 556 }
564 this.onError_(remoting.Error.HOST_IS_OFFLINE); 557 this.onError_(remoting.Error.HOST_IS_OFFLINE);
565 }; 558 };
566 559
567 /** 560 /**
568 * @param {number} error An HTTP error code returned by the support-hosts 561 * @param {number} error An HTTP error code returned by the support-hosts
569 * endpoint. 562 * endpoint.
570 * @return {remoting.Error} The equivalent remoting.Error code. 563 * @return {remoting.Error} The equivalent remoting.Error code.
571 * @private 564 * @private
572 */ 565 */
573 remoting.SessionConnector.prototype.translateSupportHostsError = 566 remoting.SessionConnector.prototype.translateSupportHostsError_ =
574 function(error) { 567 function(error) {
575 switch (error) { 568 switch (error) {
576 case 0: return remoting.Error.NETWORK_FAILURE; 569 case 0: return remoting.Error.NETWORK_FAILURE;
577 case 404: return remoting.Error.INVALID_ACCESS_CODE; 570 case 404: return remoting.Error.INVALID_ACCESS_CODE;
578 case 502: // No break 571 case 502: // No break
579 case 503: return remoting.Error.SERVICE_UNAVAILABLE; 572 case 503: return remoting.Error.SERVICE_UNAVAILABLE;
580 default: return remoting.Error.UNEXPECTED; 573 default: return remoting.Error.UNEXPECTED;
581 } 574 }
582 }; 575 };
583 576
584 /** 577 /**
585 * Normalize the access code entered by the user. 578 * Normalize the access code entered by the user.
586 * 579 *
587 * @param {string} accessCode The access code, as entered by the user. 580 * @param {string} accessCode The access code, as entered by the user.
588 * @return {string} The normalized form of the code (whitespace removed). 581 * @return {string} The normalized form of the code (whitespace removed).
582 * @private
589 */ 583 */
590 remoting.SessionConnector.prototype.normalizeAccessCode_ = 584 remoting.SessionConnector.prototype.normalizeAccessCode_ =
591 function(accessCode) { 585 function(accessCode) {
592 // Trim whitespace. 586 // Trim whitespace.
593 return accessCode.replace(/\s/g, ''); 587 return accessCode.replace(/\s/g, '');
594 }; 588 };
589
590
591 /**
592 * @constructor
593 * @implements {remoting.SessionConnectorFactory}
594 */
595 remoting.DefaultSessionConnectorFactory = function() {
596 };
597
598 /**
599 * @param {HTMLElement} clientContainer Container element for the client view.
600 * @param {function(remoting.ClientSession):void} onConnected Callback on
601 * success.
602 * @param {function(remoting.Error):void} onError Callback on error.
603 * @param {function(string, string):boolean} onExtensionMessage The handler for
604 * protocol extension messages. Returns true if a message is recognized;
605 * false otherwise.
606 */
607 remoting.DefaultSessionConnectorFactory.prototype.createConnector =
608 function(clientContainer, onConnected, onError, onExtensionMessage) {
609 return new remoting.SessionConnector(
610 clientContainer, onConnected, onError, onExtensionMessage);
611 };
612
613 /**
614 * @type {remoting.SessionConnectorFactory}
615 */
616 remoting.SessionConnector.factory =
617 new remoting.DefaultSessionConnectorFactory();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698