/src/mozilla-central/dom/payments/ipc/PaymentRequestChild.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | #include "mozilla/dom/PaymentRequest.h" |
9 | | #include "mozilla/dom/PaymentRequestManager.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace dom { |
13 | | |
14 | | PaymentRequestChild::PaymentRequestChild(PaymentRequest* aRequest) |
15 | | : mRequest(aRequest) |
16 | 0 | { |
17 | 0 | mRequest->SetIPC(this); |
18 | 0 | } |
19 | | |
20 | | nsresult |
21 | | PaymentRequestChild::RequestPayment(const IPCPaymentActionRequest& aAction) |
22 | 0 | { |
23 | 0 | if (!mRequest) { |
24 | 0 | return NS_ERROR_FAILURE; |
25 | 0 | } |
26 | 0 | if (!SendRequestPayment(aAction)) { |
27 | 0 | return NS_ERROR_FAILURE; |
28 | 0 | } |
29 | 0 | return NS_OK; |
30 | 0 | } |
31 | | |
32 | | mozilla::ipc::IPCResult |
33 | | PaymentRequestChild::RecvRespondPayment(const IPCPaymentActionResponse& aResponse) |
34 | 0 | { |
35 | 0 | if (!mRequest) { |
36 | 0 | return IPC_FAIL_NO_REASON(this); |
37 | 0 | } |
38 | 0 | const IPCPaymentActionResponse& response = aResponse; |
39 | 0 | RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton(); |
40 | 0 | MOZ_ASSERT(manager); |
41 | 0 |
|
42 | 0 | // Hold a strong reference to our request for the entire response. |
43 | 0 | RefPtr<PaymentRequest> request(mRequest); |
44 | 0 | nsresult rv = manager->RespondPayment(request, response); |
45 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { |
46 | 0 | return IPC_FAIL_NO_REASON(this); |
47 | 0 | } |
48 | 0 | return IPC_OK(); |
49 | 0 | } |
50 | | |
51 | | mozilla::ipc::IPCResult |
52 | | PaymentRequestChild::RecvChangeShippingAddress(const nsString& aRequestId, |
53 | | const IPCPaymentAddress& aAddress) |
54 | 0 | { |
55 | 0 | if (!mRequest) { |
56 | 0 | return IPC_FAIL_NO_REASON(this); |
57 | 0 | } |
58 | 0 | RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton(); |
59 | 0 | MOZ_ASSERT(manager); |
60 | 0 | RefPtr<PaymentRequest> request(mRequest); |
61 | 0 | nsresult rv = manager->ChangeShippingAddress(request, aAddress); |
62 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { |
63 | 0 | return IPC_FAIL_NO_REASON(this); |
64 | 0 | } |
65 | 0 | return IPC_OK(); |
66 | 0 | } |
67 | | |
68 | | mozilla::ipc::IPCResult |
69 | | PaymentRequestChild::RecvChangeShippingOption(const nsString& aRequestId, |
70 | | const nsString& aOption) |
71 | 0 | { |
72 | 0 | if (!mRequest) { |
73 | 0 | return IPC_FAIL_NO_REASON(this); |
74 | 0 | } |
75 | 0 | RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton(); |
76 | 0 | MOZ_ASSERT(manager); |
77 | 0 | RefPtr<PaymentRequest> request(mRequest); |
78 | 0 | nsresult rv = manager->ChangeShippingOption(request, aOption); |
79 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { |
80 | 0 | return IPC_FAIL_NO_REASON(this); |
81 | 0 | } |
82 | 0 | return IPC_OK(); |
83 | 0 | } |
84 | | |
85 | | mozilla::ipc::IPCResult |
86 | | PaymentRequestChild::RecvChangePayerDetail(const nsString& aRequestId, |
87 | | const nsString& aPayerName, |
88 | | const nsString& aPayerEmail, |
89 | | const nsString& aPayerPhone) |
90 | 0 | { |
91 | 0 | if (!mRequest) { |
92 | 0 | return IPC_FAIL_NO_REASON(this); |
93 | 0 | } |
94 | 0 | RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton(); |
95 | 0 | MOZ_ASSERT(manager); |
96 | 0 | RefPtr<PaymentRequest> request(mRequest); |
97 | 0 | nsresult rv = manager->ChangePayerDetail(request, aPayerName, aPayerEmail, aPayerPhone); |
98 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { |
99 | 0 | return IPC_FAIL_NO_REASON(this); |
100 | 0 | } |
101 | 0 | return IPC_OK(); |
102 | 0 | } |
103 | | |
104 | | void |
105 | | PaymentRequestChild::ActorDestroy(ActorDestroyReason aWhy) |
106 | 0 | { |
107 | 0 | if (mRequest) { |
108 | 0 | DetachFromRequest(true); |
109 | 0 | } |
110 | 0 | } |
111 | | |
112 | | void |
113 | | PaymentRequestChild::MaybeDelete(bool aCanBeInManager) |
114 | 0 | { |
115 | 0 | if (mRequest) { |
116 | 0 | DetachFromRequest(aCanBeInManager); |
117 | 0 | Send__delete__(this); |
118 | 0 | } |
119 | 0 | } |
120 | | |
121 | | void |
122 | | PaymentRequestChild::DetachFromRequest(bool aCanBeInManager) |
123 | 0 | { |
124 | 0 | MOZ_ASSERT(mRequest); |
125 | 0 |
|
126 | 0 | if (aCanBeInManager) { |
127 | 0 | RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton(); |
128 | 0 | MOZ_ASSERT(manager); |
129 | 0 |
|
130 | 0 | RefPtr<PaymentRequest> request(mRequest); |
131 | 0 | manager->RequestIPCOver(request); |
132 | 0 | } |
133 | 0 |
|
134 | 0 | mRequest->SetIPC(nullptr); |
135 | 0 | mRequest = nullptr; |
136 | 0 | } |
137 | | |
138 | | } // end of namespace dom |
139 | | } // end of namespace mozilla |