Bug 1472338: part 2) Change `clipboard.readText()` to read from the clipboard asynchr...
[gecko.git] / dom / payments / PaymentRequestData.h
blob96e9437cc1c14a573ff5b93f04ee769915e367c1
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_PaymentRequestData_h
8 #define mozilla_dom_PaymentRequestData_h
10 #include "nsIPaymentAddress.h"
11 #include "nsIPaymentRequest.h"
12 #include "nsCOMPtr.h"
13 #include "mozilla/dom/PaymentRequestParent.h"
15 namespace mozilla {
16 namespace dom {
17 namespace payments {
19 class PaymentMethodData final : public nsIPaymentMethodData {
20 public:
21 NS_DECL_ISUPPORTS
22 NS_DECL_NSIPAYMENTMETHODDATA
24 static nsresult Create(const IPCPaymentMethodData& aIPCMethodData,
25 nsIPaymentMethodData** aMethodData);
27 private:
28 PaymentMethodData(const nsAString& aSupportedMethods, const nsAString& aData);
30 ~PaymentMethodData() = default;
32 nsString mSupportedMethods;
33 nsString mData;
36 class PaymentCurrencyAmount final : public nsIPaymentCurrencyAmount {
37 public:
38 NS_DECL_ISUPPORTS
39 NS_DECL_NSIPAYMENTCURRENCYAMOUNT
41 static nsresult Create(const IPCPaymentCurrencyAmount& aIPCAmount,
42 nsIPaymentCurrencyAmount** aAmount);
44 private:
45 PaymentCurrencyAmount(const nsAString& aCurrency, const nsAString& aValue);
47 ~PaymentCurrencyAmount() = default;
49 nsString mCurrency;
50 nsString mValue;
53 class PaymentItem final : public nsIPaymentItem {
54 public:
55 NS_DECL_ISUPPORTS
56 NS_DECL_NSIPAYMENTITEM
58 static nsresult Create(const IPCPaymentItem& aIPCItem,
59 nsIPaymentItem** aItem);
61 private:
62 PaymentItem(const nsAString& aLabel, nsIPaymentCurrencyAmount* aAmount,
63 const bool aPending);
65 ~PaymentItem() = default;
67 nsString mLabel;
68 nsCOMPtr<nsIPaymentCurrencyAmount> mAmount;
69 bool mPending;
72 class PaymentDetailsModifier final : public nsIPaymentDetailsModifier {
73 public:
74 NS_DECL_ISUPPORTS
75 NS_DECL_NSIPAYMENTDETAILSMODIFIER
77 static nsresult Create(const IPCPaymentDetailsModifier& aIPCModifier,
78 nsIPaymentDetailsModifier** aModifier);
80 private:
81 PaymentDetailsModifier(const nsAString& aSupportedMethods,
82 nsIPaymentItem* aTotal,
83 nsIArray* aAdditionalDisplayItems,
84 const nsAString& aData);
86 ~PaymentDetailsModifier() = default;
88 nsString mSupportedMethods;
89 nsCOMPtr<nsIPaymentItem> mTotal;
90 nsCOMPtr<nsIArray> mAdditionalDisplayItems;
91 nsString mData;
94 class PaymentShippingOption final : public nsIPaymentShippingOption {
95 public:
96 NS_DECL_ISUPPORTS
97 NS_DECL_NSIPAYMENTSHIPPINGOPTION
99 static nsresult Create(const IPCPaymentShippingOption& aIPCOption,
100 nsIPaymentShippingOption** aOption);
102 private:
103 PaymentShippingOption(const nsAString& aId, const nsAString& aLabel,
104 nsIPaymentCurrencyAmount* aAmount,
105 const bool aSelected = false);
107 ~PaymentShippingOption() = default;
109 nsString mId;
110 nsString mLabel;
111 nsCOMPtr<nsIPaymentCurrencyAmount> mAmount;
112 bool mSelected;
115 class PaymentDetails final : public nsIPaymentDetails {
116 public:
117 NS_DECL_ISUPPORTS
118 NS_DECL_NSIPAYMENTDETAILS
120 static nsresult Create(const IPCPaymentDetails& aIPCDetails,
121 nsIPaymentDetails** aDetails);
122 nsresult Update(nsIPaymentDetails* aDetails, const bool aRequestShipping);
123 const nsString& GetShippingAddressErrors() const;
124 const nsString& GetPayerErrors() const;
125 const nsString& GetPaymentMethodErrors() const;
126 nsresult UpdateErrors(const nsAString& aError, const nsAString& aPayerErrors,
127 const nsAString& aPaymentMethodErrors,
128 const nsAString& aShippingAddressErrors);
130 private:
131 PaymentDetails(const nsAString& aId, nsIPaymentItem* aTotalItem,
132 nsIArray* aDisplayItems, nsIArray* aShippingOptions,
133 nsIArray* aModifiers, const nsAString& aError,
134 const nsAString& aShippingAddressError,
135 const nsAString& aPayerError,
136 const nsAString& aPaymentMethodError);
138 ~PaymentDetails() = default;
140 nsString mId;
141 nsCOMPtr<nsIPaymentItem> mTotalItem;
142 nsCOMPtr<nsIArray> mDisplayItems;
143 nsCOMPtr<nsIArray> mShippingOptions;
144 nsCOMPtr<nsIArray> mModifiers;
145 nsString mError;
146 nsString mShippingAddressErrors;
147 nsString mPayerErrors;
148 nsString mPaymentMethodErrors;
151 class PaymentOptions final : public nsIPaymentOptions {
152 public:
153 NS_DECL_ISUPPORTS
154 NS_DECL_NSIPAYMENTOPTIONS
156 static nsresult Create(const IPCPaymentOptions& aIPCOptions,
157 nsIPaymentOptions** aOptions);
159 private:
160 PaymentOptions(const bool aRequestPayerName, const bool aRequestPayerEmail,
161 const bool aRequestPayerPhone, const bool aRequestShipping,
162 const bool aRequestBillingAddress,
163 const nsAString& aShippintType);
164 ~PaymentOptions() = default;
166 bool mRequestPayerName;
167 bool mRequestPayerEmail;
168 bool mRequestPayerPhone;
169 bool mRequestShipping;
170 bool mRequestBillingAddress;
171 nsString mShippingType;
174 class PaymentRequest final : public nsIPaymentRequest {
175 public:
176 NS_DECL_ISUPPORTS
177 NS_DECL_NSIPAYMENTREQUEST
179 PaymentRequest(const uint64_t aTopOuterWindowId, const nsAString& aRequestId,
180 nsIPrincipal* aPrincipal, nsIArray* aPaymentMethods,
181 nsIPaymentDetails* aPaymentDetails,
182 nsIPaymentOptions* aPaymentOptions,
183 const nsAString& aShippingOption);
185 void SetIPC(PaymentRequestParent* aIPC) { mIPC = aIPC; }
187 PaymentRequestParent* GetIPC() const { return mIPC; }
189 nsresult UpdatePaymentDetails(nsIPaymentDetails* aPaymentDetails,
190 const nsAString& aShippingOption);
192 void SetCompleteStatus(const nsAString& aCompleteStatus);
194 nsresult UpdateErrors(const nsAString& aError, const nsAString& aPayerErrors,
195 const nsAString& aPaymentMethodErrors,
196 const nsAString& aShippingAddressErrors);
198 // The state represents the PaymentRequest's state in the spec. The state is
199 // not synchronized between content and parent processes.
200 // eCreated - the state means a PaymentRequest is created when new
201 // PaymentRequest() is called. This is the initial state.
202 // eInteractive - When PaymentRequest is requested to show to users, the state
203 // becomes eInteractive. Under eInteractive state, Payment UI
204 // pop up and gather the user's information until the user
205 // accepts or rejects the PaymentRequest.
206 // eClosed - When the user accepts or rejects the PaymentRequest, the
207 // state becomes eClosed. Under eClosed state, response from
208 // Payment UI would not be accepted by PaymentRequestService
209 // anymore, except the Complete response.
210 enum eState { eCreated, eInteractive, eClosed };
212 void SetState(const eState aState) { mState = aState; }
214 const eState& GetState() const { return mState; }
216 private:
217 ~PaymentRequest() = default;
219 uint64_t mTopOuterWindowId;
220 nsString mRequestId;
221 nsString mCompleteStatus;
222 nsCOMPtr<nsIPrincipal> mTopLevelPrincipal;
223 nsCOMPtr<nsIArray> mPaymentMethods;
224 nsCOMPtr<nsIPaymentDetails> mPaymentDetails;
225 nsCOMPtr<nsIPaymentOptions> mPaymentOptions;
226 nsString mShippingOption;
228 // IPC's life cycle should be controlled by IPC mechanism.
229 // PaymentRequest should not own the reference of it.
230 PaymentRequestParent* mIPC;
231 eState mState;
234 class PaymentAddress final : public nsIPaymentAddress {
235 public:
236 NS_DECL_ISUPPORTS
237 NS_DECL_NSIPAYMENTADDRESS
239 PaymentAddress() = default;
241 private:
242 ~PaymentAddress() = default;
244 nsString mCountry;
245 nsCOMPtr<nsIArray> mAddressLine;
246 nsString mRegion;
247 nsString mRegionCode;
248 nsString mCity;
249 nsString mDependentLocality;
250 nsString mPostalCode;
251 nsString mSortingCode;
252 nsString mOrganization;
253 nsString mRecipient;
254 nsString mPhone;
257 } // namespace payments
258 } // end of namespace dom
259 } // end of namespace mozilla
261 #endif