tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PaymentRequestChild.cpp (4307B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "PaymentRequestChild.h"
      8 
      9 #include "mozilla/dom/PaymentRequest.h"
     10 #include "mozilla/dom/PaymentRequestManager.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 PaymentRequestChild::PaymentRequestChild(PaymentRequest* aRequest)
     15    : mRequest(aRequest) {
     16  mRequest->SetIPC(this);
     17 }
     18 
     19 nsresult PaymentRequestChild::RequestPayment(
     20    const IPCPaymentActionRequest& aAction) {
     21  if (!mRequest) {
     22    return NS_ERROR_FAILURE;
     23  }
     24  if (!SendRequestPayment(aAction)) {
     25    return NS_ERROR_FAILURE;
     26  }
     27  return NS_OK;
     28 }
     29 
     30 mozilla::ipc::IPCResult PaymentRequestChild::RecvRespondPayment(
     31    const IPCPaymentActionResponse& aResponse) {
     32  if (!mRequest) {
     33    return IPC_FAIL_NO_REASON(this);
     34  }
     35  const IPCPaymentActionResponse& response = aResponse;
     36  RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
     37  MOZ_ASSERT(manager);
     38 
     39  // Hold a strong reference to our request for the entire response.
     40  RefPtr<PaymentRequest> request(mRequest);
     41  nsresult rv = manager->RespondPayment(request, response);
     42  if (NS_WARN_IF(NS_FAILED(rv))) {
     43    return IPC_FAIL_NO_REASON(this);
     44  }
     45  return IPC_OK();
     46 }
     47 
     48 mozilla::ipc::IPCResult PaymentRequestChild::RecvChangeShippingAddress(
     49    const nsString& aRequestId, const IPCPaymentAddress& aAddress) {
     50  if (!mRequest) {
     51    return IPC_FAIL_NO_REASON(this);
     52  }
     53  RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
     54  MOZ_ASSERT(manager);
     55  RefPtr<PaymentRequest> request(mRequest);
     56  nsresult rv = manager->ChangeShippingAddress(request, aAddress);
     57  if (NS_WARN_IF(NS_FAILED(rv))) {
     58    return IPC_FAIL_NO_REASON(this);
     59  }
     60  return IPC_OK();
     61 }
     62 
     63 mozilla::ipc::IPCResult PaymentRequestChild::RecvChangeShippingOption(
     64    const nsString& aRequestId, const nsString& aOption) {
     65  if (!mRequest) {
     66    return IPC_FAIL_NO_REASON(this);
     67  }
     68  RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
     69  MOZ_ASSERT(manager);
     70  RefPtr<PaymentRequest> request(mRequest);
     71  nsresult rv = manager->ChangeShippingOption(request, aOption);
     72  if (NS_WARN_IF(NS_FAILED(rv))) {
     73    return IPC_FAIL_NO_REASON(this);
     74  }
     75  return IPC_OK();
     76 }
     77 
     78 mozilla::ipc::IPCResult PaymentRequestChild::RecvChangePayerDetail(
     79    const nsString& aRequestId, const nsString& aPayerName,
     80    const nsString& aPayerEmail, const nsString& aPayerPhone) {
     81  if (!mRequest) {
     82    return IPC_FAIL_NO_REASON(this);
     83  }
     84  RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
     85  MOZ_ASSERT(manager);
     86  RefPtr<PaymentRequest> request(mRequest);
     87  nsresult rv =
     88      manager->ChangePayerDetail(request, aPayerName, aPayerEmail, aPayerPhone);
     89  if (NS_WARN_IF(NS_FAILED(rv))) {
     90    return IPC_FAIL_NO_REASON(this);
     91  }
     92  return IPC_OK();
     93 }
     94 
     95 mozilla::ipc::IPCResult PaymentRequestChild::RecvChangePaymentMethod(
     96    const nsString& aRequestId, const nsString& aMethodName,
     97    const IPCMethodChangeDetails& aMethodDetails) {
     98  if (!mRequest) {
     99    return IPC_FAIL_NO_REASON(this);
    100  }
    101  RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
    102  MOZ_ASSERT(manager);
    103  RefPtr<PaymentRequest> request(mRequest);
    104  nsresult rv =
    105      manager->ChangePaymentMethod(request, aMethodName, aMethodDetails);
    106  if (NS_WARN_IF(NS_FAILED(rv))) {
    107    return IPC_FAIL_NO_REASON(this);
    108  }
    109  return IPC_OK();
    110 }
    111 
    112 void PaymentRequestChild::ActorDestroy(ActorDestroyReason aWhy) {
    113  if (mRequest) {
    114    DetachFromRequest(true);
    115  }
    116 }
    117 
    118 void PaymentRequestChild::MaybeDelete(bool aCanBeInManager) {
    119  if (mRequest) {
    120    DetachFromRequest(aCanBeInManager);
    121    Send__delete__(this);
    122  }
    123 }
    124 
    125 void PaymentRequestChild::DetachFromRequest(bool aCanBeInManager) {
    126  MOZ_ASSERT(mRequest);
    127 
    128  if (aCanBeInManager) {
    129    RefPtr<PaymentRequestManager> manager =
    130        PaymentRequestManager::GetSingleton();
    131    MOZ_ASSERT(manager);
    132 
    133    RefPtr<PaymentRequest> request(mRequest);
    134    manager->RequestIPCOver(request);
    135  }
    136 
    137  mRequest->SetIPC(nullptr);
    138  mRequest = nullptr;
    139 }
    140 
    141 }  // namespace mozilla::dom