IDBEvents.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_idbevents_h__
  6. #define mozilla_dom_idbevents_h__
  7. #include "js/RootingAPI.h"
  8. #include "mozilla/dom/BindingDeclarations.h"
  9. #include "mozilla/dom/Event.h"
  10. #include "mozilla/dom/Nullable.h"
  11. #define IDBVERSIONCHANGEEVENT_IID \
  12. {0x3b65d4c3, 0x73ad, 0x492e, {0xb1, 0x2d, 0x15, 0xf9, 0xda, 0xc2, 0x08, 0x4b}}
  13. class nsAString;
  14. class nsDependentString;
  15. namespace mozilla {
  16. class ErrorResult;
  17. namespace dom {
  18. class EventTarget;
  19. class GlobalObject;
  20. struct IDBVersionChangeEventInit;
  21. namespace indexedDB {
  22. enum Bubbles {
  23. eDoesNotBubble,
  24. eDoesBubble
  25. };
  26. enum Cancelable {
  27. eNotCancelable,
  28. eCancelable
  29. };
  30. extern const char16_t* kAbortEventType;
  31. extern const char16_t* kBlockedEventType;
  32. extern const char16_t* kCompleteEventType;
  33. extern const char16_t* kErrorEventType;
  34. extern const char16_t* kSuccessEventType;
  35. extern const char16_t* kUpgradeNeededEventType;
  36. extern const char16_t* kVersionChangeEventType;
  37. extern const char16_t* kCloseEventType;
  38. already_AddRefed<nsIDOMEvent>
  39. CreateGenericEvent(EventTarget* aOwner,
  40. const nsDependentString& aType,
  41. Bubbles aBubbles,
  42. Cancelable aCancelable);
  43. } // namespace indexedDB
  44. class IDBVersionChangeEvent final : public Event
  45. {
  46. uint64_t mOldVersion;
  47. Nullable<uint64_t> mNewVersion;
  48. public:
  49. static already_AddRefed<IDBVersionChangeEvent>
  50. Create(EventTarget* aOwner,
  51. const nsDependentString& aName,
  52. uint64_t aOldVersion,
  53. uint64_t aNewVersion)
  54. {
  55. Nullable<uint64_t> newVersion(aNewVersion);
  56. return CreateInternal(aOwner, aName, aOldVersion, newVersion);
  57. }
  58. static already_AddRefed<IDBVersionChangeEvent>
  59. Create(EventTarget* aOwner,
  60. const nsDependentString& aName,
  61. uint64_t aOldVersion)
  62. {
  63. Nullable<uint64_t> newVersion(0);
  64. newVersion.SetNull();
  65. return CreateInternal(aOwner, aName, aOldVersion, newVersion);
  66. }
  67. static already_AddRefed<IDBVersionChangeEvent>
  68. Constructor(const GlobalObject& aGlobal,
  69. const nsAString& aType,
  70. const IDBVersionChangeEventInit& aOptions,
  71. ErrorResult& aRv);
  72. uint64_t
  73. OldVersion() const
  74. {
  75. return mOldVersion;
  76. }
  77. Nullable<uint64_t>
  78. GetNewVersion() const
  79. {
  80. return mNewVersion;
  81. }
  82. NS_DECLARE_STATIC_IID_ACCESSOR(IDBVERSIONCHANGEEVENT_IID)
  83. NS_DECL_ISUPPORTS_INHERITED
  84. NS_FORWARD_TO_EVENT
  85. virtual JSObject*
  86. WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
  87. private:
  88. IDBVersionChangeEvent(EventTarget* aOwner, uint64_t aOldVersion)
  89. : Event(aOwner, nullptr, nullptr)
  90. , mOldVersion(aOldVersion)
  91. {
  92. }
  93. ~IDBVersionChangeEvent()
  94. { }
  95. static already_AddRefed<IDBVersionChangeEvent>
  96. CreateInternal(EventTarget* aOwner,
  97. const nsAString& aName,
  98. uint64_t aOldVersion,
  99. Nullable<uint64_t> aNewVersion);
  100. };
  101. NS_DEFINE_STATIC_IID_ACCESSOR(IDBVersionChangeEvent, IDBVERSIONCHANGEEVENT_IID)
  102. } // namespace dom
  103. } // namespace mozilla
  104. #endif // mozilla_dom_idbevents_h__