Backed out 4 changesets (bug 1758155) for causing build bustages in NetworkConnectivityService.cpp CLOSED TREE

Backed out changeset bec8e6762e2a (bug 1758155)
Backed out changeset 230add1b5bb5 (bug 1758155)
Backed out changeset 4bc26c75c26a (bug 1758155)
Backed out changeset 7b628b437e19 (bug 1758155)
This commit is contained in:
Cristian Tuns 2023-08-16 10:32:03 -04:00
Родитель cf1b44a9fb
Коммит bc5116b463
50 изменённых файлов: 670 добавлений и 962 удалений

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

@ -13,10 +13,8 @@ class MediaTransportHandlerIPC;
class MediaTransportChild : public dom::PMediaTransportChild {
public:
#ifdef MOZ_WEBRTC
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaTransportChild, override)
explicit MediaTransportChild(MediaTransportHandlerIPC* aUser);
virtual ~MediaTransportChild();
mozilla::ipc::IPCResult RecvOnCandidate(const string& transportId,
const CandidateInfo& candidateInfo);
mozilla::ipc::IPCResult RecvOnAlpnNegotiated(const string& alpn);
@ -32,7 +30,6 @@ class MediaTransportChild : public dom::PMediaTransportChild {
const int& state);
private:
virtual ~MediaTransportChild();
RefPtr<MediaTransportHandlerIPC> mUser;
#endif // MOZ_WEBRTC
};

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

