diff --git a/netwerk/ipc/NeckoChild.cpp b/netwerk/ipc/NeckoChild.cpp index fbef3725ccd1..04ee4e65f6ad 100644 --- a/netwerk/ipc/NeckoChild.cpp +++ b/netwerk/ipc/NeckoChild.cpp @@ -32,6 +32,7 @@ #include "mozilla/net/RtspChannelChild.h" #endif #include "SerializedLoadContext.h" +#include "nsGlobalWindow.h" #include "nsIOService.h" #include "nsINetworkPredictor.h" #include "nsINetworkPredictorVerifier.h" @@ -208,8 +209,18 @@ NeckoChild::DeallocPWebSocketChild(PWebSocketChild* child) PWebSocketEventListenerChild* NeckoChild::AllocPWebSocketEventListenerChild(const uint64_t& aInnerWindowID) { + nsCOMPtr target; + if (nsGlobalWindow* win = nsGlobalWindow::GetInnerWindowWithId(aInnerWindowID)) { + target = win->EventTargetFor(TaskCategory::Other); + } + RefPtr c = - new WebSocketEventListenerChild(aInnerWindowID); + new WebSocketEventListenerChild(aInnerWindowID, target); + + if (target) { + gNeckoChild->SetEventTargetForActor(c, target); + } + return c.forget().take(); } diff --git a/netwerk/ipc/moz.build b/netwerk/ipc/moz.build index a9ff2ca04e8c..d876956d8819 100644 --- a/netwerk/ipc/moz.build +++ b/netwerk/ipc/moz.build @@ -47,6 +47,7 @@ FINAL_LIBRARY = 'xul' LOCAL_INCLUDES += [ '/caps', + '/dom/base', '/modules/libjar', '/netwerk/base', '/netwerk/protocol/http', diff --git a/netwerk/protocol/websocket/WebSocketEventListenerChild.cpp b/netwerk/protocol/websocket/WebSocketEventListenerChild.cpp index c7ea44ea0024..ba2026132a69 100644 --- a/netwerk/protocol/websocket/WebSocketEventListenerChild.cpp +++ b/netwerk/protocol/websocket/WebSocketEventListenerChild.cpp @@ -12,8 +12,10 @@ namespace mozilla { namespace net { -WebSocketEventListenerChild::WebSocketEventListenerChild(uint64_t aInnerWindowID) - : mService(WebSocketEventService::GetOrCreate()) +WebSocketEventListenerChild::WebSocketEventListenerChild(uint64_t aInnerWindowID, + nsIEventTarget* aTarget) + : NeckoTargetHolder(aTarget) + , mService(WebSocketEventService::GetOrCreate()) , mInnerWindowID(aInnerWindowID) {} @@ -28,8 +30,9 @@ WebSocketEventListenerChild::RecvWebSocketCreated(const uint32_t& aWebSocketSeri const nsCString& aProtocols) { if (mService) { + nsCOMPtr target = GetNeckoTarget(); mService->WebSocketCreated(aWebSocketSerialID, mInnerWindowID, aURI, - aProtocols); + aProtocols, target); } return IPC_OK(); @@ -42,8 +45,9 @@ WebSocketEventListenerChild::RecvWebSocketOpened(const uint32_t& aWebSocketSeria const nsCString& aExtensions) { if (mService) { + nsCOMPtr target = GetNeckoTarget(); mService->WebSocketOpened(aWebSocketSerialID, mInnerWindowID, - aEffectiveURI, aProtocols, aExtensions); + aEffectiveURI, aProtocols, aExtensions, target); } return IPC_OK(); @@ -55,8 +59,9 @@ WebSocketEventListenerChild::RecvWebSocketMessageAvailable(const uint32_t& aWebS const uint16_t& aMessageType) { if (mService) { + nsCOMPtr target = GetNeckoTarget(); mService->WebSocketMessageAvailable(aWebSocketSerialID, mInnerWindowID, - aData, aMessageType); + aData, aMessageType, target); } return IPC_OK(); @@ -69,8 +74,9 @@ WebSocketEventListenerChild::RecvWebSocketClosed(const uint32_t& aWebSocketSeria const nsString& aReason) { if (mService) { + nsCOMPtr target = GetNeckoTarget(); mService->WebSocketClosed(aWebSocketSerialID, mInnerWindowID, - aWasClean, aCode, aReason); + aWasClean, aCode, aReason, target); } return IPC_OK(); @@ -81,8 +87,10 @@ WebSocketEventListenerChild::RecvFrameReceived(const uint32_t& aWebSocketSerialI const WebSocketFrameData& aFrameData) { if (mService) { + nsCOMPtr target = GetNeckoTarget(); RefPtr frame = new WebSocketFrame(aFrameData); - mService->FrameReceived(aWebSocketSerialID, mInnerWindowID, frame.forget()); + mService->FrameReceived(aWebSocketSerialID, mInnerWindowID, + frame.forget(), target); } return IPC_OK(); @@ -93,8 +101,10 @@ WebSocketEventListenerChild::RecvFrameSent(const uint32_t& aWebSocketSerialID, const WebSocketFrameData& aFrameData) { if (mService) { + nsCOMPtr target = GetNeckoTarget(); RefPtr frame = new WebSocketFrame(aFrameData); - mService->FrameSent(aWebSocketSerialID, mInnerWindowID, frame.forget()); + mService->FrameSent(aWebSocketSerialID, mInnerWindowID, + frame.forget(), target); } return IPC_OK(); diff --git a/netwerk/protocol/websocket/WebSocketEventListenerChild.h b/netwerk/protocol/websocket/WebSocketEventListenerChild.h index 3883174dee2c..2cd509d954b4 100644 --- a/netwerk/protocol/websocket/WebSocketEventListenerChild.h +++ b/netwerk/protocol/websocket/WebSocketEventListenerChild.h @@ -7,6 +7,7 @@ #ifndef mozilla_net_WebSocketEventListenerChild_h #define mozilla_net_WebSocketEventListenerChild_h +#include "mozilla/net/NeckoTargetHolder.h" #include "mozilla/net/PWebSocketEventListenerChild.h" namespace mozilla { @@ -15,11 +16,13 @@ namespace net { class WebSocketEventService; class WebSocketEventListenerChild final : public PWebSocketEventListenerChild + , public NeckoTargetHolder { public: NS_INLINE_DECL_REFCOUNTING(WebSocketEventListenerChild) - explicit WebSocketEventListenerChild(uint64_t aInnerWindowID); + explicit WebSocketEventListenerChild(uint64_t aInnerWindowID, + nsIEventTarget* aTarget); mozilla::ipc::IPCResult RecvWebSocketCreated(const uint32_t& aWebSocketSerialID, const nsString& aURI, diff --git a/netwerk/protocol/websocket/WebSocketEventService.cpp b/netwerk/protocol/websocket/WebSocketEventService.cpp index 2f9486a706ae..2bc94b8ce33f 100644 --- a/netwerk/protocol/websocket/WebSocketEventService.cpp +++ b/netwerk/protocol/websocket/WebSocketEventService.cpp @@ -245,7 +245,8 @@ void WebSocketEventService::WebSocketCreated(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID, const nsAString& aURI, - const nsACString& aProtocols) + const nsACString& aProtocols, + nsIEventTarget* aTarget) { // Let's continue only if we have some listeners. if (!HasListeners()) { @@ -255,7 +256,9 @@ WebSocketEventService::WebSocketCreated(uint32_t aWebSocketSerialID, RefPtr runnable = new WebSocketCreatedRunnable(aWebSocketSerialID, aInnerWindowID, aURI, aProtocols); - DebugOnly rv = NS_DispatchToMainThread(runnable); + DebugOnly rv = aTarget + ? aTarget->Dispatch(runnable, NS_DISPATCH_NORMAL) + : NS_DispatchToMainThread(runnable); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed"); } @@ -264,7 +267,8 @@ WebSocketEventService::WebSocketOpened(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID, const nsAString& aEffectiveURI, const nsACString& aProtocols, - const nsACString& aExtensions) + const nsACString& aExtensions, + nsIEventTarget* aTarget) { // Let's continue only if we have some listeners. if (!HasListeners()) { @@ -274,7 +278,9 @@ WebSocketEventService::WebSocketOpened(uint32_t aWebSocketSerialID, RefPtr runnable = new WebSocketOpenedRunnable(aWebSocketSerialID, aInnerWindowID, aEffectiveURI, aProtocols, aExtensions); - DebugOnly rv = NS_DispatchToMainThread(runnable); + DebugOnly rv = aTarget + ? aTarget->Dispatch(runnable, NS_DISPATCH_NORMAL) + : NS_DispatchToMainThread(runnable); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed"); } @@ -282,7 +288,8 @@ void WebSocketEventService::WebSocketMessageAvailable(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID, const nsACString& aData, - uint16_t aMessageType) + uint16_t aMessageType, + nsIEventTarget* aTarget) { // Let's continue only if we have some listeners. if (!HasListeners()) { @@ -292,7 +299,9 @@ WebSocketEventService::WebSocketMessageAvailable(uint32_t aWebSocketSerialID, RefPtr runnable = new WebSocketMessageAvailableRunnable(aWebSocketSerialID, aInnerWindowID, aData, aMessageType); - DebugOnly rv = NS_DispatchToMainThread(runnable); + DebugOnly rv = aTarget + ? aTarget->Dispatch(runnable, NS_DISPATCH_NORMAL) + : NS_DispatchToMainThread(runnable); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed"); } @@ -301,7 +310,8 @@ WebSocketEventService::WebSocketClosed(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID, bool aWasClean, uint16_t aCode, - const nsAString& aReason) + const nsAString& aReason, + nsIEventTarget* aTarget) { // Let's continue only if we have some listeners. if (!HasListeners()) { @@ -311,14 +321,17 @@ WebSocketEventService::WebSocketClosed(uint32_t aWebSocketSerialID, RefPtr runnable = new WebSocketClosedRunnable(aWebSocketSerialID, aInnerWindowID, aWasClean, aCode, aReason); - DebugOnly rv = NS_DispatchToMainThread(runnable); + DebugOnly rv = aTarget + ? aTarget->Dispatch(runnable, NS_DISPATCH_NORMAL) + : NS_DispatchToMainThread(runnable); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed"); } void WebSocketEventService::FrameReceived(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID, - already_AddRefed aFrame) + already_AddRefed aFrame, + nsIEventTarget* aTarget) { RefPtr frame(Move(aFrame)); MOZ_ASSERT(frame); @@ -331,14 +344,17 @@ WebSocketEventService::FrameReceived(uint32_t aWebSocketSerialID, RefPtr runnable = new WebSocketFrameRunnable(aWebSocketSerialID, aInnerWindowID, frame.forget(), false /* frameSent */); - DebugOnly rv = NS_DispatchToMainThread(runnable); + DebugOnly rv = aTarget + ? aTarget->Dispatch(runnable, NS_DISPATCH_NORMAL) + : NS_DispatchToMainThread(runnable); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed"); } void WebSocketEventService::FrameSent(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID, - already_AddRefed aFrame) + already_AddRefed aFrame, + nsIEventTarget* aTarget) { RefPtr frame(Move(aFrame)); MOZ_ASSERT(frame); @@ -352,7 +368,9 @@ WebSocketEventService::FrameSent(uint32_t aWebSocketSerialID, new WebSocketFrameRunnable(aWebSocketSerialID, aInnerWindowID, frame.forget(), true /* frameSent */); - DebugOnly rv = NS_DispatchToMainThread(runnable); + DebugOnly rv = aTarget + ? aTarget->Dispatch(runnable, NS_DISPATCH_NORMAL) + : NS_DispatchToMainThread(runnable); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed"); } diff --git a/netwerk/protocol/websocket/WebSocketEventService.h b/netwerk/protocol/websocket/WebSocketEventService.h index f23267999861..790636dd7748 100644 --- a/netwerk/protocol/websocket/WebSocketEventService.h +++ b/netwerk/protocol/websocket/WebSocketEventService.h @@ -39,32 +39,38 @@ public: void WebSocketCreated(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID, const nsAString& aURI, - const nsACString& aProtocols); + const nsACString& aProtocols, + nsIEventTarget* aTarget = nullptr); void WebSocketOpened(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID, const nsAString& aEffectiveURI, const nsACString& aProtocols, - const nsACString& aExtensions); + const nsACString& aExtensions, + nsIEventTarget* aTarget = nullptr); void WebSocketMessageAvailable(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID, const nsACString& aData, - uint16_t aMessageType); + uint16_t aMessageType, + nsIEventTarget* aTarget = nullptr); void WebSocketClosed(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID, bool aWasClean, uint16_t aCode, - const nsAString& aReason); + const nsAString& aReason, + nsIEventTarget* aTarget = nullptr); void FrameReceived(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID, - already_AddRefed aFrame); + already_AddRefed aFrame, + nsIEventTarget* aTarget = nullptr); void FrameSent(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID, - already_AddRefed aFrame); + already_AddRefed aFrame, + nsIEventTarget* aTarget = nullptr); already_AddRefed CreateFrameIfNeeded(bool aFinBit, bool aRsvBit1, bool aRsvBit2, bool aRsvBit3,