Bug Summary

File:root/firefox-clang/obj-x86_64-pc-linux-gnu/dom/payments/./../../../dom/payments/PaymentRequestService.cpp
Warning:line 563, column 5
Value stored to 'rv' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_dom_payments0.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/dom/payments -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/dom/payments -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -D _GLIBCXX_ASSERTIONS=1 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /root/firefox-clang/dom/payments -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dom/payments -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /root/firefox-clang/ipc/chromium/src -I /root/firefox-clang/third_party/abseil-cpp -I /root/firefox-clang/toolkit/components/telemetry -I /root/firefox-clang/xpcom/base -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-character-conversion -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c++ Unified_cpp_dom_payments0.cpp
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#include "PaymentRequestService.h"
6
7#include "BasicCardPayment.h"
8#include "mozilla/ClearOnShutdown.h"
9#include "mozilla/dom/BasicCardPaymentBinding.h"
10#include "mozilla/dom/PaymentRequestParent.h"
11#include "nsArrayUtils.h"
12#include "nsCOMPtr.h"
13#include "nsComponentManagerUtils.h"
14#include "nsIMutableArray.h"
15#include "nsServiceManagerUtils.h"
16#include "nsSimpleEnumerator.h"
17
18namespace mozilla::dom {
19
20StaticRefPtr<PaymentRequestService> gPaymentService;
21
22namespace {
23
24class PaymentRequestEnumerator final : public nsSimpleEnumerator {
25 public:
26 NS_DECL_NSISIMPLEENUMERATORvirtual nsresult HasMoreElements(bool *_retval) override; virtual
nsresult GetNext(nsISupports **_retval) override;
27
28 PaymentRequestEnumerator() : mIndex(0) {}
29
30 const nsID& DefaultInterface() override {
31 return NS_GET_IID(nsIPaymentRequest)(nsIPaymentRequest::kIID);
32 }
33
34 private:
35 ~PaymentRequestEnumerator() override = default;
36 uint32_t mIndex;
37};
38
39NS_IMETHODIMPnsresult
40PaymentRequestEnumerator::HasMoreElements(bool* aReturn) {
41 NS_ENSURE_ARG_POINTER(aReturn)do { if ((__builtin_expect(!!(!(aReturn)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aReturn" ") failed", nullptr
, "./../../../dom/payments/PaymentRequestService.cpp", 41); return
NS_ERROR_INVALID_POINTER; } } while (false)
;
42 *aReturn = false;
43 if (NS_WARN_IF(!gPaymentService)NS_warn_if_impl(!gPaymentService, "!gPaymentService", "./../../../dom/payments/PaymentRequestService.cpp"
, 43)
) {
44 return NS_ERROR_FAILURE;
45 }
46 RefPtr<PaymentRequestService> service = gPaymentService;
47 *aReturn = mIndex < service->NumPayments();
48 return NS_OK;
49}
50
51NS_IMETHODIMPnsresult
52PaymentRequestEnumerator::GetNext(nsISupports** aItem) {
53 NS_ENSURE_ARG_POINTER(aItem)do { if ((__builtin_expect(!!(!(aItem)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aItem" ") failed", nullptr
, "./../../../dom/payments/PaymentRequestService.cpp", 53); return
NS_ERROR_INVALID_POINTER; } } while (false)
;
54 if (NS_WARN_IF(!gPaymentService)NS_warn_if_impl(!gPaymentService, "!gPaymentService", "./../../../dom/payments/PaymentRequestService.cpp"
, 54)
) {
55 return NS_ERROR_FAILURE;
56 }
57 RefPtr<payments::PaymentRequest> rowRequest =
58 gPaymentService->GetPaymentRequestByIndex(mIndex);
59 if (!rowRequest) {
60 return NS_ERROR_FAILURE;
61 }
62 mIndex++;
63 rowRequest.forget(aItem);
64 return NS_OK;
65}
66
67} // end of anonymous namespace
68
69/* PaymentRequestService */
70
71NS_IMPL_ISUPPORTS(PaymentRequestService, nsIPaymentRequestService)MozExternalRefCountType PaymentRequestService::AddRef(void) {
static_assert(!std::is_destructible_v<PaymentRequestService
>, "Reference-counted class " "PaymentRequestService" " should not have a public destructor. "
"Make this class's destructor non-public"); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(int32_t
(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "./../../../dom/payments/PaymentRequestService.cpp"
, 71); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 71
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("PaymentRequestService" != nullptr)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!("PaymentRequestService" != nullptr))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("\"PaymentRequestService\" != nullptr"
" (" "Must specify a name" ")", "./../../../dom/payments/PaymentRequestService.cpp"
, 71); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"PaymentRequestService\" != nullptr"
") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null
, 71); __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("PaymentRequestService" " not thread-safe"); nsrefcnt count =
++mRefCnt; NS_LogAddRef((this), (count), ("PaymentRequestService"
), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType
PaymentRequestService::Release(void) { do { static_assert( mozilla
::detail::AssertionConditionType<decltype(int32_t(mRefCnt)
> 0)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(int32_t(mRefCnt) > 0))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release"
")", "./../../../dom/payments/PaymentRequestService.cpp", 71
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 71)
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("PaymentRequestService" != nullptr)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!("PaymentRequestService" != nullptr))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("\"PaymentRequestService\" != nullptr"
" (" "Must specify a name" ")", "./../../../dom/payments/PaymentRequestService.cpp"
, 71); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"PaymentRequestService\" != nullptr"
") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null
, 71); __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("PaymentRequestService" " not thread-safe"); const char* const
nametmp = "PaymentRequestService"; nsrefcnt count = --mRefCnt
; NS_LogRelease((this), (count), (nametmp)); if (count == 0) {
mRefCnt = 1; delete (this); return 0; } return count; } nsresult
PaymentRequestService::QueryInterface(const nsIID& aIID,
void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!"
, "aInstancePtr", "./../../../dom/payments/PaymentRequestService.cpp"
, 71); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(1 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<PaymentRequestService, nsIPaymentRequestService
>, int32_t( reinterpret_cast<char*>(static_cast<nsIPaymentRequestService
*>((PaymentRequestService*)0x1000)) - reinterpret_cast<
char*>((PaymentRequestService*)0x1000))}, {&mozilla::detail
::kImplementedIID<PaymentRequestService, nsISupports>, int32_t
(reinterpret_cast<char*>(static_cast<nsISupports*>
( static_cast<nsIPaymentRequestService*>((PaymentRequestService
*)0x1000))) - reinterpret_cast<char*>((PaymentRequestService
*)0x1000))}, { nullptr, 0 } } ; static_assert(std::size(table
) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI
(static_cast<void*>(this), aIID, aInstancePtr, table); return
rv; }
72
73already_AddRefed<PaymentRequestService> PaymentRequestService::GetSingleton() {
74 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../dom/payments/PaymentRequestService.cpp", 74); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { MOZ_CrashSequence
(__null, 74); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
75 if (!gPaymentService) {
76 gPaymentService = new PaymentRequestService();
77 ClearOnShutdown(&gPaymentService);
78 }
79 RefPtr<PaymentRequestService> service = gPaymentService;
80 return service.forget();
81}
82
83uint32_t PaymentRequestService::NumPayments() const {
84 return mRequestQueue.Length();
85}
86
87already_AddRefed<payments::PaymentRequest>
88PaymentRequestService::GetPaymentRequestByIndex(const uint32_t aIndex) {
89 if (aIndex >= mRequestQueue.Length()) {
90 return nullptr;
91 }
92 RefPtr<payments::PaymentRequest> request = mRequestQueue[aIndex];
93 MOZ_ASSERT(request)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(request)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(request))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("request", "./../../../dom/payments/PaymentRequestService.cpp"
, 93); AnnotateMozCrashReason("MOZ_ASSERT" "(" "request" ")")
; do { MOZ_CrashSequence(__null, 93); __attribute__((nomerge)
) ::abort(); } while (false); } } while (false)
;
94 return request.forget();
95}
96
97NS_IMETHODIMPnsresult
98PaymentRequestService::GetPaymentRequestById(const nsAString& aRequestId,
99 nsIPaymentRequest** aRequest) {
100 NS_ENSURE_ARG_POINTER(aRequest)do { if ((__builtin_expect(!!(!(aRequest)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aRequest" ") failed", nullptr
, "./../../../dom/payments/PaymentRequestService.cpp", 100); return
NS_ERROR_INVALID_POINTER; } } while (false)
;
101 *aRequest = nullptr;
102 RefPtr<payments::PaymentRequest> rowRequest;
103 nsresult rv = GetPaymentRequestById(aRequestId, getter_AddRefs(rowRequest));
104 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 104)
) {
105 return rv;
106 }
107 rowRequest.forget(aRequest);
108 return NS_OK;
109}
110
111nsresult PaymentRequestService::GetPaymentRequestById(
112 const nsAString& aRequestId, payments::PaymentRequest** aRequest) {
113 NS_ENSURE_ARG_POINTER(aRequest)do { if ((__builtin_expect(!!(!(aRequest)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aRequest" ") failed", nullptr
, "./../../../dom/payments/PaymentRequestService.cpp", 113); return
NS_ERROR_INVALID_POINTER; } } while (false)
;
114 *aRequest = nullptr;
115 uint32_t numRequests = mRequestQueue.Length();
116 for (uint32_t index = 0; index < numRequests; ++index) {
117 RefPtr<payments::PaymentRequest> request = mRequestQueue[index];
118 MOZ_ASSERT(request)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(request)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(request))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("request", "./../../../dom/payments/PaymentRequestService.cpp"
, 118); AnnotateMozCrashReason("MOZ_ASSERT" "(" "request" ")"
); do { MOZ_CrashSequence(__null, 118); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
119 nsAutoString requestId;
120 nsresult rv = request->GetRequestId(requestId);
121 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 121); return rv; } } while (false)
;
122 if (requestId == aRequestId) {
123 request.forget(aRequest);
124 break;
125 }
126 }
127 return NS_OK;
128}
129
130NS_IMETHODIMPnsresult
131PaymentRequestService::Enumerate(nsISimpleEnumerator** aEnumerator) {
132 NS_ENSURE_ARG_POINTER(aEnumerator)do { if ((__builtin_expect(!!(!(aEnumerator)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aEnumerator" ") failed"
, nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 132); return NS_ERROR_INVALID_POINTER; } } while (false)
;
133 nsCOMPtr<nsISimpleEnumerator> enumerator = new PaymentRequestEnumerator();
134 enumerator.forget(aEnumerator);
135 return NS_OK;
136}
137
138NS_IMETHODIMPnsresult
139PaymentRequestService::Cleanup() {
140 mRequestQueue.Clear();
141 return NS_OK;
142}
143
144NS_IMETHODIMPnsresult
145PaymentRequestService::SetTestingUIService(nsIPaymentUIService* aUIService) {
146 // aUIService can be nullptr
147 mTestingUIService = aUIService;
148 return NS_OK;
149}
150
151nsresult PaymentRequestService::LaunchUIAction(const nsAString& aRequestId,
152 uint32_t aActionType) {
153 nsCOMPtr<nsIPaymentUIService> uiService;
154 nsresult rv;
155 if (mTestingUIService) {
156 uiService = mTestingUIService;
157 } else {
158 uiService = do_GetService(NS_PAYMENT_UI_SERVICE_CONTRACT_ID"@mozilla.org/dom/payments/payment-ui-service;1", &rv);
159 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 159)
) {
160 return rv;
161 }
162 }
163 switch (aActionType) {
164 case IPCPaymentActionRequest::TIPCPaymentShowActionRequest: {
165 rv = uiService->ShowPayment(aRequestId);
166 break;
167 }
168 case IPCPaymentActionRequest::TIPCPaymentAbortActionRequest: {
169 rv = uiService->AbortPayment(aRequestId);
170 break;
171 }
172 case IPCPaymentActionRequest::TIPCPaymentCompleteActionRequest: {
173 rv = uiService->CompletePayment(aRequestId);
174 break;
175 }
176 case IPCPaymentActionRequest::TIPCPaymentUpdateActionRequest: {
177 rv = uiService->UpdatePayment(aRequestId);
178 break;
179 }
180 case IPCPaymentActionRequest::TIPCPaymentCloseActionRequest: {
181 rv = uiService->ClosePayment(aRequestId);
182 break;
183 }
184 default: {
185 return NS_ERROR_FAILURE;
186 }
187 }
188 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 188)
) {
189 return rv;
190 }
191 return NS_OK;
192}
193
194nsresult PaymentRequestService::RequestPayment(
195 const nsAString& aRequestId, const IPCPaymentActionRequest& aAction,
196 PaymentRequestParent* aIPC) {
197 NS_ENSURE_ARG_POINTER(aIPC)do { if ((__builtin_expect(!!(!(aIPC)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aIPC" ") failed", nullptr
, "./../../../dom/payments/PaymentRequestService.cpp", 197); return
NS_ERROR_INVALID_POINTER; } } while (false)
;
198
199 nsresult rv = NS_OK;
200 uint32_t type = aAction.type();
201
202 RefPtr<payments::PaymentRequest> request;
203 if (type != IPCPaymentActionRequest::TIPCPaymentCreateActionRequest) {
204 rv = GetPaymentRequestById(aRequestId, getter_AddRefs(request));
205 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 205)
) {
206 return rv;
207 }
208 if (!request &&
209 type != IPCPaymentActionRequest::TIPCPaymentCloseActionRequest) {
210 return NS_ERROR_FAILURE;
211 }
212 if (request) {
213 request->SetIPC(aIPC);
214 }
215 }
216
217 switch (type) {
218 case IPCPaymentActionRequest::TIPCPaymentCreateActionRequest: {
219 MOZ_ASSERT(!request)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!request)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!request))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("!request", "./../../../dom/payments/PaymentRequestService.cpp"
, 219); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!request" ")"
); do { MOZ_CrashSequence(__null, 219); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
220 const IPCPaymentCreateActionRequest& action = aAction;
221 nsCOMPtr<nsIMutableArray> methodData =
222 do_CreateInstance(NS_ARRAY_CONTRACTID"@mozilla.org/array;1");
223 MOZ_ASSERT(methodData)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(methodData)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(methodData))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("methodData", "./../../../dom/payments/PaymentRequestService.cpp"
, 223); AnnotateMozCrashReason("MOZ_ASSERT" "(" "methodData" ")"
); do { MOZ_CrashSequence(__null, 223); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
224 for (const IPCPaymentMethodData& data : action.methodData()) {
225 nsCOMPtr<nsIPaymentMethodData> method;
226 rv = payments::PaymentMethodData::Create(data, getter_AddRefs(method));
227 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 227); return rv; } } while (false)
;
228 rv = methodData->AppendElement(method);
229 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 229); return rv; } } while (false)
;
230 }
231 nsCOMPtr<nsIPaymentDetails> details;
232 rv = payments::PaymentDetails::Create(action.details(),
233 getter_AddRefs(details));
234 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 234); return rv; } } while (false)
;
235 nsCOMPtr<nsIPaymentOptions> options;
236 rv = payments::PaymentOptions::Create(action.options(),
237 getter_AddRefs(options));
238 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 238); return rv; } } while (false)
;
239 RefPtr<payments::PaymentRequest> request = new payments::PaymentRequest(
240 action.topOuterWindowId(), aRequestId, action.topLevelPrincipal(),
241 methodData, details, options, action.shippingOption());
242
243 if (!mRequestQueue.AppendElement(request, mozilla::fallible)) {
244 return NS_ERROR_OUT_OF_MEMORY;
245 }
246 break;
247 }
248 case IPCPaymentActionRequest::TIPCPaymentCanMakeActionRequest: {
249 nsCOMPtr<nsIPaymentCanMakeActionResponse> canMakeResponse =
250 do_CreateInstance(NS_PAYMENT_CANMAKE_ACTION_RESPONSE_CONTRACT_ID"@mozilla.org/dom/payments/payment-canmake-action-response;1");
251 MOZ_ASSERT(canMakeResponse)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(canMakeResponse)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(canMakeResponse))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("canMakeResponse"
, "./../../../dom/payments/PaymentRequestService.cpp", 251); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "canMakeResponse" ")"); do { MOZ_CrashSequence
(__null, 251); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
252 rv = canMakeResponse->Init(aRequestId, CanMakePayment(aRequestId));
253 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 253)
) {
254 return rv;
255 }
256 rv = RespondPayment(canMakeResponse.get());
257 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 257)
) {
258 return rv;
259 }
260 break;
261 }
262 case IPCPaymentActionRequest::TIPCPaymentShowActionRequest: {
263 const IPCPaymentShowActionRequest& action = aAction;
264 rv = ShowPayment(aRequestId, action.isUpdating());
265 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 265)
) {
266 return rv;
267 }
268 break;
269 }
270 case IPCPaymentActionRequest::TIPCPaymentAbortActionRequest: {
271 MOZ_ASSERT(request)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(request)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(request))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("request", "./../../../dom/payments/PaymentRequestService.cpp"
, 271); AnnotateMozCrashReason("MOZ_ASSERT" "(" "request" ")"
); do { MOZ_CrashSequence(__null, 271); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
272 request->SetState(payments::PaymentRequest::eInteractive);
273 rv = LaunchUIAction(aRequestId, type);
274 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 274)
) {
275 return rv;
276 }
277 break;
278 }
279 case IPCPaymentActionRequest::TIPCPaymentCompleteActionRequest: {
280 MOZ_ASSERT(request)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(request)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(request))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("request", "./../../../dom/payments/PaymentRequestService.cpp"
, 280); AnnotateMozCrashReason("MOZ_ASSERT" "(" "request" ")"
); do { MOZ_CrashSequence(__null, 280); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
281 const IPCPaymentCompleteActionRequest& action = aAction;
282 request->SetCompleteStatus(action.completeStatus());
283 rv = LaunchUIAction(aRequestId, type);
284 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 284)
) {
285 return rv;
286 }
287 break;
288 }
289 case IPCPaymentActionRequest::TIPCPaymentUpdateActionRequest: {
290 const IPCPaymentUpdateActionRequest& action = aAction;
291 nsCOMPtr<nsIPaymentDetails> details;
292 rv = payments::PaymentDetails::Create(action.details(),
293 getter_AddRefs(details));
294 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 294)
) {
295 return rv;
296 }
297 MOZ_ASSERT(request)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(request)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(request))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("request", "./../../../dom/payments/PaymentRequestService.cpp"
, 297); AnnotateMozCrashReason("MOZ_ASSERT" "(" "request" ")"
); do { MOZ_CrashSequence(__null, 297); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
298 rv = request->UpdatePaymentDetails(details, action.shippingOption());
299 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 299)
) {
300 return rv;
301 }
302 nsAutoString completeStatus;
303 rv = request->GetCompleteStatus(completeStatus);
304 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 304)
) {
305 return rv;
306 }
307 if (completeStatus.Equals(u"initial"_ns)) {
308 request->SetCompleteStatus(u""_ns);
309 }
310 MOZ_ASSERT(mShowingRequest && mShowingRequest == request)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mShowingRequest && mShowingRequest == request
)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(mShowingRequest && mShowingRequest == request
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mShowingRequest && mShowingRequest == request", "./../../../dom/payments/PaymentRequestService.cpp"
, 310); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mShowingRequest && mShowingRequest == request"
")"); do { MOZ_CrashSequence(__null, 310); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
311 rv = LaunchUIAction(aRequestId, type);
312 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 312)
) {
313 return rv;
314 }
315 break;
316 }
317 case IPCPaymentActionRequest::TIPCPaymentCloseActionRequest: {
318 rv = LaunchUIAction(aRequestId, type);
319 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 319)
) {
320 return rv;
321 }
322 if (mShowingRequest == request) {
323 mShowingRequest = nullptr;
324 }
325 mRequestQueue.RemoveElement(request);
326 break;
327 }
328 case IPCPaymentActionRequest::TIPCPaymentRetryActionRequest: {
329 const IPCPaymentRetryActionRequest& action = aAction;
330 MOZ_ASSERT(request)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(request)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(request))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("request", "./../../../dom/payments/PaymentRequestService.cpp"
, 330); AnnotateMozCrashReason("MOZ_ASSERT" "(" "request" ")"
); do { MOZ_CrashSequence(__null, 330); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
331 request->UpdateErrors(action.error(), action.payerErrors(),
332 action.paymentMethodErrors(),
333 action.shippingAddressErrors());
334 request->SetState(payments::PaymentRequest::eInteractive);
335 MOZ_ASSERT(mShowingRequest == request)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mShowingRequest == request)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mShowingRequest == request))
), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mShowingRequest == request"
, "./../../../dom/payments/PaymentRequestService.cpp", 335); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mShowingRequest == request" ")"); do { MOZ_CrashSequence
(__null, 335); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
336 rv = LaunchUIAction(
337 aRequestId, IPCPaymentActionRequest::TIPCPaymentUpdateActionRequest);
338 break;
339 }
340 default: {
341 return NS_ERROR_FAILURE;
342 }
343 }
344 return NS_OK;
345}
346
347NS_IMETHODIMPnsresult
348PaymentRequestService::RespondPayment(nsIPaymentActionResponse* aResponse) {
349 NS_ENSURE_ARG_POINTER(aResponse)do { if ((__builtin_expect(!!(!(aResponse)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aResponse" ") failed", nullptr
, "./../../../dom/payments/PaymentRequestService.cpp", 349); return
NS_ERROR_INVALID_POINTER; } } while (false)
;
350 nsAutoString requestId;
351 nsresult rv = aResponse->GetRequestId(requestId);
352 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 352); return rv; } } while (false)
;
353
354 RefPtr<payments::PaymentRequest> request;
355 rv = GetPaymentRequestById(requestId, getter_AddRefs(request));
356 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 356)
) {
357 return rv;
358 }
359 if (!request) {
360 return NS_ERROR_FAILURE;
361 }
362 uint32_t type;
363 rv = aResponse->GetType(&type);
364 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 364); return rv; } } while (false)
;
365
366 // PaymentRequest can only be responded when
367 // 1. the state is eInteractive
368 // 2. the state is eClosed and response type is COMPLETE_ACTION
369 // 3. the state is eCreated and response type is CANMAKE_ACTION
370 payments::PaymentRequest::eState state = request->GetState();
371 bool canBeResponded = (state == payments::PaymentRequest::eInteractive) ||
372 (state == payments::PaymentRequest::eClosed &&
373 type == nsIPaymentActionResponse::COMPLETE_ACTION) ||
374 (state == payments::PaymentRequest::eCreated &&
375 type == nsIPaymentActionResponse::CANMAKE_ACTION);
376 if (!canBeResponded) {
377 return NS_ERROR_FAILURE;
378 }
379
380 if (!request->GetIPC()) {
381 return NS_ERROR_FAILURE;
382 }
383 rv = request->GetIPC()->RespondPayment(aResponse);
384 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 384)
) {
385 return rv;
386 }
387
388 // Remove PaymentRequest from mRequestQueue while receive succeeded abort
389 // response or complete response
390 switch (type) {
391 case nsIPaymentActionResponse::ABORT_ACTION: {
392 nsCOMPtr<nsIPaymentAbortActionResponse> response =
393 do_QueryInterface(aResponse);
394 MOZ_ASSERT(response)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(response)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(response))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("response", "./../../../dom/payments/PaymentRequestService.cpp"
, 394); AnnotateMozCrashReason("MOZ_ASSERT" "(" "response" ")"
); do { MOZ_CrashSequence(__null, 394); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
395 bool isSucceeded;
396 rv = response->IsSucceeded(&isSucceeded);
397 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 397); return rv; } } while (false)
;
398 mShowingRequest = nullptr;
399 if (isSucceeded) {
400 mRequestQueue.RemoveElement(request);
401 request->SetState(payments::PaymentRequest::eClosed);
402 }
403 break;
404 }
405 case nsIPaymentActionResponse::SHOW_ACTION: {
406 request->SetState(payments::PaymentRequest::eClosed);
407 nsCOMPtr<nsIPaymentShowActionResponse> response =
408 do_QueryInterface(aResponse);
409 MOZ_ASSERT(response)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(response)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(response))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("response", "./../../../dom/payments/PaymentRequestService.cpp"
, 409); AnnotateMozCrashReason("MOZ_ASSERT" "(" "response" ")"
); do { MOZ_CrashSequence(__null, 409); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
410 uint32_t acceptStatus;
411 rv = response->GetAcceptStatus(&acceptStatus);
412 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 412); return rv; } } while (false)
;
413 if (acceptStatus != nsIPaymentActionResponse::PAYMENT_ACCEPTED) {
414 // Check if rejecting the showing PaymentRequest.
415 // If yes, set mShowingRequest as nullptr.
416 if (mShowingRequest == request) {
417 mShowingRequest = nullptr;
418 }
419 mRequestQueue.RemoveElement(request);
420 }
421 break;
422 }
423 case nsIPaymentActionResponse::COMPLETE_ACTION: {
424 mShowingRequest = nullptr;
425 mRequestQueue.RemoveElement(request);
426 break;
427 }
428 default: {
429 break;
430 }
431 }
432 return NS_OK;
433}
434
435NS_IMETHODIMPnsresult
436PaymentRequestService::ChangeShippingAddress(const nsAString& aRequestId,
437 nsIPaymentAddress* aAddress) {
438 RefPtr<payments::PaymentRequest> request;
439 nsresult rv = GetPaymentRequestById(aRequestId, getter_AddRefs(request));
440 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 440)
) {
441 return rv;
442 }
443 if (!request) {
444 return NS_ERROR_FAILURE;
445 }
446 if (request->GetState() != payments::PaymentRequest::eInteractive) {
447 return NS_ERROR_FAILURE;
448 }
449 if (!request->GetIPC()) {
450 return NS_ERROR_FAILURE;
451 }
452 rv = request->GetIPC()->ChangeShippingAddress(aRequestId, aAddress);
453 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 453)
) {
454 return rv;
455 }
456 return NS_OK;
457}
458
459NS_IMETHODIMPnsresult
460PaymentRequestService::ChangeShippingOption(const nsAString& aRequestId,
461 const nsAString& aOption) {
462 RefPtr<payments::PaymentRequest> request;
463 nsresult rv = GetPaymentRequestById(aRequestId, getter_AddRefs(request));
464 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 464)
) {
465 return rv;
466 }
467 if (!request) {
468 return NS_ERROR_FAILURE;
469 }
470 if (request->GetState() != payments::PaymentRequest::eInteractive) {
471 return NS_ERROR_FAILURE;
472 }
473 if (!request->GetIPC()) {
474 return NS_ERROR_FAILURE;
475 }
476 rv = request->GetIPC()->ChangeShippingOption(aRequestId, aOption);
477 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 477)
) {
478 return rv;
479 }
480 return NS_OK;
481}
482
483NS_IMETHODIMPnsresult
484PaymentRequestService::ChangePayerDetail(const nsAString& aRequestId,
485 const nsAString& aPayerName,
486 const nsAString& aPayerEmail,
487 const nsAString& aPayerPhone) {
488 RefPtr<payments::PaymentRequest> request;
489 nsresult rv = GetPaymentRequestById(aRequestId, getter_AddRefs(request));
490 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 490)
) {
491 return rv;
492 }
493 MOZ_ASSERT(request)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(request)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(request))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("request", "./../../../dom/payments/PaymentRequestService.cpp"
, 493); AnnotateMozCrashReason("MOZ_ASSERT" "(" "request" ")"
); do { MOZ_CrashSequence(__null, 493); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
494 if (!request->GetIPC()) {
495 return NS_ERROR_FAILURE;
496 }
497 rv = request->GetIPC()->ChangePayerDetail(aRequestId, aPayerName, aPayerEmail,
498 aPayerPhone);
499 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 499)
) {
500 return rv;
501 }
502 return NS_OK;
503}
504
505NS_IMETHODIMPnsresult
506PaymentRequestService::ChangePaymentMethod(
507 const nsAString& aRequestId, const nsAString& aMethodName,
508 nsIMethodChangeDetails* aMethodDetails) {
509 RefPtr<payments::PaymentRequest> request;
510 nsresult rv = GetPaymentRequestById(aRequestId, getter_AddRefs(request));
511 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 511)
) {
512 return rv;
513 }
514 if (!request) {
515 return NS_ERROR_FAILURE;
516 }
517 if (request->GetState() != payments::PaymentRequest::eInteractive) {
518 return NS_ERROR_FAILURE;
519 }
520 if (!request->GetIPC()) {
521 return NS_ERROR_FAILURE;
522 }
523 rv = request->GetIPC()->ChangePaymentMethod(aRequestId, aMethodName,
524 aMethodDetails);
525 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 525)
) {
526 return rv;
527 }
528 return NS_OK;
529}
530
531bool PaymentRequestService::CanMakePayment(const nsAString& aRequestId) {
532 /*
533 * TODO: Check third party payment app support by traversing all
534 * registered third party payment apps.
535 */
536 return IsBasicCardPayment(aRequestId);
537}
538
539nsresult PaymentRequestService::ShowPayment(const nsAString& aRequestId,
540 bool aIsUpdating) {
541 nsresult rv;
542 RefPtr<payments::PaymentRequest> request;
543 rv = GetPaymentRequestById(aRequestId, getter_AddRefs(request));
544 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 544)
) {
545 return rv;
546 }
547 MOZ_ASSERT(request)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(request)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(request))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("request", "./../../../dom/payments/PaymentRequestService.cpp"
, 547); AnnotateMozCrashReason("MOZ_ASSERT" "(" "request" ")"
); do { MOZ_CrashSequence(__null, 547); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
548 request->SetState(payments::PaymentRequest::eInteractive);
549 if (aIsUpdating) {
550 request->SetCompleteStatus(u"initial"_ns);
551 }
552
553 if (mShowingRequest || !CanMakePayment(aRequestId)) {
554 uint32_t responseStatus;
555 if (mShowingRequest) {
556 responseStatus = nsIPaymentActionResponse::PAYMENT_REJECTED;
557 } else {
558 responseStatus = nsIPaymentActionResponse::PAYMENT_NOTSUPPORTED;
559 }
560 nsCOMPtr<nsIPaymentShowActionResponse> showResponse =
561 do_CreateInstance(NS_PAYMENT_SHOW_ACTION_RESPONSE_CONTRACT_ID"@mozilla.org/dom/payments/payment-show-action-response;1");
562 MOZ_ASSERT(showResponse)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(showResponse)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(showResponse))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("showResponse", "./../../../dom/payments/PaymentRequestService.cpp"
, 562); AnnotateMozCrashReason("MOZ_ASSERT" "(" "showResponse"
")"); do { MOZ_CrashSequence(__null, 562); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
563 rv = showResponse->Init(aRequestId, responseStatus, u""_ns, nullptr, u""_ns,
Value stored to 'rv' is never read
564 u""_ns, u""_ns);
565 rv = RespondPayment(showResponse.get());
566 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 566)
) {
567 return rv;
568 }
569 } else {
570 mShowingRequest = request;
571 rv = LaunchUIAction(aRequestId,
572 IPCPaymentActionRequest::TIPCPaymentShowActionRequest);
573 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../dom/payments/PaymentRequestService.cpp"
, 573)
) {
574 return rv;
575 }
576 }
577 return NS_OK;
578}
579
580bool PaymentRequestService::IsBasicCardPayment(const nsAString& aRequestId) {
581 RefPtr<payments::PaymentRequest> request;
582 nsresult rv = GetPaymentRequestById(aRequestId, getter_AddRefs(request));
583 NS_ENSURE_SUCCESS(rv, false)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "false", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 583); return false; } } while (false)
;
584 nsCOMPtr<nsIArray> methods;
585 rv = request->GetPaymentMethods(getter_AddRefs(methods));
586 NS_ENSURE_SUCCESS(rv, false)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "false", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 586); return false; } } while (false)
;
587 uint32_t length;
588 rv = methods->GetLength(&length);
589 NS_ENSURE_SUCCESS(rv, false)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "false", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 589); return false; } } while (false)
;
590 RefPtr<BasicCardService> service = BasicCardService::GetService();
591 MOZ_ASSERT(service)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(service)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(service))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("service", "./../../../dom/payments/PaymentRequestService.cpp"
, 591); AnnotateMozCrashReason("MOZ_ASSERT" "(" "service" ")"
); do { MOZ_CrashSequence(__null, 591); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
592 for (uint32_t index = 0; index < length; ++index) {
593 nsCOMPtr<nsIPaymentMethodData> method = do_QueryElementAt(methods, index);
594 MOZ_ASSERT(method)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(method)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(method))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("method", "./../../../dom/payments/PaymentRequestService.cpp"
, 594); AnnotateMozCrashReason("MOZ_ASSERT" "(" "method" ")")
; do { MOZ_CrashSequence(__null, 594); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
595 nsAutoString supportedMethods;
596 rv = method->GetSupportedMethods(supportedMethods);
597 NS_ENSURE_SUCCESS(rv, false)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "false", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../dom/payments/PaymentRequestService.cpp"
, 597); return false; } } while (false)
;
598 if (service->IsBasicCardPayment(supportedMethods)) {
599 return true;
600 }
601 }
602 return false;
603}
604
605} // namespace mozilla::dom