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
#include "IDBEvents.h"
8
9
#include "mozilla/ErrorResult.h"
10
#include "mozilla/dom/EventTarget.h"
11
#include "mozilla/dom/IDBVersionChangeEventBinding.h"
12
#include "nsString.h"
13
14
using namespace mozilla;
15
using namespace mozilla::dom;
16
using namespace mozilla::dom::indexedDB;
17
18
namespace mozilla {
19
namespace dom {
20
namespace indexedDB {
21
22
const char16_t* kAbortEventType = u"abort";
23
const char16_t* kBlockedEventType = u"blocked";
24
const char16_t* kCompleteEventType = u"complete";
25
const char16_t* kErrorEventType = u"error";
26
const char16_t* kSuccessEventType = u"success";
27
const char16_t* kUpgradeNeededEventType = u"upgradeneeded";
28
const char16_t* kVersionChangeEventType = u"versionchange";
29
const char16_t* kCloseEventType = u"close";
30
31
already_AddRefed<Event> CreateGenericEvent(EventTarget* aOwner,
32
const nsDependentString& aType,
33
Bubbles aBubbles,
34
Cancelable aCancelable) {
35
RefPtr<Event> event = new Event(aOwner, nullptr, nullptr);
36
37
event->InitEvent(aType, aBubbles == eDoesBubble ? true : false,
38
aCancelable == eCancelable ? true : false);
39
40
event->SetTrusted(true);
41
42
return event.forget();
43
}
44
45
} // namespace indexedDB
46
47
// static
48
already_AddRefed<IDBVersionChangeEvent> IDBVersionChangeEvent::CreateInternal(
49
EventTarget* aOwner, const nsAString& aType, uint64_t aOldVersion,
50
const Nullable<uint64_t>& aNewVersion) {
51
RefPtr<IDBVersionChangeEvent> event =
52
new IDBVersionChangeEvent(aOwner, aOldVersion);
53
if (!aNewVersion.IsNull()) {
54
event->mNewVersion.SetValue(aNewVersion.Value());
55
}
56
57
event->InitEvent(aType, false, false);
58
59
event->SetTrusted(true);
60
61
return event.forget();
62
}
63
64
already_AddRefed<IDBVersionChangeEvent> IDBVersionChangeEvent::Constructor(
65
const GlobalObject& aGlobal, const nsAString& aType,
66
const IDBVersionChangeEventInit& aOptions) {
67
nsCOMPtr<EventTarget> target = do_QueryInterface(aGlobal.GetAsSupports());
68
69
return CreateInternal(target, aType, aOptions.mOldVersion,
70
aOptions.mNewVersion);
71
}
72
73
NS_IMPL_ADDREF_INHERITED(IDBVersionChangeEvent, Event)
74
NS_IMPL_RELEASE_INHERITED(IDBVersionChangeEvent, Event)
75
76
NS_INTERFACE_MAP_BEGIN(IDBVersionChangeEvent)
77
NS_INTERFACE_MAP_ENTRY(IDBVersionChangeEvent)
78
NS_INTERFACE_MAP_END_INHERITING(Event)
79
80
JSObject* IDBVersionChangeEvent::WrapObjectInternal(
81
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
82
return IDBVersionChangeEvent_Binding::Wrap(aCx, this, aGivenProto);
83
}
84
85
} // namespace dom
86
} // namespace mozilla