2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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 11:18:04 +03:00
|
|
|
|
2014-02-26 09:23:57 +04:00
|
|
|
#include "mozilla/dom/DataContainerEvent.h"
|
2013-05-16 18:10:30 +04:00
|
|
|
#include "nsContentUtils.h"
|
2014-03-31 01:28:00 +04:00
|
|
|
#include "nsIDocument.h"
|
2013-05-20 23:34:12 +04:00
|
|
|
#include "nsIXPConnect.h"
|
2007-12-11 11:18:04 +03:00
|
|
|
|
2014-02-26 09:23:57 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-10-02 07:46:04 +04:00
|
|
|
|
2014-02-26 09:23:57 +04:00
|
|
|
DataContainerEvent::DataContainerEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent)
|
2014-03-05 04:37:43 +04:00
|
|
|
: Event(aOwner, aPresContext, aEvent)
|
2007-12-11 11:18:04 +03:00
|
|
|
{
|
2015-02-23 18:03:40 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(mOwner);
|
|
|
|
if (win) {
|
|
|
|
if (nsIDocument* doc = win->GetExtantDoc()) {
|
2014-03-31 01:28:00 +04:00
|
|
|
doc->WarnOnceAbout(nsIDocument::eDataContainerEvent);
|
|
|
|
}
|
|
|
|
}
|
2007-12-11 11:18:04 +03:00
|
|
|
}
|
|
|
|
|
2014-02-26 09:23:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(DataContainerEvent)
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DataContainerEvent, Event)
|
2015-07-27 05:29:52 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mData)
|
2007-12-11 11:18:04 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DataContainerEvent, Event)
|
2015-07-27 05:29:52 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mData)
|
2007-12-11 11:18:04 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(DataContainerEvent, Event)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DataContainerEvent, Event)
|
2007-12-11 11:18:04 +03:00
|
|
|
|
2014-02-26 09:23:57 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DataContainerEvent)
|
2007-12-11 11:18:04 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDataContainerEvent)
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(Event)
|
2007-12-11 11:18:04 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-26 09:23:57 +04:00
|
|
|
DataContainerEvent::GetData(const nsAString& aKey, nsIVariant** aData)
|
2007-12-11 11:18:04 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aData);
|
|
|
|
|
|
|
|
mData.Get(aKey, aData);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-26 09:23:57 +04:00
|
|
|
DataContainerEvent::SetData(const nsAString& aKey, nsIVariant* aData)
|
2007-12-11 11:18:04 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aData);
|
|
|
|
|
|
|
|
// Make sure this event isn't already being dispatched.
|
2012-12-16 05:26:04 +04:00
|
|
|
NS_ENSURE_STATE(!mEvent->mFlags.mIsBeingDispatched);
|
2012-05-18 21:30:49 +04:00
|
|
|
mData.Put(aKey, aData);
|
|
|
|
return NS_OK;
|
2007-12-11 11:18:04 +03:00
|
|
|
}
|
|
|
|
|
2013-05-16 18:10:30 +04:00
|
|
|
void
|
2014-02-26 09:23:57 +04:00
|
|
|
DataContainerEvent::SetData(JSContext* aCx, const nsAString& aKey,
|
|
|
|
JS::Handle<JS::Value> aVal,
|
|
|
|
ErrorResult& aRv)
|
2013-05-16 18:10:30 +04: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);
|
|
|
|
}
|
|
|
|
|
2014-02-26 09:23:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-08-12 14:39:31 +03:00
|
|
|
already_AddRefed<DataContainerEvent>
|
|
|
|
NS_NewDOMDataContainerEvent(EventTarget* aOwner,
|
2014-02-26 09:23:57 +04:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataContainerEvent> it =
|
2015-08-12 14:39:31 +03:00
|
|
|
new DataContainerEvent(aOwner, aPresContext, aEvent);
|
|
|
|
return it.forget();
|
2014-02-26 09:23:57 +04:00
|
|
|
}
|
|
|
|
|