Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/payments/PaymentRequestData.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_PaymentRequestData_h
8
#define mozilla_dom_PaymentRequestData_h
9
10
#include "nsIPaymentAddress.h"
11
#include "nsIPaymentRequest.h"
12
#include "nsCOMPtr.h"
13
#include "mozilla/dom/PaymentRequestParent.h"
14
15
namespace mozilla {
16
namespace dom {
17
namespace payments {
18
19
class PaymentMethodData final : public nsIPaymentMethodData
20
{
21
public:
22
  NS_DECL_ISUPPORTS
23
  NS_DECL_NSIPAYMENTMETHODDATA
24
25
  static nsresult Create(const IPCPaymentMethodData& aIPCMethodData,
26
                         nsIPaymentMethodData** aMethodData);
27
28
private:
29
  PaymentMethodData(const nsAString& aSupportedMethods,
30
                    const nsAString& aData);
31
32
0
  ~PaymentMethodData() = default;
33
34
  nsString mSupportedMethods;
35
  nsString mData;
36
};
37
38
class PaymentCurrencyAmount final : public nsIPaymentCurrencyAmount
39
{
40
public:
41
  NS_DECL_ISUPPORTS
42
  NS_DECL_NSIPAYMENTCURRENCYAMOUNT
43
44
  static nsresult Create(const IPCPaymentCurrencyAmount& aIPCAmount,
45
                         nsIPaymentCurrencyAmount** aAmount);
46
47
private:
48
  PaymentCurrencyAmount(const nsAString& aCurrency,
49
                        const nsAString& aValue);
50
51
0
  ~PaymentCurrencyAmount() = default;
52
53
  nsString mCurrency;
54
  nsString mValue;
55
};
56
57
class PaymentItem final : public nsIPaymentItem
58
{
59
public:
60
  NS_DECL_ISUPPORTS
61
  NS_DECL_NSIPAYMENTITEM
62
63
  static nsresult Create(const IPCPaymentItem& aIPCItem, nsIPaymentItem** aItem);
64
65
private:
66
  PaymentItem(const nsAString& aLabel,
67
              nsIPaymentCurrencyAmount* aAmount,
68
              const bool aPending,
69
              const nsAString& aType);
70
71
0
  ~PaymentItem() = default;
72
73
  nsString mLabel;
74
  nsCOMPtr<nsIPaymentCurrencyAmount> mAmount;
75
  bool mPending;
76
  nsString mType;
77
};
78
79
class PaymentDetailsModifier final : public nsIPaymentDetailsModifier
80
{
81
public:
82
  NS_DECL_ISUPPORTS
83
  NS_DECL_NSIPAYMENTDETAILSMODIFIER
84
85
  static nsresult Create(const IPCPaymentDetailsModifier& aIPCModifier,
86
                         nsIPaymentDetailsModifier** aModifier);
87
88
private:
89
  PaymentDetailsModifier(const nsAString& aSupportedMethods,
90
                         nsIPaymentItem* aTotal,
91
                         nsIArray* aAdditionalDisplayItems,
92
                         const nsAString& aData);
93
94
0
  ~PaymentDetailsModifier() = default;
95
96
  nsString mSupportedMethods;
97
  nsCOMPtr<nsIPaymentItem> mTotal;
98
  nsCOMPtr<nsIArray> mAdditionalDisplayItems;
99
  nsString mData;
100
};
101
102
class PaymentShippingOption final : public nsIPaymentShippingOption
103
{
104
public:
105
  NS_DECL_ISUPPORTS
106
  NS_DECL_NSIPAYMENTSHIPPINGOPTION
107
108
  static nsresult Create(const IPCPaymentShippingOption& aIPCOption,
109
                         nsIPaymentShippingOption** aOption);
110
111
private:
112
  PaymentShippingOption(const nsAString& aId,
113
                        const nsAString& aLabel,
114
                        nsIPaymentCurrencyAmount* aAmount,
115
                        const bool aSelected=false);
116
117
0
  ~PaymentShippingOption() = default;
118
119
  nsString mId;
120
  nsString mLabel;
121
  nsCOMPtr<nsIPaymentCurrencyAmount> mAmount;
122
  bool mSelected;
123
};
124
125
class PaymentDetails final : public nsIPaymentDetails
126
{
127
public:
128
  NS_DECL_ISUPPORTS
129
  NS_DECL_NSIPAYMENTDETAILS
130
131
132
  static nsresult Create(const IPCPaymentDetails& aIPCDetails,
133
                         nsIPaymentDetails** aDetails);
134
  nsresult Update(nsIPaymentDetails* aDetails, const bool aRequestShipping);
135
  const nsString& GetShippingAddressErrors() const;
136
  const nsString& GetPayer() const;
137
  const nsString& GetPaymentMethod() const;
138
  nsresult UpdateErrors(const nsAString& aError,
139
                        const nsAString& aPayerErrors,
140
                        const nsAString& aPaymentMethodErrors,
141
                        const nsAString& aShippingAddressErrors);
142
143
private:
144
  PaymentDetails(const nsAString& aId,
145
                 nsIPaymentItem* aTotalItem,
146
                 nsIArray* aDisplayItems,
147
                 nsIArray* aShippingOptions,
148
                 nsIArray* aModifiers,
149
                 const nsAString& aError,
150
                 const nsAString& aShippingAddressError,
151
                 const nsAString& aPayerError,
152
                 const nsAString& aPaymentMethodError);
153
154
0
  ~PaymentDetails() = default;
155
156
  nsString mId;
157
  nsCOMPtr<nsIPaymentItem> mTotalItem;
158
  nsCOMPtr<nsIArray> mDisplayItems;
159
  nsCOMPtr<nsIArray> mShippingOptions;
160
  nsCOMPtr<nsIArray> mModifiers;
161
  nsString mError;
162
  nsString mShippingAddressErrors;
163
  nsString mPayerErrors;
164
  nsString mPaymentMethodErrors;
165
};
166
167
class PaymentOptions final : public nsIPaymentOptions
168
{
169
public:
170
  NS_DECL_ISUPPORTS
171
  NS_DECL_NSIPAYMENTOPTIONS
172
173
  static nsresult Create(const IPCPaymentOptions& aIPCOptions,
174
                         nsIPaymentOptions** aOptions);
175
176
private:
177
  PaymentOptions(const bool aRequestPayerName,
178
                 const bool aRequestPayerEmail,
179
                 const bool aRequestPayerPhone,
180
                 const bool aRequestShipping,
181
                 const nsAString& aShippintType);
182
0
  ~PaymentOptions() = default;
183
184
  bool mRequestPayerName;
185
  bool mRequestPayerEmail;
186
  bool mRequestPayerPhone;
187
  bool mRequestShipping;
188
  nsString mShippingType;
189
};
190
191
class PaymentRequest final : public nsIPaymentRequest
192
{
193
public:
194
  NS_DECL_ISUPPORTS
195
  NS_DECL_NSIPAYMENTREQUEST
196
197
  PaymentRequest(const uint64_t aTabId,
198
                 const nsAString& aRequestId,
199
                 nsIPrincipal* aPrincipal,
200
                 nsIArray* aPaymentMethods,
201
                 nsIPaymentDetails* aPaymentDetails,
202
                 nsIPaymentOptions* aPaymentOptions,
203
                 const nsAString& aShippingOption);
204
205
  void SetIPC(PaymentRequestParent* aIPC)
206
0
  {
207
0
    mIPC = aIPC;
208
0
  }
209
210
  PaymentRequestParent* GetIPC() const
211
0
  {
212
0
    return mIPC;
213
0
  }
214
215
  nsresult
216
  UpdatePaymentDetails(nsIPaymentDetails* aPaymentDetails,
217
                       const nsAString& aShippingOption);
218
219
  void
220
  SetCompleteStatus(const nsAString& aCompleteStatus);
221
222
  nsresult
223
  UpdateErrors(const nsAString& aError,
224
               const nsAString& aPayerErrors,
225
               const nsAString& aPaymentMethodErrors,
226
               const nsAString& aShippingAddressErrors);
227
228
  // The state represents the PaymentRequest's state in the spec. The state is
229
  // not synchronized between content and parent processes.
230
  // eCreated     - the state means a PaymentRequest is created when new
231
  //                PaymentRequest() is called. This is the initial state.
232
  // eInteractive - When PaymentRequest is requested to show to users, the state
233
  //                becomes eInteractive. Under eInteractive state, Payment UI
234
  //                pop up and gather the user's information until the user
235
  //                accepts or rejects the PaymentRequest.
236
  // eClosed      - When the user accepts or rejects the PaymentRequest, the
237
  //                state becomes eClosed. Under eClosed state, response from
238
  //                Payment UI would not be accepted by PaymentRequestService
239
  //                anymore, except the Complete response.
240
  enum eState {
241
    eCreated,
242
    eInteractive,
243
    eClosed
244
  };
245
246
  void
247
  SetState(const eState aState)
248
0
  {
249
0
    mState = aState;
250
0
  }
251
252
  const eState&
253
  GetState() const
254
0
  {
255
0
    return mState;
256
0
  }
257
258
private:
259
0
  ~PaymentRequest() = default;
260
261
  uint64_t mTabId;
262
  nsString mRequestId;
263
  nsString mCompleteStatus;
264
  nsCOMPtr<nsIPrincipal> mTopLevelPrincipal;
265
  nsCOMPtr<nsIArray> mPaymentMethods;
266
  nsCOMPtr<nsIPaymentDetails> mPaymentDetails;
267
  nsCOMPtr<nsIPaymentOptions> mPaymentOptions;
268
  nsString mShippingOption;
269
270
  // IPC's life cycle should be controlled by IPC mechanism.
271
  // PaymentRequest should not own the reference of it.
272
  PaymentRequestParent* mIPC;
273
  eState mState;
274
};
275
276
class PaymentAddress final : public nsIPaymentAddress
277
{
278
public:
279
  NS_DECL_ISUPPORTS
280
  NS_DECL_NSIPAYMENTADDRESS
281
282
0
  PaymentAddress() = default;
283
284
private:
285
0
  ~PaymentAddress() = default;
286
287
  nsString mCountry;
288
  nsCOMPtr<nsIArray> mAddressLine;
289
  nsString mRegion;
290
  nsString mCity;
291
  nsString mDependentLocality;
292
  nsString mPostalCode;
293
  nsString mSortingCode;
294
  nsString mOrganization;
295
  nsString mRecipient;
296
  nsString mPhone;
297
};
298
299
} // end of namespace payment
300
} // end of namespace dom
301
} // end of namespace mozilla
302
303
#endif