dom/indexedDB/IDBEvents.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial