dom/indexedDB/IDBEvents.cpp

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

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "IDBEvents.h"
michael@0 8
michael@0 9 #include "nsJSON.h"
michael@0 10 #include "nsThreadUtils.h"
michael@0 11
michael@0 12 #include "IDBRequest.h"
michael@0 13 #include "IDBTransaction.h"
michael@0 14
michael@0 15 USING_INDEXEDDB_NAMESPACE
michael@0 16 using namespace mozilla::dom;
michael@0 17
michael@0 18 namespace {
michael@0 19
michael@0 20 class EventFiringRunnable : public nsRunnable
michael@0 21 {
michael@0 22 public:
michael@0 23 EventFiringRunnable(EventTarget* aTarget,
michael@0 24 nsIDOMEvent* aEvent)
michael@0 25 : mTarget(aTarget), mEvent(aEvent)
michael@0 26 { }
michael@0 27
michael@0 28 NS_IMETHOD Run() {
michael@0 29 bool dummy;
michael@0 30 return mTarget->DispatchEvent(mEvent, &dummy);
michael@0 31 }
michael@0 32
michael@0 33 private:
michael@0 34 nsCOMPtr<EventTarget> mTarget;
michael@0 35 nsCOMPtr<nsIDOMEvent> mEvent;
michael@0 36 };
michael@0 37
michael@0 38 } // anonymous namespace
michael@0 39
michael@0 40 already_AddRefed<nsIDOMEvent>
michael@0 41 mozilla::dom::indexedDB::CreateGenericEvent(mozilla::dom::EventTarget* aOwner,
michael@0 42 const nsAString& aType,
michael@0 43 Bubbles aBubbles,
michael@0 44 Cancelable aCancelable)
michael@0 45 {
michael@0 46 nsCOMPtr<nsIDOMEvent> event;
michael@0 47 NS_NewDOMEvent(getter_AddRefs(event), aOwner, nullptr, nullptr);
michael@0 48 nsresult rv = event->InitEvent(aType,
michael@0 49 aBubbles == eDoesBubble ? true : false,
michael@0 50 aCancelable == eCancelable ? true : false);
michael@0 51 NS_ENSURE_SUCCESS(rv, nullptr);
michael@0 52
michael@0 53 event->SetTrusted(true);
michael@0 54
michael@0 55 return event.forget();
michael@0 56 }
michael@0 57
michael@0 58 // static
michael@0 59 already_AddRefed<IDBVersionChangeEvent>
michael@0 60 IDBVersionChangeEvent::CreateInternal(mozilla::dom::EventTarget* aOwner,
michael@0 61 const nsAString& aType,
michael@0 62 uint64_t aOldVersion,
michael@0 63 uint64_t aNewVersion)
michael@0 64 {
michael@0 65 nsRefPtr<IDBVersionChangeEvent> event(new IDBVersionChangeEvent(aOwner));
michael@0 66
michael@0 67 nsresult rv = event->InitEvent(aType, false, false);
michael@0 68 NS_ENSURE_SUCCESS(rv, nullptr);
michael@0 69
michael@0 70 event->SetTrusted(true);
michael@0 71
michael@0 72 event->mOldVersion = aOldVersion;
michael@0 73 event->mNewVersion = aNewVersion;
michael@0 74
michael@0 75 return event.forget();
michael@0 76 }
michael@0 77
michael@0 78 // static
michael@0 79 already_AddRefed<nsIRunnable>
michael@0 80 IDBVersionChangeEvent::CreateRunnableInternal(mozilla::dom::EventTarget* aTarget,
michael@0 81 const nsAString& aType,
michael@0 82 uint64_t aOldVersion,
michael@0 83 uint64_t aNewVersion)
michael@0 84 {
michael@0 85 nsRefPtr<Event> event =
michael@0 86 CreateInternal(aTarget, aType, aOldVersion, aNewVersion);
michael@0 87 NS_ENSURE_TRUE(event, nullptr);
michael@0 88
michael@0 89 nsCOMPtr<nsIRunnable> runnable(new EventFiringRunnable(aTarget, event));
michael@0 90 return runnable.forget();
michael@0 91 }
michael@0 92
michael@0 93 NS_IMPL_ADDREF_INHERITED(IDBVersionChangeEvent, Event)
michael@0 94 NS_IMPL_RELEASE_INHERITED(IDBVersionChangeEvent, Event)
michael@0 95
michael@0 96 NS_INTERFACE_MAP_BEGIN(IDBVersionChangeEvent)
michael@0 97 NS_INTERFACE_MAP_ENTRY(IDBVersionChangeEvent)
michael@0 98 NS_INTERFACE_MAP_END_INHERITING(Event)

mercurial