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_MerchantValidationEvent_h
8 #define mozilla_dom_MerchantValidationEvent_h
9 
10 #include "mozilla/Attributes.h"
11 #include "mozilla/Result.h"
12 #include "mozilla/dom/Event.h"
13 #include "mozilla/dom/MerchantValidationEventBinding.h"
14 #include "mozilla/dom/PromiseNativeHandler.h"
15 
16 class nsIURI;
17 
18 namespace mozilla {
19 class ErrorResult;
20 
21 namespace dom {
22 
23 class Promise;
24 class PaymentRequest;
25 class MerchantValidationEvent : public Event, public PromiseNativeHandler {
26  public:
27   NS_DECL_ISUPPORTS_INHERITED
28   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
29       MerchantValidationEvent, Event)
30 
31   explicit MerchantValidationEvent(EventTarget* aOwner);
32 
33   virtual JSObject* WrapObjectInternal(
34       JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
35 
36   virtual void ResolvedCallback(JSContext* aCx,
37                                 JS::Handle<JS::Value> aValue) override;
38   virtual void RejectedCallback(JSContext* aCx,
39                                 JS::Handle<JS::Value> aValue) override;
40 
41   static already_AddRefed<MerchantValidationEvent> Constructor(
42       EventTarget* aOwner, const nsAString& aType,
43       const MerchantValidationEventInit& aEventInitDict, ErrorResult& aRv);
44 
45   // Called by WebIDL constructor
46   static already_AddRefed<MerchantValidationEvent> Constructor(
47       const GlobalObject& aGlobal, const nsAString& aType,
48       const MerchantValidationEventInit& aEventInitDict, ErrorResult& aRv);
49 
50   void Complete(Promise& aPromise, ErrorResult& aRv);
51 
52   void SetRequest(PaymentRequest* aRequest);
53 
54   void GetValidationURL(nsAString& aValidationURL);
55 
56   void GetMethodName(nsAString& aMethodName);
57 
58   void SetMethodName(const nsAString& aMethodName);
59 
60  protected:
61   void init(const MerchantValidationEventInit& aEventInitDict,
62             ErrorResult& aRv);
63   ~MerchantValidationEvent();
64 
65  private:
66   // Indicating whether an Complete()-initiated update is currently in progress.
67   bool mWaitForUpdate;
68   nsCOMPtr<nsIURI> mValidationURL;
69   RefPtr<PaymentRequest> mRequest;
70   nsString mMethodName;
71 };
72 
73 }  // namespace dom
74 }  // namespace mozilla
75 
76 #endif  // mozilla_dom_MerchantValidationEvent_h
77