import changes from `dev' branch of rmottola/Arctic-Fox:

- Bug 1203802 - Websocket Frame Listener API for devtool Network Inspector - part 1 - WindowID added into WebSocketChannel, r=michal (80cae04416)
- Bug 1203802 - Websocket Frame Listener API for devtool Network Inspector - part 2 - WebSocketFrameService, r=michal (66e1935806)
- Bug 1203802 - Websocket Frame Listener API for devtool Network Inspector - part 3 - timestamp, r=michal (1ee78cbab5)
- Bug 1203802 - Websocket Frame Listener API for devtool Network Inspector - part 4 - IPC, r=michal (651d908780)
- Bug 1215092 - WebSocketEventService and WebSocket discovering - part 1 - Renaming WebSocketFrameService, r=michal (c215f04303)
- Bug 1215092 - WebSocketEventService and WebSocket discovering - part 2 - Unique Serial number for WebSocketChannel in IPC, r=michal (9a42b6b898)
- Bug 1215092 - WebSocketEventService and WebSocket discovering - part 3 - Events, r=michal (3e22a9b8a9)
- Bug 1215092 - WebSocketEventService and WebSocket discovering - part 4 - MessageAvailable event, r=michal (03606add66)
- Bug 1185351 - Don't force inline style CSP checks on native anonymous content; r=ckerschb (51deea3648)
- Bug 1212477 - Needs a way to access to <canvas>'s context (2d, webgl) from Anonymous Content API; r=roc;r=smaug (ed3335513d)
- Bug 1119692 - Part 1: Get cached jar file fd if it exists instead of always openning it. r=smaug, r=jduell (399a3701dd)
- Bug 1119692 - Part 2: Always use scheme jar:remoteopenfile: for out-of-process apps to ease sandboxing code. r=fabrice (d3783120a9)
- Bug 1212244 - Same-process sendAsyncMessage can now throw instead of OOM. r=smaug (f22bbeb173)
- Bug 1207752 - Increase how long we let incremental GC run before forcing it to finish. r=smaug (ef731501a0)
- Bug 1213019. Get UnmapBuffer as part of MapBufferRanges features. r=jgilbert (0e1a1d7ffd)
- Bug 941858 - Do not scale down elements passed to setDragImage. r=roc (7c1f18056e)
- Bug 1212027 - part 1 - rename ipdl lowering helpers to reflect intent, not function; r=jld (f2c80853a7)
- Bug 1212027 - part 2 - add a C++ AST type for 'auto'; r=jld (480120b163)
- Bug 1212027 - part 3 - use class interfaces when cloning managees; r=jld (98d8aa9322)
- Bug 1212027 - part 4 - use class interfaces when destroying managees; r=jld (2ed9d48242)
- Add default initializers for primitive fields in IPDL structs. (bug 1154522, r=billm) (981f0e0d82)
- Bug 1158905 - remove dead code from protocol Transition functions; r=bent (e4a43b880a)
- Bug 1207921 - Call makeReply before dtorEpilogue so that we don't end up with a nullptr deref r=billm (f7d4530a72)
- Bug 1212248 - Align the creation of cpow in ContentBridgeParent to ContentParent. r=khuey (ace596456a)
- Bug 1212027 - part 5 - add LoneManagedOrNull for simplifying a lot of upcoming code; r=jld (6aec494580)
- Bug 1212027 - part 6 - add an IsEmpty method to nsTHashtable; r=erahm (cabe26f3d6)
- bug 1209615 - use TabParent::GetTopLevelDocAccessible() in OuterDocAccessible::RemoteChildDoc() r=davidb (0765f27bb5)
- Bug 1214316 - Improve assertions on top level remote accessible doc handling, r=tbsaunde (257c6c8ef6)
- Bug 1212027 - part 7 - modify IPDL codegen to store sub-protocols in a hashtable rather than an array; r=jld,nical,cpearce,billm (99dd4fa79c)
- Bug 1212027 - followup - qualify PBrowserParent in GonkPermission.cpp; r=me (051e7e1bde)
- Bug 1217250 - Fix some IPDL tests that were broken by bug 1212027; r=froydnj (d368b3aa02)
- Bug 1202634 - Make sure TabParent LoadContext for pop-ups shares private browsing state of opener. r=billm (b347018487)
- Bug 1191740 - Add originAttributes in TabContext. r=bholley (43ea8ca527)
- Bug 1191740 - Factor out nsFrameLoader::GetNewTabContext. r=bholley (3311ab7287)
- Bug 1180088 - Use origin-based permission check on parent side for signed packaged web app. r=kanru. (01659e2906)
- Bug 1205399 - Backend for disabling of notifications for a site from the UI. r=nsm (6380757077)
- Bug 1208295 - Dispatch notifications-open-settings upon receiving alertsettingscallback so UI can open notification settings. r=nsm (776ab25c91)
- Bug 1212129 - e10s support for disabling site notifications. r=wchen (e896f87940)
- Bug 1208622 - Separate API entry points. r=bz (a324f95322)
This commit is contained in:
2022-11-09 15:10:01 +08:00
parent f468c29a62
commit 139dd41f0f
117 changed files with 4118 additions and 708 deletions
+75 -12
View File
@@ -38,6 +38,7 @@
#include "nsIStringBundle.h"
#include "nsIConsoleService.h"
#include "mozilla/dom/CloseEvent.h"
#include "mozilla/net/WebSocketEventService.h"
#include "nsICryptoHash.h"
#include "nsJSUtils.h"
#include "nsIScriptError.h"
@@ -128,7 +129,8 @@ public:
ErrorResult& aRv,
bool* aConnectionFailed);
void AsyncOpen(nsIPrincipal* aPrincipal, ErrorResult& aRv);
void AsyncOpen(nsIPrincipal* aPrincipal, uint64_t aInnerWindowID,
ErrorResult& aRv);
nsresult ParseURL(const nsAString& aURL);
nsresult InitializeConnection(nsIPrincipal* aPrincipal);
@@ -241,6 +243,8 @@ public:
mozilla::Mutex mMutex;
bool mWorkerShuttingDown;
RefPtr<WebSocketEventService> mService;
private:
~WebSocketImpl()
{
@@ -631,11 +635,8 @@ WebSocketImpl::Disconnect()
// until the end of the method.
RefPtr<WebSocketImpl> kungfuDeathGrip = this;
nsCOMPtr<nsIThread> mainThread;
if (NS_FAILED(NS_GetMainThread(getter_AddRefs(mainThread))) ||
NS_FAILED(NS_ProxyRelease(mainThread, mChannel))) {
NS_WARNING("Failed to proxy release of channel, leaking instead!");
}
NS_ReleaseOnMainThread(mChannel);
NS_ReleaseOnMainThread(static_cast<nsIWebSocketEventService*>(mService.forget().take()));
mWebSocket->DontKeepAliveAnyMore();
mWebSocket->mImpl = nullptr;
@@ -770,6 +771,11 @@ WebSocketImpl::OnStart(nsISupports* aContext)
mWebSocket->SetReadyState(WebSocket::OPEN);
mService->WebSocketOpened(mChannel->Serial(),mInnerWindowID,
mWebSocket->mEffectiveURL,
mWebSocket->mEstablishedProtocol,
mWebSocket->mEstablishedExtensions);
// Let's keep the object alive because the webSocket can be CCed in the
// onopen callback.
RefPtr<WebSocket> webSocket = mWebSocket;
@@ -1126,6 +1132,7 @@ protected:
virtual bool InitWithWindow(nsPIDOMWindow* aWindow) override
{
AssertIsOnMainThread();
MOZ_ASSERT(aWindow);
nsIDocument* doc = aWindow->GetExtantDoc();
if (!doc) {
@@ -1139,7 +1146,23 @@ protected:
return true;
}
mImpl->AsyncOpen(principal, mRv);
if (aWindow->IsOuterWindow()) {
aWindow = aWindow->GetCurrentInnerWindow();
}
MOZ_ASSERT(aWindow);
uint64_t windowID = 0;
nsCOMPtr<nsPIDOMWindow> topWindow = aWindow->GetScriptableTop();
if (topWindow) {
topWindow = topWindow->GetCurrentInnerWindow();
}
if (topWindow) {
windowID = topWindow->WindowID();
}
mImpl->AsyncOpen(principal, windowID, mRv);
return true;
}
@@ -1148,7 +1171,7 @@ protected:
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aTopLevelWorkerPrivate && !aTopLevelWorkerPrivate->GetWindow());
mImpl->AsyncOpen(aTopLevelWorkerPrivate->GetPrincipal(), mRv);
mImpl->AsyncOpen(aTopLevelWorkerPrivate->GetPrincipal(), 0, mRv);
return true;
}
@@ -1198,6 +1221,8 @@ WebSocket::Constructor(const GlobalObject& aGlobal,
}
}
MOZ_ASSERT_IF(ownerWindow, ownerWindow->IsInnerWindow());
nsTArray<nsString> protocolArray;
for (uint32_t index = 0, len = aProtocols.Length(); index < len; ++index) {
@@ -1310,7 +1335,20 @@ WebSocket::Constructor(const GlobalObject& aGlobal,
if (NS_IsMainThread()) {
MOZ_ASSERT(principal);
webSocket->mImpl->AsyncOpen(principal, aRv);
nsPIDOMWindow* outerWindow = ownerWindow->GetOuterWindow();
uint64_t windowID = 0;
nsCOMPtr<nsPIDOMWindow> topWindow = outerWindow->GetScriptableTop();
if (topWindow) {
topWindow = topWindow->GetCurrentInnerWindow();
}
if (topWindow) {
windowID = topWindow->WindowID();
}
webSocket->mImpl->AsyncOpen(principal, windowID, aRv);
} else {
RefPtr<AsyncOpenRunnable> runnable =
new AsyncOpenRunnable(webSocket->mImpl, aRv);
@@ -1328,6 +1366,12 @@ WebSocket::Constructor(const GlobalObject& aGlobal,
return nullptr;
}
// Let's inform devtools about this new active WebSocket.
webSocket->mImpl->mService->WebSocketCreated(webSocket->mImpl->mChannel->Serial(),
webSocket->mImpl->mInnerWindowID,
webSocket->mURI,
webSocket->mImpl->mRequestedProtocolList);
cws.Done();
return webSocket.forget();
}
@@ -1413,6 +1457,8 @@ WebSocketImpl::Init(JSContext* aCx,
AssertIsOnMainThread();
MOZ_ASSERT(aPrincipal);
mService = WebSocketEventService::GetOrCreate();
// We need to keep the implementation alive in case the init disconnects it
// because of some error.
RefPtr<WebSocketImpl> kungfuDeathGrip = this;
@@ -1606,7 +1652,8 @@ WebSocketImpl::Init(JSContext* aCx,
}
void
WebSocketImpl::AsyncOpen(nsIPrincipal* aPrincipal, ErrorResult& aRv)
WebSocketImpl::AsyncOpen(nsIPrincipal* aPrincipal, uint64_t aInnerWindowID,
ErrorResult& aRv)
{
MOZ_ASSERT(NS_IsMainThread(), "Not running on main thread");
@@ -1622,10 +1669,12 @@ WebSocketImpl::AsyncOpen(nsIPrincipal* aPrincipal, ErrorResult& aRv)
aRv = NS_NewURI(getter_AddRefs(uri), mURI);
MOZ_ASSERT(!aRv.Failed());
aRv = mChannel->AsyncOpen(uri, asciiOrigin, this, nullptr);
aRv = mChannel->AsyncOpen(uri, asciiOrigin, aInnerWindowID, this, nullptr);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
mInnerWindowID = aInnerWindowID;
}
//-----------------------------------------------------------------------------
@@ -1805,14 +1854,20 @@ WebSocket::CreateAndDispatchMessageEvent(JSContext* aCx,
return NS_OK;
}
uint16_t messageType = nsIWebSocketEventListener::TYPE_STRING;
// Create appropriate JS object for message
JS::Rooted<JS::Value> jsData(aCx);
if (aIsBinary) {
if (mBinaryType == dom::BinaryType::Blob) {
messageType = nsIWebSocketEventListener::TYPE_BLOB;
nsresult rv = nsContentUtils::CreateBlobBuffer(aCx, GetOwner(), aData,
&jsData);
NS_ENSURE_SUCCESS(rv, rv);
} else if (mBinaryType == dom::BinaryType::Arraybuffer) {
messageType = nsIWebSocketEventListener::TYPE_ARRAYBUFFER;
JS::Rooted<JSObject*> arrayBuf(aCx);
nsresult rv = nsContentUtils::CreateArrayBuffer(aCx, aData,
arrayBuf.address());
@@ -1832,6 +1887,10 @@ WebSocket::CreateAndDispatchMessageEvent(JSContext* aCx,
jsData.setString(jsString);
}
mImpl->mService->WebSocketMessageAvailable(mImpl->mChannel->Serial(),
mImpl->mInnerWindowID,
aData, messageType);
// create an event that uses the MessageEvent interface,
// which does not bubble, is not cancelable, and has no default action
@@ -1851,11 +1910,15 @@ WebSocket::CreateAndDispatchMessageEvent(JSContext* aCx,
nsresult
WebSocket::CreateAndDispatchCloseEvent(bool aWasClean,
uint16_t aCode,
const nsAString &aReason)
const nsAString& aReason)
{
MOZ_ASSERT(mImpl);
AssertIsOnTargetThread();
mImpl->mService->WebSocketClosed(mImpl->mChannel->Serial(),
mImpl->mInnerWindowID,
aWasClean, aCode, aReason);
nsresult rv = CheckInnerWindowCorrectness();
if (NS_FAILED(rv)) {
return NS_OK;