forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIDBEvents.h
163 lines (137 loc) · 4.88 KB
/
IDBEvents.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_indexeddb_idbevents_h__
#define mozilla_dom_indexeddb_idbevents_h__
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
#include "nsIRunnable.h"
#include "nsDOMEvent.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/indexedDB/IDBObjectStore.h"
#include "mozilla/dom/IDBVersionChangeEventBinding.h"
#define SUCCESS_EVT_STR "success"
#define ERROR_EVT_STR "error"
#define COMPLETE_EVT_STR "complete"
#define ABORT_EVT_STR "abort"
#define VERSIONCHANGE_EVT_STR "versionchange"
#define BLOCKED_EVT_STR "blocked"
#define UPGRADENEEDED_EVT_STR "upgradeneeded"
#define IDBVERSIONCHANGEEVENT_IID \
{ 0x3b65d4c3, 0x73ad, 0x492e, \
{ 0xb1, 0x2d, 0x15, 0xf9, 0xda, 0xc2, 0x08, 0x4b } }
BEGIN_INDEXEDDB_NAMESPACE
enum Bubbles {
eDoesNotBubble,
eDoesBubble
};
enum Cancelable {
eNotCancelable,
eCancelable
};
already_AddRefed<nsIDOMEvent>
CreateGenericEvent(mozilla::dom::EventTarget* aOwner,
const nsAString& aType,
Bubbles aBubbles,
Cancelable aCancelable);
class IDBVersionChangeEvent : public nsDOMEvent
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_FORWARD_TO_NSDOMEVENT
NS_DECLARE_STATIC_IID_ACCESSOR(IDBVERSIONCHANGEEVENT_IID)
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
{
return mozilla::dom::IDBVersionChangeEventBinding::Wrap(aCx, aScope, this);
}
static already_AddRefed<IDBVersionChangeEvent>
Constructor(const GlobalObject& aGlobal,
const nsAString& aType,
const IDBVersionChangeEventInit& aOptions,
ErrorResult& aRv)
{
uint64_t newVersion = 0;
if (!aOptions.mNewVersion.IsNull()) {
newVersion = aOptions.mNewVersion.Value();
}
nsCOMPtr<EventTarget> target = do_QueryInterface(aGlobal.GetAsSupports());
return CreateInternal(target, aType, aOptions.mOldVersion, newVersion);
}
uint64_t OldVersion()
{
return mOldVersion;
}
mozilla::dom::Nullable<uint64_t> GetNewVersion()
{
return mNewVersion
? mozilla::dom::Nullable<uint64_t>(mNewVersion)
: mozilla::dom::Nullable<uint64_t>();
}
inline static already_AddRefed<nsDOMEvent>
Create(mozilla::dom::EventTarget* aOwner,
int64_t aOldVersion,
int64_t aNewVersion)
{
return CreateInternal(aOwner,
NS_LITERAL_STRING(VERSIONCHANGE_EVT_STR),
aOldVersion, aNewVersion);
}
inline static already_AddRefed<nsDOMEvent>
CreateBlocked(mozilla::dom::EventTarget* aOwner,
uint64_t aOldVersion,
uint64_t aNewVersion)
{
return CreateInternal(aOwner, NS_LITERAL_STRING(BLOCKED_EVT_STR),
aOldVersion, aNewVersion);
}
inline static already_AddRefed<nsDOMEvent>
CreateUpgradeNeeded(mozilla::dom::EventTarget* aOwner,
uint64_t aOldVersion,
uint64_t aNewVersion)
{
return CreateInternal(aOwner,
NS_LITERAL_STRING(UPGRADENEEDED_EVT_STR),
aOldVersion, aNewVersion);
}
inline static already_AddRefed<nsIRunnable>
CreateRunnable(mozilla::dom::EventTarget* aTarget,
uint64_t aOldVersion,
uint64_t aNewVersion)
{
return CreateRunnableInternal(aTarget,
NS_LITERAL_STRING(VERSIONCHANGE_EVT_STR),
aOldVersion, aNewVersion);
}
static already_AddRefed<nsIRunnable>
CreateBlockedRunnable(mozilla::dom::EventTarget* aTarget,
uint64_t aOldVersion,
uint64_t aNewVersion)
{
return CreateRunnableInternal(aTarget,
NS_LITERAL_STRING(BLOCKED_EVT_STR),
aOldVersion, aNewVersion);
}
protected:
IDBVersionChangeEvent(mozilla::dom::EventTarget* aOwner)
: nsDOMEvent(aOwner, nullptr, nullptr)
{
SetIsDOMBinding();
}
virtual ~IDBVersionChangeEvent() { }
static already_AddRefed<IDBVersionChangeEvent>
CreateInternal(mozilla::dom::EventTarget* aOwner,
const nsAString& aType,
uint64_t aOldVersion,
uint64_t aNewVersion);
static already_AddRefed<nsIRunnable>
CreateRunnableInternal(mozilla::dom::EventTarget* aOwner,
const nsAString& aType,
uint64_t aOldVersion,
uint64_t aNewVersion);
uint64_t mOldVersion;
uint64_t mNewVersion;
};
END_INDEXEDDB_NAMESPACE
#endif // mozilla_dom_indexeddb_idbevents_h__