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/. */
9 #include "mozilla/ErrorResult.h"
10 #include "mozilla/dom/EventTarget.h"
11 #include "mozilla/dom/IDBVersionChangeEventBinding.h"
14 using namespace mozilla
;
15 using namespace mozilla::dom
;
16 using namespace mozilla::dom::indexedDB
;
18 namespace mozilla::dom
{
21 const char16_t
* kAbortEventType
= u
"abort";
22 const char16_t
* kBlockedEventType
= u
"blocked";
23 const char16_t
* kCompleteEventType
= u
"complete";
24 const char16_t
* kErrorEventType
= u
"error";
25 const char16_t
* kSuccessEventType
= u
"success";
26 const char16_t
* kUpgradeNeededEventType
= u
"upgradeneeded";
27 const char16_t
* kVersionChangeEventType
= u
"versionchange";
28 const char16_t
* kCloseEventType
= u
"close";
30 RefPtr
<Event
> CreateGenericEvent(EventTarget
* aOwner
,
31 const nsDependentString
& aType
,
32 Bubbles aBubbles
, Cancelable aCancelable
) {
33 RefPtr
<Event
> event
= MakeAndAddRef
<Event
>(aOwner
, nullptr, nullptr);
35 event
->InitEvent(aType
, aBubbles
== eDoesBubble
, aCancelable
== eCancelable
);
37 event
->SetTrusted(true);
42 } // namespace indexedDB
45 RefPtr
<IDBVersionChangeEvent
> IDBVersionChangeEvent::CreateInternal(
46 EventTarget
* aOwner
, const nsAString
& aType
, uint64_t aOldVersion
,
47 const Nullable
<uint64_t>& aNewVersion
) {
48 RefPtr
<IDBVersionChangeEvent
> event
=
49 new IDBVersionChangeEvent(aOwner
, aOldVersion
);
50 if (!aNewVersion
.IsNull()) {
51 event
->mNewVersion
.SetValue(aNewVersion
.Value());
54 event
->InitEvent(aType
, false, false);
56 event
->SetTrusted(true);
61 RefPtr
<IDBVersionChangeEvent
> IDBVersionChangeEvent::Create(
62 EventTarget
* aOwner
, const nsDependentString
& aName
, uint64_t aOldVersion
,
63 uint64_t aNewVersion
) {
64 Nullable
<uint64_t> newVersion(aNewVersion
);
65 return CreateInternal(aOwner
, aName
, aOldVersion
, newVersion
);
68 RefPtr
<IDBVersionChangeEvent
> IDBVersionChangeEvent::Create(
69 EventTarget
* aOwner
, const nsDependentString
& aName
, uint64_t aOldVersion
) {
70 Nullable
<uint64_t> newVersion(0);
72 return CreateInternal(aOwner
, aName
, aOldVersion
, newVersion
);
75 RefPtr
<IDBVersionChangeEvent
> IDBVersionChangeEvent::Constructor(
76 const GlobalObject
& aGlobal
, const nsAString
& aType
,
77 const IDBVersionChangeEventInit
& aOptions
) {
78 nsCOMPtr
<EventTarget
> target
= do_QueryInterface(aGlobal
.GetAsSupports());
80 return CreateInternal(target
, aType
, aOptions
.mOldVersion
,
81 aOptions
.mNewVersion
);
84 NS_IMPL_ADDREF_INHERITED(IDBVersionChangeEvent
, Event
)
85 NS_IMPL_RELEASE_INHERITED(IDBVersionChangeEvent
, Event
)
87 NS_INTERFACE_MAP_BEGIN(IDBVersionChangeEvent
)
88 NS_INTERFACE_MAP_ENTRY(IDBVersionChangeEvent
)
89 NS_INTERFACE_MAP_END_INHERITING(Event
)
91 JSObject
* IDBVersionChangeEvent::WrapObjectInternal(
92 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
93 return IDBVersionChangeEvent_Binding::Wrap(aCx
, this, aGivenProto
);
96 } // namespace mozilla::dom