dom/indexedDB/IDBEvents.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/indexedDB/IDBEvents.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,164 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_indexeddb_idbevents_h__
    1.11 +#define mozilla_dom_indexeddb_idbevents_h__
    1.12 +
    1.13 +#include "mozilla/dom/indexedDB/IndexedDatabase.h"
    1.14 +
    1.15 +#include "nsIRunnable.h"
    1.16 +
    1.17 +#include "mozilla/dom/Event.h"
    1.18 +#include "mozilla/dom/Nullable.h"
    1.19 +#include "mozilla/dom/indexedDB/IDBObjectStore.h"
    1.20 +#include "mozilla/dom/IDBVersionChangeEventBinding.h"
    1.21 +
    1.22 +#define SUCCESS_EVT_STR "success"
    1.23 +#define ERROR_EVT_STR "error"
    1.24 +#define COMPLETE_EVT_STR "complete"
    1.25 +#define ABORT_EVT_STR "abort"
    1.26 +#define VERSIONCHANGE_EVT_STR "versionchange"
    1.27 +#define BLOCKED_EVT_STR "blocked"
    1.28 +#define UPGRADENEEDED_EVT_STR "upgradeneeded"
    1.29 +
    1.30 +#define IDBVERSIONCHANGEEVENT_IID \
    1.31 +  { 0x3b65d4c3, 0x73ad, 0x492e, \
    1.32 +    { 0xb1, 0x2d, 0x15, 0xf9, 0xda, 0xc2, 0x08, 0x4b } }
    1.33 +
    1.34 +BEGIN_INDEXEDDB_NAMESPACE
    1.35 +
    1.36 +enum Bubbles {
    1.37 +  eDoesNotBubble,
    1.38 +  eDoesBubble
    1.39 +};
    1.40 +
    1.41 +enum Cancelable {
    1.42 +  eNotCancelable,
    1.43 +  eCancelable
    1.44 +};
    1.45 +
    1.46 +already_AddRefed<nsIDOMEvent>
    1.47 +CreateGenericEvent(mozilla::dom::EventTarget* aOwner,
    1.48 +                   const nsAString& aType,
    1.49 +                   Bubbles aBubbles,
    1.50 +                   Cancelable aCancelable);
    1.51 +
    1.52 +class IDBVersionChangeEvent : public Event
    1.53 +{
    1.54 +public:
    1.55 +  NS_DECL_ISUPPORTS_INHERITED
    1.56 +  NS_FORWARD_TO_EVENT
    1.57 +  NS_DECLARE_STATIC_IID_ACCESSOR(IDBVERSIONCHANGEEVENT_IID)
    1.58 +
    1.59 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
    1.60 +  {
    1.61 +    return mozilla::dom::IDBVersionChangeEventBinding::Wrap(aCx, this);
    1.62 +  }
    1.63 +
    1.64 +  static already_AddRefed<IDBVersionChangeEvent>
    1.65 +  Constructor(const GlobalObject& aGlobal,
    1.66 +              const nsAString& aType,
    1.67 +              const IDBVersionChangeEventInit& aOptions,
    1.68 +              ErrorResult& aRv)
    1.69 +  {
    1.70 +    uint64_t newVersion = 0;
    1.71 +    if (!aOptions.mNewVersion.IsNull()) {
    1.72 +      newVersion = aOptions.mNewVersion.Value();
    1.73 +    }
    1.74 +    nsCOMPtr<EventTarget> target = do_QueryInterface(aGlobal.GetAsSupports());
    1.75 +    return CreateInternal(target, aType, aOptions.mOldVersion, newVersion);
    1.76 +  }
    1.77 +
    1.78 +  uint64_t OldVersion()
    1.79 +  {
    1.80 +    return mOldVersion;
    1.81 +  }
    1.82 +
    1.83 +  mozilla::dom::Nullable<uint64_t> GetNewVersion()
    1.84 +  {
    1.85 +    return mNewVersion
    1.86 +      ? mozilla::dom::Nullable<uint64_t>(mNewVersion)
    1.87 +      : mozilla::dom::Nullable<uint64_t>();
    1.88 +  }
    1.89 +
    1.90 +  inline static already_AddRefed<Event>
    1.91 +  Create(mozilla::dom::EventTarget* aOwner,
    1.92 +         int64_t aOldVersion,
    1.93 +         int64_t aNewVersion)
    1.94 +  {
    1.95 +    return CreateInternal(aOwner,
    1.96 +                          NS_LITERAL_STRING(VERSIONCHANGE_EVT_STR),
    1.97 +                          aOldVersion, aNewVersion);
    1.98 +  }
    1.99 +
   1.100 +  inline static already_AddRefed<Event>
   1.101 +  CreateBlocked(mozilla::dom::EventTarget* aOwner,
   1.102 +                uint64_t aOldVersion,
   1.103 +                uint64_t aNewVersion)
   1.104 +  {
   1.105 +    return CreateInternal(aOwner, NS_LITERAL_STRING(BLOCKED_EVT_STR),
   1.106 +                          aOldVersion, aNewVersion);
   1.107 +  }
   1.108 +
   1.109 +  inline static already_AddRefed<Event>
   1.110 +  CreateUpgradeNeeded(mozilla::dom::EventTarget* aOwner,
   1.111 +                      uint64_t aOldVersion,
   1.112 +                      uint64_t aNewVersion)
   1.113 +  {
   1.114 +    return CreateInternal(aOwner,
   1.115 +                          NS_LITERAL_STRING(UPGRADENEEDED_EVT_STR),
   1.116 +                          aOldVersion, aNewVersion);
   1.117 +  }
   1.118 +
   1.119 +  inline static already_AddRefed<nsIRunnable>
   1.120 +  CreateRunnable(mozilla::dom::EventTarget* aTarget,
   1.121 +                 uint64_t aOldVersion,
   1.122 +                 uint64_t aNewVersion)
   1.123 +  {
   1.124 +    return CreateRunnableInternal(aTarget,
   1.125 +                                  NS_LITERAL_STRING(VERSIONCHANGE_EVT_STR),
   1.126 +                                  aOldVersion, aNewVersion);
   1.127 +  }
   1.128 +
   1.129 +  static already_AddRefed<nsIRunnable>
   1.130 +  CreateBlockedRunnable(mozilla::dom::EventTarget* aTarget,
   1.131 +                        uint64_t aOldVersion,
   1.132 +                        uint64_t aNewVersion)
   1.133 +  {
   1.134 +    return CreateRunnableInternal(aTarget,
   1.135 +                                  NS_LITERAL_STRING(BLOCKED_EVT_STR),
   1.136 +                                  aOldVersion, aNewVersion);
   1.137 +  }
   1.138 +
   1.139 +protected:
   1.140 +  IDBVersionChangeEvent(mozilla::dom::EventTarget* aOwner)
   1.141 +    : Event(aOwner, nullptr, nullptr)
   1.142 +  {
   1.143 +    SetIsDOMBinding();
   1.144 +  }
   1.145 +  virtual ~IDBVersionChangeEvent() { }
   1.146 +
   1.147 +  static already_AddRefed<IDBVersionChangeEvent>
   1.148 +  CreateInternal(mozilla::dom::EventTarget* aOwner,
   1.149 +                 const nsAString& aType,
   1.150 +                 uint64_t aOldVersion,
   1.151 +                 uint64_t aNewVersion);
   1.152 +
   1.153 +  static already_AddRefed<nsIRunnable>
   1.154 +  CreateRunnableInternal(mozilla::dom::EventTarget* aOwner,
   1.155 +                         const nsAString& aType,
   1.156 +                         uint64_t aOldVersion,
   1.157 +                         uint64_t aNewVersion);
   1.158 +
   1.159 +  uint64_t mOldVersion;
   1.160 +  uint64_t mNewVersion;
   1.161 +};
   1.162 +
   1.163 +NS_DEFINE_STATIC_IID_ACCESSOR(IDBVersionChangeEvent, IDBVERSIONCHANGEEVENT_IID)
   1.164 +
   1.165 +END_INDEXEDDB_NAMESPACE
   1.166 +
   1.167 +#endif // mozilla_dom_indexeddb_idbevents_h__

mercurial