michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_indexeddb_idbevents_h__ michael@0: #define mozilla_dom_indexeddb_idbevents_h__ michael@0: michael@0: #include "mozilla/dom/indexedDB/IndexedDatabase.h" michael@0: michael@0: #include "nsIRunnable.h" michael@0: michael@0: #include "mozilla/dom/Event.h" michael@0: #include "mozilla/dom/Nullable.h" michael@0: #include "mozilla/dom/indexedDB/IDBObjectStore.h" michael@0: #include "mozilla/dom/IDBVersionChangeEventBinding.h" michael@0: michael@0: #define SUCCESS_EVT_STR "success" michael@0: #define ERROR_EVT_STR "error" michael@0: #define COMPLETE_EVT_STR "complete" michael@0: #define ABORT_EVT_STR "abort" michael@0: #define VERSIONCHANGE_EVT_STR "versionchange" michael@0: #define BLOCKED_EVT_STR "blocked" michael@0: #define UPGRADENEEDED_EVT_STR "upgradeneeded" michael@0: michael@0: #define IDBVERSIONCHANGEEVENT_IID \ michael@0: { 0x3b65d4c3, 0x73ad, 0x492e, \ michael@0: { 0xb1, 0x2d, 0x15, 0xf9, 0xda, 0xc2, 0x08, 0x4b } } michael@0: michael@0: BEGIN_INDEXEDDB_NAMESPACE michael@0: michael@0: enum Bubbles { michael@0: eDoesNotBubble, michael@0: eDoesBubble michael@0: }; michael@0: michael@0: enum Cancelable { michael@0: eNotCancelable, michael@0: eCancelable michael@0: }; michael@0: michael@0: already_AddRefed michael@0: CreateGenericEvent(mozilla::dom::EventTarget* aOwner, michael@0: const nsAString& aType, michael@0: Bubbles aBubbles, michael@0: Cancelable aCancelable); michael@0: michael@0: class IDBVersionChangeEvent : public Event michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_FORWARD_TO_EVENT michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(IDBVERSIONCHANGEEVENT_IID) michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE michael@0: { michael@0: return mozilla::dom::IDBVersionChangeEventBinding::Wrap(aCx, this); michael@0: } michael@0: michael@0: static already_AddRefed michael@0: Constructor(const GlobalObject& aGlobal, michael@0: const nsAString& aType, michael@0: const IDBVersionChangeEventInit& aOptions, michael@0: ErrorResult& aRv) michael@0: { michael@0: uint64_t newVersion = 0; michael@0: if (!aOptions.mNewVersion.IsNull()) { michael@0: newVersion = aOptions.mNewVersion.Value(); michael@0: } michael@0: nsCOMPtr target = do_QueryInterface(aGlobal.GetAsSupports()); michael@0: return CreateInternal(target, aType, aOptions.mOldVersion, newVersion); michael@0: } michael@0: michael@0: uint64_t OldVersion() michael@0: { michael@0: return mOldVersion; michael@0: } michael@0: michael@0: mozilla::dom::Nullable GetNewVersion() michael@0: { michael@0: return mNewVersion michael@0: ? mozilla::dom::Nullable(mNewVersion) michael@0: : mozilla::dom::Nullable(); michael@0: } michael@0: michael@0: inline static already_AddRefed michael@0: Create(mozilla::dom::EventTarget* aOwner, michael@0: int64_t aOldVersion, michael@0: int64_t aNewVersion) michael@0: { michael@0: return CreateInternal(aOwner, michael@0: NS_LITERAL_STRING(VERSIONCHANGE_EVT_STR), michael@0: aOldVersion, aNewVersion); michael@0: } michael@0: michael@0: inline static already_AddRefed michael@0: CreateBlocked(mozilla::dom::EventTarget* aOwner, michael@0: uint64_t aOldVersion, michael@0: uint64_t aNewVersion) michael@0: { michael@0: return CreateInternal(aOwner, NS_LITERAL_STRING(BLOCKED_EVT_STR), michael@0: aOldVersion, aNewVersion); michael@0: } michael@0: michael@0: inline static already_AddRefed michael@0: CreateUpgradeNeeded(mozilla::dom::EventTarget* aOwner, michael@0: uint64_t aOldVersion, michael@0: uint64_t aNewVersion) michael@0: { michael@0: return CreateInternal(aOwner, michael@0: NS_LITERAL_STRING(UPGRADENEEDED_EVT_STR), michael@0: aOldVersion, aNewVersion); michael@0: } michael@0: michael@0: inline static already_AddRefed michael@0: CreateRunnable(mozilla::dom::EventTarget* aTarget, michael@0: uint64_t aOldVersion, michael@0: uint64_t aNewVersion) michael@0: { michael@0: return CreateRunnableInternal(aTarget, michael@0: NS_LITERAL_STRING(VERSIONCHANGE_EVT_STR), michael@0: aOldVersion, aNewVersion); michael@0: } michael@0: michael@0: static already_AddRefed michael@0: CreateBlockedRunnable(mozilla::dom::EventTarget* aTarget, michael@0: uint64_t aOldVersion, michael@0: uint64_t aNewVersion) michael@0: { michael@0: return CreateRunnableInternal(aTarget, michael@0: NS_LITERAL_STRING(BLOCKED_EVT_STR), michael@0: aOldVersion, aNewVersion); michael@0: } michael@0: michael@0: protected: michael@0: IDBVersionChangeEvent(mozilla::dom::EventTarget* aOwner) michael@0: : Event(aOwner, nullptr, nullptr) michael@0: { michael@0: SetIsDOMBinding(); michael@0: } michael@0: virtual ~IDBVersionChangeEvent() { } michael@0: michael@0: static already_AddRefed michael@0: CreateInternal(mozilla::dom::EventTarget* aOwner, michael@0: const nsAString& aType, michael@0: uint64_t aOldVersion, michael@0: uint64_t aNewVersion); michael@0: michael@0: static already_AddRefed michael@0: CreateRunnableInternal(mozilla::dom::EventTarget* aOwner, michael@0: const nsAString& aType, michael@0: uint64_t aOldVersion, michael@0: uint64_t aNewVersion); michael@0: michael@0: uint64_t mOldVersion; michael@0: uint64_t mNewVersion; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(IDBVersionChangeEvent, IDBVERSIONCHANGEEVENT_IID) michael@0: michael@0: END_INDEXEDDB_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_indexeddb_idbevents_h__