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

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

mercurial