Bug 775368 - Porting Websockets to WebIDL, r=bz

--HG--
rename : content/base/src/nsWebSocket.cpp => content/base/src/WebSocket.cpp
rename : content/base/src/nsWebSocket.h => content/base/src/WebSocket.h
This commit is contained in:
Andrea Marchesini 2012-09-10 09:48:14 -04:00
Родитель 79b412d25a
Коммит 26d50534e0
13 изменённых файлов: 838 добавлений и 873 удалений

Просмотреть файл

@ -83,7 +83,6 @@ XPIDLSRCS = \
nsIXMLHttpRequest.idl \
nsIContentSecurityPolicy.idl \
nsIMessageManager.idl \
nsIWebSocket.idl \
nsIEventSource.idl \
$(NULL)

Просмотреть файл

@ -1,95 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
interface nsIDOMEventListener;
interface nsIPrincipal;
interface nsIScriptContext;
interface nsPIDOMWindow;
interface nsIDOMDOMStringList;
interface nsIVariant;
%{C++
#include "nsTArray.h"
class nsString;
%}
[ref] native nsStringTArrayRef(nsTArray<nsString>);
/**
* The nsIWebSocket interface enables Web applications to maintain
* bidirectional communications with server-side processes as described in:
*
* http://dev.w3.org/html5/websockets/
*
*/
[scriptable, uuid(5224dbe7-58ac-43e6-93ba-f288a1421dff)]
interface nsIWebSocket : nsISupports
{
readonly attribute DOMString url;
readonly attribute DOMString extensions;
readonly attribute DOMString protocol;
//ready state
const unsigned short CONNECTING = 0;
const unsigned short OPEN = 1;
const unsigned short CLOSING = 2;
const unsigned short CLOSED = 3;
readonly attribute unsigned short readyState;
readonly attribute unsigned long bufferedAmount;
// "blob" by default: can set to "blob" or "arraybuffer": setting to other
// values will throw SYNTAX_ERR exception.
attribute DOMString binaryType;
// event handler attributes
[implicit_jscontext] attribute jsval onopen;
[implicit_jscontext] attribute jsval onmessage;
[implicit_jscontext] attribute jsval onerror;
[implicit_jscontext] attribute jsval onclose;
/**
* Transmits data to other end of the connection.
* @param data The data to be transmitted. Arraybuffers and Blobs are sent as
* binary data. Strings are sent as UTF-8 text data. Other types are
* converted to a String and sent as a String.
* @return if the connection is still established and the data was queued or
* sent successfully.
*/
[implicit_jscontext] void send(in nsIVariant data);
/**
* Closes the Web Socket connection or connection attempt, if any.
* If the connection is already closed, it does nothing.
*/
[optional_argc] void close([optional] in unsigned short code,
[optional] in DOMString reason);
/**
* Initialize the object for use from C++ code with the principal, script
* context, and owner window that should be used.
*
* @param principal The principal to use for the request. This must not be
* null.
* @param scriptContext The script context to use for the request. May be
* null.
* @param ownerWindow The associated window for the request. May be null.
* @param url The url for opening the socket. This must not be empty, and
* must have an absolute url, using either the ws or wss schemes.
* @param protocol Specifies array of sub-protocols acceptable to the client.
* If the length of the array is at least one, the server
* must select one of the listed sub-protocols for the
* connection to be successful. If empty, no sub-protocol is
* specified. The server selected sub-protocol can be read
* from the protocol attribute after connection.
*/
[noscript] void init(in nsIPrincipal principal,
in nsIScriptContext scriptContext,
in nsPIDOMWindow ownerWindow,
in DOMString url,
in nsStringTArrayRef protocol);
};

Просмотреть файл

