Bug 1343747 - Part 2: Label runnables in WebSocketEventListenerChild. r=mayhemer

Use inner window id to get the window's event target and use it to label runnables.
This commit is contained in:
Kershaw Chang 2017-06-13 20:15:00 -04:00
Родитель b4232a0b60
Коммит b59d3c86ec
6 изменённых файлов: 77 добавлений и 28 удалений

Просмотреть файл

@ -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<nsIEventTarget> target;
if (nsGlobalWindow* win = nsGlobalWindow::GetInnerWindowWithId(aInnerWindowID)) {
target = win->EventTargetFor(TaskCategory::Other);
}
RefPtr<WebSocketEventListenerChild> c =
new WebSocketEventListenerChild(aInnerWindowID);
new WebSocketEventListenerChild(aInnerWindowID, target);
if (target) {
gNeckoChild->SetEventTargetForActor(c, target);
}
return c.forget().take();
}

Просмотреть файл

@ -47,6 +47,7 @@ FINAL_LIBRARY = 'xul'
LOCAL_INCLUDES += [
'/caps',
'/dom/base',
'/modules/libjar',
'/netwerk/base',
'/netwerk/protocol/http',

Просмотреть файл

@ -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<nsIEventTarget> 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<nsIEventTarget> 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<nsIEventTarget> 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<nsIEventTarget> 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<nsIEventTarget> target = GetNeckoTarget();
RefPtr<WebSocketFrame> 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<nsIEventTarget> target = GetNeckoTarget();
RefPtr<WebSocketFrame> frame = new WebSocketFrame(aFrameData);
mService->FrameSent(aWebSocketSerialID, mInnerWindowID, frame.forget());
mService->FrameSent(aWebSocketSerialID, mInnerWindowID,
frame.forget(), target);
}
return IPC_OK();

Просмотреть файл

@ -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,

Просмотреть файл

@ -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<WebSocketCreatedRunnable> runnable =
new WebSocketCreatedRunnable(aWebSocketSerialID, aInnerWindowID,
aURI, aProtocols);
DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
DebugOnly<nsresult> 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<WebSocketOpenedRunnable> runnable =
new WebSocketOpenedRunnable(aWebSocketSerialID, aInnerWindowID,
aEffectiveURI, aProtocols, aExtensions);
DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
DebugOnly<nsresult> 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<WebSocketMessageAvailableRunnable> runnable =
new WebSocketMessageAvailableRunnable(aWebSocketSerialID, aInnerWindowID,
aData, aMessageType);
DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
DebugOnly<nsresult> 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<WebSocketClosedRunnable> runnable =
new WebSocketClosedRunnable(aWebSocketSerialID, aInnerWindowID,
aWasClean, aCode, aReason);
DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
DebugOnly<nsresult> 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<WebSocketFrame> aFrame)
already_AddRefed<WebSocketFrame> aFrame,
nsIEventTarget* aTarget)
{
RefPtr<WebSocketFrame> frame(Move(aFrame));
MOZ_ASSERT(frame);
@ -331,14 +344,17 @@ WebSocketEventService::FrameReceived(uint32_t aWebSocketSerialID,
RefPtr<WebSocketFrameRunnable> runnable =
new WebSocketFrameRunnable(aWebSocketSerialID, aInnerWindowID,
frame.forget(), false /* frameSent */);
DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
DebugOnly<nsresult> 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<WebSocketFrame> aFrame)
already_AddRefed<WebSocketFrame> aFrame,
nsIEventTarget* aTarget)
{
RefPtr<WebSocketFrame> frame(Move(aFrame));
MOZ_ASSERT(frame);
@ -352,7 +368,9 @@ WebSocketEventService::FrameSent(uint32_t aWebSocketSerialID,
new WebSocketFrameRunnable(aWebSocketSerialID, aInnerWindowID,
frame.forget(), true /* frameSent */);
DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
DebugOnly<nsresult> rv = aTarget
? aTarget->Dispatch(runnable, NS_DISPATCH_NORMAL)
: NS_DispatchToMainThread(runnable);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed");
}

Просмотреть файл

@ -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<WebSocketFrame> aFrame);
already_AddRefed<WebSocketFrame> aFrame,
nsIEventTarget* aTarget = nullptr);
void FrameSent(uint32_t aWebSocketSerialID,
uint64_t aInnerWindowID,
already_AddRefed<WebSocketFrame> aFrame);
already_AddRefed<WebSocketFrame> aFrame,
nsIEventTarget* aTarget = nullptr);
already_AddRefed<WebSocketFrame>
CreateFrameIfNeeded(bool aFinBit, bool aRsvBit1, bool aRsvBit2, bool aRsvBit3,