2010-06-23 12:46:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
#include "IDBEvents.h"
|
|
|
|
|
|
|
|
#include "nsContentUtils.h"
|
2011-10-03 12:11:31 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2010-11-10 15:25:44 -08:00
|
|
|
#include "nsDOMException.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "nsJSON.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
#include "IDBRequest.h"
|
2010-06-28 09:46:21 -07:00
|
|
|
#include "IDBTransaction.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
USING_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class EventFiringRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EventFiringRunnable(nsIDOMEventTarget* aTarget,
|
|
|
|
nsIDOMEvent* aEvent)
|
|
|
|
: mTarget(aTarget), mEvent(aEvent)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool dummy;
|
2010-06-23 12:46:08 -07:00
|
|
|
return mTarget->DispatchEvent(mEvent, &dummy);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> mTarget;
|
|
|
|
nsCOMPtr<nsIDOMEvent> mEvent;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
already_AddRefed<nsDOMEvent>
|
|
|
|
mozilla::dom::indexedDB::CreateGenericEvent(const nsAString& aType,
|
2011-11-23 06:15:15 -08:00
|
|
|
Bubbles aBubbles,
|
|
|
|
Cancelable aCancelable)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<nsDOMEvent> event(new nsDOMEvent(nsnull, nsnull));
|
2011-11-23 06:15:15 -08:00
|
|
|
nsresult rv = event->InitEvent(aType,
|
|
|
|
aBubbles == eDoesBubble ? true : false,
|
|
|
|
aCancelable == eCancelable ? true : false);
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = event->SetTrusted(true);
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
return event.forget();
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
// static
|
2011-10-20 09:10:56 -07:00
|
|
|
already_AddRefed<nsDOMEvent>
|
2011-01-06 22:21:36 -08:00
|
|
|
IDBVersionChangeEvent::CreateInternal(const nsAString& aType,
|
2011-10-20 09:10:56 -07:00
|
|
|
PRUint64 aOldVersion,
|
|
|
|
PRUint64 aNewVersion)
|
2010-10-19 10:58:52 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<IDBVersionChangeEvent> event(new IDBVersionChangeEvent());
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsresult rv = event->InitEvent(aType, false, false);
|
2010-10-19 10:58:52 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = event->SetTrusted(true);
|
2010-10-19 10:58:52 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
event->mOldVersion = aOldVersion;
|
|
|
|
event->mNewVersion = aNewVersion;
|
2011-01-06 22:21:36 -08:00
|
|
|
|
|
|
|
nsDOMEvent* result;
|
|
|
|
event.forget(&result);
|
|
|
|
return result;
|
2010-10-19 10:58:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<nsIRunnable>
|
2011-01-06 22:21:36 -08:00
|
|
|
IDBVersionChangeEvent::CreateRunnableInternal(const nsAString& aType,
|
2011-10-20 09:10:56 -07:00
|
|
|
PRUint64 aOldVersion,
|
|
|
|
PRUint64 aNewVersion,
|
2010-10-19 10:58:52 -07:00
|
|
|
nsIDOMEventTarget* aTarget)
|
|
|
|
{
|
2011-10-20 09:10:56 -07:00
|
|
|
nsRefPtr<nsDOMEvent> event =
|
|
|
|
CreateInternal(aType, aOldVersion, aNewVersion);
|
2010-10-19 10:58:52 -07:00
|
|
|
NS_ENSURE_TRUE(event, nsnull);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable(new EventFiringRunnable(aTarget, event));
|
|
|
|
return runnable.forget();
|
|
|
|
}
|
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(IDBVersionChangeEvent, nsDOMEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IDBVersionChangeEvent, nsDOMEvent)
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(IDBVersionChangeEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIIDBVersionChangeEvent)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBVersionChangeEvent)
|
2011-01-06 22:21:36 -08:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
DOMCI_DATA(IDBVersionChangeEvent, IDBVersionChangeEvent)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-10-20 09:10:56 -07:00
|
|
|
IDBVersionChangeEvent::GetOldVersion(PRUint64* aOldVersion)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aOldVersion);
|
|
|
|
*aOldVersion = mOldVersion;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-06-01 10:21:12 -07:00
|
|
|
IDBVersionChangeEvent::GetNewVersion(JSContext* aCx,
|
|
|
|
JS::Value* aNewVersion)
|
2010-10-19 10:58:52 -07:00
|
|
|
{
|
2011-10-20 09:10:56 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aNewVersion);
|
2012-05-25 11:48:27 -07:00
|
|
|
|
|
|
|
if (!mNewVersion) {
|
|
|
|
*aNewVersion = JSVAL_NULL;
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
else if (!JS_NewNumberValue(aCx, double(mNewVersion), aNewVersion)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2012-05-25 11:48:27 -07:00
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|