mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bugzilla 640003 websockets ietf-07 r=smaug r=biesi sr=bz
This commit is contained in:
parent
c2f7522f58
commit
2ded010403
@ -4861,7 +4861,7 @@ NSS_DISABLE_DBM=
|
||||
NECKO_WIFI=1
|
||||
NECKO_COOKIES=1
|
||||
NECKO_DISK_CACHE=1
|
||||
NECKO_PROTOCOLS_DEFAULT="about data file ftp http res viewsource wyciwyg"
|
||||
NECKO_PROTOCOLS_DEFAULT="about data file ftp http res viewsource websocket wyciwyg"
|
||||
USE_ARM_KUSER=
|
||||
BUILD_CTYPES=1
|
||||
XPC_IDISPATCH_SUPPORT=
|
||||
|
@ -51,10 +51,11 @@ interface nsPIDOMWindow;
|
||||
* http://dev.w3.org/html5/websockets/
|
||||
*
|
||||
*/
|
||||
[scriptable, uuid(4403cd57-07fc-477f-a062-d6ba7dd0781b)]
|
||||
[scriptable, uuid(431aea4c-568a-470e-b876-c57a29ff0fc6)]
|
||||
interface nsIWebSocket : nsISupports
|
||||
{
|
||||
readonly attribute DOMString url;
|
||||
readonly attribute DOMString protocol;
|
||||
|
||||
//ready state
|
||||
const unsigned short CONNECTING = 0;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -50,7 +50,6 @@
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsDOMEventTargetWrapperCache.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIProxiedProtocolHandler.h"
|
||||
|
||||
#define DEFAULT_WS_SCHEME_PORT 80
|
||||
#define DEFAULT_WSS_SCHEME_PORT 443
|
||||
@ -101,8 +100,6 @@ public:
|
||||
PRBool aWantsUntrusted,
|
||||
PRUint8 optional_argc);
|
||||
|
||||
static void ReleaseGlobals();
|
||||
|
||||
// Determine if preferences allow WebSocket
|
||||
static PRBool PrefEnabled();
|
||||
|
||||
@ -116,7 +113,7 @@ protected:
|
||||
nsresult EstablishConnection();
|
||||
|
||||
nsresult CreateAndDispatchSimpleEvent(const nsString& aName);
|
||||
nsresult CreateAndDispatchMessageEvent(nsCString *aData);
|
||||
nsresult CreateAndDispatchMessageEvent(const nsACString& aData);
|
||||
nsresult CreateAndDispatchCloseEvent(PRBool aWasClean);
|
||||
|
||||
// called from mConnection accordingly to the situation
|
||||
@ -147,7 +144,8 @@ protected:
|
||||
nsCString mAsciiHost; // hostname
|
||||
PRUint32 mPort;
|
||||
nsCString mResource; // [filepath[?query]]
|
||||
nsCString mOrigin;
|
||||
nsString mUTF16Origin;
|
||||
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
nsCString mProtocol;
|
||||
|
||||
@ -175,44 +173,4 @@ private:
|
||||
nsWebSocket& operator=(const nsWebSocket& x);
|
||||
};
|
||||
|
||||
#define NS_WSPROTOCOLHANDLER_CONTRACTID \
|
||||
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "ws"
|
||||
|
||||
#define NS_WSSPROTOCOLHANDLER_CONTRACTID \
|
||||
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "wss"
|
||||
|
||||
#define NS_WSPROTOCOLHANDLER_CID \
|
||||
{ /* a4e6aa3b-b6db-4809-aa11-e292e074cbc4 */ \
|
||||
0xa4e6aa3b, \
|
||||
0xb6db, \
|
||||
0x4809, \
|
||||
{0xaa, 0x11, 0xe2, 0x92, 0xe0, 0x74, 0xcb, 0xc4} \
|
||||
}
|
||||
|
||||
#define NS_WSSPROTOCOLHANDLER_CID \
|
||||
{ /* c6531804-b5c8-4a53-80bf-e339b82d3161 */ \
|
||||
0xc6531804, \
|
||||
0xb5c8, \
|
||||
0x4a53, \
|
||||
{0x80, 0xbf, 0xe3, 0x39, 0xb8, 0x2d, 0x31, 0x61} \
|
||||
}
|
||||
|
||||
class nsWSProtocolHandler: public nsIProxiedProtocolHandler
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPROTOCOLHANDLER
|
||||
NS_DECL_NSIPROXIEDPROTOCOLHANDLER
|
||||
|
||||
nsWSProtocolHandler() {};
|
||||
};
|
||||
|
||||
class nsWSSProtocolHandler: public nsWSProtocolHandler
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD GetScheme(nsACString & aScheme);
|
||||
NS_IMETHOD GetDefaultPort(PRInt32 *aDefaultPort);
|
||||
nsWSSProtocolHandler() {};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -309,8 +309,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(txNodeSetAdaptor, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMSerializer)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsXMLHttpRequest, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebSocket)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWSProtocolHandler)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWSSProtocolHandler)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDOMFileReader, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFormData)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFileDataProtocolHandler)
|
||||
@ -842,8 +840,6 @@ NS_DEFINE_NAMED_CID(NS_FORMDATA_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_FILEDATAPROTOCOLHANDLER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_XMLHTTPREQUEST_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_WEBSOCKET_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_WSPROTOCOLHANDLER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_WSSPROTOCOLHANDLER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_DOMPARSER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_DOMSTORAGE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_DOMSTORAGE2_CID);
|
||||
@ -991,8 +987,6 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
|
||||
{ &kNS_FILEDATAPROTOCOLHANDLER_CID, false, NULL, nsFileDataProtocolHandlerConstructor },
|
||||
{ &kNS_XMLHTTPREQUEST_CID, false, NULL, nsXMLHttpRequestConstructor },
|
||||
{ &kNS_WEBSOCKET_CID, false, NULL, nsWebSocketConstructor },
|
||||
{ &kNS_WSPROTOCOLHANDLER_CID, false, NULL, nsWSProtocolHandlerConstructor },
|
||||
{ &kNS_WSSPROTOCOLHANDLER_CID, false, NULL, nsWSSProtocolHandlerConstructor },
|
||||
{ &kNS_DOMPARSER_CID, false, NULL, nsDOMParserConstructor },
|
||||
{ &kNS_DOMSTORAGE_CID, false, NULL, NS_NewDOMStorage },
|
||||
{ &kNS_DOMSTORAGE2_CID, false, NULL, NS_NewDOMStorage2 },
|
||||
@ -1135,8 +1129,6 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
|
||||
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX FILEDATA_SCHEME, &kNS_FILEDATAPROTOCOLHANDLER_CID },
|
||||
{ NS_XMLHTTPREQUEST_CONTRACTID, &kNS_XMLHTTPREQUEST_CID },
|
||||
{ NS_WEBSOCKET_CONTRACTID, &kNS_WEBSOCKET_CID },
|
||||
{ NS_WSPROTOCOLHANDLER_CONTRACTID, &kNS_WSPROTOCOLHANDLER_CID },
|
||||
{ NS_WSSPROTOCOLHANDLER_CONTRACTID, &kNS_WSSPROTOCOLHANDLER_CID },
|
||||
{ NS_DOMPARSER_CONTRACTID, &kNS_DOMPARSER_CID },
|
||||
{ "@mozilla.org/dom/storage;1", &kNS_DOMSTORAGE_CID },
|
||||
{ "@mozilla.org/dom/storage;2", &kNS_DOMSTORAGE2_CID },
|
||||
|
@ -80,7 +80,6 @@
|
||||
#include "nsTextFragment.h"
|
||||
#include "nsCSSRuleProcessor.h"
|
||||
#include "nsCrossSiteListenerProxy.h"
|
||||
#include "nsWebSocket.h"
|
||||
#include "nsDOMThreadService.h"
|
||||
#include "nsHTMLDNSPrefetch.h"
|
||||
#include "nsHtml5Module.h"
|
||||
@ -369,8 +368,6 @@ nsLayoutStatics::Shutdown()
|
||||
|
||||
nsCORSListenerProxy::Shutdown();
|
||||
|
||||
nsWebSocket::ReleaseGlobals();
|
||||
|
||||
nsIPresShell::ReleaseStatics();
|
||||
|
||||
nsHtml5Module::ReleaseStatics();
|
||||
|
@ -782,6 +782,33 @@ pref("network.ftp.control.qos", 0);
|
||||
|
||||
// <ws>: WebSocket
|
||||
pref("network.websocket.enabled", true);
|
||||
|
||||
// mobile might want to set this much smaller
|
||||
pref("network.websocket.max-message-size", 16000000);
|
||||
|
||||
// Should we automatically follow http 3xx redirects during handshake
|
||||
pref("network.websocket.auto-follow-http-redirects", false);
|
||||
|
||||
// the number of seconds to wait for websocket connection to be opened
|
||||
pref("network.websocket.timeout.open", 20);
|
||||
|
||||
// the number of seconds to wait for a clean close after sending the client
|
||||
// close message
|
||||
pref("network.websocket.timeout.close", 20);
|
||||
|
||||
// the number of seconds of idle read activity to sustain before sending a
|
||||
// ping probe. 0 to disable.
|
||||
pref("network.websocket.timeout.ping.request", 0);
|
||||
|
||||
// the deadline, expressed in seconds, for some read activity to occur after
|
||||
// generating a ping. If no activity happens then an error and unclean close
|
||||
// event is sent to the javascript websockets application
|
||||
pref("network.websocket.timeout.ping.response", 10);
|
||||
|
||||
// Defines whether or not to try and negotiate the stream-deflate compression
|
||||
// extension with the websocket server
|
||||
pref("network.websocket.extensions.stream-deflate", true);
|
||||
|
||||
// </ws>
|
||||
|
||||
// If false, remote JAR files that are served with a content type other than
|
||||
|
@ -734,6 +734,26 @@
|
||||
{0x9d, 0x7c, 0xc3, 0xce, 0x73, 0x28, 0x4d, 0x01} \
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* netwerk/protocol/websocket/ classes
|
||||
*/
|
||||
|
||||
#define NS_WEBSOCKETPROTOCOLHANDLER_CID \
|
||||
{ /* {dc01db59-a513-4c90-824b-085cce06c0aa} */ \
|
||||
0xdc01db59, \
|
||||
0xa513, \
|
||||
0x4c90, \
|
||||
{0x82, 0x4b, 0x08, 0x5c, 0xce, 0x06, 0xc0, 0xaa} \
|
||||
}
|
||||
|
||||
#define NS_WEBSOCKETSSLPROTOCOLHANDLER_CID \
|
||||
{ /* {dc01dbbb-a5bb-4cbb-82bb-085cce06c0bb} */ \
|
||||
0xdc01dbbb, \
|
||||
0xa5bb, \
|
||||
0x4cbb, \
|
||||
{0x82, 0xbb, 0x08, 0x5c, 0xce, 0x06, 0xc0, 0xbb} \
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* netwerk/protocol/about/ classes
|
||||
*/
|
||||
|
@ -281,6 +281,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsViewSourceHandler)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWyciwygProtocolHandler)
|
||||
#endif
|
||||
|
||||
#ifdef NECKO_PROTOCOL_websocket
|
||||
#include "nsWebSocketHandler.h"
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebSocketHandler)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebSocketSSLHandler)
|
||||
} // namespace mozilla::net
|
||||
} // namespace mozilla
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "nsURIChecker.h"
|
||||
@ -624,6 +634,9 @@ static void nsNetShutdown()
|
||||
|
||||
// Release DNS service reference.
|
||||
nsDNSPrefetch::Shutdown();
|
||||
|
||||
// Release the Websocket Admission Manager
|
||||
mozilla::net::nsWebSocketHandler::Shutdown();
|
||||
}
|
||||
|
||||
NS_DEFINE_NAMED_CID(NS_IOSERVICE_CID);
|
||||
@ -740,6 +753,10 @@ NS_DEFINE_NAMED_CID(NS_VIEWSOURCEHANDLER_CID);
|
||||
#ifdef NECKO_PROTOCOL_wyciwyg
|
||||
NS_DEFINE_NAMED_CID(NS_WYCIWYGPROTOCOLHANDLER_CID);
|
||||
#endif
|
||||
#ifdef NECKO_PROTOCOL_websocket
|
||||
NS_DEFINE_NAMED_CID(NS_WEBSOCKETPROTOCOLHANDLER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_WEBSOCKETSSLPROTOCOLHANDLER_CID);
|
||||
#endif
|
||||
#if defined(XP_WIN)
|
||||
NS_DEFINE_NAMED_CID(NS_NETWORK_LINK_SERVICE_CID);
|
||||
#elif defined(MOZ_WIDGET_COCOA)
|
||||
@ -869,6 +886,12 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
|
||||
#ifdef NECKO_PROTOCOL_wyciwyg
|
||||
{ &kNS_WYCIWYGPROTOCOLHANDLER_CID, false, NULL, nsWyciwygProtocolHandlerConstructor },
|
||||
#endif
|
||||
#ifdef NECKO_PROTOCOL_websocket
|
||||
{ &kNS_WEBSOCKETPROTOCOLHANDLER_CID, false, NULL,
|
||||
mozilla::net::nsWebSocketHandlerConstructor },
|
||||
{ &kNS_WEBSOCKETSSLPROTOCOLHANDLER_CID, false, NULL,
|
||||
mozilla::net::nsWebSocketSSLHandlerConstructor },
|
||||
#endif
|
||||
#if defined(XP_WIN)
|
||||
{ &kNS_NETWORK_LINK_SERVICE_CID, false, NULL, nsNotifyAddrListenerConstructor },
|
||||
#elif defined(MOZ_WIDGET_COCOA)
|
||||
@ -1005,6 +1028,10 @@ static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
|
||||
#ifdef NECKO_PROTOCOL_wyciwyg
|
||||
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "wyciwyg", &kNS_WYCIWYGPROTOCOLHANDLER_CID },
|
||||
#endif
|
||||
#ifdef NECKO_PROTOCOL_websocket
|
||||
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "ws", &kNS_WEBSOCKETPROTOCOLHANDLER_CID },
|
||||
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "wss", &kNS_WEBSOCKETSSLPROTOCOLHANDLER_CID },
|
||||
#endif
|
||||
#if defined(XP_WIN)
|
||||
{ NS_NETWORK_LINK_SERVICE_CONTRACTID, &kNS_NETWORK_LINK_SERVICE_CID },
|
||||
#elif defined(MOZ_WIDGET_COCOA)
|
||||
|
@ -51,6 +51,7 @@
|
||||
#undef NECKO_PROTOCOL_http
|
||||
#undef NECKO_PROTOCOL_res
|
||||
#undef NECKO_PROTOCOL_viewsource
|
||||
#undef NECKO_PROTOCOL_websocket
|
||||
#undef NECKO_PROTOCOL_wyciwyg
|
||||
|
||||
#endif
|
||||
|
@ -51,6 +51,7 @@ PARALLEL_DIRS = \
|
||||
http \
|
||||
res \
|
||||
viewsource \
|
||||
websocket \
|
||||
wyciwyg \
|
||||
$(NULL)
|
||||
|
||||
|
69
netwerk/protocol/websocket/Makefile.in
Normal file
69
netwerk/protocol/websocket/Makefile.in
Normal file
@ -0,0 +1,69 @@
|
||||
# ***** 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 <mcmanus@ducksong.com>
|
||||
#
|
||||
# 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 ***** */
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
LIBRARY_NAME = nkwebsocket_s
|
||||
LIBXUL_LIBRARY = 1
|
||||
XPIDL_MODULE = necko_websocket
|
||||
GRE_MODULE = 1
|
||||
FORCE_STATIC_LIB = 1
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIWebSocketProtocol.idl \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsWebSocketHandler.cpp
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
-I$(srcdir)/../../base/src \
|
||||
-I$(topsrcdir)/xpcom/ds \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
DEFINES += -DIMPL_NS_NET
|
190
netwerk/protocol/websocket/nsIWebSocketProtocol.idl
Normal file
190
netwerk/protocol/websocket/nsIWebSocketProtocol.idl
Normal file
@ -0,0 +1,190 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** 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 <mcmanus@ducksong.com>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIInterfaceRequestor;
|
||||
interface nsIRunnable;
|
||||
interface nsILoadGroup;
|
||||
|
||||
#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
|
||||
{
|
||||
/**
|
||||
* The original URI used to construct the protocol connection. This is used
|
||||
* in the case of a redirect or URI "resolution" (e.g. resolving a
|
||||
* resource: URI to a file: URI) so that the original pre-redirect
|
||||
* URI can still be obtained. This is never null.
|
||||
*/
|
||||
readonly attribute nsIURI originalURI;
|
||||
|
||||
/**
|
||||
* The readonly URI corresponding to the protocol connection after any
|
||||
* redirections are completed.
|
||||
*/
|
||||
readonly attribute nsIURI URI;
|
||||
|
||||
/**
|
||||
* The notification callbacks for authorization, etc..
|
||||
*/
|
||||
attribute nsIInterfaceRequestor notificationCallbacks;
|
||||
|
||||
/**
|
||||
* Transport-level security information (if any)
|
||||
*/
|
||||
readonly attribute nsISupports securityInfo;
|
||||
|
||||
/**
|
||||
* The load group of the websockets code.
|
||||
*/
|
||||
attribute nsILoadGroup loadGroup;
|
||||
|
||||
/**
|
||||
* Sec-Websocket-Protocol value
|
||||
*/
|
||||
attribute ACString protocol;
|
||||
|
||||
/**
|
||||
* Asynchronously open the websocket connection. Received messages are fed
|
||||
* to the socket listener as they arrive. The socket listener's methods
|
||||
* are called on the thread that calls asyncOpen and are not called until
|
||||
* after asyncOpen returns. If asyncOpen returns successfully, the
|
||||
* protocol implementation promises to call at least onStart and onStop of
|
||||
* the listener.
|
||||
*
|
||||
* NOTE: Implementations should throw NS_ERROR_ALREADY_OPENED if the
|
||||
* websocket connection is reopened.
|
||||
*
|
||||
* @param aURI the uri of the websocket protocol - may be redirected
|
||||
* @param aOrigin the uri of the originating resource
|
||||
* @param aListener the nsIWebSocketListener implementation
|
||||
* @param aContext an opaque parameter forwarded to aListener's methods
|
||||
*/
|
||||
void asyncOpen(in nsIURI aURI,
|
||||
in ACString aOrigin,
|
||||
in nsIWebSocketListener aListener,
|
||||
in nsISupports aContext);
|
||||
|
||||
/*
|
||||
* Close the websocket connection for writing - no more calls to sendMsg
|
||||
* or sendBinaryMsg should be made after calling this. The listener object
|
||||
* may receive more messages if a server close has not yet been received.
|
||||
*/
|
||||
void close();
|
||||
|
||||
/**
|
||||
* Use to send text message down the connection to WebSocket peer.
|
||||
*
|
||||
* @param aMsg the utf8 string to send
|
||||
*/
|
||||
void sendMsg(in AUTF8String aMsg);
|
||||
|
||||
/**
|
||||
* Use to send binary message down the connection to WebSocket peer.
|
||||
*
|
||||
* @param aMsg the data to send
|
||||
*/
|
||||
void sendBinaryMsg(in ACString aMsg);
|
||||
};
|
2549
netwerk/protocol/websocket/nsWebSocketHandler.cpp
Normal file
2549
netwerk/protocol/websocket/nsWebSocketHandler.cpp
Normal file
File diff suppressed because it is too large
Load Diff
268
netwerk/protocol/websocket/nsWebSocketHandler.h
Normal file
268
netwerk/protocol/websocket/nsWebSocketHandler.h
Normal file
@ -0,0 +1,268 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** 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) 2010 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Wellington Fernando de Macedo <wfernandom2004@gmail.com> (original author)
|
||||
* Patrick McManus <mcmanus@ducksong.com>
|
||||
*
|
||||
* 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 "nsIWebSocketProtocol.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIEventTarget.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsISocketTransport.h"
|
||||
#include "nsIAsyncInputStream.h"
|
||||
#include "nsIAsyncOutputStream.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsIDNSListener.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
#include "nsIChannelEventSink.h"
|
||||
#include "nsIAsyncVerifyRedirectCallback.h"
|
||||
#include "nsIStringStream.h"
|
||||
#include "nsIHttpChannelInternal.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsDeque.h"
|
||||
|
||||
namespace mozilla { namespace net {
|
||||
|
||||
class nsPostMessage;
|
||||
class nsWSAdmissionManager;
|
||||
class nsWSCompression;
|
||||
class WSCallOnInputStreamReady;
|
||||
|
||||
class nsWebSocketHandler : public nsIWebSocketProtocol,
|
||||
public nsIHttpUpgradeListener,
|
||||
public nsIStreamListener,
|
||||
public nsIProtocolHandler,
|
||||
public nsIInputStreamCallback,
|
||||
public nsIOutputStreamCallback,
|
||||
public nsITimerCallback,
|
||||
public nsIDNSListener,
|
||||
public nsIInterfaceRequestor,
|
||||
public nsIChannelEventSink
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIWEBSOCKETPROTOCOL
|
||||
NS_DECL_NSIHTTPUPGRADELISTENER
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
NS_DECL_NSIPROTOCOLHANDLER
|
||||
NS_DECL_NSIINPUTSTREAMCALLBACK
|
||||
NS_DECL_NSIOUTPUTSTREAMCALLBACK
|
||||
NS_DECL_NSITIMERCALLBACK
|
||||
NS_DECL_NSIDNSLISTENER
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
NS_DECL_NSICHANNELEVENTSINK
|
||||
|
||||
nsWebSocketHandler();
|
||||
static void Shutdown();
|
||||
|
||||
enum {
|
||||
// Non Control Frames
|
||||
kContinuation = 0x0,
|
||||
kText = 0x1,
|
||||
kBinary = 0x2,
|
||||
|
||||
// Control Frames
|
||||
kClose = 0x8,
|
||||
kPing = 0x9,
|
||||
kPong = 0xA
|
||||
};
|
||||
|
||||
const static PRUint32 kControlFrameMask = 0x8;
|
||||
const static PRInt32 kDefaultWSPort = 80;
|
||||
const static PRInt32 kDefaultWSSPort = 443;
|
||||
const static PRUint8 kMaskBit = 0x80;
|
||||
const static PRUint8 kFinalFragBit = 0x80;
|
||||
|
||||
// section 7.4.1 defines these
|
||||
const static PRUint16 kCloseNormal = 1000;
|
||||
const static PRUint16 kCloseGoingAway = 1001;
|
||||
const static PRUint16 kCloseProtocolError = 1002;
|
||||
const static PRUint16 kCloseUnsupported = 1003;
|
||||
const static PRUint16 kCloseTooLarge = 1004;
|
||||
|
||||
protected:
|
||||
virtual ~nsWebSocketHandler();
|
||||
PRBool mEncrypted;
|
||||
|
||||
private:
|
||||
friend class nsPostMessage;
|
||||
friend class nsWSAdmissionManager;
|
||||
friend class WSCallOnInputStreamReady;
|
||||
|
||||
void SendMsgInternal(nsCString *aMsg, PRInt32 datalen);
|
||||
void PrimeNewOutgoingMessage();
|
||||
void GeneratePong(PRUint8 *payload, PRUint32 len);
|
||||
void GeneratePing();
|
||||
|
||||
nsresult BeginOpen();
|
||||
nsresult HandleExtensions();
|
||||
nsresult SetupRequest();
|
||||
nsresult ApplyForAdmission();
|
||||
|
||||
void StopSession(nsresult reason);
|
||||
void AbortSession(nsresult reason);
|
||||
void ReleaseSession();
|
||||
|
||||
void EnsureHdrOut(PRUint32 size);
|
||||
void ApplyMask(PRUint32 mask, PRUint8 *data, PRUint64 len);
|
||||
|
||||
PRBool IsPersistentFramePtr();
|
||||
nsresult ProcessInput(PRUint8 *buffer, PRUint32 count);
|
||||
PRUint32 UpdateReadBuffer(PRUint8 *buffer, PRUint32 count);
|
||||
|
||||
class OutboundMessage
|
||||
{
|
||||
public:
|
||||
OutboundMessage (nsCString *str)
|
||||
: mMsg(str), mIsControl(PR_FALSE), mBinaryLen(-1) {}
|
||||
|
||||
OutboundMessage (nsCString *str, PRInt32 dataLen)
|
||||
: mMsg(str), mIsControl(PR_FALSE), mBinaryLen(dataLen) {}
|
||||
|
||||
OutboundMessage ()
|
||||
: mMsg(nsnull), mIsControl(PR_TRUE), mBinaryLen(-1) {}
|
||||
|
||||
~OutboundMessage() { delete mMsg; }
|
||||
|
||||
PRBool IsControl() { return mIsControl; }
|
||||
const nsCString *Msg() { return mMsg; }
|
||||
PRInt32 BinaryLen() { return mBinaryLen; }
|
||||
PRInt32 Length()
|
||||
{
|
||||
if (mBinaryLen >= 0)
|
||||
return mBinaryLen;
|
||||
return mMsg ? mMsg->Length() : 0;
|
||||
}
|
||||
PRUint8 *BeginWriting()
|
||||
{ return (PRUint8 *)(mMsg ? mMsg->BeginWriting() : nsnull); }
|
||||
PRUint8 *BeginReading()
|
||||
{ return (PRUint8 *)(mMsg ? mMsg->BeginReading() : nsnull); }
|
||||
|
||||
private:
|
||||
nsCString *mMsg;
|
||||
PRBool mIsControl;
|
||||
PRInt32 mBinaryLen;
|
||||
};
|
||||
|
||||
nsCOMPtr<nsIURI> mOriginalURI;
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
nsCOMPtr<nsIWebSocketListener> mListener;
|
||||
nsCOMPtr<nsISupports> mContext;
|
||||
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
||||
nsCOMPtr<nsIEventTarget> mSocketThread;
|
||||
nsCOMPtr<nsIHttpChannelInternal> mChannel;
|
||||
nsCOMPtr<nsIHttpChannel> mHttpChannel;
|
||||
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
||||
nsCOMPtr<nsICancelable> mDNSRequest;
|
||||
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
|
||||
|
||||
nsCString mProtocol;
|
||||
nsCString mOrigin;
|
||||
nsCString mHashedSecret;
|
||||
nsCString mAddress;
|
||||
|
||||
nsCOMPtr<nsISocketTransport> mTransport;
|
||||
nsCOMPtr<nsIAsyncInputStream> mSocketIn;
|
||||
nsCOMPtr<nsIAsyncOutputStream> mSocketOut;
|
||||
|
||||
nsCOMPtr<nsITimer> mCloseTimer;
|
||||
PRUint32 mCloseTimeout; /* milliseconds */
|
||||
|
||||
nsCOMPtr<nsITimer> mOpenTimer;
|
||||
PRUint32 mOpenTimeout; /* milliseconds */
|
||||
|
||||
nsCOMPtr<nsITimer> mPingTimer;
|
||||
PRUint32 mPingTimeout; /* milliseconds */
|
||||
PRUint32 mPingResponseTimeout; /* milliseconds */
|
||||
|
||||
PRUint32 mRecvdHttpOnStartRequest : 1;
|
||||
PRUint32 mRecvdHttpUpgradeTransport : 1;
|
||||
PRUint32 mRequestedClose : 1;
|
||||
PRUint32 mClientClosed : 1;
|
||||
PRUint32 mServerClosed : 1;
|
||||
PRUint32 mStopped : 1;
|
||||
PRUint32 mCalledOnStop : 1;
|
||||
PRUint32 mPingOutstanding : 1;
|
||||
PRUint32 mAllowCompression : 1;
|
||||
PRUint32 mAutoFollowRedirects : 1;
|
||||
PRUint32 mReleaseOnTransmit : 1;
|
||||
|
||||
PRInt32 mMaxMessageSize;
|
||||
nsresult mStopOnClose;
|
||||
|
||||
// These are for the read buffers
|
||||
PRUint8 *mFramePtr;
|
||||
PRUint8 *mBuffer;
|
||||
PRUint8 mFragmentOpcode;
|
||||
PRUint32 mFragmentAccumulator;
|
||||
PRUint32 mBuffered;
|
||||
PRUint32 mBufferSize;
|
||||
nsCOMPtr<nsIStreamListener> mInflateReader;
|
||||
nsCOMPtr<nsIStringInputStream> mInflateStream;
|
||||
|
||||
// These are for the send buffers
|
||||
const static PRInt32 kCopyBreak = 1000;
|
||||
|
||||
OutboundMessage *mCurrentOut;
|
||||
PRUint32 mCurrentOutSent;
|
||||
nsDeque mOutgoingMessages;
|
||||
nsDeque mOutgoingPingMessages;
|
||||
nsDeque mOutgoingPongMessages;
|
||||
PRUint32 mHdrOutToSend;
|
||||
PRUint8 *mHdrOut;
|
||||
PRUint8 mOutHeader[kCopyBreak + 16];
|
||||
nsWSCompression *mCompressor;
|
||||
PRUint32 mDynamicOutputSize;
|
||||
PRUint8 *mDynamicOutput;
|
||||
};
|
||||
|
||||
class nsWebSocketSSLHandler : public nsWebSocketHandler
|
||||
{
|
||||
public:
|
||||
nsWebSocketSSLHandler() {nsWebSocketHandler::mEncrypted = PR_TRUE;}
|
||||
protected:
|
||||
virtual ~nsWebSocketSSLHandler() {}
|
||||
};
|
||||
|
||||
}} // namespace mozilla::net
|
@ -50,10 +50,10 @@
|
||||
#include "nsComponentManagerUtils.h"
|
||||
|
||||
// nsISupports implementation
|
||||
NS_IMPL_ISUPPORTS3(nsHTTPCompressConv,
|
||||
nsIStreamConverter,
|
||||
nsIStreamListener,
|
||||
nsIRequestObserver)
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS3(nsHTTPCompressConv,
|
||||
nsIStreamConverter,
|
||||
nsIStreamListener,
|
||||
nsIRequestObserver)
|
||||
|
||||
// nsFTPDirListingConv methods
|
||||
nsHTTPCompressConv::nsHTTPCompressConv()
|
||||
|
Loading…
Reference in New Issue
Block a user