PaymentRequestManager.h (4124B)
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 "PaymentRequest.h" 11 #include "mozilla/dom/PaymentRequestBinding.h" 12 #include "mozilla/dom/PaymentRequestUpdateEventBinding.h" 13 #include "mozilla/dom/PaymentResponseBinding.h" 14 #include "nsCOMPtr.h" 15 #include "nsISupports.h" 16 #include "nsTArray.h" 17 18 namespace mozilla::dom { 19 20 class PaymentRequestChild; 21 class IPCMethodChangeDetails; 22 class IPCPaymentAddress; 23 class IPCPaymentActionResponse; 24 class IPCPaymentActionRequest; 25 26 /* 27 * PaymentRequestManager is a singleton used to manage the created 28 * PaymentRequests. It is also the communication agent to chrome process. 29 */ 30 class PaymentRequestManager final { 31 public: 32 NS_INLINE_DECL_REFCOUNTING(PaymentRequestManager) 33 34 static already_AddRefed<PaymentRequestManager> GetSingleton(); 35 36 /* 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. 40 */ 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, 46 ErrorResult& aRv); 47 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); 60 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); 74 75 bool IsRegionSupported(const nsAString& region) const; 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 PaymentRequestManager(); 83 ~PaymentRequestManager(); 84 85 PaymentRequestChild* GetPaymentChild(PaymentRequest* aRequest); 86 87 nsresult SendRequestPayment(PaymentRequest* aRequest, 88 const IPCPaymentActionRequest& action, 89 bool aResponseExpected = true); 90 91 void NotifyRequestDone(PaymentRequest* aRequest); 92 93 // Strong pointer to requests with ongoing IPC messages to the parent. 94 nsTHashMap<nsRefPtrHashKey<PaymentRequest>, uint32_t> mActivePayments; 95 96 nsTArray<nsString> mSupportedRegions; 97 }; 98 99 } // namespace mozilla::dom 100 101 #endif