summaryrefslogtreecommitdiffstats
path: root/dom/payments/ipc/PaymentRequestChild.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/payments/ipc/PaymentRequestChild.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/payments/ipc/PaymentRequestChild.cpp')
-rw-r--r--dom/payments/ipc/PaymentRequestChild.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/dom/payments/ipc/PaymentRequestChild.cpp b/dom/payments/ipc/PaymentRequestChild.cpp
new file mode 100644
index 0000000000..a3a22bf346
--- /dev/null
+++ b/dom/payments/ipc/PaymentRequestChild.cpp
@@ -0,0 +1,140 @@
+/* -*- 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 "PaymentRequestChild.h"
+#include "mozilla/dom/PaymentRequest.h"
+#include "mozilla/dom/PaymentRequestManager.h"
+
+namespace mozilla::dom {
+
+PaymentRequestChild::PaymentRequestChild(PaymentRequest* aRequest)
+ : mRequest(aRequest) {
+ mRequest->SetIPC(this);
+}
+
+nsresult PaymentRequestChild::RequestPayment(
+ const IPCPaymentActionRequest& aAction) {
+ if (!mRequest) {
+ return NS_ERROR_FAILURE;
+ }
+ if (!SendRequestPayment(aAction)) {
+ return NS_ERROR_FAILURE;
+ }
+ return NS_OK;
+}
+
+mozilla::ipc::IPCResult PaymentRequestChild::RecvRespondPayment(
+ const IPCPaymentActionResponse& aResponse) {
+ if (!mRequest) {
+ return IPC_FAIL_NO_REASON(this);
+ }
+ const IPCPaymentActionResponse& response = aResponse;
+ RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
+ MOZ_ASSERT(manager);
+
+ // Hold a strong reference to our request for the entire response.
+ RefPtr<PaymentRequest> request(mRequest);
+ nsresult rv = manager->RespondPayment(request, response);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return IPC_FAIL_NO_REASON(this);
+ }
+ return IPC_OK();
+}
+
+mozilla::ipc::IPCResult PaymentRequestChild::RecvChangeShippingAddress(
+ const nsString& aRequestId, const IPCPaymentAddress& aAddress) {
+ if (!mRequest) {
+ return IPC_FAIL_NO_REASON(this);
+ }
+ RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
+ MOZ_ASSERT(manager);
+ RefPtr<PaymentRequest> request(mRequest);
+ nsresult rv = manager->ChangeShippingAddress(request, aAddress);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return IPC_FAIL_NO_REASON(this);
+ }
+ return IPC_OK();
+}
+
+mozilla::ipc::IPCResult PaymentRequestChild::RecvChangeShippingOption(
+ const nsString& aRequestId, const nsString& aOption) {
+ if (!mRequest) {
+ return IPC_FAIL_NO_REASON(this);
+ }
+ RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
+ MOZ_ASSERT(manager);
+ RefPtr<PaymentRequest> request(mRequest);
+ nsresult rv = manager->ChangeShippingOption(request, aOption);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return IPC_FAIL_NO_REASON(this);
+ }
+ return IPC_OK();
+}
+
+mozilla::ipc::IPCResult PaymentRequestChild::RecvChangePayerDetail(
+ const nsString& aRequestId, const nsString& aPayerName,
+ const nsString& aPayerEmail, const nsString& aPayerPhone) {
+ if (!mRequest) {
+ return IPC_FAIL_NO_REASON(this);
+ }
+ RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
+ MOZ_ASSERT(manager);
+ RefPtr<PaymentRequest> request(mRequest);
+ nsresult rv =
+ manager->ChangePayerDetail(request, aPayerName, aPayerEmail, aPayerPhone);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return IPC_FAIL_NO_REASON(this);
+ }
+ return IPC_OK();
+}
+
+mozilla::ipc::IPCResult PaymentRequestChild::RecvChangePaymentMethod(
+ const nsString& aRequestId, const nsString& aMethodName,
+ const IPCMethodChangeDetails& aMethodDetails) {
+ if (!mRequest) {
+ return IPC_FAIL_NO_REASON(this);
+ }
+ RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
+ MOZ_ASSERT(manager);
+ RefPtr<PaymentRequest> request(mRequest);
+ nsresult rv =
+ manager->ChangePaymentMethod(request, aMethodName, aMethodDetails);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return IPC_FAIL_NO_REASON(this);
+ }
+ return IPC_OK();
+}
+
+void PaymentRequestChild::ActorDestroy(ActorDestroyReason aWhy) {
+ if (mRequest) {
+ DetachFromRequest(true);
+ }
+}
+
+void PaymentRequestChild::MaybeDelete(bool aCanBeInManager) {
+ if (mRequest) {
+ DetachFromRequest(aCanBeInManager);
+ Send__delete__(this);
+ }
+}
+
+void PaymentRequestChild::DetachFromRequest(bool aCanBeInManager) {
+ MOZ_ASSERT(mRequest);
+
+ if (aCanBeInManager) {
+ RefPtr<PaymentRequestManager> manager =
+ PaymentRequestManager::GetSingleton();
+ MOZ_ASSERT(manager);
+
+ RefPtr<PaymentRequest> request(mRequest);
+ manager->RequestIPCOver(request);
+ }
+
+ mRequest->SetIPC(nullptr);
+ mRequest = nullptr;
+}
+
+} // namespace mozilla::dom