michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "IDBEvents.h" michael@0: michael@0: #include "nsJSON.h" michael@0: #include "nsThreadUtils.h" michael@0: michael@0: #include "IDBRequest.h" michael@0: #include "IDBTransaction.h" michael@0: michael@0: USING_INDEXEDDB_NAMESPACE michael@0: using namespace mozilla::dom; michael@0: michael@0: namespace { michael@0: michael@0: class EventFiringRunnable : public nsRunnable michael@0: { michael@0: public: michael@0: EventFiringRunnable(EventTarget* aTarget, michael@0: nsIDOMEvent* aEvent) michael@0: : mTarget(aTarget), mEvent(aEvent) michael@0: { } michael@0: michael@0: NS_IMETHOD Run() { michael@0: bool dummy; michael@0: return mTarget->DispatchEvent(mEvent, &dummy); michael@0: } michael@0: michael@0: private: michael@0: nsCOMPtr mTarget; michael@0: nsCOMPtr mEvent; michael@0: }; michael@0: michael@0: } // anonymous namespace michael@0: michael@0: already_AddRefed michael@0: mozilla::dom::indexedDB::CreateGenericEvent(mozilla::dom::EventTarget* aOwner, michael@0: const nsAString& aType, michael@0: Bubbles aBubbles, michael@0: Cancelable aCancelable) michael@0: { michael@0: nsCOMPtr event; michael@0: NS_NewDOMEvent(getter_AddRefs(event), aOwner, nullptr, nullptr); michael@0: nsresult rv = event->InitEvent(aType, michael@0: aBubbles == eDoesBubble ? true : false, michael@0: aCancelable == eCancelable ? true : false); michael@0: NS_ENSURE_SUCCESS(rv, nullptr); michael@0: michael@0: event->SetTrusted(true); michael@0: michael@0: return event.forget(); michael@0: } michael@0: michael@0: // static michael@0: already_AddRefed michael@0: IDBVersionChangeEvent::CreateInternal(mozilla::dom::EventTarget* aOwner, michael@0: const nsAString& aType, michael@0: uint64_t aOldVersion, michael@0: uint64_t aNewVersion) michael@0: { michael@0: nsRefPtr event(new IDBVersionChangeEvent(aOwner)); michael@0: michael@0: nsresult rv = event->InitEvent(aType, false, false); michael@0: NS_ENSURE_SUCCESS(rv, nullptr); michael@0: michael@0: event->SetTrusted(true); michael@0: michael@0: event->mOldVersion = aOldVersion; michael@0: event->mNewVersion = aNewVersion; michael@0: michael@0: return event.forget(); michael@0: } michael@0: michael@0: // static michael@0: already_AddRefed michael@0: IDBVersionChangeEvent::CreateRunnableInternal(mozilla::dom::EventTarget* aTarget, michael@0: const nsAString& aType, michael@0: uint64_t aOldVersion, michael@0: uint64_t aNewVersion) michael@0: { michael@0: nsRefPtr event = michael@0: CreateInternal(aTarget, aType, aOldVersion, aNewVersion); michael@0: NS_ENSURE_TRUE(event, nullptr); michael@0: michael@0: nsCOMPtr runnable(new EventFiringRunnable(aTarget, event)); michael@0: return runnable.forget(); michael@0: } michael@0: michael@0: NS_IMPL_ADDREF_INHERITED(IDBVersionChangeEvent, Event) michael@0: NS_IMPL_RELEASE_INHERITED(IDBVersionChangeEvent, Event) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN(IDBVersionChangeEvent) michael@0: NS_INTERFACE_MAP_ENTRY(IDBVersionChangeEvent) michael@0: NS_INTERFACE_MAP_END_INHERITING(Event)