diff --git a/content/base/src/nsWebSocket.cpp b/content/base/src/nsWebSocket.cpp index f3454bd3d65..ea1fa436001 100644 --- a/content/base/src/nsWebSocket.cpp +++ b/content/base/src/nsWebSocket.cpp @@ -72,7 +72,8 @@ #include "nsJSUtils.h" #include "nsIScriptError.h" #include "nsNetUtil.h" -#include "nsIWebSocketProtocol.h" +#include "nsIWebSocketChannel.h" +#include "nsIWebSocketListener.h" #include "nsILoadGroup.h" #include "nsIRequest.h" #include "mozilla/Preferences.h" @@ -147,7 +148,7 @@ private: PRUint32 mOutgoingBufferedAmount; nsWebSocket* mOwner; // weak reference - nsCOMPtr mWebSocketProtocol; + nsCOMPtr mWebSocketChannel; PRPackedBool mClosedCleanly; @@ -187,7 +188,7 @@ nsWebSocketEstablishedConnection::~nsWebSocketEstablishedConnection() { NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread"); NS_ABORT_IF_FALSE(!mOwner, "Disconnect wasn't called!"); - NS_ABORT_IF_FALSE(!mWebSocketProtocol, "Disconnect wasn't called!"); + NS_ABORT_IF_FALSE(!mWebSocketChannel, "Disconnect wasn't called!"); } nsresult @@ -251,7 +252,7 @@ nsWebSocketEstablishedConnection::PostMessage(const nsString& aMessage) rv = NS_BASE_STREAM_CLOSED; } else { mOutgoingBufferedAmount += buf.Length(); - mWebSocketProtocol->SendMsg(buf); + mWebSocketChannel->SendMsg(buf); rv = NS_OK; } @@ -271,16 +272,16 @@ nsWebSocketEstablishedConnection::Init(nsWebSocket *aOwner) mOwner = aOwner; if (mOwner->mSecure) { - mWebSocketProtocol = + mWebSocketChannel = do_CreateInstance("@mozilla.org/network/protocol;1?name=wss", &rv); } else { - mWebSocketProtocol = + mWebSocketChannel = do_CreateInstance("@mozilla.org/network/protocol;1?name=ws", &rv); } NS_ENSURE_SUCCESS(rv, rv); - rv = mWebSocketProtocol->SetNotificationCallbacks(this); + rv = mWebSocketChannel->SetNotificationCallbacks(this); NS_ENSURE_SUCCESS(rv, rv); // add ourselves to the document's load group and @@ -288,19 +289,19 @@ nsWebSocketEstablishedConnection::Init(nsWebSocket *aOwner) nsCOMPtr loadGroup; rv = GetLoadGroup(getter_AddRefs(loadGroup)); if (loadGroup) { - rv = mWebSocketProtocol->SetLoadGroup(loadGroup); + rv = mWebSocketChannel->SetLoadGroup(loadGroup); NS_ENSURE_SUCCESS(rv, rv); rv = loadGroup->AddRequest(this, nsnull); NS_ENSURE_SUCCESS(rv, rv); } if (!mOwner->mProtocol.IsEmpty()) - rv = mWebSocketProtocol->SetProtocol(mOwner->mProtocol); + rv = mWebSocketChannel->SetProtocol(mOwner->mProtocol); NS_ENSURE_SUCCESS(rv, rv); nsCString utf8Origin; CopyUTF16toUTF8(mOwner->mUTF16Origin, utf8Origin); - rv = mWebSocketProtocol->AsyncOpen(mOwner->mURI, + rv = mWebSocketChannel->AsyncOpen(mOwner->mURI, utf8Origin, this, nsnull); NS_ENSURE_SUCCESS(rv, rv); @@ -388,7 +389,7 @@ nsWebSocketEstablishedConnection::Close() return NS_OK; } - return mWebSocketProtocol->Close(); + return mWebSocketChannel->Close(); } nsresult @@ -451,7 +452,7 @@ nsWebSocketEstablishedConnection::Disconnect() mOwner->DontKeepAliveAnyMore(); mStatus = CONN_CLOSED; mOwner = nsnull; - mWebSocketProtocol = nsnull; + mWebSocketChannel = nsnull; nsLayoutStatics::Release(); return NS_OK; @@ -504,7 +505,7 @@ nsWebSocketEstablishedConnection::OnStart(nsISupports *aContext) return NS_OK; if (!mOwner->mProtocol.IsEmpty()) - mWebSocketProtocol->GetProtocol(mOwner->mProtocol); + mWebSocketChannel->GetProtocol(mOwner->mProtocol); mStatus = CONN_CONNECTED_AND_READY; mOwner->SetReadyState(nsIWebSocket::OPEN); diff --git a/netwerk/protocol/websocket/BaseWebSocketChannel.cpp b/netwerk/protocol/websocket/BaseWebSocketChannel.cpp index 488e436284e..7c359525e05 100644 --- a/netwerk/protocol/websocket/BaseWebSocketChannel.cpp +++ b/netwerk/protocol/websocket/BaseWebSocketChannel.cpp @@ -63,7 +63,7 @@ BaseWebSocketChannel::BaseWebSocketChannel() } //----------------------------------------------------------------------------- -// BaseWebSocketChannel::nsIWebSocketProtocol +// BaseWebSocketChannel::nsIWebSocketChannel //----------------------------------------------------------------------------- NS_IMETHODIMP diff --git a/netwerk/protocol/websocket/BaseWebSocketChannel.h b/netwerk/protocol/websocket/BaseWebSocketChannel.h index 36096e601b9..150ece4805a 100644 --- a/netwerk/protocol/websocket/BaseWebSocketChannel.h +++ b/netwerk/protocol/websocket/BaseWebSocketChannel.h @@ -40,7 +40,8 @@ #ifndef mozilla_net_BaseWebSocketChannel_h #define mozilla_net_BaseWebSocketChannel_h -#include "nsIWebSocketProtocol.h" +#include "nsIWebSocketChannel.h" +#include "nsIWebSocketListener.h" #include "nsIProtocolHandler.h" #include "nsCOMPtr.h" #include "nsString.h" @@ -51,7 +52,7 @@ namespace net { const static PRInt32 kDefaultWSPort = 80; const static PRInt32 kDefaultWSSPort = 443; -class BaseWebSocketChannel : public nsIWebSocketProtocol, +class BaseWebSocketChannel : public nsIWebSocketChannel, public nsIProtocolHandler { public: @@ -63,7 +64,7 @@ class BaseWebSocketChannel : public nsIWebSocketProtocol, NS_IMETHOD_(nsrefcnt ) AddRef(void) = 0; NS_IMETHOD_(nsrefcnt ) Release(void) = 0; - // Partial implementation of nsIWebSocketProtocol + // Partial implementation of nsIWebSocketChannel // NS_IMETHOD GetOriginalURI(nsIURI **aOriginalURI); NS_IMETHOD GetURI(nsIURI **aURI); diff --git a/netwerk/protocol/websocket/Makefile.in b/netwerk/protocol/websocket/Makefile.in index 7e3581ab185..7050212cee5 100644 --- a/netwerk/protocol/websocket/Makefile.in +++ b/netwerk/protocol/websocket/Makefile.in @@ -52,7 +52,8 @@ FORCE_STATIC_LIB = 1 EXPORTS_NAMESPACES = mozilla/net XPIDLSRCS = \ - nsIWebSocketProtocol.idl \ + nsIWebSocketChannel.idl \ + nsIWebSocketListener.idl \ $(NULL) CPPSRCS = \ diff --git a/netwerk/protocol/websocket/PWebSocket.ipdl b/netwerk/protocol/websocket/PWebSocket.ipdl index 2c6003b67fa..6fdd408fb2d 100644 --- a/netwerk/protocol/websocket/PWebSocket.ipdl +++ b/netwerk/protocol/websocket/PWebSocket.ipdl @@ -53,7 +53,7 @@ async protocol PWebSocket manager PNecko; parent: - // Forwarded methods corresponding to methods on nsIWebSocketProtocolHandler + // Forwarded methods corresponding to methods on nsIWebSocketChannelHandler AsyncOpen(URI aURI, nsCString aOrigin, nsCString aProtocol, bool aSecure); Close(); SendMsg(nsCString aMsg); diff --git a/netwerk/protocol/websocket/WebSocketChannelChild.cpp b/netwerk/protocol/websocket/WebSocketChannelChild.cpp index 6e1b0c22aac..555edd47b39 100644 --- a/netwerk/protocol/websocket/WebSocketChannelChild.cpp +++ b/netwerk/protocol/websocket/WebSocketChannelChild.cpp @@ -69,13 +69,13 @@ NS_IMETHODIMP_(nsrefcnt) WebSocketChannelChild::Release() } NS_INTERFACE_MAP_BEGIN(WebSocketChannelChild) - NS_INTERFACE_MAP_ENTRY(nsIWebSocketProtocol) + NS_INTERFACE_MAP_ENTRY(nsIWebSocketChannel) NS_INTERFACE_MAP_ENTRY(nsIProtocolHandler) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebSocketProtocol) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebSocketChannel) NS_INTERFACE_MAP_END WebSocketChannelChild::WebSocketChannelChild(bool aSecure) -: mEventQ(static_cast(this)) +: mEventQ(static_cast(this)) , mIPCOpen(false) , mCancelled(false) { diff --git a/netwerk/protocol/websocket/WebSocketChannelChild.h b/netwerk/protocol/websocket/WebSocketChannelChild.h index 5ed3d5dd8ec..32043d02d7d 100644 --- a/netwerk/protocol/websocket/WebSocketChannelChild.h +++ b/netwerk/protocol/websocket/WebSocketChannelChild.h @@ -58,7 +58,7 @@ class WebSocketChannelChild : public BaseWebSocketChannel, NS_DECL_ISUPPORTS - // nsIWebSocketProtocol methods BaseWebSocketChannel didn't implement for us + // nsIWebSocketChannel methods BaseWebSocketChannel didn't implement for us // NS_SCRIPTABLE NS_IMETHOD AsyncOpen(nsIURI *aURI, const nsACString &aOrigin, diff --git a/netwerk/protocol/websocket/WebSocketChannelParent.h b/netwerk/protocol/websocket/WebSocketChannelParent.h index 9f6770ba27b..925330768a5 100644 --- a/netwerk/protocol/websocket/WebSocketChannelParent.h +++ b/netwerk/protocol/websocket/WebSocketChannelParent.h @@ -75,7 +75,7 @@ class WebSocketChannelParent : public PWebSocketParent, void ActorDestroy(ActorDestroyReason why); nsCOMPtr mAuthProvider; - nsCOMPtr mChannel; + nsCOMPtr mChannel; bool mIPCOpen; }; diff --git a/netwerk/protocol/websocket/nsIWebSocketProtocol.idl b/netwerk/protocol/websocket/nsIWebSocketChannel.idl similarity index 65% rename from netwerk/protocol/websocket/nsIWebSocketProtocol.idl rename to netwerk/protocol/websocket/nsIWebSocketChannel.idl index 3a67ff3c8b0..208765166b3 100644 --- a/netwerk/protocol/websocket/nsIWebSocketProtocol.idl +++ b/netwerk/protocol/websocket/nsIWebSocketChannel.idl @@ -1,4 +1,5 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set sw=4 ts=4 et tw=80 : */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -38,79 +39,13 @@ interface nsIURI; interface nsIInterfaceRequestor; -interface nsIRunnable; interface nsILoadGroup; +interface nsIWebSocketListener; #include "nsISupports.idl" -/** - * nsIWebSocketListener - */ -[scriptable, uuid(b0c27050-31e9-42e5-bc59-499d54b52f99)] -interface nsIWebSocketListener : nsISupports -{ - /** - * Called to signify the establishment of the message stream. - * Any listener that receives onStart will also receive OnStop. - * - * @param aContext user defined context - */ - void onStart(in nsISupports aContext); - - /** - * Called to signify the completion of the message stream. - * OnStop is the final notification the listener will receive and it - * completes the WebSocket connection. This event can be received in error - * cases even if nsIWebSocketProtocol::Close() has not been called. - * - * @param aContext user defined context - * @param aStatusCode reason for stopping (NS_OK if completed successfully) - */ - void onStop(in nsISupports aContext, - in nsresult aStatusCode); - - /** - * Called to deliver text message. - * - * @param aContext user defined context - * @param aMsg the message data - */ - void onMessageAvailable(in nsISupports aContext, - in AUTF8String aMsg); - - /** - * Called to deliver binary message. - * - * @param aContext user defined context - * @param aMsg the message data - */ - void onBinaryMessageAvailable(in nsISupports aContext, - in ACString aMsg); - - /** - * Called to acknowledge message sent via sendMsg() or sendBinaryMsg. - * - * @param aContext user defined context - * @param aSize number of bytes placed in OS send buffer - */ - void onAcknowledge(in nsISupports aContext, in PRUint32 aSize); - - /** - * Called to inform receipt of WebSocket Close message from server. - * In the case of errors onStop() can be called without ever - * receiving server close. - * - * No additional messages through onMessageAvailable(), - * onBinaryMessageAvailable() or onAcknowledge() will be delievered - * to the listener after onServerClose(), though outgoing messages can still - * be sent through the nsIWebSocketProtocol connection. - */ - void onServerClose(in nsISupports aContext); - -}; - -[scriptable, uuid(dc01db59-a513-4c90-824b-085cce06c0aa)] -interface nsIWebSocketProtocol : nsISupports +[scriptable, uuid(398a2460-a46d-11e0-8264-0800200c9a66)] +interface nsIWebSocketChannel : nsISupports { /** * The original URI used to construct the protocol connection. This is used diff --git a/netwerk/protocol/websocket/nsIWebSocketListener.idl b/netwerk/protocol/websocket/nsIWebSocketListener.idl new file mode 100644 index 00000000000..2c508ec7d61 --- /dev/null +++ b/netwerk/protocol/websocket/nsIWebSocketListener.idl @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set sw=4 ts=4 et tw=80 : */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla. + * + * The Initial Developer of the Original Code is + * Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Patrick McManus + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +/** + * nsIWebSocketListener: passed to nsIWebSocketChannel::AsyncOpen. Receives + * websocket traffic events as they arrive. + */ +[scriptable, uuid(b0c27050-31e9-42e5-bc59-499d54b52f99)] +interface nsIWebSocketListener : nsISupports +{ + /** + * Called to signify the establishment of the message stream. + * Any listener that receives onStart will also receive OnStop. + * + * @param aContext user defined context + */ + void onStart(in nsISupports aContext); + + /** + * Called to signify the completion of the message stream. + * OnStop is the final notification the listener will receive and it + * completes the WebSocket connection. This event can be received in error + * cases even if nsIWebSocketChannel::Close() has not been called. + * + * @param aContext user defined context + * @param aStatusCode reason for stopping (NS_OK if completed successfully) + */ + void onStop(in nsISupports aContext, + in nsresult aStatusCode); + + /** + * Called to deliver text message. + * + * @param aContext user defined context + * @param aMsg the message data + */ + void onMessageAvailable(in nsISupports aContext, + in AUTF8String aMsg); + + /** + * Called to deliver binary message. + * + * @param aContext user defined context + * @param aMsg the message data + */ + void onBinaryMessageAvailable(in nsISupports aContext, + in ACString aMsg); + + /** + * Called to acknowledge message sent via sendMsg() or sendBinaryMsg. + * + * @param aContext user defined context + * @param aSize number of bytes placed in OS send buffer + */ + void onAcknowledge(in nsISupports aContext, in PRUint32 aSize); + + /** + * Called to inform receipt of WebSocket Close message from server. + * In the case of errors onStop() can be called without ever + * receiving server close. + * + * No additional messages through onMessageAvailable(), + * onBinaryMessageAvailable() or onAcknowledge() will be delievered + * to the listener after onServerClose(), though outgoing messages can still + * be sent through the nsIWebSocketChannel connection. + */ + void onServerClose(in nsISupports aContext); + +}; + + diff --git a/netwerk/protocol/websocket/nsWebSocketHandler.cpp b/netwerk/protocol/websocket/nsWebSocketHandler.cpp index 44cb3c0b862..489ee2f998f 100644 --- a/netwerk/protocol/websocket/nsWebSocketHandler.cpp +++ b/netwerk/protocol/websocket/nsWebSocketHandler.cpp @@ -78,7 +78,7 @@ namespace mozilla { namespace net { NS_IMPL_THREADSAFE_ISUPPORTS11(nsWebSocketHandler, - nsIWebSocketProtocol, + nsIWebSocketChannel, nsIHttpUpgradeListener, nsIRequestObserver, nsIStreamListener, diff --git a/netwerk/protocol/websocket/nsWebSocketHandler.h b/netwerk/protocol/websocket/nsWebSocketHandler.h index 5720c9ea78a..a151a8c3423 100644 --- a/netwerk/protocol/websocket/nsWebSocketHandler.h +++ b/netwerk/protocol/websocket/nsWebSocketHandler.h @@ -40,7 +40,6 @@ #ifndef mozilla_net_nsWebSocketHandler_h #define mozilla_net_nsWebSocketHandler_h -#include "nsIWebSocketProtocol.h" #include "nsIURI.h" #include "nsISupports.h" #include "nsIInterfaceRequestor.h" @@ -93,7 +92,7 @@ public: NS_DECL_NSIINTERFACEREQUESTOR NS_DECL_NSICHANNELEVENTSINK - // nsIWebSocketProtocol methods BaseWebSocketChannel didn't implement for us + // nsIWebSocketChannel methods BaseWebSocketChannel didn't implement for us // NS_IMETHOD AsyncOpen(nsIURI *aURI, const nsACString &aOrigin,