Bug 1392411 Part 1 - Report stacks to net monitor when creating web sockets, r=bzbarsky.

--HG--
extra : histedit_source : 19a30fceb5c8073551265398287aaa8fb226a228
This commit is contained in:
Brian Hackett 2019-05-19 12:44:37 -10:00
parent f828f39c0f
commit 9e70cb8a66

View File

@ -18,6 +18,7 @@
#include "mozilla/dom/nsCSPContext.h"
#include "mozilla/dom/nsCSPUtils.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/SerializedStackHolder.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/WorkerRef.h"
#include "mozilla/dom/WorkerRunnable.h"
@ -124,7 +125,8 @@ class WebSocketImpl final : public nsIInterfaceRequestor,
nsresult AsyncOpen(nsIPrincipal* aPrincipal, uint64_t aInnerWindowID,
nsITransportProvider* aTransportProvider,
const nsACString& aNegotiatedExtensions);
const nsACString& aNegotiatedExtensions,
UniquePtr<SerializedStackHolder> aOriginStack);
nsresult ParseURL(const nsAString& aURL);
nsresult InitializeConnection(nsIPrincipal* aPrincipal,
@ -1119,11 +1121,13 @@ class ConnectRunnable final : public WebSocketMainThreadRunnable {
class AsyncOpenRunnable final : public WebSocketMainThreadRunnable {
public:
explicit AsyncOpenRunnable(WebSocketImpl* aImpl)
explicit AsyncOpenRunnable(WebSocketImpl* aImpl,
UniquePtr<SerializedStackHolder> aOriginStack)
: WebSocketMainThreadRunnable(
aImpl->mWorkerRef->Private(),
NS_LITERAL_CSTRING("WebSocket :: AsyncOpen")),
mImpl(aImpl),
mOriginStack(std::move(aOriginStack)),
mErrorCode(NS_OK) {
MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread();
@ -1159,7 +1163,8 @@ class AsyncOpenRunnable final : public WebSocketMainThreadRunnable {
windowID = topInner->WindowID();
}
mErrorCode = mImpl->AsyncOpen(principal, windowID, nullptr, EmptyCString());
mErrorCode = mImpl->AsyncOpen(principal, windowID, nullptr, EmptyCString(),
std::move(mOriginStack));
return true;
}
@ -1168,7 +1173,7 @@ class AsyncOpenRunnable final : public WebSocketMainThreadRunnable {
MOZ_ASSERT(aTopLevelWorkerPrivate && !aTopLevelWorkerPrivate->GetWindow());
mErrorCode = mImpl->AsyncOpen(aTopLevelWorkerPrivate->GetPrincipal(), 0,
nullptr, EmptyCString());
nullptr, EmptyCString(), nullptr);
return true;
}
@ -1176,6 +1181,8 @@ class AsyncOpenRunnable final : public WebSocketMainThreadRunnable {
// Raw pointer. This worker runs synchronously.
WebSocketImpl* mImpl;
UniquePtr<SerializedStackHolder> mOriginStack;
nsresult mErrorCode;
};
@ -1355,6 +1362,9 @@ already_AddRefed<WebSocket> WebSocket::ConstructorCommon(
return nullptr;
}
UniquePtr<SerializedStackHolder> stack =
GetCurrentStackForNetMonitor(aGlobal.Context());
if (NS_IsMainThread()) {
MOZ_ASSERT(principal);
@ -1373,12 +1383,13 @@ already_AddRefed<WebSocket> WebSocket::ConstructorCommon(
}
aRv = webSocket->mImpl->AsyncOpen(principal, windowID, aTransportProvider,
aNegotiatedExtensions);
aNegotiatedExtensions, std::move(stack));
} else {
MOZ_ASSERT(!aTransportProvider && aNegotiatedExtensions.IsEmpty(),
"not yet implemented");
RefPtr<AsyncOpenRunnable> runnable =
new AsyncOpenRunnable(webSocket->mImpl);
new AsyncOpenRunnable(webSocket->mImpl, std::move(stack));
runnable->Dispatch(Canceling, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
@ -1632,7 +1643,8 @@ nsresult WebSocketImpl::Init(JSContext* aCx, nsIPrincipal* aLoadingPrincipal,
nsresult WebSocketImpl::AsyncOpen(nsIPrincipal* aPrincipal,
uint64_t aInnerWindowID,
nsITransportProvider* aTransportProvider,
const nsACString& aNegotiatedExtensions) {
const nsACString& aNegotiatedExtensions,
UniquePtr<SerializedStackHolder> aOriginStack) {
MOZ_ASSERT(NS_IsMainThread(), "Not running on main thread");
MOZ_ASSERT_IF(!aTransportProvider, aNegotiatedExtensions.IsEmpty());
@ -1659,6 +1671,8 @@ nsresult WebSocketImpl::AsyncOpen(nsIPrincipal* aPrincipal,
return NS_ERROR_CONTENT_BLOCKED;
}
NotifyNetworkMonitorAlternateStack(mChannel, std::move(aOriginStack));
mInnerWindowID = aInnerWindowID;
return NS_OK;