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"
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/dom/EventTarget.h"
|
|
|
|
#include "mozilla/dom/IDBVersionChangeEventBinding.h"
|
|
|
|
#include "nsString.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
using namespace mozilla;
|
2013-04-19 15:18:32 -07:00
|
|
|
using namespace mozilla::dom;
|
2014-09-26 16:21:57 -07:00
|
|
|
using namespace mozilla::dom::indexedDB;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace indexedDB {
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
const char16_t* kAbortEventType = MOZ_UTF16("abort");
|
|
|
|
const char16_t* kBlockedEventType = MOZ_UTF16("blocked");
|
|
|
|
const char16_t* kCompleteEventType = MOZ_UTF16("complete");
|
|
|
|
const char16_t* kErrorEventType = MOZ_UTF16("error");
|
|
|
|
const char16_t* kSuccessEventType = MOZ_UTF16("success");
|
|
|
|
const char16_t* kUpgradeNeededEventType = MOZ_UTF16("upgradeneeded");
|
|
|
|
const char16_t* kVersionChangeEventType = MOZ_UTF16("versionchange");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
already_AddRefed<nsIDOMEvent>
|
2014-09-26 16:21:57 -07:00
|
|
|
CreateGenericEvent(EventTarget* aOwner,
|
|
|
|
const nsDependentString& aType,
|
|
|
|
Bubbles aBubbles,
|
|
|
|
Cancelable aCancelable)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2013-03-09 03:34:29 -08:00
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
2014-09-26 16:21:57 -07:00
|
|
|
nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), aOwner, nullptr, nullptr);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = event->InitEvent(aType,
|
|
|
|
aBubbles == eDoesBubble ? true : false,
|
|
|
|
aCancelable == eCancelable ? true : false);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-12-22 00:18:08 -08:00
|
|
|
event->SetTrusted(true);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
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
|
2013-07-05 10:57:28 -07:00
|
|
|
already_AddRefed<IDBVersionChangeEvent>
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBVersionChangeEvent::CreateInternal(EventTarget* aOwner,
|
2013-03-09 03:34:29 -08:00
|
|
|
const nsAString& aType,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t aOldVersion,
|
2014-09-26 16:21:57 -07:00
|
|
|
Nullable<uint64_t> aNewVersion)
|
2010-10-19 10:58:52 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
nsRefPtr<IDBVersionChangeEvent> event =
|
|
|
|
new IDBVersionChangeEvent(aOwner, aOldVersion);
|
|
|
|
if (!aNewVersion.IsNull()) {
|
|
|
|
event->mNewVersion.SetValue(aNewVersion.Value());
|
|
|
|
}
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsresult rv = event->InitEvent(aType, false, false);
|
2014-09-26 16:21:57 -07:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2012-12-22 00:18:08 -08:00
|
|
|
event->SetTrusted(true);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2012-12-22 00:18:08 -08:00
|
|
|
return event.forget();
|
2010-10-19 10:58:52 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
already_AddRefed<IDBVersionChangeEvent>
|
|
|
|
IDBVersionChangeEvent::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const IDBVersionChangeEventInit& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2010-10-19 10:58:52 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
nsCOMPtr<EventTarget> target = do_QueryInterface(aGlobal.GetAsSupports());
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return CreateInternal(target,
|
|
|
|
aType,
|
|
|
|
aOptions.mOldVersion,
|
|
|
|
aOptions.mNewVersion);
|
2010-10-19 10:58:52 -07:00
|
|
|
}
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(IDBVersionChangeEvent, Event)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IDBVersionChangeEvent, Event)
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(IDBVersionChangeEvent)
|
2013-07-11 10:36:42 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(IDBVersionChangeEvent)
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(Event)
|
2014-09-26 16:21:57 -07:00
|
|
|
|
|
|
|
JSObject*
|
2014-10-17 16:16:58 -07:00
|
|
|
IDBVersionChangeEvent::WrapObjectInternal(JSContext* aCx)
|
2014-09-26 16:21:57 -07:00
|
|
|
{
|
|
|
|
return IDBVersionChangeEventBinding::Wrap(aCx, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|