1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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/. */
7 #ifndef mozilla_dom_indexeddb_idbevents_h__
8 #define mozilla_dom_indexeddb_idbevents_h__
10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
12 #include "nsIRunnable.h"
14 #include "mozilla/dom/Event.h"
15 #include "mozilla/dom/Nullable.h"
16 #include "mozilla/dom/indexedDB/IDBObjectStore.h"
17 #include "mozilla/dom/IDBVersionChangeEventBinding.h"
19 #define SUCCESS_EVT_STR "success"
20 #define ERROR_EVT_STR "error"
21 #define COMPLETE_EVT_STR "complete"
22 #define ABORT_EVT_STR "abort"
23 #define VERSIONCHANGE_EVT_STR "versionchange"
24 #define BLOCKED_EVT_STR "blocked"
25 #define UPGRADENEEDED_EVT_STR "upgradeneeded"
27 #define IDBVERSIONCHANGEEVENT_IID \
28 { 0x3b65d4c3, 0x73ad, 0x492e, \
29 { 0xb1, 0x2d, 0x15, 0xf9, 0xda, 0xc2, 0x08, 0x4b } }
31 BEGIN_INDEXEDDB_NAMESPACE
43 already_AddRefed
<nsIDOMEvent
>
44 CreateGenericEvent(mozilla::dom::EventTarget
* aOwner
,
45 const nsAString
& aType
,
47 Cancelable aCancelable
);
49 class IDBVersionChangeEvent
: public Event
52 NS_DECL_ISUPPORTS_INHERITED
54 NS_DECLARE_STATIC_IID_ACCESSOR(IDBVERSIONCHANGEEVENT_IID
)
56 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
58 return mozilla::dom::IDBVersionChangeEventBinding::Wrap(aCx
, this);
61 static already_AddRefed
<IDBVersionChangeEvent
>
62 Constructor(const GlobalObject
& aGlobal
,
63 const nsAString
& aType
,
64 const IDBVersionChangeEventInit
& aOptions
,
67 uint64_t newVersion
= 0;
68 if (!aOptions
.mNewVersion
.IsNull()) {
69 newVersion
= aOptions
.mNewVersion
.Value();
71 nsCOMPtr
<EventTarget
> target
= do_QueryInterface(aGlobal
.GetAsSupports());
72 return CreateInternal(target
, aType
, aOptions
.mOldVersion
, newVersion
);
80 mozilla::dom::Nullable
<uint64_t> GetNewVersion()
83 ? mozilla::dom::Nullable
<uint64_t>(mNewVersion
)
84 : mozilla::dom::Nullable
<uint64_t>();
87 inline static already_AddRefed
<Event
>
88 Create(mozilla::dom::EventTarget
* aOwner
,
92 return CreateInternal(aOwner
,
93 NS_LITERAL_STRING(VERSIONCHANGE_EVT_STR
),
94 aOldVersion
, aNewVersion
);
97 inline static already_AddRefed
<Event
>
98 CreateBlocked(mozilla::dom::EventTarget
* aOwner
,
100 uint64_t aNewVersion
)
102 return CreateInternal(aOwner
, NS_LITERAL_STRING(BLOCKED_EVT_STR
),
103 aOldVersion
, aNewVersion
);
106 inline static already_AddRefed
<Event
>
107 CreateUpgradeNeeded(mozilla::dom::EventTarget
* aOwner
,
108 uint64_t aOldVersion
,
109 uint64_t aNewVersion
)
111 return CreateInternal(aOwner
,
112 NS_LITERAL_STRING(UPGRADENEEDED_EVT_STR
),
113 aOldVersion
, aNewVersion
);
116 inline static already_AddRefed
<nsIRunnable
>
117 CreateRunnable(mozilla::dom::EventTarget
* aTarget
,
118 uint64_t aOldVersion
,
119 uint64_t aNewVersion
)
121 return CreateRunnableInternal(aTarget
,
122 NS_LITERAL_STRING(VERSIONCHANGE_EVT_STR
),
123 aOldVersion
, aNewVersion
);
126 static already_AddRefed
<nsIRunnable
>
127 CreateBlockedRunnable(mozilla::dom::EventTarget
* aTarget
,
128 uint64_t aOldVersion
,
129 uint64_t aNewVersion
)
131 return CreateRunnableInternal(aTarget
,
132 NS_LITERAL_STRING(BLOCKED_EVT_STR
),
133 aOldVersion
, aNewVersion
);
137 IDBVersionChangeEvent(mozilla::dom::EventTarget
* aOwner
)
138 : Event(aOwner
, nullptr, nullptr)
142 virtual ~IDBVersionChangeEvent() { }
144 static already_AddRefed
<IDBVersionChangeEvent
>
145 CreateInternal(mozilla::dom::EventTarget
* aOwner
,
146 const nsAString
& aType
,
147 uint64_t aOldVersion
,
148 uint64_t aNewVersion
);
150 static already_AddRefed
<nsIRunnable
>
151 CreateRunnableInternal(mozilla::dom::EventTarget
* aOwner
,
152 const nsAString
& aType
,
153 uint64_t aOldVersion
,
154 uint64_t aNewVersion
);
156 uint64_t mOldVersion
;
157 uint64_t mNewVersion
;
160 NS_DEFINE_STATIC_IID_ACCESSOR(IDBVersionChangeEvent
, IDBVERSIONCHANGEEVENT_IID
)
162 END_INDEXEDDB_NAMESPACE
164 #endif // mozilla_dom_indexeddb_idbevents_h__