2017-10-26 22:08:41 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2017-05-25 17:50:32 +00:00
|
|
|
/* 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"
|
2018-05-31 20:30:29 +00:00
|
|
|
#include "mozilla/dom/PaymentRequest.h"
|
2017-05-25 17:50:32 +00:00
|
|
|
#include "mozilla/dom/PaymentRequestManager.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-05-31 20:30:29 +00:00
|
|
|
PaymentRequestChild::PaymentRequestChild(PaymentRequest* aRequest)
|
|
|
|
: mRequest(aRequest) {
|
|
|
|
mRequest->SetIPC(this);
|
2017-05-25 17:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PaymentRequestChild::RequestPayment(
|
|
|
|
const IPCPaymentActionRequest& aAction) {
|
2018-05-31 20:30:29 +00:00
|
|
|
if (!mRequest) {
|
2017-05-25 17:50:32 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2017-06-14 07:59:00 +00:00
|
|
|
if (!SendRequestPayment(aAction)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2017-05-25 17:50:32 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-14 07:59:00 +00:00
|
|
|
mozilla::ipc::IPCResult PaymentRequestChild::RecvRespondPayment(
|
|
|
|
const IPCPaymentActionResponse& aResponse) {
|
2018-05-31 20:30:29 +00:00
|
|
|
if (!mRequest) {
|
2017-06-14 07:59:00 +00:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
const IPCPaymentActionResponse& response = aResponse;
|
|
|
|
RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
|
|
|
|
MOZ_ASSERT(manager);
|
2018-05-31 23:20:51 +00:00
|
|
|
|
|
|
|
// Hold a strong reference to our request for the entire response.
|
|
|
|
RefPtr<PaymentRequest> request(mRequest);
|
|
|
|
nsresult rv = manager->RespondPayment(request, response);
|
2017-06-14 07:59:00 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-06-23 09:15:51 +00:00
|
|
|
mozilla::ipc::IPCResult PaymentRequestChild::RecvChangeShippingAddress(
|
|
|
|
const nsString& aRequestId, const IPCPaymentAddress& aAddress) {
|
2018-05-31 20:30:29 +00:00
|
|
|
if (!mRequest) {
|
2017-06-23 09:15:51 +00:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
|
|
|
|
MOZ_ASSERT(manager);
|
2018-05-31 23:20:51 +00:00
|
|
|
RefPtr<PaymentRequest> request(mRequest);
|
|
|
|
nsresult rv = manager->ChangeShippingAddress(request, aAddress);
|
2017-06-23 09:15:51 +00:00
|
|
|
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) {
|
2018-05-31 20:30:29 +00:00
|
|
|
if (!mRequest) {
|
2017-06-23 09:15:51 +00:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
|
|
|
|
MOZ_ASSERT(manager);
|
2018-05-31 23:20:51 +00:00
|
|
|
RefPtr<PaymentRequest> request(mRequest);
|
|
|
|
nsresult rv = manager->ChangeShippingOption(request, aOption);
|
2017-06-23 09:15:51 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-09-19 11:23:33 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-11-27 13:05:00 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2017-05-25 17:50:32 +00:00
|
|
|
void PaymentRequestChild::ActorDestroy(ActorDestroyReason aWhy) {
|
2018-05-31 20:30:29 +00:00
|
|
|
if (mRequest) {
|
2018-06-19 22:55:32 +00:00
|
|
|
DetachFromRequest(true);
|
2017-06-14 07:59:00 +00:00
|
|
|
}
|
2017-05-25 17:50:32 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 22:55:32 +00:00
|
|
|
void PaymentRequestChild::MaybeDelete(bool aCanBeInManager) {
|
2018-05-31 20:30:29 +00:00
|
|
|
if (mRequest) {
|
2018-06-19 22:55:32 +00:00
|
|
|
DetachFromRequest(aCanBeInManager);
|
2017-05-25 17:50:32 +00:00
|
|
|
Send__delete__(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-19 22:55:32 +00:00
|
|
|
void PaymentRequestChild::DetachFromRequest(bool aCanBeInManager) {
|
2018-05-31 20:30:29 +00:00
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
2018-06-19 22:55:32 +00:00
|
|
|
if (aCanBeInManager) {
|
|
|
|
RefPtr<PaymentRequestManager> manager =
|
|
|
|
PaymentRequestManager::GetSingleton();
|
|
|
|
MOZ_ASSERT(manager);
|
|
|
|
|
|
|
|
RefPtr<PaymentRequest> request(mRequest);
|
|
|
|
manager->RequestIPCOver(request);
|
|
|
|
}
|
2018-05-31 20:30:29 +00:00
|
|
|
|
|
|
|
mRequest->SetIPC(nullptr);
|
|
|
|
mRequest = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-25 17:50:32 +00:00
|
|
|
} // end of namespace dom
|
|
|
|
} // end of namespace mozilla
|