Source code

Revision control

Other Tools

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
already_AddRefed<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
static already_AddRefed<IDBVersionChangeEvent> Create(
61
EventTarget* aOwner, const nsDependentString& aName, uint64_t aOldVersion,
62
uint64_t aNewVersion) {
63
Nullable<uint64_t> newVersion(aNewVersion);
64
return CreateInternal(aOwner, aName, aOldVersion, newVersion);
65
}
66
67
static already_AddRefed<IDBVersionChangeEvent> Create(
68
EventTarget* aOwner, const nsDependentString& aName,
69
uint64_t aOldVersion) {
70
Nullable<uint64_t> newVersion(0);
71
newVersion.SetNull();
72
return CreateInternal(aOwner, aName, aOldVersion, newVersion);
73
}
74
75
static already_AddRefed<IDBVersionChangeEvent> Constructor(
76
const GlobalObject& aGlobal, const nsAString& aType,
77
const IDBVersionChangeEventInit& aOptions);
78
79
uint64_t OldVersion() const { return mOldVersion; }
80
81
Nullable<uint64_t> GetNewVersion() const { return mNewVersion; }
82
83
NS_DECLARE_STATIC_IID_ACCESSOR(IDBVERSIONCHANGEEVENT_IID)
84
85
NS_DECL_ISUPPORTS_INHERITED
86
87
virtual JSObject* WrapObjectInternal(
88
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
89
90
private:
91
IDBVersionChangeEvent(EventTarget* aOwner, uint64_t aOldVersion)
92
: Event(aOwner, nullptr, nullptr), mOldVersion(aOldVersion) {}
93
94
~IDBVersionChangeEvent() = default;
95
96
static already_AddRefed<IDBVersionChangeEvent> CreateInternal(
97
EventTarget* aOwner, const nsAString& aType, uint64_t aOldVersion,
98
const Nullable<uint64_t>& aNewVersion);
99
};
100
101
NS_DEFINE_STATIC_IID_ACCESSOR(IDBVersionChangeEvent, IDBVERSIONCHANGEEVENT_IID)
102
103
} // namespace dom
104
} // namespace mozilla
105
106
#endif // mozilla_dom_idbevents_h__