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/. */
7 #ifndef mozilla_dom_PaymentRequestManager_h
8 #define mozilla_dom_PaymentRequestManager_h
10 #include "nsISupports.h"
11 #include "PaymentRequest.h"
12 #include "mozilla/dom/PaymentRequestBinding.h"
13 #include "mozilla/dom/PaymentRequestUpdateEventBinding.h"
14 #include "mozilla/dom/PaymentResponseBinding.h"
18 namespace mozilla::dom
{
20 class PaymentRequestChild
;
21 class IPCMethodChangeDetails
;
22 class IPCPaymentAddress
;
23 class IPCPaymentActionResponse
;
24 class IPCPaymentActionRequest
;
27 * PaymentRequestManager is a singleton used to manage the created
28 * PaymentRequests. It is also the communication agent to chrome process.
30 class PaymentRequestManager final
{
32 NS_INLINE_DECL_REFCOUNTING(PaymentRequestManager
)
34 static already_AddRefed
<PaymentRequestManager
> GetSingleton();
37 * This method is used to create PaymentRequest object and send corresponding
38 * data to chrome process for internal payment creation, such that content
39 * process can ask specific task by sending requestId only.
41 void CreatePayment(JSContext
* aCx
, nsPIDOMWindowInner
* aWindow
,
42 nsIPrincipal
* aTopLevelPrincipal
,
43 const Sequence
<PaymentMethodData
>& aMethodData
,
44 const PaymentDetailsInit
& aDetails
,
45 const PaymentOptions
& aOptions
, PaymentRequest
** aRequest
,
48 void CanMakePayment(PaymentRequest
* aRequest
, ErrorResult
& aRv
);
49 void ShowPayment(PaymentRequest
* aRequest
, ErrorResult
& aRv
);
50 void AbortPayment(PaymentRequest
* aRequest
, ErrorResult
& aRv
);
51 void CompletePayment(PaymentRequest
* aRequest
,
52 const PaymentComplete
& aComplete
, ErrorResult
& aRv
,
53 bool aTimedOut
= false);
54 void UpdatePayment(JSContext
* aCx
, PaymentRequest
* aRequest
,
55 const PaymentDetailsUpdate
& aDetails
,
56 bool aRequestShipping
, ErrorResult
& aRv
);
57 nsresult
ClosePayment(PaymentRequest
* aRequest
);
58 void RetryPayment(JSContext
* aCx
, PaymentRequest
* aRequest
,
59 const PaymentValidationErrors
& aErrors
, ErrorResult
& aRv
);
61 nsresult
RespondPayment(PaymentRequest
* aRequest
,
62 const IPCPaymentActionResponse
& aResponse
);
63 nsresult
ChangeShippingAddress(PaymentRequest
* aRequest
,
64 const IPCPaymentAddress
& aAddress
);
65 nsresult
ChangeShippingOption(PaymentRequest
* aRequest
,
66 const nsAString
& aOption
);
67 nsresult
ChangePayerDetail(PaymentRequest
* aRequest
,
68 const nsAString
& aPayerName
,
69 const nsAString
& aPayerEmail
,
70 const nsAString
& aPayerPhone
);
71 nsresult
ChangePaymentMethod(PaymentRequest
* aRequest
,
72 const nsAString
& aMethodName
,
73 const IPCMethodChangeDetails
& aMethodDetails
);
75 bool IsRegionSupported(const nsAString
& region
) const;
77 // Called to ensure that we don't "leak" aRequest if we shut down while it had
78 // an active request to the parent.
79 void RequestIPCOver(PaymentRequest
* aRequest
);
82 PaymentRequestManager();
83 ~PaymentRequestManager();
85 PaymentRequestChild
* GetPaymentChild(PaymentRequest
* aRequest
);
87 nsresult
SendRequestPayment(PaymentRequest
* aRequest
,
88 const IPCPaymentActionRequest
& action
,
89 bool aResponseExpected
= true);
91 void NotifyRequestDone(PaymentRequest
* aRequest
);
93 // Strong pointer to requests with ongoing IPC messages to the parent.
94 nsTHashMap
<nsRefPtrHashKey
<PaymentRequest
>, uint32_t> mActivePayments
;
96 nsTArray
<nsString
> mSupportedRegions
;
99 } // namespace mozilla::dom