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_idbevents_h__
8 #define mozilla_dom_idbevents_h__
9 
10 #include "js/RootingAPI.h"
11 #include "mozilla/dom/BindingDeclarations.h"
12 #include "mozilla/dom/Event.h"
13 #include "mozilla/dom/Nullable.h"
14 #include "nsStringFwd.h"
15 
16 #define IDBVERSIONCHANGEEVENT_IID                    \
17   {                                                  \
18     0x3b65d4c3, 0x73ad, 0x492e, {                    \
19       0xb1, 0x2d, 0x15, 0xf9, 0xda, 0xc2, 0x08, 0x4b \
20     }                                                \
21   }
22 
23 namespace mozilla {
24 
25 class ErrorResult;
26 
27 namespace dom {
28 
29 class EventTarget;
30 class GlobalObject;
31 struct IDBVersionChangeEventInit;
32 
33 namespace indexedDB {
34 
35 enum Bubbles { eDoesNotBubble, eDoesBubble };
36 
37 enum Cancelable { eNotCancelable, eCancelable };
38 
39 extern const char16_t* kAbortEventType;
40 extern const char16_t* kBlockedEventType;
41 extern const char16_t* kCompleteEventType;
42 extern const char16_t* kErrorEventType;
43 extern const char16_t* kSuccessEventType;
44 extern const char16_t* kUpgradeNeededEventType;
45 extern const char16_t* kVersionChangeEventType;
46 extern const char16_t* kCloseEventType;
47 
48 [[nodiscard]] RefPtr<Event> CreateGenericEvent(EventTarget* aOwner,
49                                                const nsDependentString& aType,
50                                                Bubbles aBubbles,
51                                                Cancelable aCancelable);
52 
53 }  // namespace indexedDB
54 
55 class IDBVersionChangeEvent final : public Event {
56   uint64_t mOldVersion;
57   Nullable<uint64_t> mNewVersion;
58 
59  public:
60   [[nodiscard]] static RefPtr<IDBVersionChangeEvent> Create(
61       EventTarget* aOwner, const nsDependentString& aName, uint64_t aOldVersion,
62       uint64_t aNewVersion);
63 
64   [[nodiscard]] static RefPtr<IDBVersionChangeEvent> Create(
65       EventTarget* aOwner, const nsDependentString& aName,
66       uint64_t aOldVersion);
67 
68   [[nodiscard]] static RefPtr<IDBVersionChangeEvent> Constructor(
69       const GlobalObject& aGlobal, const nsAString& aType,
70       const IDBVersionChangeEventInit& aOptions);
71 
OldVersion()72   uint64_t OldVersion() const { return mOldVersion; }
73 
GetNewVersion()74   Nullable<uint64_t> GetNewVersion() const { return mNewVersion; }
75 
76   NS_DECLARE_STATIC_IID_ACCESSOR(IDBVERSIONCHANGEEVENT_IID)
77 
78   NS_DECL_ISUPPORTS_INHERITED
79 
80   virtual JSObject* WrapObjectInternal(
81       JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
82 
83  private:
IDBVersionChangeEvent(EventTarget * aOwner,uint64_t aOldVersion)84   IDBVersionChangeEvent(EventTarget* aOwner, uint64_t aOldVersion)
85       : Event(aOwner, nullptr, nullptr), mOldVersion(aOldVersion) {}
86 
87   ~IDBVersionChangeEvent() = default;
88 
89   [[nodiscard]] static RefPtr<IDBVersionChangeEvent> CreateInternal(
90       EventTarget* aOwner, const nsAString& aType, uint64_t aOldVersion,
91       const Nullable<uint64_t>& aNewVersion);
92 };
93 
94 NS_DEFINE_STATIC_IID_ACCESSOR(IDBVersionChangeEvent, IDBVERSIONCHANGEEVENT_IID)
95 
96 }  // namespace dom
97 }  // namespace mozilla
98 
99 #endif  // mozilla_dom_idbevents_h__
100