@ -122,7 +122,7 @@ CPPSRCS = \
nsTraversal.cpp \
nsTreeSanitizer.cpp \
nsTreeWalker.cpp \
nsWebSocket.cpp \
WebSocket.cpp \
nsXHTMLContentSerializer.cpp \
nsXMLContentSerializer.cpp \
nsXMLHttpRequest.cpp \

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,302 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef WebSocket_h__
#define WebSocket_h__
#include "mozilla/Util.h"
#include "nsWrapperCache.h"
#include "nsIWebSocketListener.h"
#include "nsISupports.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/TypedArray.h"
#include "mozilla/dom/BindingUtils.h"
// Need this for BinaryType.
#include "mozilla/dom/WebSocketBinding.h"
#include "jsfriendapi.h"
#include "nsISupportsUtils.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIPrincipal.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIDOMEventListener.h"
#include "nsDOMEventTargetHelper.h"
#include "nsAutoPtr.h"
#include "nsIDOMDOMStringList.h"
#include "nsIInterfaceRequestor.h"
#include "nsIWebSocketChannel.h"
#include "nsIWebSocketListener.h"
#include "nsIObserver.h"
#include "nsIRequest.h"
#include "nsWeakReference.h"
#define DEFAULT_WS_SCHEME_PORT 80
#define DEFAULT_WSS_SCHEME_PORT 443
namespace mozilla {
namespace dom {
#define IMPL_EVENT_HANDLER(_lowercase) \
inline JSObject* GetOn##_lowercase(JSContext* aCx) \
{ \
JS::Value val; \
nsresult rv = GetOn##_lowercase(aCx, &val); \
return NS_SUCCEEDED(rv) ? JSVAL_TO_OBJECT(val) : nullptr; \
} \
void SetOn##_lowercase(JSContext* aCx, JSObject* aCallback, \
ErrorResult& aRv) \
{ \
aRv = SetOn##_lowercase(aCx, OBJECT_TO_JSVAL(aCallback)); \
} \
NS_IMETHOD GetOn##_lowercase(JSContext* cx, JS::Value* aVal); \
NS_IMETHOD SetOn##_lowercase(JSContext* cx, const JS::Value& aVal);
class WebSocket : public nsDOMEventTargetHelper,
public nsIInterfaceRequestor,
public nsIWebSocketListener,
public nsIObserver,
public nsSupportsWeakReference,
public nsIRequest
{
friend class CallDispatchConnectionCloseEvents;
friend class nsAutoCloseWS;
public:
enum {
CONNECTING = 0,
OPEN = 1,
CLOSING = 2,
CLOSED = 3
};
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_INHERITED(WebSocket,
nsDOMEventTargetHelper)
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSIWEBSOCKETLISTENER
NS_DECL_NSIOBSERVER
NS_DECL_NSIREQUEST
// nsIDOMEventTarget
NS_IMETHOD AddEventListener(const nsAString& aType,
nsIDOMEventListener *aListener,
bool aUseCapture,
bool aWantsUntrusted,
uint8_t optional_argc);
NS_IMETHOD RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
bool aUseCapture);
virtual void DisconnectFromOwner();
// nsWrapperCache
nsPIDOMWindow* GetParentObject() { return GetOwner(); }
JSObject* WrapObject(JSContext *cx,
JSObject *scope,
bool *triedToWrap);
public: // static helpers:
// Determine if preferences allow WebSocket
static bool PrefEnabled();
public: // WebIDL interface:
// Constructor:
static already_AddRefed<WebSocket> Constructor(JSContext *aCx,
nsISupports* aGlobal,
const nsAString& aUrl,
ErrorResult& rv);
static already_AddRefed<WebSocket> Constructor(JSContext *aCx,
nsISupports* aGlobal,
const nsAString& aUrl,
const nsAString& aProtocol,
ErrorResult& rv);
static already_AddRefed<WebSocket> Constructor(JSContext *aCx,
nsISupports* aGlobal,
const nsAString& aUrl,
const Sequence<nsString>& aProtocols,
ErrorResult& rv);
// webIDL: readonly attribute DOMString url
void GetUrl(nsAString& aResult);
// webIDL: readonly attribute unsigned short readyState;
uint16_t GetReadyState() { return (uint16_t)mReadyState; }
// webIDL: readonly attribute unsigned long bufferedAmount;
uint32_t GetBufferedAmount() { return (uint32_t) mOutgoingBufferedAmount; }
// webIDL: attribute Function? onopen;
IMPL_EVENT_HANDLER(open)
// webIDL: attribute Function? onerror;
IMPL_EVENT_HANDLER(error)
// webIDL: attribute Function? onclose;
IMPL_EVENT_HANDLER(close)
// webIDL: readonly attribute DOMString extensions;
void GetExtensions(nsAString& aResult);
// webIDL: readonly attribute DOMString protocol;
void GetProtocol(nsAString& aResult);
// webIDL: void close(optional unsigned short code, optional DOMString reason):
void Close(const Optional<uint16_t>& aCode,
const Optional<nsAString>& aReason,
ErrorResult& aRv);
// webIDL: attribute Function? onmessage;
IMPL_EVENT_HANDLER(message)
// webIDL: attribute DOMString binaryType;
BinaryType GetBinaryType() { return mBinaryType; }
void SetBinaryType(BinaryType aData) { mBinaryType = aData; }
// webIDL: void send(DOMString|Blob|ArrayBufferView data);
void Send(const nsAString& aData,
ErrorResult& aRv);
void Send(nsIDOMBlob* aData,
ErrorResult& aRv);
void Send(ArrayBuffer& aData,
ErrorResult& aRv);
void Send(ArrayBufferView& aData,
ErrorResult& aRv);
private: // constructor && distructor
WebSocket();
virtual ~WebSocket();
protected:
nsresult Init(JSContext* aCx,
nsIPrincipal* aPrincipal,
nsPIDOMWindow* aOwnerWindow,
const nsAString& aURL,
nsTArray<nsString>& aProtocolArray);
void Send(nsIInputStream* aMsgStream,
const nsACString& aMsgString,
PRUint32 aMsgLength,
bool aIsBinary,
ErrorResult& aRv);
nsresult ParseURL(const nsString& aURL);
nsresult EstablishConnection();
// These methods when called can release the WebSocket object
nsresult FailConnection(uint16_t reasonCode,
const nsACString& aReasonString = EmptyCString());
nsresult CloseConnection(uint16_t reasonCode,
const nsACString& aReasonString = EmptyCString());
nsresult Disconnect();
nsresult ConsoleError();
nsresult PrintErrorOnConsole(const char* aBundleURI,
const PRUnichar* aError,
const PRUnichar** aFormatStrings,
PRUint32 aFormatStringsLen);
nsresult DoOnMessageAvailable(const nsACString& aMsg,
bool isBinary);
// ConnectionCloseEvents: 'error' event if needed, then 'close' event.
// - These must not be dispatched while we are still within an incoming call
// from JS (ex: close()). Set 'sync' to false in that case to dispatch in a
// separate new event.
nsresult ScheduleConnectionCloseEvents(nsISupports* aContext,
nsresult aStatusCode,
bool sync);
// 2nd half of ScheduleConnectionCloseEvents, sometimes run in its own event.
void DispatchConnectionCloseEvents();
// These methods actually do the dispatch for various events.
nsresult CreateAndDispatchSimpleEvent(const nsString& aName);
nsresult CreateAndDispatchMessageEvent(const nsACString& aData,
bool isBinary);
nsresult CreateAndDispatchCloseEvent(bool aWasClean,
PRUint16 aCode,
const nsString& aReason);
nsresult CreateResponseBlob(const nsACString& aData,
JSContext* aCx,
jsval& jsData);
// if there are "strong event listeners" (see comment in WebSocket.cpp) or
// outgoing not sent messages then this method keeps the object alive
// when js doesn't have strong references to it.
void UpdateMustKeepAlive();
// ATTENTION, when calling this method the object can be released
// (and possibly collected).
void DontKeepAliveAnyMore();
nsresult UpdateURI();
protected: //data
nsCOMPtr<nsIWebSocketChannel> mChannel;
// related to the WebSocket constructor steps
nsString mOriginalURL;
nsString mEffectiveURL; // after redirects
bool mSecure; // if true it is using SSL and the wss scheme,
// otherwise it is using the ws scheme with no SSL
bool mKeepingAlive;
bool mCheckMustKeepAlive;
bool mOnCloseScheduled;
bool mFailed;
bool mDisconnected;
// Set attributes of DOM 'onclose' message
bool mCloseEventWasClean;
nsString mCloseEventReason;
uint16_t mCloseEventCode;
nsCString mAsciiHost; // hostname
uint32_t mPort;
nsCString mResource; // [filepath[?query]]
nsString mUTF16Origin;
nsCOMPtr<nsIURI> mURI;
nsCString mRequestedProtocolList;
nsCString mEstablishedProtocol;
nsCString mEstablishedExtensions;
uint16_t mReadyState;
nsCOMPtr<nsIPrincipal> mPrincipal;
uint32_t mOutgoingBufferedAmount;
BinaryType mBinaryType;
// Web Socket owner information:
// - the script file name, UTF8 encoded.
// - source code line number where the Web Socket object was constructed.
// - the ID of the inner window where the script lives. Note that this may not
// be the same as the Web Socket owner window.
// These attributes are used for error reporting.
nsCString mScriptFile;
uint32_t mScriptLine;
uint64_t mInnerWindowID;
private:
WebSocket(const WebSocket& x) MOZ_DELETE; // prevent bad usage
WebSocket& operator=(const WebSocket& x) MOZ_DELETE;
};
} //namespace dom
} //namespace mozilla
#endif

Просмотреть файл

@ -1,193 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsWebSocket_h__
#define nsWebSocket_h__
#include "nsISupportsUtils.h"
#include "nsIWebSocket.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIJSNativeInitializer.h"
#include "nsIPrincipal.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIDOMEventListener.h"
#include "nsDOMEventTargetHelper.h"
#include "nsAutoPtr.h"
#include "nsIDOMDOMStringList.h"
#include "nsIInterfaceRequestor.h"
#include "nsIWebSocketChannel.h"
#include "nsIWebSocketListener.h"
#include "nsIObserver.h"
#include "nsIRequest.h"
#include "nsWeakReference.h"
#define DEFAULT_WS_SCHEME_PORT 80
#define DEFAULT_WSS_SCHEME_PORT 443
#define NS_WEBSOCKET_CID \
{ /* 7ca25214-98dc-40a6-bc1f-41ddbe41f46c */ \
0x7ca25214, 0x98dc, 0x40a6, \
{0xbc, 0x1f, 0x41, 0xdd, 0xbe, 0x41, 0xf4, 0x6c} }
#define NS_WEBSOCKET_CONTRACTID "@mozilla.org/websocket;1"
class CallDispatchConnectionCloseEvents;
class nsAutoCloseWS;
class nsWebSocket: public nsDOMEventTargetHelper,
public nsIWebSocket,
public nsIJSNativeInitializer,
public nsIInterfaceRequestor,
public nsIWebSocketListener,
public nsIObserver,
public nsSupportsWeakReference,
public nsIRequest
{
friend class CallDispatchConnectionCloseEvents;
friend class nsAutoCloseWS;
public:
nsWebSocket();
virtual ~nsWebSocket();
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_INHERITED(nsWebSocket,
nsDOMEventTargetHelper)
NS_DECL_NSIWEBSOCKET
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSIWEBSOCKETLISTENER
NS_DECL_NSIOBSERVER
NS_DECL_NSIREQUEST
// nsIJSNativeInitializer
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,
JSObject* aObject, uint32_t aArgc, jsval* aArgv);
// nsIDOMEventTarget
NS_IMETHOD AddEventListener(const nsAString& aType,
nsIDOMEventListener *aListener,
bool aUseCapture,
bool aWantsUntrusted,
uint8_t optional_argc);
NS_IMETHOD RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
bool aUseCapture);
// Determine if preferences allow WebSocket
static bool PrefEnabled();
virtual void DisconnectFromOwner();
protected:
nsresult ParseURL(const nsString& aURL);
nsresult EstablishConnection();
// These methods when called can release the WebSocket object
nsresult FailConnection(uint16_t reasonCode,
const nsACString& aReasonString = EmptyCString());
nsresult CloseConnection(uint16_t reasonCode,
const nsACString& aReasonString = EmptyCString());
nsresult Disconnect();
nsresult ConsoleError();
nsresult PrintErrorOnConsole(const char *aBundleURI,
const PRUnichar *aError,
const PRUnichar **aFormatStrings,
uint32_t aFormatStringsLen);
// Get msg info out of JS variable being sent (string, arraybuffer, blob)
nsresult GetSendParams(nsIVariant *aData, nsCString &aStringOut,
nsCOMPtr<nsIInputStream> &aStreamOut,
bool &aIsBinary, uint32_t &aOutgoingLength,
JSContext *aCx);
nsresult DoOnMessageAvailable(const nsACString & aMsg, bool isBinary);
// ConnectionCloseEvents: 'error' event if needed, then 'close' event.
// - These must not be dispatched while we are still within an incoming call
// from JS (ex: close()). Set 'sync' to false in that case to dispatch in a
// separate new event.
nsresult ScheduleConnectionCloseEvents(nsISupports *aContext,
nsresult aStatusCode,
bool sync);
// 2nd half of ScheduleConnectionCloseEvents, sometimes run in its own event.
void DispatchConnectionCloseEvents();
// These methods actually do the dispatch for various events.
nsresult CreateAndDispatchSimpleEvent(const nsString& aName);
nsresult CreateAndDispatchMessageEvent(const nsACString& aData,
bool isBinary);
nsresult CreateAndDispatchCloseEvent(bool aWasClean, uint16_t aCode,
const nsString &aReason);
nsresult CreateResponseBlob(const nsACString& aData, JSContext *aCx,
jsval &jsData);
// if there are "strong event listeners" (see comment in nsWebSocket.cpp) or
// outgoing not sent messages then this method keeps the object alive
// when js doesn't have strong references to it.
void UpdateMustKeepAlive();
// ATTENTION, when calling this method the object can be released
// (and possibly collected).
void DontKeepAliveAnyMore();
nsresult UpdateURI();
nsCOMPtr<nsIWebSocketChannel> mChannel;
// related to the WebSocket constructor steps
nsString mOriginalURL;
nsString mEffectiveURL; // after redirects
bool mSecure; // if true it is using SSL and the wss scheme,
// otherwise it is using the ws scheme with no SSL
bool mKeepingAlive;
bool mCheckMustKeepAlive;
bool mOnCloseScheduled;
bool mFailed;
bool mDisconnected;
// Set attributes of DOM 'onclose' message
bool mCloseEventWasClean;
nsString mCloseEventReason;
uint16_t mCloseEventCode;
nsCString mAsciiHost; // hostname
uint32_t mPort;
nsCString mResource; // [filepath[?query]]
nsString mUTF16Origin;
nsCOMPtr<nsIURI> mURI;
nsCString mRequestedProtocolList;
nsCString mEstablishedProtocol;
nsCString mEstablishedExtensions;
uint16_t mReadyState;
nsCOMPtr<nsIPrincipal> mPrincipal;
uint32_t mOutgoingBufferedAmount;
enum
{
WS_BINARY_TYPE_ARRAYBUFFER,
WS_BINARY_TYPE_BLOB,
} mBinaryType;
// Web Socket owner information:
// - the script file name, UTF8 encoded.
// - source code line number where the Web Socket object was constructed.
// - the ID of the inner window where the script lives. Note that this may not
// be the same as the Web Socket owner window.
// These attributes are used for error reporting.
nsCString mScriptFile;
uint32_t mScriptLine;
uint64_t mInnerWindowID;
private:
nsWebSocket(const nsWebSocket& x); // prevent bad usage
nsWebSocket& operator=(const nsWebSocket& x);
};
#endif

