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

Unified Diff: remoting/webapp/crd/js/xmpp_connection.js

Issue 1133913002: [Chromoting] Move shared webapp JS files from crd/js -> base/js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/webapp/crd/js/xhr_unittest.js ('k') | remoting/webapp/crd/js/xmpp_connection_unittest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/crd/js/xmpp_connection.js
diff --git a/remoting/webapp/crd/js/xmpp_connection.js b/remoting/webapp/crd/js/xmpp_connection.js
deleted file mode 100644
index f6137788bd501a7c01d34c9d0ec18bceb9e25bde..0000000000000000000000000000000000000000
--- a/remoting/webapp/crd/js/xmpp_connection.js
+++ /dev/null
@@ -1,341 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-'use strict';
-
-/** @suppress {duplicate} */
-var remoting = remoting || {};
-
-/**
- * A connection to an XMPP server.
- *
- * @constructor
- * @implements {remoting.SignalStrategy}
- */
-remoting.XmppConnection = function() {
- /** @private */
- this.server_ = '';
- /** @private */
- this.port_ = 0;
- /** @private {?function(remoting.SignalStrategy.State):void} */
- this.onStateChangedCallback_ = null;
- /** @private {?function(Element):void} */
- this.onIncomingStanzaCallback_ = null;
- /** @type {?remoting.TcpSocket} @private */
- this.socket_ = null;
- /** @private */
- this.state_ = remoting.SignalStrategy.State.NOT_CONNECTED;
- /** @private */
- this.sendPending_ = false;
- /** @private */
- this.startTlsPending_ = false;
- /** @private {Array<ArrayBuffer>} */
- this.sendQueue_ = [];
- /** @private {remoting.XmppLoginHandler} */
- this.loginHandler_ = null;
- /** @private {remoting.XmppStreamParser} */
- this.streamParser_ = null;
- /** @private */
- this.jid_ = '';
- /** @private */
- this.error_ = remoting.Error.none();
-};
-
-/**
- * @param {function(remoting.SignalStrategy.State):void} onStateChangedCallback
- */
-remoting.XmppConnection.prototype.setStateChangedCallback = function(
- onStateChangedCallback) {
- this.onStateChangedCallback_ = onStateChangedCallback;
-};
-
-remoting.XmppConnection.prototype.setSocketForTests = function(
- /** remoting.TcpSocket */ socket) {
- this.socket_ = socket;
-};
-
-/**
- * @param {?function(Element):void} onIncomingStanzaCallback Callback to call on
- * incoming messages.
- */
-remoting.XmppConnection.prototype.setIncomingStanzaCallback =
- function(onIncomingStanzaCallback) {
- this.onIncomingStanzaCallback_ = onIncomingStanzaCallback;
-};
-
-/**
- * @param {string} server
- * @param {string} username
- * @param {string} authToken
- */
-remoting.XmppConnection.prototype.connect =
- function(server, username, authToken) {
- base.debug.assert(this.state_ == remoting.SignalStrategy.State.NOT_CONNECTED);
- base.debug.assert(this.onStateChangedCallback_ != null);
-
- this.error_ = remoting.Error.none();
- var hostnameAndPort = server.split(':', 2);
- this.server_ = hostnameAndPort[0];
- this.port_ =
- (hostnameAndPort.length == 2) ? parseInt(hostnameAndPort[1], 10) : 5222;
-
- // The server name is passed as to attribute in the <stream>. When connecting
- // to talk.google.com it affects the certificate the server will use for TLS:
- // talk.google.com uses gmail certificate when specified server is gmail.com
- // or googlemail.com and google.com cert otherwise. In the same time it
- // doesn't accept talk.google.com as target server. Here we use google.com
- // server name when authenticating to talk.google.com. This ensures that the
- // server will use google.com cert which will be accepted by the TLS
- // implementation in Chrome (TLS API doesn't allow specifying domain other
- // than the one that was passed to connect()).
- var xmppServer = this.server_;
- if (xmppServer == 'talk.google.com')
- xmppServer = 'google.com';
-
- // <starttls> handshake before starting TLS is not needed when connecting on
- // the HTTPS port.
- var needHandshakeBeforeTls = this.port_ != 443;
-
- /** @type {remoting.XmppLoginHandler} */
- this.loginHandler_ = new remoting.XmppLoginHandler(
- xmppServer, username, authToken, needHandshakeBeforeTls,
- this.sendString_.bind(this), this.startTls_.bind(this),
- this.onHandshakeDone_.bind(this), this.onError_.bind(this));
- this.setState_(remoting.SignalStrategy.State.CONNECTING);
-
- if (!this.socket_) {
- this.socket_ = new remoting.TcpSocket();
- }
- var that = this;
- this.socket_.connect(this.server_, this.port_)
- .then(this.onSocketConnected_.bind(this))
- .catch(function(error) {
- that.onError_(new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE),
- 'Failed to connect to ' + that.server_ + ': ' + error);
- });
-};
-
-/** @param {string} message */
-remoting.XmppConnection.prototype.sendMessage = function(message) {
- base.debug.assert(this.state_ == remoting.SignalStrategy.State.CONNECTED);
- this.sendString_(message);
-};
-
-/**
- * @param {remoting.LogToServer} logToServer The LogToServer instance for the
- * connection.
- */
-remoting.XmppConnection.prototype.sendConnectionSetupResults =
- function(logToServer) {
-};
-
-/** @return {remoting.SignalStrategy.State} Current state */
-remoting.XmppConnection.prototype.getState = function() {
- return this.state_;
-};
-
-/** @return {!remoting.Error} Error when in FAILED state. */
-remoting.XmppConnection.prototype.getError = function() {
- return this.error_;
-};
-
-/** @return {string} Current JID when in CONNECTED state. */
-remoting.XmppConnection.prototype.getJid = function() {
- return this.jid_;
-};
-
-/** @return {remoting.SignalStrategy.Type} The signal strategy type. */
-remoting.XmppConnection.prototype.getType = function() {
- return remoting.SignalStrategy.Type.XMPP;
-};
-
-remoting.XmppConnection.prototype.dispose = function() {
- base.dispose(this.socket_);
- this.socket_ = null;
- this.setState_(remoting.SignalStrategy.State.CLOSED);
-};
-
-/** @private */
-remoting.XmppConnection.prototype.onSocketConnected_ = function() {
- // Check if connection was destroyed.
- if (this.state_ != remoting.SignalStrategy.State.CONNECTING) {
- return;
- }
-
- this.setState_(remoting.SignalStrategy.State.HANDSHAKE);
- this.loginHandler_.start();
-
- if (!this.startTlsPending_) {
- this.socket_.startReceiving(this.onReceive_.bind(this),
- this.onReceiveError_.bind(this));
- }
-};
-
-/**
- * @param {ArrayBuffer} data
- * @private
- */
-remoting.XmppConnection.prototype.onReceive_ = function(data) {
- base.debug.assert(this.state_ == remoting.SignalStrategy.State.HANDSHAKE ||
- this.state_ == remoting.SignalStrategy.State.CONNECTED);
-
- if (this.state_ == remoting.SignalStrategy.State.HANDSHAKE) {
- this.loginHandler_.onDataReceived(data);
- } else if (this.state_ == remoting.SignalStrategy.State.CONNECTED) {
- this.streamParser_.appendData(data);
- }
-};
-
-/**
- * @param {number} errorCode
- * @private
- */
-remoting.XmppConnection.prototype.onReceiveError_ = function(errorCode) {
- this.onError_(new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE),
- 'Failed to receive from XMPP socket: ' + errorCode);
-};
-
-/**
- * @param {string} text
- * @private
- */
-remoting.XmppConnection.prototype.sendString_ = function(text) {
- this.sendBuffer_(base.encodeUtf8(text));
-};
-
-/**
- * @param {ArrayBuffer} data
- * @private
- */
-remoting.XmppConnection.prototype.sendBuffer_ = function(data) {
- this.sendQueue_.push(data);
- this.flushSendQueue_();
-};
-
-/**
- * @private
- */
-remoting.XmppConnection.prototype.flushSendQueue_ = function() {
- if (this.sendPending_ || this.sendQueue_.length == 0) {
- return;
- }
-
- var that = this;
-
- this.sendPending_ = true;
- this.socket_.send(this.sendQueue_[0])
- .then(function(/** number */ bytesSent) {
- that.sendPending_ = false;
- that.onSent_(bytesSent);
- })
- .catch(function(/** number */ error) {
- that.sendPending_ = false;
- that.onError_(new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE),
- 'TCP write failed with error ' + error);
- });
-};
-
-/**
- * @param {number} bytesSent
- * @private
- */
-remoting.XmppConnection.prototype.onSent_ = function(bytesSent) {
- // Ignore send() result if the socket was closed.
- if (this.state_ != remoting.SignalStrategy.State.HANDSHAKE &&
- this.state_ != remoting.SignalStrategy.State.CONNECTED) {
- return;
- }
-
- base.debug.assert(this.sendQueue_.length > 0);
-
- var data = this.sendQueue_[0];
- base.debug.assert(bytesSent <= data.byteLength);
- if (bytesSent == data.byteLength) {
- this.sendQueue_.shift();
- } else {
- this.sendQueue_[0] = data.slice(data.byteLength - bytesSent);
- }
-
- this.flushSendQueue_();
-};
-
-/**
- * @private
- */
-remoting.XmppConnection.prototype.startTls_ = function() {
- base.debug.assert(!this.startTlsPending_);
-
- var that = this;
-
- this.startTlsPending_ = true;
- this.socket_.startTls()
- .then(function() {
- that.startTlsPending_ = false;
- that.socket_.startReceiving(that.onReceive_.bind(that),
- that.onReceiveError_.bind(that));
-
- that.loginHandler_.onTlsStarted();
- })
- .catch(function(/** number */ error) {
- that.startTlsPending_ = false;
- that.onError_(new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE),
- 'Failed to start TLS: ' + error);
- });
-}
-
-/**
- * @param {string} jid
- * @param {remoting.XmppStreamParser} streamParser
- * @private
- */
-remoting.XmppConnection.prototype.onHandshakeDone_ =
- function(jid, streamParser) {
- this.jid_ = jid;
- this.streamParser_ = streamParser;
- this.streamParser_.setCallbacks(this.onIncomingStanza_.bind(this),
- this.onParserError_.bind(this));
- this.setState_(remoting.SignalStrategy.State.CONNECTED);
-};
-
-/**
- * @param {Element} stanza
- * @private
- */
-remoting.XmppConnection.prototype.onIncomingStanza_ = function(stanza) {
- if (this.onIncomingStanzaCallback_) {
- this.onIncomingStanzaCallback_(stanza);
- }
-};
-
-/**
- * @param {string} text
- * @private
- */
-remoting.XmppConnection.prototype.onParserError_ = function(text) {
- this.onError_(remoting.Error.unexpected(), text);
-};
-
-/**
- * @param {!remoting.Error} error
- * @param {string} text
- * @private
- */
-remoting.XmppConnection.prototype.onError_ = function(error, text) {
- console.error(text);
- this.error_ = error;
- base.dispose(this.socket_);
- this.socket_ = null;
- this.setState_(remoting.SignalStrategy.State.FAILED);
-};
-
-/**
- * @param {remoting.SignalStrategy.State} newState
- * @private
- */
-remoting.XmppConnection.prototype.setState_ = function(newState) {
- if (this.state_ != newState) {
- this.state_ = newState;
- this.onStateChangedCallback_(this.state_);
- }
-};
« no previous file with comments | « remoting/webapp/crd/js/xhr_unittest.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