Bug 504553 - Patch 1 - WebSockets in Workers: Dispatch WebSocketChannel::StartWebsocketConnect to target thread, r=jduell

This commit is contained in:
Steve Workman
2014-04-17 11:53:58 -07:00
parent a77bff707b
commit b5e87b7edb
8 changed files with 118 additions and 42 deletions

View File

@@ -49,13 +49,13 @@ NS_INTERFACE_MAP_BEGIN(WebSocketChannelChild)
NS_INTERFACE_MAP_ENTRY(nsIThreadRetargetableRequest)
NS_INTERFACE_MAP_END
WebSocketChannelChild::WebSocketChannelChild(bool aSecure)
WebSocketChannelChild::WebSocketChannelChild(bool aEncrypted)
: mIPCOpen(false)
{
NS_ABORT_IF_FALSE(NS_IsMainThread(), "not main thread");
LOG(("WebSocketChannelChild::WebSocketChannelChild() %p\n", this));
BaseWebSocketChannel::mEncrypted = aSecure;
mEncrypted = aEncrypted;
mEventQ = new ChannelEventQueue(static_cast<nsIWebSocketChannel*>(this));
}
@@ -80,6 +80,18 @@ WebSocketChannelChild::ReleaseIPDLReference()
Release();
}
void
WebSocketChannelChild::GetEffectiveURL(nsAString& aEffectiveURL) const
{
aEffectiveURL = mEffectiveURL;
}
bool
WebSocketChannelChild::IsEncrypted() const
{
return mEncrypted;
}
class WrappedChannelEvent : public nsRunnable
{
public:
@@ -113,43 +125,57 @@ class StartEvent : public ChannelEvent
public:
StartEvent(WebSocketChannelChild* aChild,
const nsCString& aProtocol,
const nsCString& aExtensions)
const nsCString& aExtensions,
const nsString& aEffectiveURL,
bool aEncrypted)
: mChild(aChild)
, mProtocol(aProtocol)
, mExtensions(aExtensions)
, mEffectiveURL(aEffectiveURL)
, mEncrypted(aEncrypted)
{}
void Run()
{
mChild->OnStart(mProtocol, mExtensions);
mChild->OnStart(mProtocol, mExtensions, mEffectiveURL, mEncrypted);
}
private:
WebSocketChannelChild* mChild;
nsCString mProtocol;
nsCString mExtensions;
nsString mEffectiveURL;
bool mEncrypted;
};
bool
WebSocketChannelChild::RecvOnStart(const nsCString& aProtocol,
const nsCString& aExtensions)
const nsCString& aExtensions,
const nsString& aEffectiveURL,
const bool& aEncrypted)
{
if (mEventQ->ShouldEnqueue()) {
mEventQ->Enqueue(new StartEvent(this, aProtocol, aExtensions));
mEventQ->Enqueue(new StartEvent(this, aProtocol, aExtensions,
aEffectiveURL, aEncrypted));
} else if (mTargetThread) {
DispatchToTargetThread(new StartEvent(this, aProtocol, aExtensions));
DispatchToTargetThread(new StartEvent(this, aProtocol, aExtensions,
aEffectiveURL, aEncrypted));
} else {
OnStart(aProtocol, aExtensions);
OnStart(aProtocol, aExtensions, aEffectiveURL, aEncrypted);
}
return true;
}
void
WebSocketChannelChild::OnStart(const nsCString& aProtocol,
const nsCString& aExtensions)
const nsCString& aExtensions,
const nsString& aEffectiveURL,
const bool& aEncrypted)
{
LOG(("WebSocketChannelChild::RecvOnStart() %p\n", this));
SetProtocol(aProtocol);
mNegotiatedExtensions = aExtensions;
mEffectiveURL = aEffectiveURL;
mEncrypted = aEncrypted;
if (mListener) {
AutoEventEnqueuer ensureSerialDispatch(mEventQ);;