mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 1517601, part 2 - Create and use a new WebSocketEvent base class instead of ChannelEvent. r=mayhemer
In the next patch, I want to change the signature of Run(), so I need to create a new base class for these inner WebSocket events. For now, this class is the same as ChannelEvent, except that it does not have the GetEventTarget method, which is never called. Depends on D19585 Differential Revision: https://phabricator.services.mozilla.com/D19586 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
d4a4aebf1c
commit
836727fcd1
@ -119,35 +119,44 @@ void WebSocketChannelChild::GetEffectiveURL(nsAString& aEffectiveURL) const {
|
||||
|
||||
bool WebSocketChannelChild::IsEncrypted() const { return mEncrypted; }
|
||||
|
||||
class WrappedChannelEvent : public Runnable {
|
||||
class WebSocketEvent {
|
||||
public:
|
||||
explicit WrappedChannelEvent(ChannelEvent* aChannelEvent)
|
||||
: Runnable("net::WrappedChannelEvent"), mChannelEvent(aChannelEvent) {
|
||||
MOZ_RELEASE_ASSERT(aChannelEvent);
|
||||
WebSocketEvent() { MOZ_COUNT_CTOR(WebSocketEvent); }
|
||||
virtual ~WebSocketEvent() { MOZ_COUNT_DTOR(WebSocketEvent); }
|
||||
virtual void Run() = 0;
|
||||
};
|
||||
|
||||
class WrappedWebSocketEvent : public Runnable {
|
||||
public:
|
||||
explicit WrappedWebSocketEvent(WebSocketEvent* aWebSocketEvent)
|
||||
: Runnable("net::WrappedWebSocketEvent"),
|
||||
mWebSocketEvent(aWebSocketEvent) {
|
||||
MOZ_RELEASE_ASSERT(aWebSocketEvent);
|
||||
}
|
||||
NS_IMETHOD Run() override {
|
||||
mChannelEvent->Run();
|
||||
mWebSocketEvent->Run();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
nsAutoPtr<ChannelEvent> mChannelEvent;
|
||||
nsAutoPtr<WebSocketEvent> mWebSocketEvent;
|
||||
};
|
||||
|
||||
class EventTargetDispatcher : public ChannelEvent {
|
||||
public:
|
||||
EventTargetDispatcher(ChannelEvent* aChannelEvent,
|
||||
EventTargetDispatcher(WebSocketEvent* aWebSocketEvent,
|
||||
nsIEventTarget* aEventTarget)
|
||||
: mChannelEvent(aChannelEvent), mEventTarget(aEventTarget) {}
|
||||
: mWebSocketEvent(aWebSocketEvent), mEventTarget(aEventTarget) {}
|
||||
|
||||
void Run() override {
|
||||
if (mEventTarget) {
|
||||
mEventTarget->Dispatch(new WrappedChannelEvent(mChannelEvent.forget()),
|
||||
NS_DISPATCH_NORMAL);
|
||||
mEventTarget->Dispatch(
|
||||
new WrappedWebSocketEvent(mWebSocketEvent.forget()),
|
||||
NS_DISPATCH_NORMAL);
|
||||
return;
|
||||
}
|
||||
|
||||
mChannelEvent->Run();
|
||||
mWebSocketEvent->Run();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIEventTarget> GetEventTarget() override {
|
||||
@ -159,11 +168,11 @@ class EventTargetDispatcher : public ChannelEvent {
|
||||
}
|
||||
|
||||
private:
|
||||
nsAutoPtr<ChannelEvent> mChannelEvent;
|
||||
nsAutoPtr<WebSocketEvent> mWebSocketEvent;
|
||||
nsCOMPtr<nsIEventTarget> mEventTarget;
|
||||
};
|
||||
|
||||
class StartEvent : public ChannelEvent {
|
||||
class StartEvent : public WebSocketEvent {
|
||||
public:
|
||||
StartEvent(WebSocketChannelChild* aChild, const nsCString& aProtocol,
|
||||
const nsCString& aExtensions, const nsString& aEffectiveURL,
|
||||
@ -178,10 +187,6 @@ class StartEvent : public ChannelEvent {
|
||||
mChild->OnStart(mProtocol, mExtensions, mEffectiveURL, mEncrypted);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIEventTarget> GetEventTarget() override {
|
||||
return do_AddRef(GetCurrentThreadEventTarget());
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<WebSocketChannelChild> mChild;
|
||||
nsCString mProtocol;
|
||||
@ -222,17 +227,13 @@ void WebSocketChannelChild::OnStart(const nsCString& aProtocol,
|
||||
}
|
||||
}
|
||||
|
||||
class StopEvent : public ChannelEvent {
|
||||
class StopEvent : public WebSocketEvent {
|
||||
public:
|
||||
StopEvent(WebSocketChannelChild* aChild, const nsresult& aStatusCode)
|
||||
: mChild(aChild), mStatusCode(aStatusCode) {}
|
||||
|
||||
void Run() override { mChild->OnStop(mStatusCode); }
|
||||
|
||||
already_AddRefed<nsIEventTarget> GetEventTarget() override {
|
||||
return do_AddRef(GetCurrentThreadEventTarget());
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<WebSocketChannelChild> mChild;
|
||||
nsresult mStatusCode;
|
||||
@ -261,7 +262,7 @@ void WebSocketChannelChild::OnStop(const nsresult& aStatusCode) {
|
||||
}
|
||||
}
|
||||
|
||||
class MessageEvent : public ChannelEvent {
|
||||
class MessageEvent : public WebSocketEvent {
|
||||
public:
|
||||
MessageEvent(WebSocketChannelChild* aChild, const nsCString& aMessage,
|
||||
bool aBinary)
|
||||
@ -275,10 +276,6 @@ class MessageEvent : public ChannelEvent {
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<nsIEventTarget> GetEventTarget() override {
|
||||
return do_AddRef(GetCurrentThreadEventTarget());
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<WebSocketChannelChild> mChild;
|
||||
nsCString mMessage;
|
||||
@ -333,17 +330,13 @@ void WebSocketChannelChild::OnBinaryMessageAvailable(const nsCString& aMsg) {
|
||||
}
|
||||
}
|
||||
|
||||
class AcknowledgeEvent : public ChannelEvent {
|
||||
class AcknowledgeEvent : public WebSocketEvent {
|
||||
public:
|
||||
AcknowledgeEvent(WebSocketChannelChild* aChild, const uint32_t& aSize)
|
||||
: mChild(aChild), mSize(aSize) {}
|
||||
|
||||
void Run() override { mChild->OnAcknowledge(mSize); }
|
||||
|
||||
already_AddRefed<nsIEventTarget> GetEventTarget() override {
|
||||
return do_AddRef(GetCurrentThreadEventTarget());
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<WebSocketChannelChild> mChild;
|
||||
uint32_t mSize;
|
||||
@ -373,7 +366,7 @@ void WebSocketChannelChild::OnAcknowledge(const uint32_t& aSize) {
|
||||
}
|
||||
}
|
||||
|
||||
class ServerCloseEvent : public ChannelEvent {
|
||||
class ServerCloseEvent : public WebSocketEvent {
|
||||
public:
|
||||
ServerCloseEvent(WebSocketChannelChild* aChild, const uint16_t aCode,
|
||||
const nsCString& aReason)
|
||||
@ -381,10 +374,6 @@ class ServerCloseEvent : public ChannelEvent {
|
||||
|
||||
void Run() override { mChild->OnServerClose(mCode, mReason); }
|
||||
|
||||
already_AddRefed<nsIEventTarget> GetEventTarget() override {
|
||||
return do_AddRef(GetCurrentThreadEventTarget());
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<WebSocketChannelChild> mChild;
|
||||
uint16_t mCode;
|
||||
|
Loading…
Reference in New Issue
Block a user