@ -13,9 +13,8 @@ namespace mozilla {
class MediaTransportParent : public dom::PMediaTransportParent {
public:
#ifdef MOZ_WEBRTC
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaTransportParent, override)
MediaTransportParent();
virtual ~MediaTransportParent();
mozilla::ipc::IPCResult RecvGetIceLog(const nsCString& pattern,
GetIceLogResolver&& aResolve);
@ -58,9 +57,9 @@ class MediaTransportParent : public dom::PMediaTransportParent {
const double& now,
GetIceStatsResolver&& aResolve);
private:
virtual ~MediaTransportParent();
void ActorDestroy(ActorDestroyReason aWhy);
private:
// Hide the sigslot/MediaTransportHandler stuff from IPC.
class Impl;
std::unique_ptr<Impl> mImpl;

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

@ -28,8 +28,13 @@ using mozilla::net::NrIceStunAddrArray from "mozilla/net/PStunAddrsParams.h";
namespace mozilla {
namespace dom {
[ManualDealloc]
async protocol PMediaTransport {
manager PBackground;
parent:
async __delete__();
#ifdef MOZ_WEBRTC
async GetIceLog(nsCString pattern) returns (WebrtcGlobalLog loglines);
async ClearIceLog();

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

@ -8,7 +8,6 @@
#include "mozilla/net/SocketProcessBridgeChild.h"
#include "mozilla/RefPtr.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "common/browser_logging/CSFLog.h"
@ -25,64 +24,40 @@ MediaTransportHandlerIPC::MediaTransportHandlerIPC(
: MediaTransportHandler(aCallbackThread) {}
void MediaTransportHandlerIPC::Initialize() {
using EndpointPromise =
MozPromise<mozilla::ipc::Endpoint<mozilla::dom::PMediaTransportChild>,
nsCString, true>;
mInitPromise =
net::SocketProcessBridgeChild::GetSocketProcessBridge()
->Then(
GetCurrentSerialEventTarget(), __func__,
[](const RefPtr<net::SocketProcessBridgeChild>& aBridge) {
mozilla::ipc::Endpoint<mozilla::dom::PMediaTransportParent>
parentEndpoint;
mozilla::ipc::Endpoint<mozilla::dom::PMediaTransportChild>
childEndpoint;
mozilla::dom::PMediaTransport::CreateEndpoints(&parentEndpoint,
&childEndpoint);
if (!aBridge || !aBridge->SendInitMediaTransport(
std::move(parentEndpoint))) {
NS_WARNING(
"MediaTransportHandlerIPC async init failed! Webrtc "
"networking "
"will not work!");
return EndpointPromise::CreateAndReject(
nsCString("SendInitMediaTransport failed!"), __func__);
}
return EndpointPromise::CreateAndResolve(
std::move(childEndpoint), __func__);
},
[](const nsCString& aError) {
return EndpointPromise::CreateAndReject(aError, __func__);
})
->Then(
mCallbackThread, __func__,
[this, self = RefPtr<MediaTransportHandlerIPC>(this)](
mozilla::ipc::Endpoint<mozilla::dom::PMediaTransportChild>&&
aEndpoint) {
RefPtr<MediaTransportChild> child =
new MediaTransportChild(this);
aEndpoint.Bind(child);
// IPC owns mChild! When it is done with it, mChild will let us
// know it is going away.
mChild = child;
CSFLogDebug(LOGTAG, "%s Init done", __func__);
return InitPromise::CreateAndResolve(true, __func__);
},
[=](const nsCString& aError) {
CSFLogError(
LOGTAG,
mInitPromise = net::SocketProcessBridgeChild::GetSocketProcessBridge()->Then(
mCallbackThread, __func__,
[this, self = RefPtr<MediaTransportHandlerIPC>(this)](
const RefPtr<net::SocketProcessBridgeChild>& aBridge) {
ipc::PBackgroundChild* actor =
ipc::BackgroundChild::GetOrCreateSocketActorForCurrentThread();
// An actor that can't send is possible if the socket process has
// crashed but hasn't been reconnected properly. See
// SocketProcessBridgeChild::ActorDestroy for more info.
if (!actor || !actor->CanSend()) {
NS_WARNING(
"MediaTransportHandlerIPC async init failed! Webrtc networking "
"will not work!");
return InitPromise::CreateAndReject(
nsCString("GetOrCreateSocketActorForCurrentThread failed!"),
__func__);
}
MediaTransportChild* child = new MediaTransportChild(this);
// PBackgroungChild owns mChild! When it is done with it,
// mChild will let us know it it going away.
mChild = actor->SendPMediaTransportConstructor(child);
CSFLogDebug(LOGTAG, "%s Init done", __func__);
return InitPromise::CreateAndResolve(true, __func__);
},
[=](const nsCString& aError) {
CSFLogError(LOGTAG,
"MediaTransportHandlerIPC async init failed! Webrtc "
"networking will not work! Error was %s",
aError.get());
NS_WARNING(
"MediaTransportHandlerIPC async init failed! Webrtc "
"networking "
"will not work!");
return InitPromise::CreateAndReject(aError, __func__);
});
NS_WARNING(
"MediaTransportHandlerIPC async init failed! Webrtc networking "
"will not work!");
return InitPromise::CreateAndReject(aError, __func__);
});
}
RefPtr<MediaTransportHandler::IceLogPromise>
@ -196,7 +171,7 @@ nsresult MediaTransportHandlerIPC::SetIceConfig(
void MediaTransportHandlerIPC::Destroy() {
if (mChild) {
mChild->Close();
MediaTransportChild::Send__delete__(mChild);
mChild = nullptr;
}
delete this;

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

@ -235,4 +235,6 @@ mozilla::ipc::IPCResult MediaTransportParent::RecvGetIceStats(
return ipc::IPCResult::Ok();
}
void MediaTransportParent::ActorDestroy(ActorDestroyReason aWhy) {}
} // namespace mozilla

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

@ -21,6 +21,13 @@ class ContentProcess;
} // namespace dom
namespace net {
class SocketProcessChild;
class SocketProcessBridgeChild;
} // namespace net
namespace ipc {
class PBackgroundChild;
@ -37,6 +44,10 @@ class PBackgroundStarterChild;
// create the actor if it doesn't exist yet. Thereafter (assuming success)
// GetForCurrentThread() will return the same actor every time.
//
// GetOrCreateSocketActorForCurrentThread, which is like
// GetOrCreateForCurrentThread, is used to get or create PBackground actor
// between child process and socket process.
//
// CloseForCurrentThread() will close the current PBackground actor. Subsequent
// calls to GetForCurrentThread will return null. CloseForCurrentThread() may
// only be called exactly once for each thread-specific actor. Currently it is
@ -45,12 +56,13 @@ class PBackgroundStarterChild;
// The PBackgroundChild actor and all its sub-protocol actors will be
// automatically destroyed when its designated thread completes.
//
// InitContentStarter must be called on the main thread
// Init{Content,Socket,SocketBridge}Starter must be called on the main thread
// with an actor bridging to the relevant target process type before these
// methods can be used.
class BackgroundChild final {
friend class mozilla::dom::ContentParent;
friend class mozilla::dom::ContentProcess;
friend class mozilla::net::SocketProcessChild;
public:
// See above.
@ -59,12 +71,25 @@ class BackgroundChild final {
// See above.
static PBackgroundChild* GetOrCreateForCurrentThread();
// See above.
static PBackgroundChild* GetOrCreateSocketActorForCurrentThread();
// See above.
static PBackgroundChild* GetOrCreateForSocketParentBridgeForCurrentThread();
// See above.
static void CloseForCurrentThread();
// See above.
static void InitContentStarter(mozilla::dom::ContentChild* aContent);
// See above.
static void InitSocketStarter(mozilla::net::SocketProcessChild* aSocket);
// See above.
static void InitSocketBridgeStarter(
mozilla::net::SocketProcessBridgeChild* aSocketBridge);
private:
// Only called by this class's friends.
static void Startup();

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

@ -21,6 +21,7 @@
#include "mozilla/dom/PBackgroundSDBConnectionChild.h"
#include "mozilla/dom/PFileSystemRequestChild.h"
#include "mozilla/dom/EndpointForReportChild.h"
#include "mozilla/dom/PMediaTransportChild.h"
#include "mozilla/dom/PVsync.h"
#include "mozilla/dom/TemporaryIPCBlobChild.h"
#include "mozilla/dom/cache/ActorUtils.h"
@ -514,6 +515,21 @@ bool BackgroundChildImpl::DeallocPEndpointForReportChild(
return true;
}
dom::PMediaTransportChild* BackgroundChildImpl::AllocPMediaTransportChild() {
// We don't allocate here: MediaTransportHandlerIPC is in charge of that,
// so we don't need to know the implementation particulars here.
MOZ_ASSERT_UNREACHABLE(
"The only thing that ought to be creating a PMediaTransportChild is "
"MediaTransportHandlerIPC!");
return nullptr;
}
bool BackgroundChildImpl::DeallocPMediaTransportChild(
dom::PMediaTransportChild* aActor) {
delete aActor;
return true;
}
} // namespace mozilla::ipc
mozilla::ipc::IPCResult TestChild::Recv__delete__(const nsACString& aTestArg) {

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

@ -198,6 +198,11 @@ class BackgroundChildImpl : public PBackgroundChild {
virtual bool DeallocPEndpointForReportChild(
PEndpointForReportChild* aActor) override;
virtual dom::PMediaTransportChild* AllocPMediaTransportChild() override;
virtual bool DeallocPMediaTransportChild(
dom::PMediaTransportChild* aActor) override;
};
class BackgroundChildImpl::ThreadLocal final {

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

@ -34,6 +34,8 @@
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/PBackgroundStarter.h"
#include "mozilla/ipc/ProtocolTypes.h"
#include "mozilla/net/SocketProcessChild.h"
#include "mozilla/net/SocketProcessBridgeChild.h"
#include "nsCOMPtr.h"
#include "nsIEventTarget.h"
#include "nsIObserver.h"
@ -79,6 +81,10 @@ class ChildImpl;
// Utility Functions
// -----------------------------------------------------------------------------
void AssertIsInMainOrSocketProcess() {
MOZ_ASSERT(XRE_IsParentProcess() || XRE_IsSocketProcess());
}
void AssertIsOnMainThread() { THREADSAFETY_ASSERT(NS_IsMainThread()); }
// -----------------------------------------------------------------------------
@ -100,7 +106,7 @@ class ParentImpl final : public BackgroundParentImpl {
TimerCallbackClosure(nsIThread* aThread,
nsTArray<IToplevelProtocol*>* aLiveActors)
: mThread(aThread), mLiveActors(aLiveActors) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnMainThread();
MOZ_ASSERT(aThread);
MOZ_ASSERT(aLiveActors);
@ -140,7 +146,7 @@ class ParentImpl final : public BackgroundParentImpl {
// create the background thread after application shutdown has started.
static bool sShutdownHasStarted;
// null if this is a same-process actor.
// null if this is a same-process or socket process actor.
const RefPtr<ThreadsafeContentParentHandle> mContent;
// Set when the actor is opened successfully and used to handle shutdown
@ -195,29 +201,31 @@ class ParentImpl final : public BackgroundParentImpl {
static void ShutdownTimerCallback(nsITimer* aTimer, void* aClosure);
// NOTE: ParentImpl could be used in 2 cases below.
// NOTE: ParentImpl could be used in 4 cases below.
// 1. Within the parent process.
// 2. Between parent process and content process.
// |aContent| should be not null for case 2. For cases 1, it's null.
// 3. Between socket process and content process.
// 4. Between parent process and socket process.
// |aContent| should be not null for case 2. For cases 1, 3 and 4, it's null.
explicit ParentImpl(ThreadsafeContentParentHandle* aContent,
bool aIsOtherProcessActor)
: mContent(aContent),
mLiveActorArray(nullptr),
mIsOtherProcessActor(aIsOtherProcessActor),
mActorDestroyed(false) {
AssertIsInMainProcess();
MOZ_ASSERT(XRE_IsParentProcess() || XRE_IsSocketProcess());
MOZ_ASSERT_IF(!aIsOtherProcessActor, XRE_IsParentProcess());
}
~ParentImpl() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnMainThread();
}
void MainThreadActorDestroy();
void SetLiveActorArray(nsTArray<IToplevelProtocol*>* aLiveActorArray) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aLiveActorArray);
MOZ_ASSERT(!aLiveActorArray->Contains(this));
@ -501,6 +509,12 @@ class ChildImpl final : public BackgroundChildImpl {
// For PBackground between parent and content process.
static ThreadInfoWrapper sParentAndContentProcessThreadInfo;
// For PBackground between socket and content process.
static ThreadInfoWrapper sSocketAndContentProcessThreadInfo;
// For PBackground between socket and parent process.
static ThreadInfoWrapper sSocketAndParentProcessThreadInfo;
// This is only modified on the main thread. It prevents us from trying to
// create the background thread after application shutdown has started.
static bool sShutdownHasStarted;
@ -569,6 +583,12 @@ class ChildImpl final : public BackgroundChildImpl {
// Forwarded from BackgroundChild.
static PBackgroundChild* GetOrCreateForCurrentThread();
// Forwarded from BackgroundChild.
static PBackgroundChild* GetOrCreateSocketActorForCurrentThread();
// Forwarded from BackgroundChild.
static PBackgroundChild* GetOrCreateForSocketParentBridgeForCurrentThread();
static void CloseForCurrentThread();
// Forwarded from BackgroundChildImpl.
@ -577,6 +597,13 @@ class ChildImpl final : public BackgroundChildImpl {
// Forwarded from BackgroundChild.
static void InitContentStarter(mozilla::dom::ContentChild* aContent);
// Forwarded from BackgroundChild.
static void InitSocketStarter(mozilla::net::SocketProcessChild* aSocket);
// Forwarded from BackgroundChild.
static void InitSocketBridgeStarter(
mozilla::net::SocketProcessBridgeChild* aSocketBridge);
static void ThreadLocalDestructor(void* aThreadLocal);
// This class is reference counted.
@ -676,6 +703,17 @@ PBackgroundChild* BackgroundChild::GetOrCreateForCurrentThread() {
return ChildImpl::GetOrCreateForCurrentThread();
}
// static
PBackgroundChild* BackgroundChild::GetOrCreateSocketActorForCurrentThread() {
return ChildImpl::GetOrCreateSocketActorForCurrentThread();
}
// static
PBackgroundChild*
BackgroundChild::GetOrCreateForSocketParentBridgeForCurrentThread() {
return ChildImpl::GetOrCreateForSocketParentBridgeForCurrentThread();
}
// static
void BackgroundChild::CloseForCurrentThread() {
ChildImpl::CloseForCurrentThread();
@ -686,6 +724,17 @@ void BackgroundChild::InitContentStarter(ContentChild* aContent) {
ChildImpl::InitContentStarter(aContent);
}
// static
void BackgroundChild::InitSocketStarter(net::SocketProcessChild* aSocket) {
ChildImpl::InitSocketStarter(aSocket);
}
// static
void BackgroundChild::InitSocketBridgeStarter(
net::SocketProcessBridgeChild* aSocketBridge) {
ChildImpl::InitSocketBridgeStarter(aSocketBridge);
}
// -----------------------------------------------------------------------------
// BackgroundChildImpl Public Methods
// -----------------------------------------------------------------------------
@ -720,6 +769,10 @@ bool ParentImpl::sShutdownHasStarted = false;
ChildImpl::ThreadInfoWrapper ChildImpl::sParentAndContentProcessThreadInfo;
ChildImpl::ThreadInfoWrapper ChildImpl::sSocketAndContentProcessThreadInfo;
ChildImpl::ThreadInfoWrapper ChildImpl::sSocketAndParentProcessThreadInfo;
bool ChildImpl::sShutdownHasStarted = false;
// -----------------------------------------------------------------------------
@ -760,7 +813,7 @@ uint64_t ParentImpl::GetChildID(PBackgroundParent* aBackgroundActor) {
bool ParentImpl::AllocStarter(ContentParent* aContent,
Endpoint<PBackgroundStarterParent>&& aEndpoint,
bool aCrossProcess) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnMainThread();
MOZ_ASSERT(aEndpoint.IsValid());
@ -794,7 +847,7 @@ bool ParentImpl::AllocStarter(ContentParent* aContent,
// static
bool ParentImpl::CreateBackgroundThread() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnMainThread();
MOZ_ASSERT(!sBackgroundThread);
MOZ_ASSERT(!sLiveActorsForBackgroundThread);
@ -861,7 +914,7 @@ bool ParentImpl::CreateBackgroundThread() {
// static
void ParentImpl::ShutdownBackgroundThread() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnMainThread();
MOZ_ASSERT(sShutdownHasStarted);
MOZ_ASSERT_IF(!sBackgroundThread, !sLiveActorCount);
@ -913,7 +966,7 @@ void ParentImpl::ShutdownBackgroundThread() {
// static
void ParentImpl::ShutdownTimerCallback(nsITimer* aTimer, void* aClosure) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnMainThread();
MOZ_ASSERT(sShutdownHasStarted);
MOZ_ASSERT(sLiveActorCount);
@ -949,7 +1002,7 @@ void ParentImpl::ShutdownTimerCallback(nsITimer* aTimer, void* aClosure) {
void ParentImpl::Destroy() {
// May be called on any thread!
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(
NewNonOwningRunnableMethod("ParentImpl::MainThreadActorDestroy", this,
@ -957,7 +1010,7 @@ void ParentImpl::Destroy() {
}
void ParentImpl::MainThreadActorDestroy() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnMainThread();
MOZ_ASSERT_IF(!mIsOtherProcessActor, !mContent);
@ -969,7 +1022,7 @@ void ParentImpl::MainThreadActorDestroy() {
}
void ParentImpl::ActorDestroy(ActorDestroyReason aWhy) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(!mActorDestroyed);
MOZ_ASSERT_IF(mIsOtherProcessActor, mLiveActorArray);
@ -1000,7 +1053,7 @@ NS_IMPL_ISUPPORTS(ParentImpl::ShutdownObserver, nsIObserver)
NS_IMETHODIMP
ParentImpl::ShutdownObserver::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnMainThread();
MOZ_ASSERT(!sShutdownHasStarted);
MOZ_ASSERT(!strcmp(aTopic, NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID));
@ -1020,14 +1073,14 @@ BackgroundStarterParent::BackgroundStarterParent(
ThreadsafeContentParentHandle* aContent, bool aCrossProcess)
: mCrossProcess(aCrossProcess), mContent(aContent) {
AssertIsOnMainThread();
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
MOZ_ASSERT_IF(!mCrossProcess, !mContent);
MOZ_ASSERT_IF(!mCrossProcess, XRE_IsParentProcess());
}
void BackgroundStarterParent::SetLiveActorArray(
nsTArray<IToplevelProtocol*>* aLiveActorArray) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aLiveActorArray);
MOZ_ASSERT(!aLiveActorArray->Contains(this));
@ -1090,6 +1143,8 @@ void ChildImpl::Startup() {
// assert that we're being called on the main thread here.
sParentAndContentProcessThreadInfo.Startup();
sSocketAndContentProcessThreadInfo.Startup();
sSocketAndParentProcessThreadInfo.Startup();
nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
MOZ_RELEASE_ASSERT(observerService);
@ -1119,6 +1174,8 @@ void ChildImpl::Shutdown() {
AssertIsOnMainThread();
sParentAndContentProcessThreadInfo.Shutdown();
sSocketAndContentProcessThreadInfo.Shutdown();
sSocketAndParentProcessThreadInfo.Shutdown();
sShutdownHasStarted = true;
}
@ -1146,6 +1203,17 @@ PBackgroundChild* ChildImpl::GetOrCreateForCurrentThread() {
return sParentAndContentProcessThreadInfo.GetOrCreateForCurrentThread();
}
/* static */
PBackgroundChild* ChildImpl::GetOrCreateSocketActorForCurrentThread() {
return sSocketAndContentProcessThreadInfo.GetOrCreateForCurrentThread();
}
/* static */
PBackgroundChild*
ChildImpl::GetOrCreateForSocketParentBridgeForCurrentThread() {
return sSocketAndParentProcessThreadInfo.GetOrCreateForCurrentThread();
}
// static
void ChildImpl::CloseForCurrentThread() {
MOZ_ASSERT(!NS_IsMainThread(),
@ -1153,6 +1221,8 @@ void ChildImpl::CloseForCurrentThread() {
"ChildImpl::Shutdown().");
sParentAndContentProcessThreadInfo.CloseForCurrentThread();
sSocketAndContentProcessThreadInfo.CloseForCurrentThread();
sSocketAndParentProcessThreadInfo.CloseForCurrentThread();
}
// static
@ -1184,6 +1254,17 @@ void ChildImpl::InitContentStarter(mozilla::dom::ContentChild* aContent) {
sParentAndContentProcessThreadInfo.InitStarter(aContent);
}
// static
void ChildImpl::InitSocketStarter(mozilla::net::SocketProcessChild* aSocket) {
sSocketAndParentProcessThreadInfo.InitStarter(aSocket);
}
// static
void ChildImpl::InitSocketBridgeStarter(
mozilla::net::SocketProcessBridgeChild* aSocketBridge) {
sSocketAndContentProcessThreadInfo.InitStarter(aSocketBridge);
}
// static
void ChildImpl::ThreadLocalDestructor(void* aThreadLocal) {
auto threadLocalInfo = static_cast<ThreadLocalInfo*>(aThreadLocal);

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

@ -103,6 +103,10 @@ inline void AssertIsOnBackgroundThread() {}
inline void AssertIsInMainProcess() { MOZ_ASSERT(XRE_IsParentProcess()); }
inline void AssertIsInMainOrSocketProcess() {
MOZ_ASSERT(XRE_IsParentProcess() || XRE_IsSocketProcess());
}
} // namespace ipc
} // namespace mozilla

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

@ -29,6 +29,7 @@
#include "mozilla/dom/MIDIManagerParent.h"
#include "mozilla/dom/MIDIPlatformService.h"
#include "mozilla/dom/MIDIPortParent.h"
#include "mozilla/dom/MediaTransportParent.h"
#include "mozilla/dom/MessagePortParent.h"
#include "mozilla/dom/PGamepadEventChannelParent.h"
#include "mozilla/dom/PGamepadTestChannelParent.h"
@ -65,6 +66,11 @@
#include "mozilla/ipc/PBackgroundTestParent.h"
#include "mozilla/net/BackgroundDataBridgeParent.h"
#include "mozilla/net/HttpBackgroundChannelParent.h"
#include "mozilla/net/HttpConnectionMgrParent.h"
#include "mozilla/net/WebSocketConnectionParent.h"
#include "mozilla/psm/IPCClientCertsParent.h"
#include "mozilla/psm/SelectTLSClientAuthCertParent.h"
#include "mozilla/psm/VerifySSLServerCertParent.h"
#include "nsIHttpChannelInternal.h"
#include "nsIPrincipal.h"
#include "nsProxyRelease.h"
@ -114,26 +120,37 @@ using mozilla::dom::ContentParent;
using mozilla::dom::ThreadsafeContentParentHandle;
BackgroundParentImpl::BackgroundParentImpl() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
MOZ_COUNT_CTOR(mozilla::ipc::BackgroundParentImpl);
}
BackgroundParentImpl::~BackgroundParentImpl() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnMainThread();
MOZ_COUNT_DTOR(mozilla::ipc::BackgroundParentImpl);
}
void BackgroundParentImpl::ActorDestroy(ActorDestroyReason aWhy) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
}
already_AddRefed<net::PBackgroundDataBridgeParent>
BackgroundParentImpl::AllocPBackgroundDataBridgeParent(
const uint64_t& aChannelID) {
MOZ_ASSERT(XRE_IsSocketProcess(), "Should be in socket process");
AssertIsOnBackgroundThread();
RefPtr<net::BackgroundDataBridgeParent> actor =
new net::BackgroundDataBridgeParent(aChannelID);
return actor.forget();
}
BackgroundParentImpl::PBackgroundTestParent*
BackgroundParentImpl::AllocPBackgroundTestParent(const nsACString& aTestArg) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return new TestParent();
@ -141,7 +158,7 @@ BackgroundParentImpl::AllocPBackgroundTestParent(const nsACString& aTestArg) {
mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBackgroundTestConstructor(
PBackgroundTestParent* aActor, const nsACString& aTestArg) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -153,7 +170,7 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBackgroundTestConstructor(
bool BackgroundParentImpl::DeallocPBackgroundTestParent(
PBackgroundTestParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -166,7 +183,7 @@ auto BackgroundParentImpl::AllocPBackgroundIDBFactoryParent(
-> already_AddRefed<PBackgroundIDBFactoryParent> {
using mozilla::dom::indexedDB::AllocPBackgroundIDBFactoryParent;
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return AllocPBackgroundIDBFactoryParent(aLoggingInfo);
@ -177,7 +194,7 @@ BackgroundParentImpl::RecvPBackgroundIDBFactoryConstructor(
PBackgroundIDBFactoryParent* aActor, const LoggingInfo& aLoggingInfo) {
using mozilla::dom::indexedDB::RecvPBackgroundIDBFactoryConstructor;
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -189,7 +206,7 @@ BackgroundParentImpl::RecvPBackgroundIDBFactoryConstructor(
auto BackgroundParentImpl::AllocPBackgroundIndexedDBUtilsParent()
-> PBackgroundIndexedDBUtilsParent* {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return mozilla::dom::indexedDB::AllocPBackgroundIndexedDBUtilsParent();
@ -197,7 +214,7 @@ auto BackgroundParentImpl::AllocPBackgroundIndexedDBUtilsParent()
bool BackgroundParentImpl::DeallocPBackgroundIndexedDBUtilsParent(
PBackgroundIndexedDBUtilsParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -206,7 +223,7 @@ bool BackgroundParentImpl::DeallocPBackgroundIndexedDBUtilsParent(
}
mozilla::ipc::IPCResult BackgroundParentImpl::RecvFlushPendingFileDeletions() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
if (!mozilla::dom::indexedDB::RecvFlushPendingFileDeletions()) {
@ -219,7 +236,7 @@ BackgroundParentImpl::PBackgroundSDBConnectionParent*
BackgroundParentImpl::AllocPBackgroundSDBConnectionParent(
const PersistenceType& aPersistenceType,
const PrincipalInfo& aPrincipalInfo) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return mozilla::dom::AllocPBackgroundSDBConnectionParent(aPersistenceType,
@ -231,7 +248,7 @@ BackgroundParentImpl::RecvPBackgroundSDBConnectionConstructor(
PBackgroundSDBConnectionParent* aActor,
const PersistenceType& aPersistenceType,
const PrincipalInfo& aPrincipalInfo) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -244,7 +261,7 @@ BackgroundParentImpl::RecvPBackgroundSDBConnectionConstructor(
bool BackgroundParentImpl::DeallocPBackgroundSDBConnectionParent(
PBackgroundSDBConnectionParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -255,7 +272,7 @@ BackgroundParentImpl::PBackgroundLSDatabaseParent*
BackgroundParentImpl::AllocPBackgroundLSDatabaseParent(
const PrincipalInfo& aPrincipalInfo, const uint32_t& aPrivateBrowsingId,
const uint64_t& aDatastoreId) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return mozilla::dom::AllocPBackgroundLSDatabaseParent(
@ -266,7 +283,7 @@ mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPBackgroundLSDatabaseConstructor(
PBackgroundLSDatabaseParent* aActor, const PrincipalInfo& aPrincipalInfo,
const uint32_t& aPrivateBrowsingId, const uint64_t& aDatastoreId) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -279,7 +296,7 @@ BackgroundParentImpl::RecvPBackgroundLSDatabaseConstructor(
bool BackgroundParentImpl::DeallocPBackgroundLSDatabaseParent(
PBackgroundLSDatabaseParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -289,7 +306,7 @@ bool BackgroundParentImpl::DeallocPBackgroundLSDatabaseParent(
BackgroundParentImpl::PBackgroundLSObserverParent*
BackgroundParentImpl::AllocPBackgroundLSObserverParent(
const uint64_t& aObserverId) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return mozilla::dom::AllocPBackgroundLSObserverParent(aObserverId);
@ -298,7 +315,7 @@ BackgroundParentImpl::AllocPBackgroundLSObserverParent(
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPBackgroundLSObserverConstructor(
PBackgroundLSObserverParent* aActor, const uint64_t& aObserverId) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -311,7 +328,7 @@ BackgroundParentImpl::RecvPBackgroundLSObserverConstructor(
bool BackgroundParentImpl::DeallocPBackgroundLSObserverParent(
PBackgroundLSObserverParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -321,7 +338,7 @@ bool BackgroundParentImpl::DeallocPBackgroundLSObserverParent(
BackgroundParentImpl::PBackgroundLSRequestParent*
BackgroundParentImpl::AllocPBackgroundLSRequestParent(
const LSRequestParams& aParams) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return mozilla::dom::AllocPBackgroundLSRequestParent(this, aParams);
@ -330,7 +347,7 @@ BackgroundParentImpl::AllocPBackgroundLSRequestParent(
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPBackgroundLSRequestConstructor(
PBackgroundLSRequestParent* aActor, const LSRequestParams& aParams) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -342,7 +359,7 @@ BackgroundParentImpl::RecvPBackgroundLSRequestConstructor(
bool BackgroundParentImpl::DeallocPBackgroundLSRequestParent(
PBackgroundLSRequestParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -352,7 +369,7 @@ bool BackgroundParentImpl::DeallocPBackgroundLSRequestParent(
BackgroundParentImpl::PBackgroundLSSimpleRequestParent*
BackgroundParentImpl::AllocPBackgroundLSSimpleRequestParent(
const LSSimpleRequestParams& aParams) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return mozilla::dom::AllocPBackgroundLSSimpleRequestParent(this, aParams);
@ -362,7 +379,7 @@ mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPBackgroundLSSimpleRequestConstructor(
PBackgroundLSSimpleRequestParent* aActor,
const LSSimpleRequestParams& aParams) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -375,7 +392,7 @@ BackgroundParentImpl::RecvPBackgroundLSSimpleRequestConstructor(
bool BackgroundParentImpl::DeallocPBackgroundLSSimpleRequestParent(
PBackgroundLSSimpleRequestParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -386,7 +403,7 @@ BackgroundParentImpl::PBackgroundLocalStorageCacheParent*
BackgroundParentImpl::AllocPBackgroundLocalStorageCacheParent(
const PrincipalInfo& aPrincipalInfo, const nsACString& aOriginKey,
const uint32_t& aPrivateBrowsingId) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return mozilla::dom::AllocPBackgroundLocalStorageCacheParent(
@ -398,7 +415,7 @@ BackgroundParentImpl::RecvPBackgroundLocalStorageCacheConstructor(
PBackgroundLocalStorageCacheParent* aActor,
const PrincipalInfo& aPrincipalInfo, const nsACString& aOriginKey,
const uint32_t& aPrivateBrowsingId) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -408,7 +425,7 @@ BackgroundParentImpl::RecvPBackgroundLocalStorageCacheConstructor(
bool BackgroundParentImpl::DeallocPBackgroundLocalStorageCacheParent(
PBackgroundLocalStorageCacheParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -418,7 +435,7 @@ bool BackgroundParentImpl::DeallocPBackgroundLocalStorageCacheParent(
auto BackgroundParentImpl::AllocPBackgroundStorageParent(
const nsAString& aProfilePath, const uint32_t& aPrivateBrowsingId)
-> PBackgroundStorageParent* {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return mozilla::dom::AllocPBackgroundStorageParent(aProfilePath,
@ -428,7 +445,7 @@ auto BackgroundParentImpl::AllocPBackgroundStorageParent(
mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBackgroundStorageConstructor(
PBackgroundStorageParent* aActor, const nsAString& aProfilePath,
const uint32_t& aPrivateBrowsingId) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -438,7 +455,7 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBackgroundStorageConstructor(
bool BackgroundParentImpl::DeallocPBackgroundStorageParent(
PBackgroundStorageParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -448,7 +465,7 @@ bool BackgroundParentImpl::DeallocPBackgroundStorageParent(
already_AddRefed<BackgroundParentImpl::PBackgroundSessionStorageManagerParent>
BackgroundParentImpl::AllocPBackgroundSessionStorageManagerParent(
const uint64_t& aTopContextId) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return dom::AllocPBackgroundSessionStorageManagerParent(aTopContextId);
@ -456,7 +473,7 @@ BackgroundParentImpl::AllocPBackgroundSessionStorageManagerParent(
already_AddRefed<mozilla::dom::PBackgroundSessionStorageServiceParent>
BackgroundParentImpl::AllocPBackgroundSessionStorageServiceParent() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return MakeAndAddRef<mozilla::dom::BackgroundSessionStorageServiceParent>();
@ -635,7 +652,7 @@ bool BackgroundParentImpl::DeallocPTemporaryIPCBlobParent(
already_AddRefed<BackgroundParentImpl::PVsyncParent>
BackgroundParentImpl::AllocPVsyncParent() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
RefPtr<mozilla::dom::VsyncParent> actor = new mozilla::dom::VsyncParent();
@ -647,7 +664,7 @@ BackgroundParentImpl::AllocPVsyncParent() {
}
camera::PCamerasParent* BackgroundParentImpl::AllocPCamerasParent() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
#ifdef MOZ_WEBRTC
@ -662,7 +679,7 @@ camera::PCamerasParent* BackgroundParentImpl::AllocPCamerasParent() {
#ifdef MOZ_WEBRTC
mozilla::ipc::IPCResult BackgroundParentImpl::RecvPCamerasConstructor(
camera::PCamerasParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
return static_cast<camera::CamerasParent*>(aActor)->RecvPCamerasConstructor();
@ -671,7 +688,7 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvPCamerasConstructor(
bool BackgroundParentImpl::DeallocPCamerasParent(
camera::PCamerasParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -693,7 +710,7 @@ auto BackgroundParentImpl::AllocPUDPSocketParent(
mozilla::ipc::IPCResult BackgroundParentImpl::RecvPUDPSocketConstructor(
PUDPSocketParent* aActor, const Maybe<PrincipalInfo>& aOptionalPrincipal,
const nsACString& aFilter) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
if (aOptionalPrincipal.isSome()) {
@ -726,11 +743,71 @@ bool BackgroundParentImpl::DeallocPUDPSocketParent(PUDPSocketParent* actor) {
return true;
}
already_AddRefed<mozilla::psm::PVerifySSLServerCertParent>
BackgroundParentImpl::AllocPVerifySSLServerCertParent(
const nsTArray<ByteArray>& aPeerCertChain, const nsACString& aHostName,
const int32_t& aPort, const OriginAttributes& aOriginAttributes,
const Maybe<ByteArray>& aStapledOCSPResponse,
const Maybe<ByteArray>& aSctsFromTLSExtension,
const Maybe<DelegatedCredentialInfoArg>& aDcInfo,
const uint32_t& aProviderFlags, const uint32_t& aCertVerifierFlags) {
RefPtr<mozilla::psm::VerifySSLServerCertParent> parent =
new mozilla::psm::VerifySSLServerCertParent();
return parent.forget();
}
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPVerifySSLServerCertConstructor(
PVerifySSLServerCertParent* aActor, nsTArray<ByteArray>&& aPeerCertChain,
const nsACString& aHostName, const int32_t& aPort,
const OriginAttributes& aOriginAttributes,
const Maybe<ByteArray>& aStapledOCSPResponse,
const Maybe<ByteArray>& aSctsFromTLSExtension,
const Maybe<DelegatedCredentialInfoArg>& aDcInfo,
const uint32_t& aProviderFlags, const uint32_t& aCertVerifierFlags) {
mozilla::psm::VerifySSLServerCertParent* authCert =
static_cast<mozilla::psm::VerifySSLServerCertParent*>(aActor);
if (!authCert->Dispatch(std::move(aPeerCertChain), aHostName, aPort,
aOriginAttributes, aStapledOCSPResponse,
aSctsFromTLSExtension, aDcInfo, aProviderFlags,
aCertVerifierFlags)) {
return IPC_FAIL_NO_REASON(this);
}
return IPC_OK();
}
already_AddRefed<mozilla::psm::PSelectTLSClientAuthCertParent>
BackgroundParentImpl::AllocPSelectTLSClientAuthCertParent(
const nsACString& aHostName, const OriginAttributes& aOriginAttributes,
const int32_t& aPort, const uint32_t& aProviderFlags,
const uint32_t& aProviderTlsFlags, const ByteArray& aServerCertBytes,
const nsTArray<ByteArray>& aCANames) {
RefPtr<mozilla::psm::SelectTLSClientAuthCertParent> parent =
new mozilla::psm::SelectTLSClientAuthCertParent();
return parent.forget();
}
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPSelectTLSClientAuthCertConstructor(
PSelectTLSClientAuthCertParent* actor, const nsACString& aHostName,
const OriginAttributes& aOriginAttributes, const int32_t& aPort,
const uint32_t& aProviderFlags, const uint32_t& aProviderTlsFlags,
const ByteArray& aServerCertBytes, nsTArray<ByteArray>&& aCANames) {
mozilla::psm::SelectTLSClientAuthCertParent* selectTLSClientAuthCertParent =
static_cast<mozilla::psm::SelectTLSClientAuthCertParent*>(actor);
if (!selectTLSClientAuthCertParent->Dispatch(
aHostName, aOriginAttributes, aPort, aProviderFlags,
aProviderTlsFlags, aServerCertBytes, std::move(aCANames))) {
return IPC_FAIL_NO_REASON(this);
}
return IPC_OK();
}
mozilla::dom::PBroadcastChannelParent*
BackgroundParentImpl::AllocPBroadcastChannelParent(
const PrincipalInfo& aPrincipalInfo, const nsACString& aOrigin,
const nsAString& aChannel) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
nsString originChannelKey;
@ -758,7 +835,7 @@ class CheckPrincipalRunnable final : public Runnable {
mContentParent(aParent),
mPrincipalInfo(aPrincipalInfo),
mOrigin(aOrigin) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(mContentParent);
@ -805,7 +882,7 @@ class CheckPrincipalRunnable final : public Runnable {
mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBroadcastChannelConstructor(
PBroadcastChannelParent* actor, const PrincipalInfo& aPrincipalInfo,
const nsACString& aOrigin, const nsAString& aChannel) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
RefPtr<ThreadsafeContentParentHandle> parent =
@ -825,7 +902,7 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBroadcastChannelConstructor(
bool BackgroundParentImpl::DeallocPBroadcastChannelParent(
PBroadcastChannelParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -835,7 +912,7 @@ bool BackgroundParentImpl::DeallocPBroadcastChannelParent(
mozilla::dom::PServiceWorkerManagerParent*
BackgroundParentImpl::AllocPServiceWorkerManagerParent() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
RefPtr<dom::ServiceWorkerManagerParent> agent =
@ -845,7 +922,7 @@ BackgroundParentImpl::AllocPServiceWorkerManagerParent() {
bool BackgroundParentImpl::DeallocPServiceWorkerManagerParent(
PServiceWorkerManagerParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -857,7 +934,7 @@ bool BackgroundParentImpl::DeallocPServiceWorkerManagerParent(
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvShutdownServiceWorkerRegistrar() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
if (BackgroundParent::IsOtherProcessActor(this)) {
@ -881,7 +958,7 @@ BackgroundParentImpl::AllocPCacheStorageParent(
PMessagePortParent* BackgroundParentImpl::AllocPMessagePortParent(
const nsID& aUUID, const nsID& aDestinationUUID,
const uint32_t& aSequenceID) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return new MessagePortParent(aUUID);
@ -890,7 +967,7 @@ PMessagePortParent* BackgroundParentImpl::AllocPMessagePortParent(
mozilla::ipc::IPCResult BackgroundParentImpl::RecvPMessagePortConstructor(
PMessagePortParent* aActor, const nsID& aUUID, const nsID& aDestinationUUID,
const uint32_t& aSequenceID) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MessagePortParent* mp = static_cast<MessagePortParent*>(aActor);
@ -900,9 +977,24 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvPMessagePortConstructor(
return IPC_OK();
}
already_AddRefed<psm::PIPCClientCertsParent>
BackgroundParentImpl::AllocPIPCClientCertsParent() {
// This should only be called in the parent process with the socket process
// as the child process, not any content processes, hence the check that the
// child ID be 0.
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(mozilla::ipc::BackgroundParent::GetChildID(this) == 0);
if (!XRE_IsParentProcess() ||
mozilla::ipc::BackgroundParent::GetChildID(this) != 0) {
return nullptr;
}
RefPtr<psm::IPCClientCertsParent> result = new psm::IPCClientCertsParent();
return result.forget();
}
bool BackgroundParentImpl::DeallocPMessagePortParent(
PMessagePortParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -913,7 +1005,7 @@ bool BackgroundParentImpl::DeallocPMessagePortParent(
mozilla::ipc::IPCResult BackgroundParentImpl::RecvMessagePortForceClose(
const nsID& aUUID, const nsID& aDestinationUUID,
const uint32_t& aSequenceID) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
if (!MessagePortParent::ForceClose(aUUID, aDestinationUUID, aSequenceID)) {
@ -924,14 +1016,14 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvMessagePortForceClose(
}
BackgroundParentImpl::PQuotaParent* BackgroundParentImpl::AllocPQuotaParent() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
return mozilla::dom::quota::AllocPQuotaParent();
}
bool BackgroundParentImpl::DeallocPQuotaParent(PQuotaParent* aActor) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
@ -939,7 +1031,7 @@ bool BackgroundParentImpl::DeallocPQuotaParent(PQuotaParent* aActor) {
}
mozilla::ipc::IPCResult BackgroundParentImpl::RecvShutdownQuotaManager() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
if (BackgroundParent::IsOtherProcessActor(this)) {
@ -954,7 +1046,7 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvShutdownQuotaManager() {
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvShutdownBackgroundSessionStorageManagers() {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
if (BackgroundParent::IsOtherProcessActor(this)) {
@ -970,7 +1062,7 @@ BackgroundParentImpl::RecvShutdownBackgroundSessionStorageManagers() {
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPropagateBackgroundSessionStorageManager(
const uint64_t& aCurrentTopContextId, const uint64_t& aTargetTopContextId) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
if (BackgroundParent::IsOtherProcessActor(this)) {
@ -986,7 +1078,7 @@ BackgroundParentImpl::RecvPropagateBackgroundSessionStorageManager(
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvRemoveBackgroundSessionStorageManager(
const uint64_t& aTopContextId) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
if (BackgroundParent::IsOtherProcessActor(this)) {
@ -1040,7 +1132,7 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvLoadSessionStorageManagerData(
already_AddRefed<dom::PFileSystemRequestParent>
BackgroundParentImpl::AllocPFileSystemRequestParent(
const FileSystemParams& aParams) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
RefPtr<FileSystemRequestParent> result = new FileSystemRequestParent();
@ -1084,7 +1176,7 @@ bool BackgroundParentImpl::DeallocPWebAuthnTransactionParent(
already_AddRefed<net::PHttpBackgroundChannelParent>
BackgroundParentImpl::AllocPHttpBackgroundChannelParent(
const uint64_t& aChannelId) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
RefPtr<net::HttpBackgroundChannelParent> actor =
@ -1096,7 +1188,7 @@ mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPHttpBackgroundChannelConstructor(
net::PHttpBackgroundChannelParent* aActor, const uint64_t& aChannelId) {
MOZ_ASSERT(aActor);
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
net::HttpBackgroundChannelParent* aParent =
@ -1112,7 +1204,7 @@ BackgroundParentImpl::RecvPHttpBackgroundChannelConstructor(
mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateMIDIPort(
Endpoint<PMIDIPortParent>&& aEndpoint, const MIDIPortInfo& aPortInfo,
const bool& aSysexEnabled) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
if (!aEndpoint.IsValid()) {
@ -1131,7 +1223,7 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateMIDIPort(
mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateMIDIManager(
Endpoint<PMIDIManagerParent>&& aEndpoint) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
if (!aEndpoint.IsValid()) {
@ -1151,7 +1243,7 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateMIDIManager(
mozilla::ipc::IPCResult BackgroundParentImpl::RecvHasMIDIDevice(
HasMIDIDeviceResolver&& aResolver) {
AssertIsInMainProcess();
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
InvokeAsync(MIDIPlatformService::OwnerThread(), __func__,
@ -1366,6 +1458,22 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvRemoveEndpoint(
return IPC_OK();
}
dom::PMediaTransportParent* BackgroundParentImpl::AllocPMediaTransportParent() {
#ifdef MOZ_WEBRTC
return new MediaTransportParent;
#else
return nullptr;
#endif
}
bool BackgroundParentImpl::DeallocPMediaTransportParent(
dom::PMediaTransportParent* aActor) {
#ifdef MOZ_WEBRTC
delete aActor;
#endif
return true;
}
already_AddRefed<dom::locks::PLockManagerParent>
BackgroundParentImpl::AllocPLockManagerParent(NotNull<nsIPrincipal*> aPrincipal,
const nsID& aClientId) {
@ -1377,9 +1485,30 @@ already_AddRefed<dom::PFetchParent> BackgroundParentImpl::AllocPFetchParent() {
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
void TestParent::ActorDestroy(ActorDestroyReason aWhy) {
mozilla::ipc::AssertIsInMainProcess();
mozilla::ipc::AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
}

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

@ -31,6 +31,9 @@ class BackgroundParentImpl : public PBackgroundParent {
already_AddRefed<PBackgroundIDBFactoryParent>
AllocPBackgroundIDBFactoryParent(const LoggingInfo& aLoggingInfo) override;
already_AddRefed<net::PBackgroundDataBridgeParent>
AllocPBackgroundDataBridgeParent(const uint64_t& aChannelID) override;
mozilla::ipc::IPCResult RecvPBackgroundIDBFactoryConstructor(
PBackgroundIDBFactoryParent* aActor,
const LoggingInfo& aLoggingInfo) override;
@ -192,6 +195,39 @@ class BackgroundParentImpl : public PBackgroundParent {
already_AddRefed<PVsyncParent> AllocPVsyncParent() override;
already_AddRefed<mozilla::psm::PVerifySSLServerCertParent>
AllocPVerifySSLServerCertParent(
const nsTArray<ByteArray>& aPeerCertChain, const nsACString& aHostName,
const int32_t& aPort, const OriginAttributes& aOriginAttributes,
const Maybe<ByteArray>& aStapledOCSPResponse,
const Maybe<ByteArray>& aSctsFromTLSExtension,
const Maybe<DelegatedCredentialInfoArg>& aDcInfo,
const uint32_t& aProviderFlags,
const uint32_t& aCertVerifierFlags) override;
mozilla::ipc::IPCResult RecvPVerifySSLServerCertConstructor(
PVerifySSLServerCertParent* aActor, nsTArray<ByteArray>&& aPeerCertChain,
const nsACString& aHostName, const int32_t& aPort,
const OriginAttributes& aOriginAttributes,
const Maybe<ByteArray>& aStapledOCSPResponse,
const Maybe<ByteArray>& aSctsFromTLSExtension,
const Maybe<DelegatedCredentialInfoArg>& aDcInfo,
const uint32_t& aProviderFlags,
const uint32_t& aCertVerifierFlags) override;
virtual already_AddRefed<mozilla::psm::PSelectTLSClientAuthCertParent>
AllocPSelectTLSClientAuthCertParent(
const nsACString& aHostName, const OriginAttributes& aOriginAttributes,
const int32_t& aPort, const uint32_t& aProviderFlags,
const uint32_t& aProviderTlsFlags, const ByteArray& aServerCertBytes,
const nsTArray<ByteArray>& aCANames) override;
virtual mozilla::ipc::IPCResult RecvPSelectTLSClientAuthCertConstructor(
PSelectTLSClientAuthCertParent* actor, const nsACString& aHostName,
const OriginAttributes& aOriginAttributes, const int32_t& aPort,
const uint32_t& aProviderFlags, const uint32_t& aProviderTlsFlags,
const ByteArray& aServerCertBytes,
nsTArray<ByteArray>&& aCANames) override;
PBroadcastChannelParent* AllocPBroadcastChannelParent(
const PrincipalInfo& aPrincipalInfo, const nsACString& aOrigin,
const nsAString& aChannel) override;
@ -235,6 +271,8 @@ class BackgroundParentImpl : public PBackgroundParent {
PMessagePortParent* aActor, const nsID& aUUID,
const nsID& aDestinationUUID, const uint32_t& aSequenceID) override;
already_AddRefed<PIPCClientCertsParent> AllocPIPCClientCertsParent() override;
bool DeallocPMessagePortParent(PMessagePortParent* aActor) override;
mozilla::ipc::IPCResult RecvMessagePortForceClose(
@ -360,6 +398,15 @@ class BackgroundParentImpl : public PBackgroundParent {
const nsAString& aGroupName, const nsACString& aEndpointURL,
const PrincipalInfo& aPrincipalInfo) override;
dom::PMediaTransportParent* AllocPMediaTransportParent() override;
bool DeallocPMediaTransportParent(
dom::PMediaTransportParent* aActor) 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(
NotNull<nsIPrincipal*> aPrincipal, const nsID& aClientId) final;

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

@ -26,6 +26,7 @@ include protocol PFileSystemRequest;
include protocol PGamepadEventChannel;
include protocol PGamepadTestChannel;
include protocol PHttpBackgroundChannel;
include protocol PIPCClientCerts;
include protocol PIdleScheduler;
include protocol PMediaTransport;
include protocol PRemoteWorker;
@ -40,14 +41,17 @@ include protocol PLockManager;
include protocol PMIDIManager;
include protocol PMIDIPort;
include protocol PQuota;
include protocol PSelectTLSClientAuthCert;
include protocol PServiceWorker;
include protocol PServiceWorkerContainer;
include protocol PServiceWorkerManager;
include protocol PServiceWorkerRegistration;
include protocol PWebAuthnTransaction;
include protocol PUDPSocket;
include protocol PVerifySSLServerCert;
include protocol PVsync;
include protocol PRemoteDecoderManager;
include protocol PWebSocketConnection;
include protocol PWebTransport;
include protocol PFetch;
@ -61,6 +65,7 @@ include PBackgroundSharedTypes;
include PBackgroundIDBSharedTypes;
include PFileSystemParams;
include ProtocolTypes;
include PSMIPCTypes;
include RemoteWorkerTypes;
include MIDITypes;
@ -82,6 +87,7 @@ namespace ipc {
[NeedsOtherPid, ChildImpl=virtual, ParentImpl=virtual]
sync protocol PBackground
{
manages PBackgroundDataBridge;
manages PBackgroundIDBFactory;
manages PBackgroundIndexedDBUtils;
manages PBackgroundSDBConnection;
@ -104,8 +110,10 @@ sync protocol PBackground
manages PGamepadEventChannel;
manages PGamepadTestChannel;
manages PHttpBackgroundChannel;
manages PIPCClientCerts;
manages PIdleScheduler;
manages PLockManager;
manages PMediaTransport;
manages PRemoteWorker;
manages PRemoteWorkerController;
manages PRemoteWorkerService;
@ -115,12 +123,15 @@ sync protocol PBackground
manages PMessagePort;
manages PCameras;
manages PQuota;
manages PSelectTLSClientAuthCert;
manages PServiceWorker;
manages PServiceWorkerContainer;
manages PServiceWorkerManager;
manages PServiceWorkerRegistration;
manages PWebAuthnTransaction;
manages PWebSocketConnection;
manages PUDPSocket;
manages PVerifySSLServerCert;
manages PVsync;
manages PFetch;
@ -128,6 +139,8 @@ parent:
// Only called at startup during mochitests to check the basic infrastructure.
async PBackgroundTest(nsCString testArg);
async PBackgroundDataBridge(uint64_t channelID);
async PBackgroundIDBFactory(LoggingInfo loggingInfo);
async PBackgroundIndexedDBUtils();
@ -272,14 +285,38 @@ parent:
async PIdleScheduler();
async PMediaTransport();
async PSelectTLSClientAuthCert(nsCString aHostName,
OriginAttributes aOriginAttributes,
int32_t aPort,
uint32_t aProviderFlags,
uint32_t aProviderTlsFlags,
ByteArray aServerCertBytes,
ByteArray[] aCANames);
async PVerifySSLServerCert(ByteArray[] aPeerCertChain,
nsCString aHostName,
int32_t aPort,
OriginAttributes aOriginAttributes,
ByteArray? aStapledOCSPResponse,
ByteArray? aSctsFromTLSExtension,
DelegatedCredentialInfoArg? aDcInfo,
uint32_t aProviderFlags,
uint32_t aCertVerifierFlags);
async EnsureRDDProcessAndCreateBridge()
returns (nsresult rv, Endpoint<PRemoteDecoderManagerChild> aEndpoint);
async EnsureUtilityProcessAndCreateBridge(RemoteDecodeIn aLocation)
returns (nsresult rv, Endpoint<PRemoteDecoderManagerChild> aEndpoint);
async PWebSocketConnection(uint32_t aListenerId);
async PLockManager(nsIPrincipal aPrincipalInfo, nsID aClientId);
async PIPCClientCerts();
async PFetch();
async RequestCameraAccess() returns (nsresult rv);

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

@ -10,13 +10,13 @@ include protocol PWebrtcTCPSocket;
include protocol PHttpTransaction;
include protocol PHttpConnectionMgr;
include protocol PInputChannelThrottleQueue;
include protocol PBackgroundStarter;
include protocol PAltService;
include protocol PAltSvcTransaction;
include protocol PTRRService;
include protocol PProxyConfigLookup;
include protocol PNativeDNSResolverOverride;
include protocol PProxyAutoConfig;
include protocol PSocketProcessBackground;
#if defined(MOZ_SANDBOX) && defined(MOZ_DEBUG) && defined(ENABLE_TESTS)
include protocol PSandboxTesting;
@ -25,6 +25,7 @@ include protocol PSandboxTesting;
include MemoryReportTypes;
include NeckoChannelParams;
include PrefsTypes;
include PSMIPCTypes;
include "mozilla/ipc/ByteBufUtils.h";
@ -120,7 +121,7 @@ parent:
PRTime aTimestamp,
uint64_t aExtraSizeData,
nsCString aExtraStringData);
async InitSocketBackground(Endpoint<PSocketProcessBackgroundParent> aEndpoint);
async InitBackground(Endpoint<PBackgroundStarterParent> aEndpoint);
async PAltService();
async PProxyConfigLookup(nullable nsIURI aUri, uint32_t aFlags);
async CachePushCheck(nullable nsIURI aPushedURL,

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

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PVerifySSLServerCert;
include protocol PSelectTLSClientAuthCert;
include protocol PIPCClientCerts;
include protocol PWebSocketConnection;
include PSMIPCTypes;
using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h";
namespace mozilla {
namespace net {
/**
* PSocketProcessBackground is the top level IPC protocol between
* a background task queue in the socket process and the parent process.
* We use this to create several IPC protocols between the socket process
* and the parent process.
*/
sync protocol PSocketProcessBackground
{
parent:
async InitVerifySSLServerCert(
Endpoint<PVerifySSLServerCertParent> aEndpoint,
ByteArray[] aPeerCertChain,
nsCString aHostName,
int32_t aPort,
OriginAttributes aOriginAttributes,
ByteArray? aStapledOCSPResponse,
ByteArray? aSctsFromTLSExtension,
DelegatedCredentialInfoArg? aDcInfo,
uint32_t aProviderFlags,
uint32_t aCertVerifierFlags);
async InitSelectTLSClientAuthCert(
Endpoint<PSelectTLSClientAuthCertParent> aEndpoint,
nsCString aHostName,
OriginAttributes aOriginAttributes,
int32_t aPort,
uint32_t aProviderFlags,
uint32_t aProviderTlsFlags,
ByteArray aServerCertBytes,
ByteArray[] aCANames);
async InitIPCClientCerts(Endpoint<PIPCClientCertsParent> aEndpoint);
async InitWebSocketConnection(Endpoint<PWebSocketConnectionParent> aEndpoint,
uint32_t aListenerId);
};
} // namespace net
} // namespace mozilla

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

@ -4,17 +4,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBackgroundDataBridge;
include protocol PMediaTransport;
include protocol PBackgroundStarter;
namespace mozilla {
namespace net {
/**
* PSocketProcessBridge is the IPC protocol between the main thread in
* the content process and the main thread in the socket process.
* We use this to create PBackgroundDataBridge and PMediaTransport protocols
* between content process and socket process.
* PSocketProcessBridge is the IPC protocol between content process and
* socket process. This protocol allows socket process to send data to
* content process bypassing parent process.
* Once created, PSocketProcessBridgeChild is the actor that lives in
* content process and PSocketProcessBridgeParent lives in
* socket process.
@ -22,19 +20,11 @@ namespace net {
[NeedsOtherPid]
sync protocol PSocketProcessBridge
{
parent:
/**
* For setting up PBackgroundDataBridge protocol, we use this message to
* create a background task queue and the BackgroundDataBridgeParent actor in
* socket process.
*/
async InitBackgroundDataBridge(Endpoint<PBackgroundDataBridgeParent> aEndpoint,
uint64_t aChannelID);
/**
* Similar to the above, this message is for PMediaTransport.
*/
async InitMediaTransport(Endpoint<PMediaTransportParent> aEndpoint);
parent:
async InitBackground(Endpoint<PBackgroundStarterParent> aEndpoint);
both:
async Test();
};
}

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

@ -1,113 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SocketProcessBackgroundChild.h"
#include "SocketProcessLogging.h"
#include "mozilla/ipc/Endpoint.h"
#include "nsThreadUtils.h"
namespace mozilla::net {
StaticMutex SocketProcessBackgroundChild::sMutex;
StaticRefPtr<SocketProcessBackgroundChild>
SocketProcessBackgroundChild::sInstance;
StaticRefPtr<nsISerialEventTarget> SocketProcessBackgroundChild::sTaskQueue;
// static
RefPtr<SocketProcessBackgroundChild>
SocketProcessBackgroundChild::GetSingleton() {
StaticMutexAutoLock lock(sMutex);
return sInstance;
}
// static
void SocketProcessBackgroundChild::Create(
ipc::Endpoint<PSocketProcessBackgroundChild>&& aEndpoint) {
if (NS_WARN_IF(!aEndpoint.IsValid())) {
MOZ_ASSERT_UNREACHABLE(
"Can't create SocketProcessBackgroundChild with invalid endpoint");
return;
}
nsCOMPtr<nsISerialEventTarget> transportQueue;
if (NS_WARN_IF(NS_FAILED(NS_CreateBackgroundTaskQueue(
"SocketBackgroundChildQueue", getter_AddRefs(transportQueue))))) {
return;
}
RefPtr<SocketProcessBackgroundChild> actor =
new SocketProcessBackgroundChild();
transportQueue->Dispatch(NS_NewRunnableFunction(
"BindSocketBackgroundChild",
[endpoint = std::move(aEndpoint), actor]() mutable {
// We checked endpoint validity before the dispatch, so this cannot
// fail.
MOZ_ALWAYS_TRUE(endpoint.Bind(actor));
}));
// Immediately store the actor and queue into the global.
// Any messages dispatched to the queue will arrive after it has been bound.
LOG(("SocketProcessBackgroundChild::Create"));
StaticMutexAutoLock lock(sMutex);
MOZ_ASSERT(!sInstance && !sTaskQueue,
"Cannot initialize SocketProcessBackgroundChild twice!");
sInstance = actor;
sTaskQueue = transportQueue;
}
// static
void SocketProcessBackgroundChild::Shutdown() {
nsCOMPtr<nsISerialEventTarget> taskQueue = TaskQueue();
if (!taskQueue) {
return;
}
taskQueue->Dispatch(
NS_NewRunnableFunction("SocketProcessBackgroundChild::Shutdown", []() {
LOG(("SocketProcessBackgroundChild::Shutdown"));
StaticMutexAutoLock lock(sMutex);
sInstance->Close();
sInstance = nullptr;
sTaskQueue = nullptr;
}));
}
// static
already_AddRefed<nsISerialEventTarget>
SocketProcessBackgroundChild::TaskQueue() {
StaticMutexAutoLock lock(sMutex);
return do_AddRef(sTaskQueue);
}
// static
nsresult SocketProcessBackgroundChild::WithActor(
const char* aName,
MoveOnlyFunction<void(SocketProcessBackgroundChild*)> aCallback) {
nsCOMPtr<nsISerialEventTarget> taskQueue = TaskQueue();
if (!taskQueue) {
return NS_ERROR_NOT_AVAILABLE;
}
return taskQueue->Dispatch(NS_NewRunnableFunction(
aName, [callback = std::move(aCallback)]() mutable {
RefPtr<SocketProcessBackgroundChild> actor =
SocketProcessBackgroundChild::GetSingleton();
if (actor) {
callback(actor);
}
}));
}
SocketProcessBackgroundChild::SocketProcessBackgroundChild() {
LOG(("SocketProcessBackgroundChild ctor"));
}
SocketProcessBackgroundChild::~SocketProcessBackgroundChild() {
LOG(("SocketProcessBackgroundChild dtor"));
}
} // namespace mozilla::net

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

@ -1,45 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_net_SocketProcessBackgroundChild_h
#define mozilla_net_SocketProcessBackgroundChild_h
#include "mozilla/MoveOnlyFunction.h"
#include "mozilla/net/PSocketProcessBackgroundChild.h"
#include "mozilla/StaticMutex.h"
#include "mozilla/StaticPtr.h"
namespace mozilla {
namespace net {
class SocketProcessBackgroundChild final
: public PSocketProcessBackgroundChild {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketProcessBackgroundChild, final)
static void Create(ipc::Endpoint<PSocketProcessBackgroundChild>&& aEndpoint);
static void Shutdown();
// |aCallback| will be called with the actor asynchronously on |sTaskQueue|.
static nsresult WithActor(
const char* aName,
MoveOnlyFunction<void(SocketProcessBackgroundChild*)> aCallback);
private:
SocketProcessBackgroundChild();
virtual ~SocketProcessBackgroundChild();
static RefPtr<SocketProcessBackgroundChild> GetSingleton();
static already_AddRefed<nsISerialEventTarget> TaskQueue();
static StaticMutex sMutex;
static StaticRefPtr<SocketProcessBackgroundChild> sInstance
MOZ_GUARDED_BY(sMutex);
static StaticRefPtr<nsISerialEventTarget> sTaskQueue MOZ_GUARDED_BY(sMutex);
};
} // namespace net
} // namespace mozilla
#endif // mozilla_net_SocketProcessBackgroundChild_h

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

@ -1,167 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SocketProcessBackgroundParent.h"
#include "SocketProcessLogging.h"
#include "mozilla/net/HttpConnectionMgrParent.h"
#include "mozilla/net/WebSocketConnectionParent.h"
#include "mozilla/psm/IPCClientCertsParent.h"
#include "mozilla/psm/VerifySSLServerCertParent.h"
#include "mozilla/psm/SelectTLSClientAuthCertParent.h"
#include "nsIHttpChannelInternal.h"
namespace mozilla::net {
SocketProcessBackgroundParent::SocketProcessBackgroundParent() {
LOG(("SocketProcessBackgroundParent ctor"));
}
SocketProcessBackgroundParent::~SocketProcessBackgroundParent() {
LOG(("SocketProcessBackgroundParent dtor"));
}
mozilla::ipc::IPCResult
SocketProcessBackgroundParent::RecvInitVerifySSLServerCert(
Endpoint<PVerifySSLServerCertParent>&& aEndpoint,
nsTArray<ByteArray>&& aPeerCertChain, const nsACString& aHostName,
const int32_t& aPort, const OriginAttributes& aOriginAttributes,
const Maybe<ByteArray>& aStapledOCSPResponse,
const Maybe<ByteArray>& aSctsFromTLSExtension,
const Maybe<DelegatedCredentialInfoArg>& aDcInfo,
const uint32_t& aProviderFlags, const uint32_t& aCertVerifierFlags) {
LOG(("SocketProcessBackgroundParent::RecvInitVerifySSLServerCert\n"));
if (!aEndpoint.IsValid()) {
return IPC_FAIL(this, "Invalid endpoint");
}
nsCOMPtr<nsISerialEventTarget> transportQueue;
if (NS_FAILED(NS_CreateBackgroundTaskQueue("VerifySSLServerCert",
getter_AddRefs(transportQueue)))) {
return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
}
transportQueue->Dispatch(NS_NewRunnableFunction(
"InitVerifySSLServerCert",
[endpoint = std::move(aEndpoint),
peerCertChain = std::move(aPeerCertChain),
hostName = nsCString(aHostName), port(aPort),
originAttributes(aOriginAttributes),
stapledOCSPResponse = std::move(aStapledOCSPResponse),
sctsFromTLSExtension = std::move(aSctsFromTLSExtension),
dcInfo = std::move(aDcInfo), providerFlags(aProviderFlags),
certVerifierFlags(aCertVerifierFlags)]() mutable {
RefPtr<psm::VerifySSLServerCertParent> parent =
new psm::VerifySSLServerCertParent();
if (!endpoint.Bind(parent)) {
return;
}
parent->Dispatch(std::move(peerCertChain), hostName, port,
originAttributes, stapledOCSPResponse,
sctsFromTLSExtension, dcInfo, providerFlags,
certVerifierFlags);
}));
return IPC_OK();
}
mozilla::ipc::IPCResult
SocketProcessBackgroundParent::RecvInitSelectTLSClientAuthCert(
Endpoint<PSelectTLSClientAuthCertParent>&& aEndpoint,
const nsACString& aHostName, const OriginAttributes& aOriginAttributes,
const int32_t& aPort, const uint32_t& aProviderFlags,
const uint32_t& aProviderTlsFlags, const ByteArray& aServerCertBytes,
nsTArray<ByteArray>&& aCANames) {
LOG(("SocketProcessBackgroundParent::RecvInitSelectTLSClientAuthCert\n"));
if (!aEndpoint.IsValid()) {
return IPC_FAIL(this, "Invalid endpoint");
}
nsCOMPtr<nsISerialEventTarget> transportQueue;
if (NS_FAILED(NS_CreateBackgroundTaskQueue("SelectTLSClientAuthCert",
getter_AddRefs(transportQueue)))) {
return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
}
transportQueue->Dispatch(NS_NewRunnableFunction(
"InitSelectTLSClientAuthCert",
[endpoint = std::move(aEndpoint), hostName = nsCString(aHostName),
originAttributes(aOriginAttributes), port(aPort),
providerFlags(aProviderFlags), providerTlsFlags(aProviderTlsFlags),
serverCertBytes(aServerCertBytes),
CANAMEs(std::move(aCANames))]() mutable {
RefPtr<psm::SelectTLSClientAuthCertParent> parent =
new psm::SelectTLSClientAuthCertParent();
if (!endpoint.Bind(parent)) {
return;
}
parent->Dispatch(hostName, originAttributes, port, providerFlags,
providerTlsFlags, serverCertBytes, std::move(CANAMEs));
}));
return IPC_OK();
}
mozilla::ipc::IPCResult SocketProcessBackgroundParent::RecvInitIPCClientCerts(
Endpoint<PIPCClientCertsParent>&& aEndpoint) {
LOG(("SocketProcessBackgroundParent::RecvInitIPCClientCerts\n"));
if (!aEndpoint.IsValid()) {
return IPC_FAIL(this, "Invalid endpoint");
}
nsCOMPtr<nsISerialEventTarget> transportQueue;
if (NS_FAILED(NS_CreateBackgroundTaskQueue("IPCClientCerts",
getter_AddRefs(transportQueue)))) {
return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
}
transportQueue->Dispatch(NS_NewRunnableFunction(
"InitIPCClientCerts", [endpoint = std::move(aEndpoint)]() mutable {
RefPtr<psm::IPCClientCertsParent> parent =
new psm::IPCClientCertsParent();
endpoint.Bind(parent);
}));
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) {
LOG(("SocketProcessBackgroundParent::ActorDestroy"));
}
} // namespace mozilla::net

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

@ -1,52 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_net_SocketProcessBackgroundParent_h
#define mozilla_net_SocketProcessBackgroundParent_h
#include "mozilla/net/PSocketProcessBackgroundParent.h"
namespace mozilla {
namespace net {
class SocketProcessBackgroundParent final
: public PSocketProcessBackgroundParent {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketProcessBackgroundParent, final)
SocketProcessBackgroundParent();
mozilla::ipc::IPCResult RecvInitVerifySSLServerCert(
Endpoint<PVerifySSLServerCertParent>&& aEndpoint,
nsTArray<ByteArray>&& aPeerCertChain, const nsACString& aHostName,
const int32_t& aPort, const OriginAttributes& aOriginAttributes,
const Maybe<ByteArray>& aStapledOCSPResponse,
const Maybe<ByteArray>& aSctsFromTLSExtension,
const Maybe<DelegatedCredentialInfoArg>& aDcInfo,
const uint32_t& aProviderFlags, const uint32_t& aCertVerifierFlags);
mozilla::ipc::IPCResult RecvInitIPCClientCerts(
Endpoint<PIPCClientCertsParent>&& aEndpoint);
mozilla::ipc::IPCResult RecvInitSelectTLSClientAuthCert(
Endpoint<PSelectTLSClientAuthCertParent>&& aEndpoint,
const nsACString& aHostName, const OriginAttributes& aOriginAttributes,
const int32_t& aPort, const uint32_t& aProviderFlags,
const uint32_t& aProviderTlsFlags, const ByteArray& aServerCertBytes,
nsTArray<ByteArray>&& aCANames);
mozilla::ipc::IPCResult RecvInitWebSocketConnection(
Endpoint<PWebSocketConnectionParent>&& aEndpoint,
const uint32_t& aListenerId);
void ActorDestroy(ActorDestroyReason aReason) override;
private:
~SocketProcessBackgroundParent();
};
} // namespace net
} // namespace mozilla
#endif // mozilla_net_SocketProcessBackgroundParent_h

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

@ -46,6 +46,9 @@ bool SocketProcessBridgeChild::Create(
}
sSocketProcessBridgeChild->mSocketProcessPid = aEndpoint.OtherPid();
mozilla::ipc::BackgroundChild::InitSocketBridgeStarter(
sSocketProcessBridgeChild);
return true;
}

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

@ -6,87 +6,59 @@
#include "SocketProcessBridgeParent.h"
#include "SocketProcessLogging.h"
#include "mozilla/dom/MediaTransportParent.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/ipc/Endpoint.h"
#include "SocketProcessChild.h"
#include "mozilla/net/BackgroundDataBridgeParent.h"
#include "nsThreadUtils.h"
namespace mozilla {
namespace net {
SocketProcessBridgeParent::SocketProcessBridgeParent(ProcessId aId) : mId(aId) {
SocketProcessBridgeParent::SocketProcessBridgeParent(ProcessId aId)
: mId(aId), mClosed(false) {
LOG(
("CONSTRUCT SocketProcessBridgeParent::SocketProcessBridgeParent "
"mId=%" PRIPID "\n",
mId));
MOZ_COUNT_CTOR(SocketProcessBridgeParent);
}
SocketProcessBridgeParent::~SocketProcessBridgeParent() {
LOG(("DESTRUCT SocketProcessBridgeParent::SocketProcessBridgeParent\n"));
LOG(
("DESTRUCT SocketProcessBridgeParent::SocketProcessBridgeParent "
"mId=%" PRIPID "\n",
mId));
MOZ_COUNT_DTOR(SocketProcessBridgeParent);
}
mozilla::ipc::IPCResult SocketProcessBridgeParent::RecvInitBackgroundDataBridge(
mozilla::ipc::Endpoint<PBackgroundDataBridgeParent>&& aEndpoint,
uint64_t aChannelID) {
LOG(("SocketProcessBridgeParent::RecvInitBackgroundDataBridge\n"));
nsCOMPtr<nsISerialEventTarget> transportQueue;
if (NS_FAILED(NS_CreateBackgroundTaskQueue("BackgroundDataBridge",
getter_AddRefs(transportQueue)))) {
return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
}
if (!aEndpoint.IsValid()) {
return IPC_FAIL(this, "Invalid endpoint");
}
transportQueue->Dispatch(NS_NewRunnableFunction(
"BackgroundDataBridgeParent::Bind",
[endpoint = std::move(aEndpoint), aChannelID]() mutable {
RefPtr<net::BackgroundDataBridgeParent> actor =
new net::BackgroundDataBridgeParent(aChannelID);
endpoint.Bind(actor);
}));
mozilla::ipc::IPCResult SocketProcessBridgeParent::RecvTest() {
LOG(("SocketProcessBridgeParent::RecvTest\n"));
Unused << SendTest();
return IPC_OK();
}
mozilla::ipc::IPCResult SocketProcessBridgeParent::RecvInitMediaTransport(
mozilla::ipc::Endpoint<mozilla::dom::PMediaTransportParent>&& aEndpoint) {
LOG(("SocketProcessBridgeParent::RecvInitMediaTransport\n"));
if (!aEndpoint.IsValid()) {
return IPC_FAIL(this, "Invalid endpoint");
mozilla::ipc::IPCResult SocketProcessBridgeParent::RecvInitBackground(
Endpoint<PBackgroundStarterParent>&& aEndpoint) {
LOG(("SocketProcessBridgeParent::RecvInitBackground mId=%" PRIPID "\n", mId));
if (!ipc::BackgroundParent::AllocStarter(nullptr, std::move(aEndpoint))) {
return IPC_FAIL(this, "BackgroundParent::Alloc failed");
}
if (!mMediaTransportTaskQueue) {
nsCOMPtr<nsISerialEventTarget> transportQueue;
if (NS_FAILED(NS_CreateBackgroundTaskQueue(
"MediaTransport", getter_AddRefs(transportQueue)))) {
return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
}
mMediaTransportTaskQueue = std::move(transportQueue);
}
mMediaTransportTaskQueue->Dispatch(NS_NewRunnableFunction(
"BackgroundDataBridgeParent::Bind",
[endpoint = std::move(aEndpoint)]() mutable {
RefPtr<MediaTransportParent> actor = new MediaTransportParent();
endpoint.Bind(actor);
}));
return IPC_OK();
}
void SocketProcessBridgeParent::ActorDestroy(ActorDestroyReason aReason) {
// See bug 1846478. We might be able to remove this dispatch.
GetCurrentSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
"SocketProcessBridgeParent::ActorDestroy", [id = mId] {
if (SocketProcessChild* child = SocketProcessChild::GetSingleton()) {
child->DestroySocketProcessBridgeParent(id);
}
}));
void SocketProcessBridgeParent::ActorDestroy(ActorDestroyReason aWhy) {
LOG(("SocketProcessBridgeParent::ActorDestroy mId=%" PRIPID "\n", mId));
mClosed = true;
GetCurrentSerialEventTarget()->Dispatch(
NewRunnableMethod("net::SocketProcessBridgeParent::DeferredDestroy", this,
&SocketProcessBridgeParent::DeferredDestroy));
}
void SocketProcessBridgeParent::DeferredDestroy() {
if (SocketProcessChild* child = SocketProcessChild::GetSingleton()) {
child->DestroySocketProcessBridgeParent(mId);
}
}
} // namespace net

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

@ -21,19 +21,20 @@ class SocketProcessBridgeParent final : public PSocketProcessBridgeParent {
explicit SocketProcessBridgeParent(ProcessId aId);
mozilla::ipc::IPCResult RecvInitBackgroundDataBridge(
Endpoint<PBackgroundDataBridgeParent>&& aEndpoint, uint64_t aChannelID);
mozilla::ipc::IPCResult RecvTest();
mozilla::ipc::IPCResult RecvInitBackground(
Endpoint<PBackgroundStarterParent>&& aEndpoint);
mozilla::ipc::IPCResult RecvInitMediaTransport(
Endpoint<PMediaTransportParent>&& aEndpoint);
void ActorDestroy(ActorDestroyReason aWhy) override;
void DeferredDestroy();
void ActorDestroy(ActorDestroyReason aReason) override;
bool Closed() const { return mClosed; }
private:
~SocketProcessBridgeParent();
nsCOMPtr<nsISerialEventTarget> mMediaTransportTaskQueue;
ProcessId mId;
bool mClosed;
};
} // namespace net

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

@ -18,6 +18,8 @@
#include "mozilla/FOGIPC.h"
#include "mozilla/glean/GleanMetrics.h"
#include "mozilla/ipc/CrashReporterClient.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/net/AltSvcTransactionChild.h"
#include "mozilla/net/BackgroundDataBridgeParent.h"
@ -25,7 +27,6 @@
#include "mozilla/net/DNSRequestParent.h"
#include "mozilla/net/NativeDNSResolverOverrideChild.h"
#include "mozilla/net/ProxyAutoConfigChild.h"
#include "mozilla/net/SocketProcessBackgroundChild.h"
#include "mozilla/net/TRRServiceChild.h"
#include "mozilla/ipc/ProcessUtils.h"
#include "mozilla/Preferences.h"
@ -104,46 +105,6 @@ void CGSShutdownServerConnections();
};
#endif
void SocketProcessChild::InitSocketBackground() {
Endpoint<PSocketProcessBackgroundParent> parentEndpoint;
Endpoint<PSocketProcessBackgroundChild> childEndpoint;
if (NS_WARN_IF(NS_FAILED(PSocketProcessBackground::CreateEndpoints(
&parentEndpoint, &childEndpoint)))) {
return;
}
SocketProcessBackgroundChild::Create(std::move(childEndpoint));
Unused << SendInitSocketBackground(std::move(parentEndpoint));
}
namespace {
class NetTeardownObserver final : public nsIObserver {
public:
NetTeardownObserver() = default;
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
private:
~NetTeardownObserver() = default;
};
NS_IMPL_ISUPPORTS(NetTeardownObserver, nsIObserver)
NS_IMETHODIMP
NetTeardownObserver::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
if (SocketProcessChild* child = SocketProcessChild::GetSingleton()) {
child->CloseIPCClientCertsActor();
}
return NS_OK;
}
} // namespace
bool SocketProcessChild::Init(mozilla::ipc::UntypedEndpoint&& aEndpoint,
const char* aParentBuildID) {
if (NS_WARN_IF(NS_FAILED(nsThreadManager::get().Init()))) {
@ -169,7 +130,8 @@ bool SocketProcessChild::Init(mozilla::ipc::UntypedEndpoint&& aEndpoint,
return false;
}
InitSocketBackground();
BackgroundChild::Startup();
BackgroundChild::InitSocketStarter(this);
SetThisProcessName("Socket Process");
#if defined(XP_MACOSX)
@ -202,27 +164,13 @@ bool SocketProcessChild::Init(mozilla::ipc::UntypedEndpoint&& aEndpoint,
return false;
}
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (obs) {
nsCOMPtr<nsIObserver> observer = new NetTeardownObserver();
Unused << obs->AddObserver(observer, "profile-change-net-teardown", false);
}
mSocketThread = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID);
if (!mSocketThread) {
return false;
}
return true;
}
void SocketProcessChild::ActorDestroy(ActorDestroyReason aWhy) {
LOG(("SocketProcessChild::ActorDestroy\n"));
{
MutexAutoLock lock(mMutex);
mShuttingDown = true;
}
mShuttingDown = true;
if (AbnormalShutdown == aWhy) {
NS_WARNING("Shutting down Socket process early due to a crash!");
@ -245,10 +193,8 @@ void SocketProcessChild::ActorDestroy(ActorDestroyReason aWhy) {
void SocketProcessChild::CleanUp() {
LOG(("SocketProcessChild::CleanUp\n"));
SocketProcessBackgroundChild::Shutdown();
for (const auto& parent : mSocketProcessBridgeParentMap.Values()) {
if (parent->CanSend()) {
if (!parent->Closed()) {
parent->Close();
}
}
@ -510,11 +456,13 @@ mozilla::ipc::IPCResult SocketProcessChild::RecvPDNSRequestConstructor(
void SocketProcessChild::AddDataBridgeToMap(
uint64_t aChannelId, BackgroundDataBridgeParent* aActor) {
ipc::AssertIsOnBackgroundThread();
MutexAutoLock lock(mMutex);
mBackgroundDataBridgeMap.InsertOrUpdate(aChannelId, RefPtr{aActor});
}
void SocketProcessChild::RemoveDataBridgeFromMap(uint64_t aChannelId) {
ipc::AssertIsOnBackgroundThread();
MutexAutoLock lock(mMutex);
mBackgroundDataBridgeMap.Remove(aChannelId);
}
@ -763,66 +711,5 @@ SocketProcessChild::RecvUnblockUntrustedModulesThread() {
}
#endif // defined(XP_WIN)
bool SocketProcessChild::IsShuttingDown() {
MutexAutoLock lock(mMutex);
return mShuttingDown;
}
void SocketProcessChild::CloseIPCClientCertsActor() {
LOG(("SocketProcessChild::CloseIPCClientCertsActor"));
MOZ_ASSERT(NS_IsMainThread());
mSocketThread->Dispatch(NS_NewRunnableFunction(
"CloseIPCClientCertsActor", [self = RefPtr{this}]() {
LOG(("CloseIPCClientCertsActor"));
if (self->mIPCClientCertsChild) {
self->mIPCClientCertsChild->Close();
self->mIPCClientCertsChild = nullptr;
}
}));
}
already_AddRefed<psm::IPCClientCertsChild>
SocketProcessChild::GetIPCClientCertsActor() {
LOG(("SocketProcessChild::GetIPCClientCertsActor"));
// Only socket thread can access the mIPCClientCertsChild.
if (!OnSocketThread()) {
return nullptr;
}
{
MutexAutoLock lock(mMutex);
if (mShuttingDown) {
return nullptr;
}
}
if (mIPCClientCertsChild) {
RefPtr<psm::IPCClientCertsChild> actorChild = mIPCClientCertsChild;
return actorChild.forget();
}
ipc::Endpoint<psm::PIPCClientCertsParent> parentEndpoint;
ipc::Endpoint<psm::PIPCClientCertsChild> childEndpoint;
psm::PIPCClientCerts::CreateEndpoints(&parentEndpoint, &childEndpoint);
if (NS_FAILED(SocketProcessBackgroundChild::WithActor(
"SendInitIPCClientCerts",
[endpoint = std::move(parentEndpoint)](
SocketProcessBackgroundChild* aActor) mutable {
Unused << aActor->SendInitIPCClientCerts(std::move(endpoint));
}))) {
return nullptr;
}
RefPtr<psm::IPCClientCertsChild> actor = new psm::IPCClientCertsChild();
if (!childEndpoint.Bind(actor)) {
return nullptr;
}
mIPCClientCertsChild = actor;
return actor.forget();
}
} // namespace net
} // namespace mozilla

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

@ -8,7 +8,6 @@
#include "mozilla/net/PSocketProcessChild.h"
#include "mozilla/ipc/InputStreamUtils.h"
#include "mozilla/psm/IPCClientCertsChild.h"
#include "mozilla/Mutex.h"
#include "nsRefPtrHashtable.h"
#include "nsTHashMap.h"
@ -25,7 +24,6 @@ namespace mozilla {
namespace net {
class ProxyAutoConfigChild;
class SocketProcessBackgroundChild;
class SocketProcessBridgeParent;
class BackgroundDataBridgeParent;
@ -92,7 +90,7 @@ class SocketProcessChild final : public PSocketProcessChild {
already_AddRefed<PAltSvcTransactionChild> AllocPAltSvcTransactionChild(
const HttpConnectionInfoCloneArgs& aConnInfo, const uint32_t& aCaps);
bool IsShuttingDown();
bool IsShuttingDown() { return mShuttingDown; }
already_AddRefed<PDNSRequestChild> AllocPDNSRequestChild(
const nsACString& aHost, const nsACString& aTrrServer,
@ -153,15 +151,10 @@ class SocketProcessChild final : public PSocketProcessChild {
mozilla::ipc::IPCResult RecvUnblockUntrustedModulesThread();
#endif // defined(XP_WIN)
already_AddRefed<psm::IPCClientCertsChild> GetIPCClientCertsActor();
void CloseIPCClientCertsActor();
protected:
friend class SocketProcessImpl;
~SocketProcessChild();
void InitSocketBackground();
private:
// Mapping of content process id and the SocketProcessBridgeParent.
// This table keeps SocketProcessBridgeParent alive in socket process.
@ -170,16 +163,11 @@ class SocketProcessChild final : public PSocketProcessChild {
RefPtr<ChildProfilerController> mProfilerController;
bool mShuttingDown{false};
// Protect the table below.
Mutex mMutex MOZ_UNANNOTATED{"SocketProcessChild::mMutex"};
nsTHashMap<uint64_t, RefPtr<BackgroundDataBridgeParent>>
mBackgroundDataBridgeMap;
bool mShuttingDown MOZ_GUARDED_BY(mMutex) = false;
nsCOMPtr<nsIEventTarget> mSocketThread;
// mIPCClientCertsChild is only accessed on the socket thread.
RefPtr<psm::IPCClientCertsChild> mIPCClientCertsChild;
};
} // namespace net

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

@ -16,7 +16,6 @@
#include "mozilla/FOGIPC.h"
#include "mozilla/net/DNSRequestParent.h"
#include "mozilla/net/ProxyConfigLookupParent.h"
#include "mozilla/net/SocketProcessBackgroundParent.h"
#include "mozilla/RemoteLazyInputStreamParent.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TelemetryIPC.h"
@ -248,25 +247,13 @@ mozilla::ipc::IPCResult SocketProcessParent::RecvObserveHttpActivity(
return IPC_OK();
}
mozilla::ipc::IPCResult SocketProcessParent::RecvInitSocketBackground(
Endpoint<PSocketProcessBackgroundParent>&& aEndpoint) {
if (!aEndpoint.IsValid()) {
return IPC_FAIL(this, "Invalid endpoint");
mozilla::ipc::IPCResult SocketProcessParent::RecvInitBackground(
Endpoint<PBackgroundStarterParent>&& aEndpoint) {
LOG(("SocketProcessParent::RecvInitBackground\n"));
if (!ipc::BackgroundParent::AllocStarter(nullptr, std::move(aEndpoint))) {
return IPC_FAIL(this, "BackgroundParent::Alloc failed");
}
nsCOMPtr<nsISerialEventTarget> transportQueue;
if (NS_FAILED(NS_CreateBackgroundTaskQueue("SocketBackgroundParentQueue",
getter_AddRefs(transportQueue)))) {
return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
}
transportQueue->Dispatch(
NS_NewRunnableFunction("BindSocketBackgroundParent",
[endpoint = std::move(aEndpoint)]() mutable {
RefPtr<SocketProcessBackgroundParent> parent =
new SocketProcessBackgroundParent();
endpoint.Bind(parent);
}));
return IPC_OK();
}

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

@ -7,6 +7,7 @@
#define mozilla_net_SocketProcessParent_h
#include "mozilla/UniquePtr.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/ipc/CrashReporterHelper.h"
#include "mozilla/ipc/InputStreamUtils.h"
#include "mozilla/net/PSocketProcessParent.h"
@ -75,11 +76,18 @@ class SocketProcessParent final
const uint32_t& aActivitySubtype, const PRTime& aTimestamp,
const uint64_t& aExtraSizeData, const nsACString& aExtraStringData);
mozilla::ipc::IPCResult RecvInitSocketBackground(
Endpoint<PSocketProcessBackgroundParent>&& aEndpoint);
mozilla::ipc::IPCResult RecvInitBackground(
Endpoint<PBackgroundStarterParent>&& aEndpoint);
already_AddRefed<PAltServiceParent> AllocPAltServiceParent();
mozilla::ipc::IPCResult RecvFindIPCClientCertObjects(
nsTArray<IPCClientCertObject>* aObjects);
mozilla::ipc::IPCResult RecvIPCClientCertSign(ByteArray aCert,
ByteArray aData,
ByteArray aParams,
ByteArray* aSignature);
already_AddRefed<PProxyConfigLookupParent> AllocPProxyConfigLookupParent(
nsIURI* aURI, const uint32_t& aProxyResolveFlags);
mozilla::ipc::IPCResult RecvPProxyConfigLookupConstructor(

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

@ -24,8 +24,6 @@ EXPORTS.mozilla.net += [
"ProxyConfigLookup.h",
"ProxyConfigLookupChild.h",
"ProxyConfigLookupParent.h",
"SocketProcessBackgroundChild.h",
"SocketProcessBackgroundParent.h",
"SocketProcessBridgeChild.h",
"SocketProcessBridgeParent.h",
"SocketProcessChild.h",
@ -51,8 +49,6 @@ UNIFIED_SOURCES += [
"ProxyConfigLookup.cpp",
"ProxyConfigLookupChild.cpp",
"ProxyConfigLookupParent.cpp",
"SocketProcessBackgroundChild.cpp",
"SocketProcessBackgroundParent.cpp",
"SocketProcessBridgeChild.cpp",
"SocketProcessBridgeParent.cpp",
"SocketProcessChild.cpp",
@ -81,7 +77,6 @@ IPDL_SOURCES = [
"PProxyAutoConfig.ipdl",
"PProxyConfigLookup.ipdl",
"PSimpleChannel.ipdl",
"PSocketProcessBackground.ipdl",
"PSocketProcessBridge.ipdl",
]

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

@ -27,7 +27,7 @@ mozilla::ipc::IPCResult BackgroundDataBridgeChild::RecvOnTransportAndData(
}
if (mBgChild->ChannelClosed()) {
Close();
Unused << Send__delete__(this);
return IPC_OK();
}
@ -44,7 +44,7 @@ mozilla::ipc::IPCResult BackgroundDataBridgeChild::RecvOnStopRequest(
}
if (mBgChild->ChannelClosed()) {
Close();
Unused << Send__delete__(this);
return IPC_OK();
}

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

@ -10,7 +10,7 @@ namespace mozilla {
namespace net {
BackgroundDataBridgeParent::BackgroundDataBridgeParent(uint64_t aChannelID)
: mChannelID(aChannelID), mBackgroundThread(GetCurrentSerialEventTarget()) {
: mChannelID(aChannelID), mBackgroundThread(NS_GetCurrentThread()) {
if (SocketProcessChild* child = SocketProcessChild::GetSingleton()) {
child->AddDataBridgeToMap(aChannelID, this);
}
@ -22,9 +22,9 @@ void BackgroundDataBridgeParent::ActorDestroy(ActorDestroyReason aWhy) {
}
}
already_AddRefed<nsISerialEventTarget>
BackgroundDataBridgeParent::GetBackgroundThread() {
return do_AddRef(mBackgroundThread);
already_AddRefed<nsIThread> BackgroundDataBridgeParent::GetBackgroundThread() {
nsCOMPtr<nsIThread> thread = mBackgroundThread;
return thread.forget();
}
void BackgroundDataBridgeParent::Destroy() {
@ -33,7 +33,7 @@ void BackgroundDataBridgeParent::Destroy() {
NS_NewRunnableFunction("BackgroundDataBridgeParent::Destroy",
[self]() {
if (self->CanSend()) {
self->Close();
Unused << self->Send__delete__(self);
}
}),
NS_DISPATCH_NORMAL));
@ -51,7 +51,7 @@ void BackgroundDataBridgeParent::OnStopRequest(
if (self->CanSend()) {
Unused << self->SendOnStopRequest(
aStatus, aTiming, aLastActiveTabOptHit, aResponseTrailers);
self->Close();
Unused << self->Send__delete__(self);
}
}),
NS_DISPATCH_NORMAL));

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

@ -16,7 +16,7 @@ class BackgroundDataBridgeParent final : public PBackgroundDataBridgeParent {
explicit BackgroundDataBridgeParent(uint64_t aChannelID);
void ActorDestroy(ActorDestroyReason aWhy) override;
already_AddRefed<nsISerialEventTarget> GetBackgroundThread();
already_AddRefed<nsIThread> GetBackgroundThread();
void Destroy();
void OnStopRequest(nsresult aStatus, const ResourceTimingStructArgs& aTiming,
const TimeStamp& aLastActiveTabOptHit,
@ -26,7 +26,7 @@ class BackgroundDataBridgeParent final : public PBackgroundDataBridgeParent {
virtual ~BackgroundDataBridgeParent() = default;
uint64_t mChannelID;
nsCOMPtr<nsISerialEventTarget> mBackgroundThread;
nsCOMPtr<nsIThread> mBackgroundThread;
};
} // namespace net

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

@ -12,7 +12,6 @@
#include "HttpChannelChild.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/net/BackgroundDataBridgeChild.h"
@ -54,17 +53,23 @@ nsresult HttpBackgroundChannelChild::Init(HttpChannelChild* aChannelChild) {
return NS_OK;
}
void HttpBackgroundChannelChild::CreateDataBridge(
Endpoint<PBackgroundDataBridgeChild>&& aEndpoint) {
void HttpBackgroundChannelChild::CreateDataBridge() {
MOZ_ASSERT(OnSocketThread());
if (!mChannelChild) {
return;
}
PBackgroundChild* actorChild =
BackgroundChild::GetOrCreateSocketActorForCurrentThread();
if (NS_WARN_IF(!actorChild)) {
return;
}
RefPtr<BackgroundDataBridgeChild> dataBridgeChild =
new BackgroundDataBridgeChild(this);
aEndpoint.Bind(dataBridgeChild);
Unused << actorChild->SendPBackgroundDataBridgeConstructor(
dataBridgeChild, mChannelChild->ChannelId());
}
void HttpBackgroundChannelChild::OnChannelClosed() {

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

@ -9,7 +9,6 @@
#define mozilla_net_HttpBackgroundChannelChild_h
#include "mozilla/net/PHttpBackgroundChannelChild.h"
#include "mozilla/ipc/Endpoint.h"
#include "nsIRunnable.h"
#include "nsTArray.h"
@ -18,7 +17,6 @@ using mozilla::ipc::IPCResult;
namespace mozilla {
namespace net {
class PBackgroundDataBridgeChild;
class BackgroundDataBridgeChild;
class HttpChannelChild;
@ -97,7 +95,7 @@ class HttpBackgroundChannelChild final : public PHttpBackgroundChannelChild {
void ActorDestroy(ActorDestroyReason aWhy) override;
void CreateDataBridge(Endpoint<PBackgroundDataBridgeChild>&& aEndpoint);
void CreateDataBridge();
private:
virtual ~HttpBackgroundChannelChild();

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

@ -8,7 +8,6 @@
// HttpLog.h should generally be included first
#include "HttpLog.h"
#include "mozilla/net/PBackgroundDataBridge.h"
#include "nsHttp.h"
#include "nsICacheEntry.h"
#include "mozilla/BasePrincipal.h"
@ -3171,20 +3170,11 @@ void HttpChannelChild::MaybeConnectToSocketProcess() {
}
SocketProcessBridgeChild::GetSocketProcessBridge()->Then(
GetCurrentSerialEventTarget(), __func__,
[bgChild, channelId = ChannelId()](
const RefPtr<SocketProcessBridgeChild>& aBridge) {
Endpoint<PBackgroundDataBridgeParent> parentEndpoint;
Endpoint<PBackgroundDataBridgeChild> childEndpoint;
PBackgroundDataBridge::CreateEndpoints(&parentEndpoint, &childEndpoint);
aBridge->SendInitBackgroundDataBridge(std::move(parentEndpoint),
channelId);
[bgChild]() {
gSocketTransportService->Dispatch(
NS_NewRunnableFunction(
"HttpBackgroundChannelChild::CreateDataBridge",
[bgChild, endpoint = std::move(childEndpoint)]() mutable {
bgChild->CreateDataBridge(std::move(endpoint));
}),
NewRunnableMethod("HttpBackgroundChannelChild::CreateDataBridge",
bgChild,
&HttpBackgroundChannelChild::CreateDataBridge),
NS_DISPATCH_NORMAL);
},
[]() { NS_WARNING("Failed to create SocketProcessBridgeChild"); });

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

@ -10,6 +10,7 @@
#include "HttpTransactionChild.h"
#include "mozilla/ipc/IPCStreamUtils.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/net/BackgroundDataBridgeParent.h"
#include "mozilla/net/ChannelEventQueue.h"
#include "mozilla/net/InputChannelThrottleQueueChild.h"
@ -26,6 +27,8 @@
#include "nsSerializationHelper.h"
#include "OpaqueResponseUtils.h"
using mozilla::ipc::BackgroundParent;
namespace mozilla::net {
NS_IMPL_ISUPPORTS(HttpTransactionChild, nsIRequestObserver, nsIStreamListener,
@ -285,6 +288,7 @@ HttpTransactionChild::OnDataAvailable(nsIRequest* aRequest,
return NS_OK;
}
ipc::AssertIsOnBackgroundThread();
MOZ_ASSERT(mDataBridgeParent);
if (!mDataBridgeParent->CanSend()) {
@ -446,7 +450,7 @@ HttpTransactionChild::OnStartRequest(nsIRequest* aRequest) {
if (dataBridgeParent) {
mDataBridgeParent = std::move(dataBridgeParent.ref());
nsCOMPtr<nsISerialEventTarget> backgroundThread =
nsCOMPtr<nsIThread> backgroundThread =
mDataBridgeParent->GetBackgroundThread();
nsCOMPtr<nsIThreadRetargetableRequest> retargetableTransactionPump;
retargetableTransactionPump = do_QueryObject(mTransactionPump);

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

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBackground;
include HttpChannelParams;
include NeckoChannelParams;
@ -11,6 +12,8 @@ namespace net {
//-------------------------------------------------------------------
async protocol PBackgroundDataBridge
{
manager PBackground;
child:
async OnTransportAndData(uint64_t offset,
uint32_t count,

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

@ -6,6 +6,8 @@
include "mozilla/ipc/TransportSecurityInfoUtils.h";
include protocol PBackground;
[RefCounted] using class nsITransportSecurityInfo from "nsITransportSecurityInfo.h";
namespace mozilla {
@ -13,6 +15,8 @@ namespace net {
protocol PWebSocketConnection
{
manager PBackground;
parent:
async OnTransportAvailable(nullable nsITransportSecurityInfo aSecurityInfo);
async OnError(nsresult aStatus);

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

@ -8,7 +8,8 @@
#include "WebSocketConnectionChild.h"
#include "WebSocketConnection.h"
#include "mozilla/net/SocketProcessBackgroundChild.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "nsISerializable.h"
#include "nsITLSSocketControl.h"
#include "nsITransportSecurityInfo.h"
@ -31,8 +32,6 @@ WebSocketConnectionChild::~WebSocketConnectionChild() {
}
void WebSocketConnectionChild::Init(uint32_t aListenerId) {
MOZ_ASSERT(NS_IsMainThread());
nsresult rv;
mSocketThread = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
MOZ_ASSERT(NS_SUCCEEDED(rv));
@ -40,24 +39,17 @@ void WebSocketConnectionChild::Init(uint32_t aListenerId) {
return;
}
ipc::Endpoint<PWebSocketConnectionParent> parentEndpoint;
ipc::Endpoint<PWebSocketConnectionChild> childEndpoint;
PWebSocketConnection::CreateEndpoints(&parentEndpoint, &childEndpoint);
if (NS_FAILED(SocketProcessBackgroundChild::WithActor(
"SendInitWebSocketConnection",
[aListenerId, endpoint = std::move(parentEndpoint)](
SocketProcessBackgroundChild* aActor) mutable {
Unused << aActor->SendInitWebSocketConnection(std::move(endpoint),
aListenerId);
}))) {
return;
}
RefPtr<WebSocketConnectionChild> self = this;
mSocketThread->Dispatch(NS_NewRunnableFunction(
"BindWebSocketConnectionChild",
[self = RefPtr{this}, endpoint = std::move(childEndpoint)]() mutable {
endpoint.Bind(self);
"WebSocketConnectionChild::Init", [self, aListenerId]() {
mozilla::ipc::PBackgroundChild* actorChild = mozilla::ipc::
BackgroundChild::GetOrCreateForSocketParentBridgeForCurrentThread();
if (!actorChild) {
return;
}
Unused << actorChild->SendPWebSocketConnectionConstructor(self,
aListenerId);
}));
}

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

@ -7,6 +7,7 @@
#include "WebSocketLog.h"
#include "WebSocketConnectionParent.h"
#include "nsIHttpChannelInternal.h"
#include "nsITransportSecurityInfo.h"
#include "nsSerializationHelper.h"
#include "nsThreadUtils.h"
@ -102,10 +103,6 @@ void WebSocketConnectionParent::ActorDestroy(ActorDestroyReason aWhy) {
listener->OnError(NS_ERROR_FAILURE);
}
}
mBackgroundThread->Dispatch(NS_NewRunnableFunction(
"WebSocketConnectionParent::DefereredDestroy", [self = RefPtr{this}]() {
LOG(("WebSocketConnectionParent::DefereredDestroy"));
}));
};
nsresult WebSocketConnectionParent::Init(
@ -126,9 +123,7 @@ void WebSocketConnectionParent::Close() {
mClosed = true;
auto task = [self = RefPtr{this}]() {
self->PWebSocketConnectionParent::Close();
};
auto task = [self = RefPtr{this}]() { Unused << self->Send__delete__(self); };
if (mBackgroundThread->IsOnCurrentThread()) {
task();

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

@ -56,7 +56,7 @@ class WebSocketConnectionParent final : public PWebSocketConnectionParent,
nsCOMPtr<nsIHttpUpgradeListener> mUpgradeListener;
RefPtr<WebSocketConnectionListener> mListener;
nsCOMPtr<nsISerialEventTarget> mBackgroundThread;
nsCOMPtr<nsIEventTarget> mBackgroundThread;
nsCOMPtr<nsITransportSecurityInfo> mSecurityInfo;
Atomic<bool> mClosed{false};
Mutex mMutex MOZ_UNANNOTATED{"WebSocketConnectionParent::mMutex"};

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

@ -11,6 +11,7 @@
#include "nsNSSIOLayer.h"
#include "mozilla/SyncRunnable.h"
#include "mozilla/ipc/BackgroundParent.h"
namespace mozilla::psm {

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

@ -12,14 +12,14 @@
namespace mozilla {
namespace net {
class SocketProcessBackgroundParent;
} // namespace net
namespace ipc {
class BackgroundParentImpl;
} // namespace ipc
namespace psm {
class IPCClientCertsParent final : public PIPCClientCertsParent {
friend class mozilla::net::SocketProcessBackgroundParent;
friend class mozilla::ipc::BackgroundParentImpl;
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(IPCClientCertsParent)

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

@ -3,6 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBackground;
include PSMIPCTypes;
using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h";
@ -12,6 +14,8 @@ namespace psm {
sync protocol PIPCClientCerts
{
manager PBackground;
parent:
// Called from the socket process to the parent process to find client
// certificates and associated keys.

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

@ -5,6 +5,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBackground;
include PSMIPCTypes;
namespace mozilla {
@ -12,6 +13,8 @@ namespace psm {
protocol PSelectTLSClientAuthCert
{
manager PBackground;
child:
async TLSClientAuthCertSelected(ByteArray aSelectedCertBytes,
ByteArray[] aSelectedCertChainBytes);

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

@ -5,15 +5,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBackground;
include PSMIPCTypes;
using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h";
namespace mozilla {
namespace psm {
protocol PVerifySSLServerCert
{
manager PBackground;
child:
async OnVerifiedSSLServerCertSuccess(ByteArray[] aBuiltCertChain,
uint16_t aCertTransparencyStatus,

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

@ -27,8 +27,9 @@
#include "TLSClientAuthCertSelection.h"
#include "cert_storage/src/cert_storage.h"
#include "mozilla/Logging.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/net/SocketProcessBackgroundChild.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "mozilla/psm/SelectTLSClientAuthCertChild.h"
#include "mozilla/psm/SelectTLSClientAuthCertParent.h"
#include "nsArray.h"
@ -749,30 +750,15 @@ SECStatus SSLGetClientAuthDataHook(void* arg, PRFileDesc* socket,
hostname(std::move(hostname)),
originAttributes(std::move(originAttributes)), port, providerFlags,
providerTlsFlags, serverCertBytes(std::move(serverCertBytes)),
caNamesBytes(std::move(caNamesBytes))]() mutable {
ipc::Endpoint<PSelectTLSClientAuthCertParent> parentEndpoint;
ipc::Endpoint<PSelectTLSClientAuthCertChild> childEndpoint;
PSelectTLSClientAuthCert::CreateEndpoints(&parentEndpoint,
&childEndpoint);
if (NS_FAILED(net::SocketProcessBackgroundChild::WithActor(
"SendInitSelectTLSClientAuthCert",
[endpoint = std::move(parentEndpoint),
hostname(std::move(hostname)),
originAttributes(std::move(originAttributes)), port,
providerFlags, providerTlsFlags,
serverCertBytes(std::move(serverCertBytes)),
caNamesBytes(std::move(caNamesBytes))](
net::SocketProcessBackgroundChild* aActor) mutable {
Unused << aActor->SendInitSelectTLSClientAuthCert(
std::move(endpoint), hostname, originAttributes,
port, providerFlags, providerTlsFlags,
ByteArray(serverCertBytes), caNamesBytes);
}))) {
return;
}
if (!childEndpoint.Bind(selectClientAuthCertificate)) {
return;
caNamesBytes(std::move(caNamesBytes))]() {
mozilla::ipc::PBackgroundChild* actorChild =
mozilla::ipc::BackgroundChild::
GetOrCreateForSocketParentBridgeForCurrentThread();
if (actorChild) {
Unused << actorChild->SendPSelectTLSClientAuthCertConstructor(
selectClientAuthCertificate, hostname, originAttributes,
port, providerFlags, providerTlsFlags,
ByteArray(serverCertBytes), caNamesBytes);
}
}));
info->SetPendingSelectClientAuthCertificate(
@ -794,6 +780,9 @@ SECStatus SSLGetClientAuthDataHook(void* arg, PRFileDesc* socket,
return SECWouldBlock;
}
using mozilla::ipc::AssertIsOnBackgroundThread;
using mozilla::ipc::IsOnBackgroundThread;
// Helper continuation for when a client authentication certificate has been
// selected in the parent process and the information needs to be sent to the
// socket process.
@ -803,13 +792,13 @@ class RemoteClientAuthCertificateSelected
explicit RemoteClientAuthCertificateSelected(
SelectTLSClientAuthCertParent* selectTLSClientAuthCertParent)
: mSelectTLSClientAuthCertParent(selectTLSClientAuthCertParent),
mEventTarget(GetCurrentSerialEventTarget()) {}
mEventTarget(NS_GetCurrentThread()) {}
NS_IMETHOD Run() override;
private:
RefPtr<SelectTLSClientAuthCertParent> mSelectTLSClientAuthCertParent;
nsCOMPtr<nsISerialEventTarget> mEventTarget;
nsCOMPtr<nsIEventTarget> mEventTarget;
};
NS_IMETHODIMP
@ -886,6 +875,8 @@ bool SelectTLSClientAuthCertParent::Dispatch(
void SelectTLSClientAuthCertParent::TLSClientAuthCertSelected(
const nsTArray<uint8_t>& aSelectedCertBytes,
nsTArray<nsTArray<uint8_t>>&& aSelectedCertChainBytes) {
AssertIsOnBackgroundThread();
if (!CanSend()) {
return;
}
@ -897,7 +888,7 @@ void SelectTLSClientAuthCertParent::TLSClientAuthCertSelected(
Unused << SendTLSClientAuthCertSelected(aSelectedCertBytes,
selectedCertChainBytes);
Close();
Unused << Send__delete__(this);
}
void SelectTLSClientAuthCertParent::ActorDestroy(

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

@ -8,9 +8,8 @@
#include "VerifySSLServerCertChild.h"
#include "CertVerifier.h"
#include "mozilla/net/SocketProcessBackgroundChild.h"
#include "mozilla/psm/PVerifySSLServerCertParent.h"
#include "mozilla/psm/PVerifySSLServerCertChild.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "nsNSSIOLayer.h"
#include "nsSerializationHelper.h"
@ -99,33 +98,19 @@ SECStatus RemoteProcessCertVerification(
dcInfo.ref().authKeyBits() = static_cast<uint32_t>(aDcInfo->authKeyBits);
}
ipc::Endpoint<PVerifySSLServerCertParent> parentEndpoint;
ipc::Endpoint<PVerifySSLServerCertChild> childEndpoint;
PVerifySSLServerCert::CreateEndpoints(&parentEndpoint, &childEndpoint);
if (NS_FAILED(net::SocketProcessBackgroundChild::WithActor(
"SendInitVerifySSLServerCert",
[endpoint = std::move(parentEndpoint),
peerCertBytes = std::move(peerCertBytes),
hostName = PromiseFlatCString(aHostName), port(aPort),
originAttributes(aOriginAttributes),
stapledOCSPResponse = std::move(stapledOCSPResponse),
sctsFromTLSExtension = std::move(sctsFromTLSExtension),
dcInfo = std::move(dcInfo), providerFlags(aProviderFlags),
certVerifierFlags(aCertVerifierFlags)](
net::SocketProcessBackgroundChild* aActor) mutable {
Unused << aActor->SendInitVerifySSLServerCert(
std::move(endpoint), peerCertBytes, hostName, port,
originAttributes, stapledOCSPResponse, sctsFromTLSExtension,
dcInfo, providerFlags, certVerifierFlags);
}))) {
mozilla::ipc::PBackgroundChild* actorChild = mozilla::ipc::BackgroundChild::
GetOrCreateForSocketParentBridgeForCurrentThread();
if (!actorChild) {
PR_SetError(SEC_ERROR_LIBRARY_FAILURE, 0);
return SECFailure;
}
RefPtr<VerifySSLServerCertChild> authCert = new VerifySSLServerCertChild(
aResultTask, std::move(aPeerCertChain), aProviderFlags);
if (!childEndpoint.Bind(authCert)) {
if (!actorChild->SendPVerifySSLServerCertConstructor(
authCert, peerCertBytes, PromiseFlatCString(aHostName), aPort,
aOriginAttributes, stapledOCSPResponse, sctsFromTLSExtension, dcInfo,
aProviderFlags, aCertVerifierFlags)) {
PR_SetError(SEC_ERROR_LIBRARY_FAILURE, 0);
return SECFailure;
}

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

@ -15,10 +15,14 @@
#include "SSLServerCertVerification.h"
#include "nsNSSIOLayer.h"
#include "nsISocketProvider.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/Unused.h"
extern mozilla::LazyLogModule gPIPNSSLog;
using mozilla::ipc::AssertIsOnBackgroundThread;
using mozilla::ipc::IsOnBackgroundThread;
using namespace mozilla::pkix;
namespace mozilla {
@ -31,6 +35,8 @@ void VerifySSLServerCertParent::OnVerifiedSSLServerCert(
uint16_t aCertificateTransparencyStatus, uint8_t aEVStatus, bool aSucceeded,
PRErrorCode aFinalError, uint32_t aOverridableErrorCategory,
bool aIsBuiltCertChainRootBuiltInRoot, bool aMadeOCSPRequests) {
AssertIsOnBackgroundThread();
if (!CanSend()) {
return;
}
@ -43,8 +49,7 @@ void VerifySSLServerCertParent::OnVerifiedSSLServerCert(
Unused << SendOnVerifiedSSLServerCertFailure(
aFinalError, aOverridableErrorCategory, aMadeOCSPRequests);
}
Close();
Unused << Send__delete__(this);
}
namespace {
@ -129,8 +134,9 @@ bool VerifySSLServerCertParent::Dispatch(
const Maybe<DelegatedCredentialInfoArg>& aDcInfo,
const uint32_t& aProviderFlags, const uint32_t& aCertVerifierFlags) {
MOZ_LOG(gPIPNSSLog, LogLevel::Debug, ("VerifySSLServerCertParent::Dispatch"));
AssertIsOnBackgroundThread();
mBackgroundThread = GetCurrentSerialEventTarget();
mBackgroundThread = NS_GetCurrentThread();
nsTArray<nsTArray<uint8_t>> peerCertBytes;
for (auto& certBytes : aPeerCertChain) {

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

@ -51,7 +51,7 @@ class VerifySSLServerCertParent : public PVerifySSLServerCertParent {
// PVerifySSLServerCertParent
void ActorDestroy(ActorDestroyReason aWhy) override;
nsCOMPtr<nsISerialEventTarget> mBackgroundThread;
nsCOMPtr<nsIEventTarget> mBackgroundThread;
};
} // namespace psm

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

@ -27,6 +27,8 @@
#include "mozilla/RandomNum.h"
#include "mozilla/StaticPrefs_security.h"
#include "mozilla/Telemetry.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "mozilla/net/SSLTokensCache.h"
#include "mozilla/net/SocketProcessChild.h"
#include "mozilla/psm/IPCClientCertsChild.h"
@ -1658,6 +1660,24 @@ loser:
return NS_ERROR_FAILURE;
}
already_AddRefed<IPCClientCertsChild> GetIPCClientCertsActor() {
PBackgroundChild* backgroundActor =
BackgroundChild::GetOrCreateForSocketParentBridgeForCurrentThread();
if (!backgroundActor) {
return nullptr;
}
RefPtr<PIPCClientCertsChild> actor =
SingleManagedOrNull(backgroundActor->ManagedPIPCClientCertsChild());
if (!actor) {
actor = backgroundActor->SendPIPCClientCertsConstructor(
new IPCClientCertsChild());
if (!actor) {
return nullptr;
}
}
return actor.forget().downcast<IPCClientCertsChild>();
}
extern "C" {
const uint8_t kIPCClientCertsObjectTypeCert = 1;
@ -1668,14 +1688,7 @@ const uint8_t kIPCClientCertsObjectTypeECKey = 3;
// parent process to find certificates and keys and send identifying
// information about them over IPC.
void DoFindObjects(FindObjectsCallback cb, void* ctx) {
net::SocketProcessChild* socketChild =
net::SocketProcessChild::GetSingleton();
if (!socketChild) {
return;
}
RefPtr<IPCClientCertsChild> ipcClientCertsActor(
socketChild->GetIPCClientCertsActor());
RefPtr<IPCClientCertsChild> ipcClientCertsActor(GetIPCClientCertsActor());
if (!ipcClientCertsActor) {
return;
}
@ -1719,14 +1732,7 @@ void DoFindObjects(FindObjectsCallback cb, void* ctx) {
void DoSign(size_t cert_len, const uint8_t* cert, size_t data_len,
const uint8_t* data, size_t params_len, const uint8_t* params,
SignCallback cb, void* ctx) {
net::SocketProcessChild* socketChild =
net::SocketProcessChild::GetSingleton();
if (!socketChild) {
return;
}
RefPtr<IPCClientCertsChild> ipcClientCertsActor(
socketChild->GetIPCClientCertsActor());
RefPtr<IPCClientCertsChild> ipcClientCertsActor(GetIPCClientCertsActor());
if (!ipcClientCertsActor) {
return;
}