Просмотреть файл

@ -171,7 +171,6 @@
#include "nsIDOMParser.h"
#include "nsIDOMSerializer.h"
#include "nsXMLHttpRequest.h"
#include "nsWebSocket.h"
#include "nsEventSource.h"
#include "nsIDOMSettingsManager.h"
#include "nsIDOMContactManager.h"
@ -1618,9 +1617,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(DesktopNotificationCenter, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(WebSocket, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(IDBFactory, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA_WITH_NAME(IDBFileHandle, FileHandle, nsEventTargetSH,
@ -1745,7 +1741,6 @@ NS_DEFINE_CONTRACT_CTOR(FileReader, NS_FILEREADER_CONTRACTID)
NS_DEFINE_CONTRACT_CTOR(ArchiveReader, NS_ARCHIVEREADER_CONTRACTID)
NS_DEFINE_CONTRACT_CTOR(FormData, NS_FORMDATA_CONTRACTID)
NS_DEFINE_CONTRACT_CTOR(XMLSerializer, NS_XMLSERIALIZER_CONTRACTID)
NS_DEFINE_CONTRACT_CTOR(WebSocket, NS_WEBSOCKET_CONTRACTID)
NS_DEFINE_CONTRACT_CTOR(XPathEvaluator, NS_XPATH_EVALUATOR_CONTRACTID)
NS_DEFINE_CONTRACT_CTOR(XSLTProcessor,
"@mozilla.org/document-transformer;1?type=xslt")
@ -1823,7 +1818,6 @@ static const nsConstructorFuncMapData kConstructorFuncMap[] =
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(ArchiveReader, ArchiveReaderCtor)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(FormData, FormDataCtor)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XMLSerializer, XMLSerializerCtor)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(WebSocket, WebSocketCtor)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XPathEvaluator, XPathEvaluatorCtor)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XSLTProcessor, XSLTProcessorCtor)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(EventSource, EventSourceCtor)
@ -4358,11 +4352,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDesktopNotificationCenter)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(WebSocket, nsIWebSocket)
DOM_CLASSINFO_MAP_ENTRY(nsIWebSocket)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(IDBFactory, nsIIDBFactory)
DOM_CLASSINFO_MAP_ENTRY(nsIIDBFactory)
DOM_CLASSINFO_MAP_END
@ -6713,13 +6702,6 @@ ConstructorEnabled(const nsGlobalNameStruct *aStruct, nsGlobalWindow *aWin)
return false;
}
// For now don't expose web sockets unless user has explicitly enabled them
if (aStruct->mDOMClassInfoID == eDOMClassInfo_WebSocket_id) {
if (!nsWebSocket::PrefEnabled()) {
return false;
}
}
// For now don't expose server events unless user has explicitly enabled them
if (aStruct->mDOMClassInfoID == eDOMClassInfo_EventSource_id) {
if (!nsEventSource::PrefEnabled()) {

Просмотреть файл

@ -484,9 +484,6 @@ DOMCI_CLASS(FormData)
DOMCI_CLASS(DesktopNotification)
DOMCI_CLASS(DesktopNotificationCenter)
// WebSocket
DOMCI_CLASS(WebSocket)
DOMCI_CLASS(IDBFactory)
DOMCI_CLASS(IDBFileHandle)
DOMCI_CLASS(IDBRequest)

Просмотреть файл

@ -236,6 +236,12 @@ DOMInterfaces = {
'headerFile': 'mozilla/dom/workers/bindings/XMLHttpRequestUpload.h'
}],
'WebSocket': [
{
'headerFile': 'WebSocket.h',
'implicitJSContext': [ 'constructor' ]
}],
####################################
# Test Interfaces of various sorts #
####################################

Просмотреть файл

@ -18,6 +18,7 @@ webidl_files = \
Performance.webidl \
PerformanceNavigation.webidl \
PerformanceTiming.webidl \
WebSocket.webidl \
XMLHttpRequest.webidl \
XMLHttpRequestEventTarget.webidl \
XMLHttpRequestUpload.webidl \

Просмотреть файл

@ -0,0 +1,69 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* http://www.whatwg.org/html/#network
*
* © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and Opera Software ASA.
* You are granted a license to use, reproduce and create derivative works of this document.
*/
enum BinaryType { "blob", "arraybuffer" };
[PrefControlled,
Constructor(DOMString url),
Constructor(DOMString url, DOMString protocols),
Constructor(DOMString url, sequence<DOMString> protocols)]
interface WebSocket : EventTarget {
readonly attribute DOMString url;
// ready state
const unsigned short CONNECTING = 0;
const unsigned short OPEN = 1;
const unsigned short CLOSING = 2;
const unsigned short CLOSED = 3;
readonly attribute unsigned short readyState;
readonly attribute unsigned long bufferedAmount;
// networking
[TreatNonCallableAsNull, SetterThrows]
attribute Function? onopen;
[TreatNonCallableAsNull, SetterThrows]
attribute Function? onerror;
[TreatNonCallableAsNull, SetterThrows]
attribute Function? onclose;
readonly attribute DOMString extensions;
readonly attribute DOMString protocol;
[Throws]
void close([Clamp] optional unsigned short code, optional DOMString reason);
// messaging
[TreatNonCallableAsNull, SetterThrows]
attribute Function? onmessage;
attribute BinaryType binaryType;
[Throws]
void send(DOMString data);
[Throws]
void send(Blob data);
[Throws]
void send(ArrayBuffer data);
[Throws]
void send(ArrayBufferView data);
};

Просмотреть файл

@ -429,9 +429,6 @@ members = [
# can't be quickstubbed
'-nsIXMLHttpRequest.upload',
# WebSocket
'nsIWebSocket.*',
# webgl
'nsIDOMWebGLRenderingContext.*',
# getContextAttributes is directly manipulating its return value

Просмотреть файл

@ -65,7 +65,6 @@
#include "nsDOMSerializer.h"
#include "nsXMLHttpRequest.h"
#include "nsChannelPolicy.h"
#include "nsWebSocket.h"
#include "nsEventSource.h"
// view stuff
@ -263,7 +262,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(txNodeSetAdaptor, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMSerializer)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsXMLHttpRequest, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEventSource)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebSocket)
NS_GENERIC_FACTORY_CONSTRUCTOR(Activity)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDOMFileReader, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(ArchiveReader)
@ -753,7 +751,6 @@ NS_DEFINE_NAMED_CID(NS_BLOBPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_BLOBURI_CID);
NS_DEFINE_NAMED_CID(NS_XMLHTTPREQUEST_CID);
NS_DEFINE_NAMED_CID(NS_EVENTSOURCE_CID);
NS_DEFINE_NAMED_CID(NS_WEBSOCKET_CID);
NS_DEFINE_NAMED_CID(NS_DOMACTIVITY_CID);
NS_DEFINE_NAMED_CID(NS_DOMPARSER_CID);
NS_DEFINE_NAMED_CID(NS_DOMSTORAGE2_CID);
@ -1029,7 +1026,6 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
{ &kNS_BLOBURI_CID, false, NULL, nsBlobURIConstructor },
{ &kNS_XMLHTTPREQUEST_CID, false, NULL, nsXMLHttpRequestConstructor },
{ &kNS_EVENTSOURCE_CID, false, NULL, nsEventSourceConstructor },
{ &kNS_WEBSOCKET_CID, false, NULL, nsWebSocketConstructor },
{ &kNS_DOMACTIVITY_CID, false, NULL, ActivityConstructor },
{ &kNS_DOMPARSER_CID, false, NULL, nsDOMParserConstructor },
{ &kNS_DOMSTORAGE2_CID, false, NULL, NS_NewDOMStorage2 },
@ -1170,7 +1166,6 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX BLOBURI_SCHEME, &kNS_BLOBPROTOCOLHANDLER_CID },
{ NS_XMLHTTPREQUEST_CONTRACTID, &kNS_XMLHTTPREQUEST_CID },
{ NS_EVENTSOURCE_CONTRACTID, &kNS_EVENTSOURCE_CID },
{ NS_WEBSOCKET_CONTRACTID, &kNS_WEBSOCKET_CID },
{ NS_DOMACTIVITY_CONTRACTID, &kNS_DOMACTIVITY_CID },
{ NS_DOMPARSER_CONTRACTID, &kNS_DOMPARSER_CID },
{ "@mozilla.org/dom/storage;2", &kNS_DOMSTORAGE2_CID },