LCOV - code coverage report
Current view: top level - dom/payments - PaymentRequest.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 3 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim:set ts=2 sw=2 sts=2 et cindent: */
       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_PaymentRequest_h
       8             : #define mozilla_dom_PaymentRequest_h
       9             : 
      10             : #include "mozilla/DOMEventTargetHelper.h"
      11             : #include "mozilla/dom/PaymentRequestBinding.h"
      12             : #include "mozilla/dom/Promise.h"
      13             : #include "mozilla/ErrorResult.h"
      14             : #include "nsWrapperCache.h"
      15             : #include "PaymentRequestUpdateEvent.h"
      16             : 
      17             : namespace mozilla {
      18             : namespace dom {
      19             : 
      20             : class EventHandlerNonNull;
      21             : class PaymentAddress;
      22             : class PaymentResponse;
      23             : 
      24             : class PaymentRequest final : public DOMEventTargetHelper
      25             : {
      26             : public:
      27             :   NS_DECL_ISUPPORTS_INHERITED
      28             : 
      29           0 :   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(PaymentRequest, DOMEventTargetHelper)
      30             : 
      31             :   virtual JSObject* WrapObject(JSContext* aCx,
      32             :                                JS::Handle<JSObject*> aGivenProto) override;
      33             : 
      34             :   static already_AddRefed<PaymentRequest>
      35             :   CreatePaymentRequest(nsPIDOMWindowInner* aWindow, nsresult& aRv);
      36             : 
      37             :   static bool PrefEnabled(JSContext* aCx, JSObject* aObj);
      38             : 
      39             :   static bool IsValidMethodData(const Sequence<PaymentMethodData>& aMethodData,
      40             :                                 nsAString& aErrorMsg);
      41             : 
      42             :   static bool
      43             :   IsValidNumber(const nsAString& aItem,
      44             :                 const nsAString& aStr,
      45             :                 nsAString& aErrorMsg);
      46             :   static bool
      47             :   IsNonNegativeNumber(const nsAString& aItem,
      48             :                       const nsAString& aStr,
      49             :                       nsAString& aErrorMsg);
      50             : 
      51             :   static bool
      52             :   IsValidDetailsInit(const PaymentDetailsInit& aDetails,
      53             :                      nsAString& aErrorMsg);
      54             : 
      55             :   static bool
      56             :   IsValidDetailsUpdate(const PaymentDetailsUpdate& aDetails);
      57             : 
      58             :   static bool
      59             :   IsValidDetailsBase(const PaymentDetailsBase& aDetails,
      60             :                      nsAString& aErrorMsg);
      61             : 
      62             :   static already_AddRefed<PaymentRequest>
      63             :   Constructor(const GlobalObject& aGlobal,
      64             :               const Sequence<PaymentMethodData>& aMethodData,
      65             :               const PaymentDetailsInit& aDetails,
      66             :               const PaymentOptions& aOptions,
      67             :               ErrorResult& aRv);
      68             : 
      69             :   already_AddRefed<Promise> CanMakePayment(ErrorResult& aRv);
      70             :   void RespondCanMakePayment(bool aResult);
      71             : 
      72             :   already_AddRefed<Promise> Show(ErrorResult& aRv);
      73             :   void RespondShowPayment(bool aAccept,
      74             :                           const nsAString& aMethodName,
      75             :                           const nsAString& aDetails,
      76             :                           const nsAString& aPayerName,
      77             :                           const nsAString& aPayerEmail,
      78             :                           const nsAString& aPayerPhone,
      79             :                           nsresult aRv = NS_ERROR_DOM_ABORT_ERR);
      80             :   void RejectShowPayment(nsresult aRejectReason);
      81             :   void RespondComplete();
      82             : 
      83             :   already_AddRefed<Promise> Abort(ErrorResult& aRv);
      84             :   void RespondAbortPayment(bool aResult);
      85             : 
      86             :   void GetId(nsAString& aRetVal) const;
      87             :   void GetInternalId(nsAString& aRetVal);
      88             :   void SetId(const nsAString& aId);
      89             : 
      90             :   bool Equals(const nsAString& aInternalId) const;
      91             : 
      92             :   bool ReadyForUpdate();
      93             :   void SetUpdating(bool aUpdating);
      94             : 
      95             :   already_AddRefed<PaymentAddress> GetShippingAddress() const;
      96             :   // Update mShippingAddress and fire shippingaddresschange event
      97             :   nsresult UpdateShippingAddress(const nsAString& aCountry,
      98             :                                  const nsTArray<nsString>& aAddressLine,
      99             :                                  const nsAString& aRegion,
     100             :                                  const nsAString& aCity,
     101             :                                  const nsAString& aDependentLocality,
     102             :                                  const nsAString& aPostalCode,
     103             :                                  const nsAString& aSortingCode,
     104             :                                  const nsAString& aLanguageCode,
     105             :                                  const nsAString& aOrganization,
     106             :                                  const nsAString& aRecipient,
     107             :                                  const nsAString& aPhone);
     108             : 
     109             : 
     110             :   void SetShippingOption(const nsAString& aShippingOption);
     111             :   void GetShippingOption(nsAString& aRetVal) const;
     112             :   nsresult UpdateShippingOption(const nsAString& aShippingOption);
     113             : 
     114             :   nsresult UpdatePayment(const PaymentDetailsUpdate& aDetails);
     115             :   void AbortUpdate(nsresult aRv);
     116             : 
     117             :   void SetShippingType(const Nullable<PaymentShippingType>& aShippingType);
     118             :   Nullable<PaymentShippingType> GetShippingType() const;
     119             : 
     120           0 :   IMPL_EVENT_HANDLER(shippingaddresschange);
     121           0 :   IMPL_EVENT_HANDLER(shippingoptionchange);
     122             : 
     123             : protected:
     124             :   ~PaymentRequest();
     125             : 
     126             :   nsresult DispatchUpdateEvent(const nsAString& aType);
     127             : 
     128             :   PaymentRequest(nsPIDOMWindowInner* aWindow, const nsAString& aInternalId);
     129             : 
     130             :   // Id for internal identification
     131             :   nsString mInternalId;
     132             :   // Id for communicating with merchant side
     133             :   // mId is initialized to details.id if it exists
     134             :   // otherwise, mId has the same value as mInternalId.
     135             :   nsString mId;
     136             :   // Promise for "PaymentRequest::CanMakePayment"
     137             :   RefPtr<Promise> mResultPromise;
     138             :   // Promise for "PaymentRequest::Show"
     139             :   RefPtr<Promise> mAcceptPromise;
     140             :   // Promise for "PaymentRequest::Abort"
     141             :   RefPtr<Promise> mAbortPromise;
     142             :   // Resolve mAcceptPromise with mResponse if user accepts the request.
     143             :   RefPtr<PaymentResponse> mResponse;
     144             :   // It is populated when the user provides a shipping address.
     145             :   RefPtr<PaymentAddress> mShippingAddress;
     146             :   // It is populated when the user chooses a shipping option.
     147             :   nsString mShippingOption;
     148             : 
     149             :   Nullable<PaymentShippingType> mShippingType;
     150             : 
     151             :   // "true" when there is a pending updateWith() call to update the payment request
     152             :   // and "false" otherwise.
     153             :   bool mUpdating;
     154             :   // The error is set in AbortUpdate(). The value is NS_OK by default.
     155             :   nsresult mUpdateError;
     156             : 
     157             :   enum {
     158             :     eUnknown,
     159             :     eCreated,
     160             :     eInteractive,
     161             :     eClosed
     162             :   } mState;
     163             : };
     164             : 
     165             : } // namespace dom
     166             : } // namespace mozilla
     167             : 
     168             : #endif // mozilla_dom_PaymentRequest_h

Generated by: LCOV version 1.13