tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PaymentRequestData.h (8225B)


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