IDBEvents.h (2980B)
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 {0x3b65d4c3, 0x73ad, 0x492e, {0xb1, 0x2d, 0x15, 0xf9, 0xda, 0xc2, 0x08, 0x4b}} 18 19 namespace mozilla { 20 21 class ErrorResult; 22 23 namespace dom { 24 25 class EventTarget; 26 class GlobalObject; 27 struct IDBVersionChangeEventInit; 28 29 namespace indexedDB { 30 31 enum Bubbles { eDoesNotBubble, eDoesBubble }; 32 33 enum Cancelable { eNotCancelable, eCancelable }; 34 35 extern const char16_t* kAbortEventType; 36 extern const char16_t* kBlockedEventType; 37 extern const char16_t* kCompleteEventType; 38 extern const char16_t* kErrorEventType; 39 extern const char16_t* kSuccessEventType; 40 extern const char16_t* kUpgradeNeededEventType; 41 extern const char16_t* kVersionChangeEventType; 42 extern const char16_t* kCloseEventType; 43 44 [[nodiscard]] RefPtr<Event> CreateGenericEvent(EventTarget* aOwner, 45 const nsDependentString& aType, 46 Bubbles aBubbles, 47 Cancelable aCancelable); 48 49 } // namespace indexedDB 50 51 class IDBVersionChangeEvent final : public Event { 52 uint64_t mOldVersion; 53 Nullable<uint64_t> mNewVersion; 54 55 public: 56 [[nodiscard]] static RefPtr<IDBVersionChangeEvent> Create( 57 EventTarget* aOwner, const nsDependentString& aName, uint64_t aOldVersion, 58 uint64_t aNewVersion); 59 60 [[nodiscard]] static RefPtr<IDBVersionChangeEvent> Create( 61 EventTarget* aOwner, const nsDependentString& aName, 62 uint64_t aOldVersion); 63 64 [[nodiscard]] static RefPtr<IDBVersionChangeEvent> Constructor( 65 const GlobalObject& aGlobal, const nsAString& aType, 66 const IDBVersionChangeEventInit& aOptions); 67 68 uint64_t OldVersion() const { return mOldVersion; } 69 70 Nullable<uint64_t> GetNewVersion() const { return mNewVersion; } 71 72 NS_INLINE_DECL_STATIC_IID(IDBVERSIONCHANGEEVENT_IID) 73 74 NS_DECL_ISUPPORTS_INHERITED 75 76 virtual JSObject* WrapObjectInternal( 77 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; 78 79 private: 80 IDBVersionChangeEvent(EventTarget* aOwner, uint64_t aOldVersion) 81 : Event(aOwner, nullptr, nullptr), mOldVersion(aOldVersion) {} 82 83 ~IDBVersionChangeEvent() = default; 84 85 [[nodiscard]] static RefPtr<IDBVersionChangeEvent> CreateInternal( 86 EventTarget* aOwner, const nsAString& aType, uint64_t aOldVersion, 87 const Nullable<uint64_t>& aNewVersion); 88 }; 89 90 } // namespace dom 91 } // namespace mozilla 92 93 #endif // mozilla_dom_idbevents_h__