2007-12-11 00:18:04 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2007-12-11 00:18:04 -08:00
|
|
|
|
2014-02-25 21:23:57 -08:00
|
|
|
#include "mozilla/dom/DataContainerEvent.h"
|
2013-05-16 07:10:30 -07:00
|
|
|
#include "nsContentUtils.h"
|
2014-03-30 14:28:00 -07:00
|
|
|
#include "nsIDocument.h"
|
2013-05-20 12:34:12 -07:00
|
|
|
#include "nsIXPConnect.h"
|
2007-12-11 00:18:04 -08:00
|
|
|
|
2014-02-25 21:23:57 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-10-01 20:46:04 -07:00
|
|
|
|
2014-02-25 21:23:57 -08:00
|
|
|
DataContainerEvent::DataContainerEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent)
|
2014-03-04 16:37:43 -08:00
|
|
|
: Event(aOwner, aPresContext, aEvent)
|
2007-12-11 00:18:04 -08:00
|
|
|
{
|
2014-03-30 14:28:00 -07:00
|
|
|
if (mOwner) {
|
|
|
|
if (nsIDocument* doc = mOwner->GetExtantDoc()) {
|
|
|
|
doc->WarnOnceAbout(nsIDocument::eDataContainerEvent);
|
|
|
|
}
|
|
|
|
}
|
2007-12-11 00:18:04 -08:00
|
|
|
}
|
|
|
|
|
2014-02-25 21:23:57 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(DataContainerEvent)
|
2013-08-01 18:29:05 -07:00
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DataContainerEvent, Event)
|
2013-09-02 01:41:57 -07:00
|
|
|
tmp->mData.Clear();
|
2007-12-11 00:18:04 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DataContainerEvent, Event)
|
2007-12-11 00:18:04 -08:00
|
|
|
tmp->mData.EnumerateRead(TraverseEntry, &cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(DataContainerEvent, Event)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DataContainerEvent, Event)
|
2007-12-11 00:18:04 -08:00
|
|
|
|
2014-02-25 21:23:57 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DataContainerEvent)
|
2007-12-11 00:18:04 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDataContainerEvent)
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(Event)
|
2007-12-11 00:18:04 -08:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-25 21:23:57 -08:00
|
|
|
DataContainerEvent::GetData(const nsAString& aKey, nsIVariant** aData)
|
2007-12-11 00:18:04 -08:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aData);
|
|
|
|
|
|
|
|
mData.Get(aKey, aData);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-25 21:23:57 -08:00
|
|
|
DataContainerEvent::SetData(const nsAString& aKey, nsIVariant* aData)
|
2007-12-11 00:18:04 -08:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aData);
|
|
|
|
|
|
|
|
// Make sure this event isn't already being dispatched.
|
2012-12-15 17:26:04 -08:00
|
|
|
NS_ENSURE_STATE(!mEvent->mFlags.mIsBeingDispatched);
|
2012-05-18 10:30:49 -07:00
|
|
|
mData.Put(aKey, aData);
|
|
|
|
return NS_OK;
|
2007-12-11 00:18:04 -08:00
|
|
|
}
|
|
|
|
|
2013-05-16 07:10:30 -07:00
|
|
|
void
|
2014-02-25 21:23:57 -08:00
|
|
|
DataContainerEvent::SetData(JSContext* aCx, const nsAString& aKey,
|
|
|
|
JS::Handle<JS::Value> aVal,
|
|
|
|
ErrorResult& aRv)
|
2013-05-16 07:10:30 -07:00
|
|
|
{
|
|
|
|
if (!nsContentUtils::XPConnect()) {
|
|
|
|
aRv = NS_ERROR_FAILURE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIVariant> val;
|
|
|
|
nsresult rv =
|
|
|
|
nsContentUtils::XPConnect()->JSToVariant(aCx, aVal, getter_AddRefs(val));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv = rv;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aRv = SetData(aKey, val);
|
|
|
|
}
|
|
|
|
|
2007-12-11 00:18:04 -08:00
|
|
|
PLDHashOperator
|
2014-02-25 21:23:57 -08:00
|
|
|
DataContainerEvent::TraverseEntry(const nsAString& aKey,
|
|
|
|
nsIVariant* aDataItem,
|
|
|
|
void* aUserArg)
|
2007-12-11 00:18:04 -08:00
|
|
|
{
|
|
|
|
nsCycleCollectionTraversalCallback *cb =
|
|
|
|
static_cast<nsCycleCollectionTraversalCallback*>(aUserArg);
|
|
|
|
cb->NoteXPCOMChild(aDataItem);
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
2014-02-25 21:23:57 -08:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewDOMDataContainerEvent(nsIDOMEvent** aInstancePtrResult,
|
|
|
|
EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent)
|
|
|
|
{
|
|
|
|
DataContainerEvent* it = new DataContainerEvent(aOwner, aPresContext, aEvent);
|
2014-03-17 13:00:11 -07:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = static_cast<Event*>(it);
|
|
|
|
return NS_OK;
|
2014-02-25 21:23:57 -08:00
|
|
|
}
|
|
|
|
|