Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 : #include "mozilla/dom/PaymentRequestManager.h"
9 :
10 : namespace mozilla {
11 : namespace dom {
12 :
13 0 : PaymentRequestChild::PaymentRequestChild()
14 0 : : mActorAlive(true)
15 : {
16 0 : }
17 :
18 : nsresult
19 0 : PaymentRequestChild::RequestPayment(const IPCPaymentActionRequest& aAction)
20 : {
21 0 : if (!mActorAlive) {
22 0 : return NS_ERROR_FAILURE;
23 : }
24 0 : if (!SendRequestPayment(aAction)) {
25 0 : return NS_ERROR_FAILURE;
26 : }
27 0 : return NS_OK;
28 : }
29 :
30 : mozilla::ipc::IPCResult
31 0 : PaymentRequestChild::RecvRespondPayment(const IPCPaymentActionResponse& aResponse)
32 : {
33 0 : if (!mActorAlive) {
34 0 : return IPC_FAIL_NO_REASON(this);
35 : }
36 0 : const IPCPaymentActionResponse& response = aResponse;
37 0 : RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
38 0 : MOZ_ASSERT(manager);
39 0 : nsresult rv = manager->RespondPayment(response);
40 0 : if (NS_WARN_IF(NS_FAILED(rv))) {
41 0 : return IPC_FAIL_NO_REASON(this);
42 : }
43 0 : return IPC_OK();
44 : }
45 :
46 : mozilla::ipc::IPCResult
47 0 : PaymentRequestChild::RecvChangeShippingAddress(const nsString& aRequestId,
48 : const IPCPaymentAddress& aAddress)
49 : {
50 0 : if (!mActorAlive) {
51 0 : return IPC_FAIL_NO_REASON(this);
52 : }
53 0 : RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
54 0 : MOZ_ASSERT(manager);
55 0 : nsresult rv = manager->ChangeShippingAddress(aRequestId, aAddress);
56 0 : if (NS_WARN_IF(NS_FAILED(rv))) {
57 0 : return IPC_FAIL_NO_REASON(this);
58 : }
59 0 : return IPC_OK();
60 : }
61 :
62 : mozilla::ipc::IPCResult
63 0 : PaymentRequestChild::RecvChangeShippingOption(const nsString& aRequestId,
64 : const nsString& aOption)
65 : {
66 0 : if (!mActorAlive) {
67 0 : return IPC_FAIL_NO_REASON(this);
68 : }
69 0 : RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
70 0 : MOZ_ASSERT(manager);
71 0 : nsresult rv = manager->ChangeShippingOption(aRequestId, aOption);
72 0 : if (NS_WARN_IF(NS_FAILED(rv))) {
73 0 : return IPC_FAIL_NO_REASON(this);
74 : }
75 0 : return IPC_OK();
76 : }
77 :
78 : void
79 0 : PaymentRequestChild::ActorDestroy(ActorDestroyReason aWhy)
80 : {
81 0 : mActorAlive = false;
82 0 : RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
83 0 : MOZ_ASSERT(manager);
84 0 : nsresult rv = manager->ReleasePaymentChild(this);
85 0 : if (NS_WARN_IF(NS_FAILED(rv))) {
86 0 : MOZ_ASSERT(false);
87 : }
88 0 : }
89 :
90 : void
91 0 : PaymentRequestChild::MaybeDelete()
92 : {
93 0 : if (mActorAlive) {
94 0 : mActorAlive = false;
95 0 : Send__delete__(this);
96 : }
97 0 : }
98 :
99 : bool
100 0 : PaymentRequestChild::SendRequestPayment(const IPCPaymentActionRequest& aAction)
101 : {
102 0 : return PPaymentRequestChild::SendRequestPayment(aAction);
103 : }
104 :
105 : } // end of namespace dom
106 : } // end of namespace mozilla
|