зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1090142 - WebSocketChannelChild should respect the order of the runnable to be dispatched. r=jduell
This commit is contained in:
Родитель
20c938e8d7
Коммит
40f8089c74
|
@ -2296,6 +2296,12 @@ WebSocketImpl::CancelInternal()
|
|||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
// If CancelInternal is called by a runnable, we may already be disconnected
|
||||
// by the time it runs.
|
||||
if (mDisconnected) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int64_t readyState = mWebSocket->ReadyState();
|
||||
if (readyState == WebSocket::CLOSING || readyState == WebSocket::CLOSED) {
|
||||
return NS_OK;
|
||||
|
|
|
@ -120,6 +120,31 @@ WebSocketChannelChild::DispatchToTargetThread(ChannelEvent *aChannelEvent)
|
|||
NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
class EventTargetDispatcher : public ChannelEvent
|
||||
{
|
||||
public:
|
||||
EventTargetDispatcher(ChannelEvent* aChannelEvent,
|
||||
nsIEventTarget* aEventTarget)
|
||||
: mChannelEvent(aChannelEvent)
|
||||
, mEventTarget(aEventTarget)
|
||||
{}
|
||||
|
||||
void Run()
|
||||
{
|
||||
if (mEventTarget) {
|
||||
mEventTarget->Dispatch(new WrappedChannelEvent(mChannelEvent.forget()),
|
||||
NS_DISPATCH_NORMAL);
|
||||
return;
|
||||
}
|
||||
|
||||
mChannelEvent->Run();
|
||||
}
|
||||
|
||||
private:
|
||||
nsAutoPtr<ChannelEvent> mChannelEvent;
|
||||
nsCOMPtr<nsIEventTarget> mEventTarget;
|
||||
};
|
||||
|
||||
class StartEvent : public ChannelEvent
|
||||
{
|
||||
public:
|
||||
|
@ -154,8 +179,10 @@ WebSocketChannelChild::RecvOnStart(const nsCString& aProtocol,
|
|||
const bool& aEncrypted)
|
||||
{
|
||||
if (mEventQ->ShouldEnqueue()) {
|
||||
mEventQ->Enqueue(new StartEvent(this, aProtocol, aExtensions,
|
||||
aEffectiveURL, aEncrypted));
|
||||
mEventQ->Enqueue(new EventTargetDispatcher(
|
||||
new StartEvent(this, aProtocol, aExtensions,
|
||||
aEffectiveURL, aEncrypted),
|
||||
mTargetThread));
|
||||
} else if (mTargetThread) {
|
||||
DispatchToTargetThread(new StartEvent(this, aProtocol, aExtensions,
|
||||
aEffectiveURL, aEncrypted));
|
||||
|
@ -205,7 +232,8 @@ bool
|
|||
WebSocketChannelChild::RecvOnStop(const nsresult& aStatusCode)
|
||||
{
|
||||
if (mEventQ->ShouldEnqueue()) {
|
||||
mEventQ->Enqueue(new StopEvent(this, aStatusCode));
|
||||
mEventQ->Enqueue(new EventTargetDispatcher(
|
||||
new StopEvent(this, aStatusCode), mTargetThread));
|
||||
} else if (mTargetThread) {
|
||||
DispatchToTargetThread(new StopEvent(this, aStatusCode));
|
||||
} else {
|
||||
|
@ -253,7 +281,8 @@ bool
|
|||
WebSocketChannelChild::RecvOnMessageAvailable(const nsCString& aMsg)
|
||||
{
|
||||
if (mEventQ->ShouldEnqueue()) {
|
||||
mEventQ->Enqueue(new MessageEvent(this, aMsg, false));
|
||||
mEventQ->Enqueue(new EventTargetDispatcher(
|
||||
new MessageEvent(this, aMsg, false), mTargetThread));
|
||||
} else if (mTargetThread) {
|
||||
DispatchToTargetThread(new MessageEvent(this, aMsg, false));
|
||||
} else {
|
||||
|
@ -276,7 +305,8 @@ bool
|
|||
WebSocketChannelChild::RecvOnBinaryMessageAvailable(const nsCString& aMsg)
|
||||
{
|
||||
if (mEventQ->ShouldEnqueue()) {
|
||||
mEventQ->Enqueue(new MessageEvent(this, aMsg, true));
|
||||
mEventQ->Enqueue(new EventTargetDispatcher(
|
||||
new MessageEvent(this, aMsg, true), mTargetThread));
|
||||
} else if (mTargetThread) {
|
||||
DispatchToTargetThread(new MessageEvent(this, aMsg, true));
|
||||
} else {
|
||||
|
@ -317,7 +347,8 @@ bool
|
|||
WebSocketChannelChild::RecvOnAcknowledge(const uint32_t& aSize)
|
||||
{
|
||||
if (mEventQ->ShouldEnqueue()) {
|
||||
mEventQ->Enqueue(new AcknowledgeEvent(this, aSize));
|
||||
mEventQ->Enqueue(new EventTargetDispatcher(
|
||||
new AcknowledgeEvent(this, aSize), mTargetThread));
|
||||
} else if (mTargetThread) {
|
||||
DispatchToTargetThread(new AcknowledgeEvent(this, aSize));
|
||||
} else {
|
||||
|
@ -362,7 +393,9 @@ WebSocketChannelChild::RecvOnServerClose(const uint16_t& aCode,
|
|||
const nsCString& aReason)
|
||||
{
|
||||
if (mEventQ->ShouldEnqueue()) {
|
||||
mEventQ->Enqueue(new ServerCloseEvent(this, aCode, aReason));
|
||||
mEventQ->Enqueue(new EventTargetDispatcher(
|
||||
new ServerCloseEvent(this, aCode, aReason),
|
||||
mTargetThread));
|
||||
} else if (mTargetThread) {
|
||||
DispatchToTargetThread(new ServerCloseEvent(this, aCode, aReason));
|
||||
} else {
|
||||
|
|
Загрузка…
Ссылка в новой задаче