summaryrefslogtreecommitdiffstats
path: root/dom/clients/manager/ClientHandleParent.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/clients/manager/ClientHandleParent.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/clients/manager/ClientHandleParent.cpp')
-rw-r--r--dom/clients/manager/ClientHandleParent.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/dom/clients/manager/ClientHandleParent.cpp b/dom/clients/manager/ClientHandleParent.cpp
new file mode 100644
index 0000000000..037a496544
--- /dev/null
+++ b/dom/clients/manager/ClientHandleParent.cpp
@@ -0,0 +1,115 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=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 "ClientHandleParent.h"
+
+#include "ClientHandleOpParent.h"
+#include "ClientManagerService.h"
+#include "ClientPrincipalUtils.h"
+#include "ClientSourceParent.h"
+#include "mozilla/dom/ClientIPCTypes.h"
+#include "mozilla/Unused.h"
+
+namespace mozilla::dom {
+
+using mozilla::ipc::IPCResult;
+
+IPCResult ClientHandleParent::RecvTeardown() {
+ Unused << Send__delete__(this);
+ return IPC_OK();
+}
+
+void ClientHandleParent::ActorDestroy(ActorDestroyReason aReason) {
+ if (mSource) {
+ mSource->DetachHandle(this);
+ mSource = nullptr;
+ } else {
+ if (!mSourcePromiseHolder.IsEmpty()) {
+ CopyableErrorResult rv;
+ rv.ThrowAbortError("Client aborted");
+ mSourcePromiseHolder.Reject(rv, __func__);
+ }
+
+ mSourcePromiseRequestHolder.DisconnectIfExists();
+ }
+}
+
+PClientHandleOpParent* ClientHandleParent::AllocPClientHandleOpParent(
+ const ClientOpConstructorArgs& aArgs) {
+ return new ClientHandleOpParent();
+}
+
+bool ClientHandleParent::DeallocPClientHandleOpParent(
+ PClientHandleOpParent* aActor) {
+ delete aActor;
+ return true;
+}
+
+IPCResult ClientHandleParent::RecvPClientHandleOpConstructor(
+ PClientHandleOpParent* aActor, const ClientOpConstructorArgs& aArgs) {
+ auto actor = static_cast<ClientHandleOpParent*>(aActor);
+ actor->Init(std::move(const_cast<ClientOpConstructorArgs&>(aArgs)));
+ return IPC_OK();
+}
+
+ClientHandleParent::ClientHandleParent()
+ : mService(ClientManagerService::GetOrCreateInstance()), mSource(nullptr) {}
+
+ClientHandleParent::~ClientHandleParent() { MOZ_DIAGNOSTIC_ASSERT(!mSource); }
+
+void ClientHandleParent::Init(const IPCClientInfo& aClientInfo) {
+ mClientId = aClientInfo.id();
+ mPrincipalInfo = aClientInfo.principalInfo();
+
+ // Callbacks are disconnected in ActorDestroy, so capturing `this` is safe.
+ mService->FindSource(aClientInfo.id(), aClientInfo.principalInfo())
+ ->Then(
+ GetCurrentSerialEventTarget(), __func__,
+ [this](bool) {
+ mSourcePromiseRequestHolder.Complete();
+ ClientSourceParent* source =
+ mService->FindExistingSource(mClientId, mPrincipalInfo);
+ if (source) {
+ FoundSource(source);
+ }
+ },
+ [this](const CopyableErrorResult&) {
+ mSourcePromiseRequestHolder.Complete();
+ Unused << Send__delete__(this);
+ })
+ ->Track(mSourcePromiseRequestHolder);
+}
+
+ClientSourceParent* ClientHandleParent::GetSource() const { return mSource; }
+
+RefPtr<SourcePromise> ClientHandleParent::EnsureSource() {
+ if (mSource) {
+ return SourcePromise::CreateAndResolve(mSource, __func__);
+ }
+
+ return mSourcePromiseHolder.Ensure(__func__);
+}
+
+void ClientHandleParent::FoundSource(ClientSourceParent* aSource) {
+ MOZ_ASSERT(aSource);
+ MOZ_ASSERT(aSource->Info().Id() == mClientId);
+ if (!ClientMatchPrincipalInfo(aSource->Info().PrincipalInfo(),
+ mPrincipalInfo)) {
+ if (mSourcePromiseHolder.IsEmpty()) {
+ CopyableErrorResult rv;
+ rv.ThrowAbortError("Client aborted");
+ mSourcePromiseHolder.Reject(rv, __func__);
+ }
+ Unused << Send__delete__(this);
+ return;
+ }
+
+ mSource = aSource;
+ mSource->AttachHandle(this);
+ mSourcePromiseHolder.ResolveIfExists(true, __func__);
+}
+
+} // namespace mozilla::dom