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

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

Issue 1054273002: [Webapp Refactor] Implements remoting.Activity. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 /** @suppress {duplicate} */ 5 /** @suppress {duplicate} */
6 var remoting = remoting || {}; 6 var remoting = remoting || {};
7 7
8 (function() { 8 (function() {
9 9
10 'use strict'; 10 'use strict';
11 11
12 // Length of the various components of the access code in number of digits. 12 // Length of the various components of the access code in number of digits.
13 var SUPPORT_ID_LENGTH = 7; 13 var SUPPORT_ID_LENGTH = 7;
14 var HOST_SECRET_LENGTH = 5; 14 var HOST_SECRET_LENGTH = 5;
15 var ACCESS_CODE_LENGTH = SUPPORT_ID_LENGTH + HOST_SECRET_LENGTH; 15 var ACCESS_CODE_LENGTH = SUPPORT_ID_LENGTH + HOST_SECRET_LENGTH;
16 16
17 /** 17 /**
18 * @param {remoting.SessionConnector} sessionConnector 18 * @param {remoting.SessionConnector} sessionConnector
19 * @constructor 19 * @constructor
20 * @implements {remoting.ConnectFlow}
20 */ 21 */
21 remoting.It2MeConnectFlow = function(sessionConnector) { 22 remoting.It2MeConnectFlow = function(sessionConnector) {
22 /** @private */ 23 /** @private */
23 this.sessionConnector_ = sessionConnector; 24 this.sessionConnector_ = sessionConnector;
24 /** @private */ 25 /** @private */
25 this.hostId_ = ''; 26 this.hostId_ = '';
26 /** @private */ 27 /** @private */
27 this.passCode_ = ''; 28 this.passCode_ = '';
28 29
29 var form = document.getElementById('access-code-form'); 30 var form = document.getElementById('access-code-form');
30 /** @private */ 31 /** @private */
31 this.accessCodeDialog_ = new remoting.InputDialog( 32 this.accessCodeDialog_ = new remoting.InputDialog(
32 remoting.AppMode.CLIENT_UNCONNECTED, 33 remoting.AppMode.CLIENT_UNCONNECTED,
33 form, 34 form,
34 form.querySelector('#access-code-entry'), 35 form.querySelector('#access-code-entry'),
35 form.querySelector('#cancel-access-code-button')); 36 form.querySelector('#cancel-access-code-button'));
36 }; 37 };
37 38
39 remoting.It2MeConnectFlow.prototype.dispose = function() {};
38 40
39 remoting.It2MeConnectFlow.prototype.start = function() { 41 remoting.It2MeConnectFlow.prototype.start = function() {
40 var that = this; 42 var that = this;
41 43
42 this.accessCodeDialog_.show().then(function(/** string */ accessCode) { 44 this.accessCodeDialog_.show().then(function(/** string */ accessCode) {
43 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); 45 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
44 return that.verifyAccessCode_(accessCode); 46 return that.verifyAccessCode_(accessCode);
45 }).then(function() { 47 }).then(function() {
46 return remoting.identity.getToken(); 48 return remoting.identity.getToken();
47 }).then(function(/** string */ token) { 49 }).then(function(/** string */ token) {
(...skipping 10 matching lines...) Expand all
58 remoting.setMode(remoting.AppMode.HOME); 60 remoting.setMode(remoting.AppMode.HOME);
59 } else { 61 } else {
60 var errorDiv = document.getElementById('connect-error-message'); 62 var errorDiv = document.getElementById('connect-error-message');
61 l10n.localizeElementFromTag(errorDiv, error.getTag()); 63 l10n.localizeElementFromTag(errorDiv, error.getTag());
62 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); 64 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME);
63 } 65 }
64 }); 66 });
65 }; 67 };
66 68
67 /** 69 /**
70 * @param {!remoting.Error} error
71 */
72 remoting.It2MeConnectFlow.prototype.onConnectionFailed = function(error) {
73 this.onError(error);
74 };
75
76 /**
77 * @param {!remoting.ConnectionInfo} connectionInfo
78 */
79 remoting.It2MeConnectFlow.prototype.onConnected = function(connectionInfo) {
80 this.accessCodeDialog_.inputField().value = '';
81 };
82
83 remoting.It2MeConnectFlow.prototype.onDisconnected = function() {
84 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME);
85 };
86
87 /**
88 * @param {!remoting.Error} error
89 */
90 remoting.It2MeConnectFlow.prototype.onError = function(error) {
91 var errorDiv = document.getElementById('connect-error-message');
92 l10n.localizeElementFromTag(errorDiv, error.getTag());
93 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME);
94 };
95
96
97 /**
68 * @param {string} accessCode 98 * @param {string} accessCode
69 * @return {Promise} Promise that resolves if the access code is valid. 99 * @return {Promise} Promise that resolves if the access code is valid.
70 * @private 100 * @private
71 */ 101 */
72 remoting.It2MeConnectFlow.prototype.verifyAccessCode_ = function(accessCode) { 102 remoting.It2MeConnectFlow.prototype.verifyAccessCode_ = function(accessCode) {
73 var normalizedAccessCode = accessCode.replace(/\s/g, ''); 103 var normalizedAccessCode = accessCode.replace(/\s/g, '');
74 if (normalizedAccessCode.length !== ACCESS_CODE_LENGTH) { 104 if (normalizedAccessCode.length !== ACCESS_CODE_LENGTH) {
75 return Promise.reject(new remoting.Error( 105 return Promise.reject(new remoting.Error(
76 remoting.Error.Tag.INVALID_ACCESS_CODE)); 106 remoting.Error.Tag.INVALID_ACCESS_CODE));
77 } 107 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 switch (error) { 168 switch (error) {
139 case 0: return new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE); 169 case 0: return new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE);
140 case 404: return new remoting.Error(remoting.Error.Tag.INVALID_ACCESS_CODE); 170 case 404: return new remoting.Error(remoting.Error.Tag.INVALID_ACCESS_CODE);
141 case 502: // No break 171 case 502: // No break
142 case 503: return new remoting.Error(remoting.Error.Tag.SERVICE_UNAVAILABLE); 172 case 503: return new remoting.Error(remoting.Error.Tag.SERVICE_UNAVAILABLE);
143 default: return remoting.Error.unexpected(); 173 default: return remoting.Error.unexpected();
144 } 174 }
145 } 175 }
146 176
147 })(); 177 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698