Bug 1472338: part 2) Change `clipboard.readText()` to read from the clipboard asynchr...
[gecko.git] / dom / payments / PaymentRequestManager.h
blob837dd4d334d48884bbd7a6e990a0ef1c2dffab51
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"
15 #include "nsCOMPtr.h"
16 #include "nsTArray.h"
18 namespace mozilla {
19 namespace dom {
21 class PaymentRequestChild;
22 class IPCMethodChangeDetails;
23 class IPCPaymentAddress;
24 class IPCPaymentActionResponse;
25 class IPCPaymentActionRequest;
28 * PaymentRequestManager is a singleton used to manage the created
29 * PaymentRequests. It is also the communication agent to chrome process.
31 class PaymentRequestManager final {
32 public:
33 NS_INLINE_DECL_REFCOUNTING(PaymentRequestManager)
35 static already_AddRefed<PaymentRequestManager> GetSingleton();
38 * This method is used to create PaymentRequest object and send corresponding
39 * data to chrome process for internal payment creation, such that content
40 * process can ask specific task by sending requestId only.
42 void CreatePayment(JSContext* aCx, nsPIDOMWindowInner* aWindow,
43 nsIPrincipal* aTopLevelPrincipal,
44 const Sequence<PaymentMethodData>& aMethodData,
45 const PaymentDetailsInit& aDetails,
46 const PaymentOptions& aOptions, PaymentRequest** aRequest,
47 ErrorResult& aRv);
49 void CanMakePayment(PaymentRequest* aRequest, ErrorResult& aRv);
50 void ShowPayment(PaymentRequest* aRequest, ErrorResult& aRv);
51 void AbortPayment(PaymentRequest* aRequest, ErrorResult& aRv);
52 void CompletePayment(PaymentRequest* aRequest,
53 const PaymentComplete& aComplete, ErrorResult& aRv,
54 bool aTimedOut = false);
55 void UpdatePayment(JSContext* aCx, PaymentRequest* aRequest,
56 const PaymentDetailsUpdate& aDetails,
57 bool aRequestShipping, ErrorResult& aRv);
58 nsresult ClosePayment(PaymentRequest* aRequest);
59 void RetryPayment(JSContext* aCx, PaymentRequest* aRequest,
60 const PaymentValidationErrors& aErrors, ErrorResult& aRv);
62 nsresult RespondPayment(PaymentRequest* aRequest,
63 const IPCPaymentActionResponse& aResponse);
64 nsresult ChangeShippingAddress(PaymentRequest* aRequest,
65 const IPCPaymentAddress& aAddress);
66 nsresult ChangeShippingOption(PaymentRequest* aRequest,
67 const nsAString& aOption);
68 nsresult ChangePayerDetail(PaymentRequest* aRequest,
69 const nsAString& aPayerName,
70 const nsAString& aPayerEmail,
71 const nsAString& aPayerPhone);
72 nsresult ChangePaymentMethod(PaymentRequest* aRequest,
73 const nsAString& aMethodName,
74 const IPCMethodChangeDetails& aMethodDetails);
76 bool IsRegionSupported(const nsAString& region) const;
78 // Called to ensure that we don't "leak" aRequest if we shut down while it had
79 // an active request to the parent.
80 void RequestIPCOver(PaymentRequest* aRequest);
82 private:
83 PaymentRequestManager();
84 ~PaymentRequestManager();
86 PaymentRequestChild* GetPaymentChild(PaymentRequest* aRequest);
88 nsresult SendRequestPayment(PaymentRequest* aRequest,
89 const IPCPaymentActionRequest& action,
90 bool aResponseExpected = true);
92 void NotifyRequestDone(PaymentRequest* aRequest);
94 // Strong pointer to requests with ongoing IPC messages to the parent.
95 nsTHashMap<nsRefPtrHashKey<PaymentRequest>, uint32_t> mActivePayments;
97 nsTArray<nsString> mSupportedRegions;
100 } // end of namespace dom
101 } // end of namespace mozilla
103 #endif