forked from mirrors/gecko-dev
Bug 1758155 - Make PWebSocketConnection a toplevel actor, r=necko-reviewers,jesup
Differential Revision: https://phabricator.services.mozilla.com/D185031
This commit is contained in:
parent
bda80165c9
commit
da7bf5ad67
10 changed files with 72 additions and 50 deletions
|
|
@ -65,8 +65,6 @@
|
||||||
#include "mozilla/ipc/PBackgroundTestParent.h"
|
#include "mozilla/ipc/PBackgroundTestParent.h"
|
||||||
#include "mozilla/net/BackgroundDataBridgeParent.h"
|
#include "mozilla/net/BackgroundDataBridgeParent.h"
|
||||||
#include "mozilla/net/HttpBackgroundChannelParent.h"
|
#include "mozilla/net/HttpBackgroundChannelParent.h"
|
||||||
#include "mozilla/net/HttpConnectionMgrParent.h"
|
|
||||||
#include "mozilla/net/WebSocketConnectionParent.h"
|
|
||||||
#include "nsIHttpChannelInternal.h"
|
#include "nsIHttpChannelInternal.h"
|
||||||
#include "nsIPrincipal.h"
|
#include "nsIPrincipal.h"
|
||||||
#include "nsProxyRelease.h"
|
#include "nsProxyRelease.h"
|
||||||
|
|
@ -1379,27 +1377,6 @@ already_AddRefed<dom::PFetchParent> BackgroundParentImpl::AllocPFetchParent() {
|
||||||
return MakeAndAddRef<dom::FetchParent>();
|
return MakeAndAddRef<dom::FetchParent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<mozilla::net::PWebSocketConnectionParent>
|
|
||||||
BackgroundParentImpl::AllocPWebSocketConnectionParent(
|
|
||||||
const uint32_t& aListenerId) {
|
|
||||||
Maybe<nsCOMPtr<nsIHttpUpgradeListener>> listener =
|
|
||||||
net::HttpConnectionMgrParent::GetAndRemoveHttpUpgradeListener(
|
|
||||||
aListenerId);
|
|
||||||
if (!listener) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
RefPtr<mozilla::net::WebSocketConnectionParent> actor =
|
|
||||||
new mozilla::net::WebSocketConnectionParent(*listener);
|
|
||||||
return actor.forget();
|
|
||||||
}
|
|
||||||
|
|
||||||
mozilla::ipc::IPCResult
|
|
||||||
BackgroundParentImpl::RecvPWebSocketConnectionConstructor(
|
|
||||||
PWebSocketConnectionParent* actor, const uint32_t& aListenerId) {
|
|
||||||
return IPC_OK();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace mozilla::ipc
|
} // namespace mozilla::ipc
|
||||||
|
|
||||||
void TestParent::ActorDestroy(ActorDestroyReason aWhy) {
|
void TestParent::ActorDestroy(ActorDestroyReason aWhy) {
|
||||||
|
|
|
||||||
|
|
@ -360,11 +360,6 @@ class BackgroundParentImpl : public PBackgroundParent {
|
||||||
const nsAString& aGroupName, const nsACString& aEndpointURL,
|
const nsAString& aGroupName, const nsACString& aEndpointURL,
|
||||||
const PrincipalInfo& aPrincipalInfo) override;
|
const PrincipalInfo& aPrincipalInfo) override;
|
||||||
|
|
||||||
already_AddRefed<mozilla::net::PWebSocketConnectionParent>
|
|
||||||
AllocPWebSocketConnectionParent(const uint32_t& aListenerId) override;
|
|
||||||
mozilla::ipc::IPCResult RecvPWebSocketConnectionConstructor(
|
|
||||||
PWebSocketConnectionParent* actor, const uint32_t& aListenerId) override;
|
|
||||||
|
|
||||||
already_AddRefed<PLockManagerParent> AllocPLockManagerParent(
|
already_AddRefed<PLockManagerParent> AllocPLockManagerParent(
|
||||||
NotNull<nsIPrincipal*> aPrincipal, const nsID& aClientId) final;
|
NotNull<nsIPrincipal*> aPrincipal, const nsID& aClientId) final;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ include protocol PWebAuthnTransaction;
|
||||||
include protocol PUDPSocket;
|
include protocol PUDPSocket;
|
||||||
include protocol PVsync;
|
include protocol PVsync;
|
||||||
include protocol PRemoteDecoderManager;
|
include protocol PRemoteDecoderManager;
|
||||||
include protocol PWebSocketConnection;
|
|
||||||
include protocol PWebTransport;
|
include protocol PWebTransport;
|
||||||
include protocol PFetch;
|
include protocol PFetch;
|
||||||
|
|
||||||
|
|
@ -121,7 +120,6 @@ sync protocol PBackground
|
||||||
manages PServiceWorkerManager;
|
manages PServiceWorkerManager;
|
||||||
manages PServiceWorkerRegistration;
|
manages PServiceWorkerRegistration;
|
||||||
manages PWebAuthnTransaction;
|
manages PWebAuthnTransaction;
|
||||||
manages PWebSocketConnection;
|
|
||||||
manages PUDPSocket;
|
manages PUDPSocket;
|
||||||
manages PVsync;
|
manages PVsync;
|
||||||
manages PFetch;
|
manages PFetch;
|
||||||
|
|
@ -280,8 +278,6 @@ parent:
|
||||||
async EnsureUtilityProcessAndCreateBridge(RemoteDecodeIn aLocation)
|
async EnsureUtilityProcessAndCreateBridge(RemoteDecodeIn aLocation)
|
||||||
returns (nsresult rv, Endpoint<PRemoteDecoderManagerChild> aEndpoint);
|
returns (nsresult rv, Endpoint<PRemoteDecoderManagerChild> aEndpoint);
|
||||||
|
|
||||||
async PWebSocketConnection(uint32_t aListenerId);
|
|
||||||
|
|
||||||
async PLockManager(nsIPrincipal aPrincipalInfo, nsID aClientId);
|
async PLockManager(nsIPrincipal aPrincipalInfo, nsID aClientId);
|
||||||
|
|
||||||
async PFetch();
|
async PFetch();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
include protocol PVerifySSLServerCert;
|
include protocol PVerifySSLServerCert;
|
||||||
include protocol PSelectTLSClientAuthCert;
|
include protocol PSelectTLSClientAuthCert;
|
||||||
include protocol PIPCClientCerts;
|
include protocol PIPCClientCerts;
|
||||||
|
include protocol PWebSocketConnection;
|
||||||
|
|
||||||
include PSMIPCTypes;
|
include PSMIPCTypes;
|
||||||
|
|
||||||
|
|
@ -48,6 +49,9 @@ parent:
|
||||||
uint64_t aBrowserId);
|
uint64_t aBrowserId);
|
||||||
|
|
||||||
async InitIPCClientCerts(Endpoint<PIPCClientCertsParent> aEndpoint);
|
async InitIPCClientCerts(Endpoint<PIPCClientCertsParent> aEndpoint);
|
||||||
|
|
||||||
|
async InitWebSocketConnection(Endpoint<PWebSocketConnectionParent> aEndpoint,
|
||||||
|
uint32_t aListenerId);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace net
|
} // namespace net
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,12 @@
|
||||||
#include "SocketProcessLogging.h"
|
#include "SocketProcessLogging.h"
|
||||||
|
|
||||||
#include "mozilla/ipc/Endpoint.h"
|
#include "mozilla/ipc/Endpoint.h"
|
||||||
|
#include "mozilla/net/HttpConnectionMgrParent.h"
|
||||||
|
#include "mozilla/net/WebSocketConnectionParent.h"
|
||||||
#include "mozilla/psm/IPCClientCertsParent.h"
|
#include "mozilla/psm/IPCClientCertsParent.h"
|
||||||
#include "mozilla/psm/VerifySSLServerCertParent.h"
|
#include "mozilla/psm/VerifySSLServerCertParent.h"
|
||||||
#include "mozilla/psm/SelectTLSClientAuthCertParent.h"
|
#include "mozilla/psm/SelectTLSClientAuthCertParent.h"
|
||||||
|
#include "nsIHttpChannelInternal.h"
|
||||||
|
|
||||||
namespace mozilla::net {
|
namespace mozilla::net {
|
||||||
|
|
||||||
|
|
@ -127,6 +130,38 @@ mozilla::ipc::IPCResult SocketProcessBackgroundParent::RecvInitIPCClientCerts(
|
||||||
return IPC_OK();
|
return IPC_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mozilla::ipc::IPCResult
|
||||||
|
SocketProcessBackgroundParent::RecvInitWebSocketConnection(
|
||||||
|
Endpoint<PWebSocketConnectionParent>&& aEndpoint,
|
||||||
|
const uint32_t& aListenerId) {
|
||||||
|
LOG(("SocketProcessBackgroundParent::RecvInitWebSocketConnection\n"));
|
||||||
|
if (!aEndpoint.IsValid()) {
|
||||||
|
return IPC_FAIL(this, "Invalid endpoint");
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsISerialEventTarget> transportQueue;
|
||||||
|
if (NS_FAILED(NS_CreateBackgroundTaskQueue("WebSocketConnection",
|
||||||
|
getter_AddRefs(transportQueue)))) {
|
||||||
|
return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
transportQueue->Dispatch(NS_NewRunnableFunction(
|
||||||
|
"InitWebSocketConnection",
|
||||||
|
[endpoint = std::move(aEndpoint), aListenerId]() mutable {
|
||||||
|
Maybe<nsCOMPtr<nsIHttpUpgradeListener>> listener =
|
||||||
|
net::HttpConnectionMgrParent::GetAndRemoveHttpUpgradeListener(
|
||||||
|
aListenerId);
|
||||||
|
if (!listener) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<WebSocketConnectionParent> actor =
|
||||||
|
new WebSocketConnectionParent(*listener);
|
||||||
|
endpoint.Bind(actor);
|
||||||
|
}));
|
||||||
|
return IPC_OK();
|
||||||
|
}
|
||||||
|
|
||||||
void SocketProcessBackgroundParent::ActorDestroy(ActorDestroyReason aReason) {
|
void SocketProcessBackgroundParent::ActorDestroy(ActorDestroyReason aReason) {
|
||||||
LOG(("SocketProcessBackgroundParent::ActorDestroy"));
|
LOG(("SocketProcessBackgroundParent::ActorDestroy"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,10 @@ class SocketProcessBackgroundParent final
|
||||||
const uint32_t& aProviderTlsFlags, const ByteArray& aServerCertBytes,
|
const uint32_t& aProviderTlsFlags, const ByteArray& aServerCertBytes,
|
||||||
nsTArray<ByteArray>&& aCANames, const uint64_t& aBrowserId);
|
nsTArray<ByteArray>&& aCANames, const uint64_t& aBrowserId);
|
||||||
|
|
||||||
|
mozilla::ipc::IPCResult RecvInitWebSocketConnection(
|
||||||
|
Endpoint<PWebSocketConnectionParent>&& aEndpoint,
|
||||||
|
const uint32_t& aListenerId);
|
||||||
|
|
||||||
void ActorDestroy(ActorDestroyReason aReason) override;
|
void ActorDestroy(ActorDestroyReason aReason) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@
|
||||||
|
|
||||||
include "mozilla/ipc/TransportSecurityInfoUtils.h";
|
include "mozilla/ipc/TransportSecurityInfoUtils.h";
|
||||||
|
|
||||||
include protocol PBackground;
|
|
||||||
|
|
||||||
[RefCounted] using class nsITransportSecurityInfo from "nsITransportSecurityInfo.h";
|
[RefCounted] using class nsITransportSecurityInfo from "nsITransportSecurityInfo.h";
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
@ -15,8 +13,6 @@ namespace net {
|
||||||
|
|
||||||
protocol PWebSocketConnection
|
protocol PWebSocketConnection
|
||||||
{
|
{
|
||||||
manager PBackground;
|
|
||||||
|
|
||||||
parent:
|
parent:
|
||||||
async OnTransportAvailable(nullable nsITransportSecurityInfo aSecurityInfo);
|
async OnTransportAvailable(nullable nsITransportSecurityInfo aSecurityInfo);
|
||||||
async OnError(nsresult aStatus);
|
async OnError(nsresult aStatus);
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
#include "WebSocketConnectionChild.h"
|
#include "WebSocketConnectionChild.h"
|
||||||
|
|
||||||
#include "WebSocketConnection.h"
|
#include "WebSocketConnection.h"
|
||||||
#include "mozilla/ipc/BackgroundChild.h"
|
#include "mozilla/ipc/Endpoint.h"
|
||||||
#include "mozilla/ipc/PBackgroundChild.h"
|
#include "mozilla/net/SocketProcessBackgroundChild.h"
|
||||||
#include "nsISerializable.h"
|
#include "nsISerializable.h"
|
||||||
#include "nsITLSSocketControl.h"
|
#include "nsITLSSocketControl.h"
|
||||||
#include "nsITransportSecurityInfo.h"
|
#include "nsITransportSecurityInfo.h"
|
||||||
|
|
@ -32,6 +32,8 @@ WebSocketConnectionChild::~WebSocketConnectionChild() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebSocketConnectionChild::Init(uint32_t aListenerId) {
|
void WebSocketConnectionChild::Init(uint32_t aListenerId) {
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
mSocketThread = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
|
mSocketThread = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
|
||||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||||
|
|
@ -39,17 +41,24 @@ void WebSocketConnectionChild::Init(uint32_t aListenerId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<WebSocketConnectionChild> self = this;
|
ipc::Endpoint<PWebSocketConnectionParent> parentEndpoint;
|
||||||
mSocketThread->Dispatch(NS_NewRunnableFunction(
|
ipc::Endpoint<PWebSocketConnectionChild> childEndpoint;
|
||||||
"WebSocketConnectionChild::Init", [self, aListenerId]() {
|
PWebSocketConnection::CreateEndpoints(&parentEndpoint, &childEndpoint);
|
||||||
mozilla::ipc::PBackgroundChild* actorChild = mozilla::ipc::
|
|
||||||
BackgroundChild::GetOrCreateForSocketParentBridgeForCurrentThread();
|
if (NS_FAILED(SocketProcessBackgroundChild::WithActor(
|
||||||
if (!actorChild) {
|
"SendInitWebSocketConnection",
|
||||||
|
[aListenerId, endpoint = std::move(parentEndpoint)](
|
||||||
|
SocketProcessBackgroundChild* aActor) mutable {
|
||||||
|
Unused << aActor->SendInitWebSocketConnection(std::move(endpoint),
|
||||||
|
aListenerId);
|
||||||
|
}))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Unused << actorChild->SendPWebSocketConnectionConstructor(self,
|
mSocketThread->Dispatch(NS_NewRunnableFunction(
|
||||||
aListenerId);
|
"BindWebSocketConnectionChild",
|
||||||
|
[self = RefPtr{this}, endpoint = std::move(childEndpoint)]() mutable {
|
||||||
|
endpoint.Bind(self);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,10 @@ void WebSocketConnectionParent::ActorDestroy(ActorDestroyReason aWhy) {
|
||||||
listener->OnError(NS_ERROR_FAILURE);
|
listener->OnError(NS_ERROR_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mBackgroundThread->Dispatch(NS_NewRunnableFunction(
|
||||||
|
"WebSocketConnectionParent::DefereredDestroy", [self = RefPtr{this}]() {
|
||||||
|
LOG(("WebSocketConnectionParent::DefereredDestroy"));
|
||||||
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
nsresult WebSocketConnectionParent::Init(
|
nsresult WebSocketConnectionParent::Init(
|
||||||
|
|
@ -123,7 +127,9 @@ void WebSocketConnectionParent::Close() {
|
||||||
|
|
||||||
mClosed = true;
|
mClosed = true;
|
||||||
|
|
||||||
auto task = [self = RefPtr{this}]() { Unused << self->Send__delete__(self); };
|
auto task = [self = RefPtr{this}]() {
|
||||||
|
self->PWebSocketConnectionParent::Close();
|
||||||
|
};
|
||||||
|
|
||||||
if (mBackgroundThread->IsOnCurrentThread()) {
|
if (mBackgroundThread->IsOnCurrentThread()) {
|
||||||
task();
|
task();
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ class WebSocketConnectionParent final : public PWebSocketConnectionParent,
|
||||||
|
|
||||||
nsCOMPtr<nsIHttpUpgradeListener> mUpgradeListener;
|
nsCOMPtr<nsIHttpUpgradeListener> mUpgradeListener;
|
||||||
RefPtr<WebSocketConnectionListener> mListener;
|
RefPtr<WebSocketConnectionListener> mListener;
|
||||||
nsCOMPtr<nsIEventTarget> mBackgroundThread;
|
nsCOMPtr<nsISerialEventTarget> mBackgroundThread;
|
||||||
nsCOMPtr<nsITransportSecurityInfo> mSecurityInfo;
|
nsCOMPtr<nsITransportSecurityInfo> mSecurityInfo;
|
||||||
Atomic<bool> mClosed{false};
|
Atomic<bool> mClosed{false};
|
||||||
Mutex mMutex MOZ_UNANNOTATED{"WebSocketConnectionParent::mMutex"};
|
Mutex mMutex MOZ_UNANNOTATED{"WebSocketConnectionParent::mMutex"};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue