Bug 504553 - patch 3 - WebSockes in Workers: Workers supported, r=smaug

This commit is contained in:
Andrea Marchesini 2014-10-10 17:58:05 +01:00
parent 99566c64c1
commit 11fb9c6ca7
7 changed files with 1056 additions and 207 deletions

File diff suppressed because it is too large Load Diff

View File

@ -26,6 +26,10 @@
namespace mozilla {
namespace dom {
namespace workers {
class WorkerPrivate;
}
class File;
class WebSocketImpl;
@ -56,7 +60,7 @@ public:
// nsWrapperCache
nsPIDOMWindow* GetParentObject() { return GetOwner(); }
virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE;
public: // static helpers:
@ -133,7 +137,10 @@ private: // constructor && distructor
// These methods actually do the dispatch for various events.
nsresult CreateAndDispatchSimpleEvent(const nsAString& aName);
nsresult CreateAndDispatchMessageEvent(const nsACString& aData,
bool isBinary);
bool aIsBinary);
nsresult CreateAndDispatchMessageEvent(JSContext* aCx,
const nsACString& aData,
bool aIsBinary);
nsresult CreateAndDispatchCloseEvent(bool aWasClean,
uint16_t aCode,
const nsAString& aReason);
@ -150,10 +157,14 @@ private:
WebSocket(const WebSocket& x) MOZ_DELETE; // prevent bad usage
WebSocket& operator=(const WebSocket& x) MOZ_DELETE;
// Raw pointer because this WebSocketImpl is created, managed an destroyed by
// Raw pointer because this WebSocketImpl is created, managed and destroyed by
// WebSocket.
WebSocketImpl* mImpl;
// This is used just to check in which thread this object is used when mImpl
// is null.
workers::WorkerPrivate* mWorkerPrivate;
bool mKeepingAlive;
bool mCheckMustKeepAlive;
};

View File

@ -81,6 +81,7 @@ EXPORTS.mozilla.dom += [
'StyleSheetList.h',
'Text.h',
'TreeWalker.h',
'WebSocket.h',
]
UNIFIED_SOURCES += [

View File

@ -1440,10 +1440,6 @@ DOMInterfaces = {
'concrete': False,
},
'WebSocket': {
'headerFile': 'WebSocket.h',
},
'Window': {
'nativeType': 'nsGlobalWindow',
'binaryNames': {

View File

@ -13,6 +13,7 @@
enum BinaryType { "blob", "arraybuffer" };
[Func="mozilla::dom::WebSocket::PrefEnabled",
Exposed=(Window,Worker),
Constructor(DOMString url),
Constructor(DOMString url, DOMString protocols),
Constructor(DOMString url, sequence<DOMString> protocols)]

View File

@ -126,6 +126,8 @@ var interfaceNamesInGlobalScope =
"URL",
// IMPORTANT: Do not change this list without review from a DOM peer!
"URLSearchParams",
// IMPORTANT: Do not change this list without review from a DOM peer!
"WebSocket",
// IMPORTANT: Do not change this list without review from a DOM peer!
"Worker",
// IMPORTANT: Do not change this list without review from a DOM peer!

View File

@ -1190,8 +1190,14 @@ WebSocketChannel::IsEncrypted() const
void
WebSocketChannel::BeginOpen()
{
if (!NS_IsMainThread()) {
NS_DispatchToMainThread(
NS_NewRunnableMethod(this, &WebSocketChannel::BeginOpen),
NS_DISPATCH_NORMAL);
return;
}
LOG(("WebSocketChannel::BeginOpen() %p\n", this));
NS_ABORT_IF_FALSE(NS_IsMainThread(), "not main thread");
nsresult rv;