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

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

Issue 1004513002: Eliminated named constants for instances of remoting.Error. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 | « remoting/webapp/crd/js/xhr.js ('k') | remoting/webapp/crd/js/xmpp_connection_unittest.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 'use strict'; 5 'use strict';
6 6
7 /** @suppress {duplicate} */ 7 /** @suppress {duplicate} */
8 var remoting = remoting || {}; 8 var remoting = remoting || {};
9 9
10 /** 10 /**
(...skipping 21 matching lines...) Expand all
32 this.startTlsPending_ = false; 32 this.startTlsPending_ = false;
33 /** @private {Array<ArrayBuffer>} */ 33 /** @private {Array<ArrayBuffer>} */
34 this.sendQueue_ = []; 34 this.sendQueue_ = [];
35 /** @private {remoting.XmppLoginHandler} */ 35 /** @private {remoting.XmppLoginHandler} */
36 this.loginHandler_ = null; 36 this.loginHandler_ = null;
37 /** @private {remoting.XmppStreamParser} */ 37 /** @private {remoting.XmppStreamParser} */
38 this.streamParser_ = null; 38 this.streamParser_ = null;
39 /** @private */ 39 /** @private */
40 this.jid_ = ''; 40 this.jid_ = '';
41 /** @private */ 41 /** @private */
42 this.error_ = remoting.Error.NONE; 42 this.error_ = remoting.Error.none();
43 }; 43 };
44 44
45 /** 45 /**
46 * @param {function(remoting.SignalStrategy.State):void} onStateChangedCallback 46 * @param {function(remoting.SignalStrategy.State):void} onStateChangedCallback
47 */ 47 */
48 remoting.XmppConnection.prototype.setStateChangedCallback = function( 48 remoting.XmppConnection.prototype.setStateChangedCallback = function(
49 onStateChangedCallback) { 49 onStateChangedCallback) {
50 this.onStateChangedCallback_ = onStateChangedCallback; 50 this.onStateChangedCallback_ = onStateChangedCallback;
51 }; 51 };
52 52
(...skipping 14 matching lines...) Expand all
67 /** 67 /**
68 * @param {string} server 68 * @param {string} server
69 * @param {string} username 69 * @param {string} username
70 * @param {string} authToken 70 * @param {string} authToken
71 */ 71 */
72 remoting.XmppConnection.prototype.connect = 72 remoting.XmppConnection.prototype.connect =
73 function(server, username, authToken) { 73 function(server, username, authToken) {
74 base.debug.assert(this.state_ == remoting.SignalStrategy.State.NOT_CONNECTED); 74 base.debug.assert(this.state_ == remoting.SignalStrategy.State.NOT_CONNECTED);
75 base.debug.assert(this.onStateChangedCallback_ != null); 75 base.debug.assert(this.onStateChangedCallback_ != null);
76 76
77 this.error_ = remoting.Error.NONE; 77 this.error_ = remoting.Error.none();
78 var hostnameAndPort = server.split(':', 2); 78 var hostnameAndPort = server.split(':', 2);
79 this.server_ = hostnameAndPort[0]; 79 this.server_ = hostnameAndPort[0];
80 this.port_ = 80 this.port_ =
81 (hostnameAndPort.length == 2) ? parseInt(hostnameAndPort[1], 10) : 5222; 81 (hostnameAndPort.length == 2) ? parseInt(hostnameAndPort[1], 10) : 5222;
82 82
83 // The server name is passed as to attribute in the <stream>. When connecting 83 // The server name is passed as to attribute in the <stream>. When connecting
84 // to talk.google.com it affects the certificate the server will use for TLS: 84 // to talk.google.com it affects the certificate the server will use for TLS:
85 // talk.google.com uses gmail certificate when specified server is gmail.com 85 // talk.google.com uses gmail certificate when specified server is gmail.com
86 // or googlemail.com and google.com cert otherwise. In the same time it 86 // or googlemail.com and google.com cert otherwise. In the same time it
87 // doesn't accept talk.google.com as target server. Here we use google.com 87 // doesn't accept talk.google.com as target server. Here we use google.com
(...skipping 16 matching lines...) Expand all
104 this.onHandshakeDone_.bind(this), this.onError_.bind(this)); 104 this.onHandshakeDone_.bind(this), this.onError_.bind(this));
105 this.setState_(remoting.SignalStrategy.State.CONNECTING); 105 this.setState_(remoting.SignalStrategy.State.CONNECTING);
106 106
107 if (!this.socket_) { 107 if (!this.socket_) {
108 this.socket_ = new remoting.TcpSocket(); 108 this.socket_ = new remoting.TcpSocket();
109 } 109 }
110 var that = this; 110 var that = this;
111 this.socket_.connect(this.server_, this.port_) 111 this.socket_.connect(this.server_, this.port_)
112 .then(this.onSocketConnected_.bind(this)) 112 .then(this.onSocketConnected_.bind(this))
113 .catch(function(error) { 113 .catch(function(error) {
114 that.onError_(remoting.Error.NETWORK_FAILURE, 114 that.onError_(new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE),
115 'Failed to connect to ' + that.server_ + ': ' + error); 115 'Failed to connect to ' + that.server_ + ': ' + error);
116 }); 116 });
117 }; 117 };
118 118
119 /** @param {string} message */ 119 /** @param {string} message */
120 remoting.XmppConnection.prototype.sendMessage = function(message) { 120 remoting.XmppConnection.prototype.sendMessage = function(message) {
121 base.debug.assert(this.state_ == remoting.SignalStrategy.State.CONNECTED); 121 base.debug.assert(this.state_ == remoting.SignalStrategy.State.CONNECTED);
122 this.sendString_(message); 122 this.sendString_(message);
123 }; 123 };
124 124
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } else if (this.state_ == remoting.SignalStrategy.State.CONNECTED) { 185 } else if (this.state_ == remoting.SignalStrategy.State.CONNECTED) {
186 this.streamParser_.appendData(data); 186 this.streamParser_.appendData(data);
187 } 187 }
188 }; 188 };
189 189
190 /** 190 /**
191 * @param {number} errorCode 191 * @param {number} errorCode
192 * @private 192 * @private
193 */ 193 */
194 remoting.XmppConnection.prototype.onReceiveError_ = function(errorCode) { 194 remoting.XmppConnection.prototype.onReceiveError_ = function(errorCode) {
195 this.onError_(remoting.Error.NETWORK_FAILURE, 195 this.onError_(new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE),
196 'Failed to receive from XMPP socket: ' + errorCode); 196 'Failed to receive from XMPP socket: ' + errorCode);
197 }; 197 };
198 198
199 /** 199 /**
200 * @param {string} text 200 * @param {string} text
201 * @private 201 * @private
202 */ 202 */
203 remoting.XmppConnection.prototype.sendString_ = function(text) { 203 remoting.XmppConnection.prototype.sendString_ = function(text) {
204 this.sendBuffer_(base.encodeUtf8(text)); 204 this.sendBuffer_(base.encodeUtf8(text));
205 }; 205 };
(...skipping 18 matching lines...) Expand all
224 var that = this; 224 var that = this;
225 225
226 this.sendPending_ = true; 226 this.sendPending_ = true;
227 this.socket_.send(this.sendQueue_[0]) 227 this.socket_.send(this.sendQueue_[0])
228 .then(function(/** number */ bytesSent) { 228 .then(function(/** number */ bytesSent) {
229 that.sendPending_ = false; 229 that.sendPending_ = false;
230 that.onSent_(bytesSent); 230 that.onSent_(bytesSent);
231 }) 231 })
232 .catch(function(/** number */ error) { 232 .catch(function(/** number */ error) {
233 that.sendPending_ = false; 233 that.sendPending_ = false;
234 that.onError_(remoting.Error.NETWORK_FAILURE, 234 that.onError_(new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE),
235 'TCP write failed with error ' + error); 235 'TCP write failed with error ' + error);
236 }); 236 });
237 }; 237 };
238 238
239 /** 239 /**
240 * @param {number} bytesSent 240 * @param {number} bytesSent
241 * @private 241 * @private
242 */ 242 */
243 remoting.XmppConnection.prototype.onSent_ = function(bytesSent) { 243 remoting.XmppConnection.prototype.onSent_ = function(bytesSent) {
244 // Ignore send() result if the socket was closed. 244 // Ignore send() result if the socket was closed.
(...skipping 27 matching lines...) Expand all
272 this.socket_.startTls() 272 this.socket_.startTls()
273 .then(function() { 273 .then(function() {
274 that.startTlsPending_ = false; 274 that.startTlsPending_ = false;
275 that.socket_.startReceiving(that.onReceive_.bind(that), 275 that.socket_.startReceiving(that.onReceive_.bind(that),
276 that.onReceiveError_.bind(that)); 276 that.onReceiveError_.bind(that));
277 277
278 that.loginHandler_.onTlsStarted(); 278 that.loginHandler_.onTlsStarted();
279 }) 279 })
280 .catch(function(/** number */ error) { 280 .catch(function(/** number */ error) {
281 that.startTlsPending_ = false; 281 that.startTlsPending_ = false;
282 that.onError_(remoting.Error.NETWORK_FAILURE, 282 that.onError_(new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE),
283 'Failed to start TLS: ' + error); 283 'Failed to start TLS: ' + error);
284 }); 284 });
285 } 285 }
286 286
287 /** 287 /**
288 * @param {string} jid 288 * @param {string} jid
289 * @param {remoting.XmppStreamParser} streamParser 289 * @param {remoting.XmppStreamParser} streamParser
290 * @private 290 * @private
291 */ 291 */
292 remoting.XmppConnection.prototype.onHandshakeDone_ = 292 remoting.XmppConnection.prototype.onHandshakeDone_ =
(...skipping 13 matching lines...) Expand all
306 if (this.onIncomingStanzaCallback_) { 306 if (this.onIncomingStanzaCallback_) {
307 this.onIncomingStanzaCallback_(stanza); 307 this.onIncomingStanzaCallback_(stanza);
308 } 308 }
309 }; 309 };
310 310
311 /** 311 /**
312 * @param {string} text 312 * @param {string} text
313 * @private 313 * @private
314 */ 314 */
315 remoting.XmppConnection.prototype.onParserError_ = function(text) { 315 remoting.XmppConnection.prototype.onParserError_ = function(text) {
316 this.onError_(remoting.Error.UNEXPECTED, text); 316 this.onError_(remoting.Error.unexpected(), text);
317 } 317 };
318 318
319 /** 319 /**
320 * @param {!remoting.Error} error 320 * @param {!remoting.Error} error
321 * @param {string} text 321 * @param {string} text
322 * @private 322 * @private
323 */ 323 */
324 remoting.XmppConnection.prototype.onError_ = function(error, text) { 324 remoting.XmppConnection.prototype.onError_ = function(error, text) {
325 console.error(text); 325 console.error(text);
326 this.error_ = error; 326 this.error_ = error;
327 base.dispose(this.socket_); 327 base.dispose(this.socket_);
328 this.socket_ = null; 328 this.socket_ = null;
329 this.setState_(remoting.SignalStrategy.State.FAILED); 329 this.setState_(remoting.SignalStrategy.State.FAILED);
330 }; 330 };
331 331
332 /** 332 /**
333 * @param {remoting.SignalStrategy.State} newState 333 * @param {remoting.SignalStrategy.State} newState
334 * @private 334 * @private
335 */ 335 */
336 remoting.XmppConnection.prototype.setState_ = function(newState) { 336 remoting.XmppConnection.prototype.setState_ = function(newState) {
337 if (this.state_ != newState) { 337 if (this.state_ != newState) {
338 this.state_ = newState; 338 this.state_ = newState;
339 this.onStateChangedCallback_(this.state_); 339 this.onStateChangedCallback_(this.state_);
340 } 340 }
341 }; 341 };
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/xhr.js ('k') | remoting/webapp/crd/js/xmpp_connection_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698