/src/mozilla-central/dom/payments/PaymentRequestManager.h
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 | | #ifndef mozilla_dom_PaymentRequestManager_h |
8 | | #define mozilla_dom_PaymentRequestManager_h |
9 | | |
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" |
15 | | #include "nsCOMPtr.h" |
16 | | #include "nsTArray.h" |
17 | | |
18 | | namespace mozilla { |
19 | | namespace dom { |
20 | | |
21 | | class PaymentRequestChild; |
22 | | class IPCPaymentActionRequest; |
23 | | |
24 | | /* |
25 | | * PaymentRequestManager is a singleton used to manage the created PaymentRequests. |
26 | | * It is also the communication agent to chrome process. |
27 | | */ |
28 | | class PaymentRequestManager final |
29 | | { |
30 | | public: |
31 | | NS_INLINE_DECL_REFCOUNTING(PaymentRequestManager) |
32 | | |
33 | | static already_AddRefed<PaymentRequestManager> GetSingleton(); |
34 | | |
35 | | /* |
36 | | * This method is used to create PaymentRequest object and send corresponding |
37 | | * data to chrome process for internal payment creation, such that content |
38 | | * process can ask specific task by sending requestId only. |
39 | | */ |
40 | | nsresult |
41 | | CreatePayment(JSContext* aCx, |
42 | | nsPIDOMWindowInner* aWindow, |
43 | | nsIPrincipal* aTopLevelPrincipal, |
44 | | const Sequence<PaymentMethodData>& aMethodData, |
45 | | const PaymentDetailsInit& aDetails, |
46 | | const PaymentOptions& aOptions, |
47 | | PaymentRequest** aRequest); |
48 | | |
49 | | nsresult CanMakePayment(PaymentRequest* aRequest); |
50 | | nsresult ShowPayment(PaymentRequest* aRequest); |
51 | | nsresult AbortPayment(PaymentRequest* aRequest, bool aDeferredShow); |
52 | | nsresult CompletePayment(PaymentRequest* aRequest, |
53 | | const PaymentComplete& aComplete, |
54 | | bool aTimedOut = false); |
55 | | nsresult UpdatePayment(JSContext* aCx, |
56 | | PaymentRequest* aRequest, |
57 | | const PaymentDetailsUpdate& aDetails, |
58 | | bool aRequestShipping, |
59 | | bool aDeferredShow); |
60 | | nsresult ClosePayment(PaymentRequest* aRequest); |
61 | | nsresult RetryPayment(JSContext* aCx, |
62 | | PaymentRequest* aRequest, |
63 | | const PaymentValidationErrors& aErrors); |
64 | | |
65 | | nsresult RespondPayment(PaymentRequest* aRequest, |
66 | | const IPCPaymentActionResponse& aResponse); |
67 | | nsresult ChangeShippingAddress(PaymentRequest* aRequest, |
68 | | const IPCPaymentAddress& aAddress); |
69 | | nsresult ChangeShippingOption(PaymentRequest* aRequest, |
70 | | const nsAString& aOption); |
71 | | |
72 | | nsresult ChangePayerDetail(PaymentRequest* aRequest, |
73 | | const nsAString& aPayerName, |
74 | | const nsAString& aPayerEmail, |
75 | | const nsAString& aPayerPhone); |
76 | | |
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); |
80 | | |
81 | | private: |
82 | 0 | PaymentRequestManager() = default; |
83 | | ~PaymentRequestManager() |
84 | 0 | { |
85 | 0 | MOZ_ASSERT(mActivePayments.Count() == 0); |
86 | 0 | } |
87 | | |
88 | | PaymentRequestChild* GetPaymentChild(PaymentRequest* aRequest); |
89 | | |
90 | | nsresult SendRequestPayment(PaymentRequest* aRequest, |
91 | | const IPCPaymentActionRequest& action, |
92 | | bool aResponseExpected = true); |
93 | | |
94 | | void NotifyRequestDone(PaymentRequest* aRequest); |
95 | | |
96 | | // Strong pointer to requests with ongoing IPC messages to the parent. |
97 | | nsDataHashtable<nsRefPtrHashKey<PaymentRequest>, uint32_t> mActivePayments; |
98 | | }; |
99 | | |
100 | | } // end of namespace dom |
101 | | } // end of namespace mozilla |
102 | | |
103 | | #endif |