Bug 1855138 - Add BackgroundParent::KillHardAsync method; r=nika,ipc-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D189482
This commit is contained in:
Jan Varga 2023-10-03 18:40:30 +00:00
Родитель 7f01b062f5
Коммит 15a964b8f8
3 изменённых файлов: 50 добавлений и 0 удалений

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

@ -184,6 +184,10 @@ class ParentImpl final : public BackgroundParentImpl {
// Forwarded from BackgroundParent.
static uint64_t GetChildID(PBackgroundParent* aBackgroundActor);
// Forwarded from BackgroundParent.
static void KillHardAsync(PBackgroundParent* aBackgroundActor,
const char* aReason);
// Forwarded from BackgroundParent.
static bool AllocStarter(ContentParent* aContent,
Endpoint<PBackgroundStarterParent>&& aEndpoint,
@ -653,6 +657,12 @@ uint64_t BackgroundParent::GetChildID(PBackgroundParent* aBackgroundActor) {
return ParentImpl::GetChildID(aBackgroundActor);
}
// static
void BackgroundParent::KillHardAsync(PBackgroundParent* aBackgroundActor,
const char* aReason) {
ParentImpl::KillHardAsync(aBackgroundActor, aReason);
}
// static
bool BackgroundParent::AllocStarter(
ContentParent* aContent, Endpoint<PBackgroundStarterParent>&& aEndpoint) {
@ -756,6 +766,38 @@ uint64_t ParentImpl::GetChildID(PBackgroundParent* aBackgroundActor) {
return 0;
}
// static
void ParentImpl::KillHardAsync(PBackgroundParent* aBackgroundActor,
const char* aReason) {
AssertIsInMainProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aBackgroundActor);
MOZ_ASSERT(BackgroundParent::IsOtherProcessActor(aBackgroundActor));
RefPtr<ThreadsafeContentParentHandle> handle =
GetContentParentHandle(aBackgroundActor);
MOZ_ASSERT(handle);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(
NS_NewRunnableFunction("ParentImpl::KillHardAsync",
[handle = std::move(handle), aReason]() {
mozilla::AssertIsOnMainThread();
if (RefPtr<ContentParent> contentParent =
handle->GetContentParent()) {
contentParent->KillHard(aReason);
}
}),
NS_DISPATCH_NORMAL));
// After we've scheduled killing of the remote process, also ensure we induce
// a connection error in the IPC channel to immediately stop all IPC
// communication on this channel.
if (aBackgroundActor->CanSend()) {
aBackgroundActor->GetIPCChannel()->InduceConnectionError();
}
}
// static
bool ParentImpl::AllocStarter(ContentParent* aContent,
Endpoint<PBackgroundStarterParent>&& aEndpoint,

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

@ -77,6 +77,9 @@ class BackgroundParent final {
static uint64_t GetChildID(PBackgroundParent* aBackgroundActor);
static void KillHardAsync(PBackgroundParent* aBackgroundActor,
const char* aReason);
private:
// Only called by ContentParent for cross-process actors.
static bool AllocStarter(ContentParent* aContent,

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

@ -816,6 +816,11 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBroadcastChannelConstructor(
return IPC_OK();
}
// XXX It's now possible to call KillHardAsync on the PBackground thread, so
// the checks can be done directly here.
// XXX Once BackgroundParent::ProcessingError calls KillHardAsync, we can
// just return IPC_FAIL() if a check fails.
RefPtr<CheckPrincipalRunnable> runnable =
new CheckPrincipalRunnable(parent.forget(), aPrincipalInfo, aOrigin);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));