Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "mozilla/dom/DataContainerEvent.h" |
michael@0 | 7 | #include "nsContentUtils.h" |
michael@0 | 8 | #include "nsIDocument.h" |
michael@0 | 9 | #include "nsIXPConnect.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | namespace dom { |
michael@0 | 13 | |
michael@0 | 14 | DataContainerEvent::DataContainerEvent(EventTarget* aOwner, |
michael@0 | 15 | nsPresContext* aPresContext, |
michael@0 | 16 | WidgetEvent* aEvent) |
michael@0 | 17 | : Event(aOwner, aPresContext, aEvent) |
michael@0 | 18 | { |
michael@0 | 19 | if (mOwner) { |
michael@0 | 20 | if (nsIDocument* doc = mOwner->GetExtantDoc()) { |
michael@0 | 21 | doc->WarnOnceAbout(nsIDocument::eDataContainerEvent); |
michael@0 | 22 | } |
michael@0 | 23 | } |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | NS_IMPL_CYCLE_COLLECTION_CLASS(DataContainerEvent) |
michael@0 | 27 | |
michael@0 | 28 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DataContainerEvent, Event) |
michael@0 | 29 | tmp->mData.Clear(); |
michael@0 | 30 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
michael@0 | 31 | |
michael@0 | 32 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DataContainerEvent, Event) |
michael@0 | 33 | tmp->mData.EnumerateRead(TraverseEntry, &cb); |
michael@0 | 34 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
michael@0 | 35 | |
michael@0 | 36 | NS_IMPL_ADDREF_INHERITED(DataContainerEvent, Event) |
michael@0 | 37 | NS_IMPL_RELEASE_INHERITED(DataContainerEvent, Event) |
michael@0 | 38 | |
michael@0 | 39 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DataContainerEvent) |
michael@0 | 40 | NS_INTERFACE_MAP_ENTRY(nsIDOMDataContainerEvent) |
michael@0 | 41 | NS_INTERFACE_MAP_END_INHERITING(Event) |
michael@0 | 42 | |
michael@0 | 43 | NS_IMETHODIMP |
michael@0 | 44 | DataContainerEvent::GetData(const nsAString& aKey, nsIVariant** aData) |
michael@0 | 45 | { |
michael@0 | 46 | NS_ENSURE_ARG_POINTER(aData); |
michael@0 | 47 | |
michael@0 | 48 | mData.Get(aKey, aData); |
michael@0 | 49 | return NS_OK; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | NS_IMETHODIMP |
michael@0 | 53 | DataContainerEvent::SetData(const nsAString& aKey, nsIVariant* aData) |
michael@0 | 54 | { |
michael@0 | 55 | NS_ENSURE_ARG(aData); |
michael@0 | 56 | |
michael@0 | 57 | // Make sure this event isn't already being dispatched. |
michael@0 | 58 | NS_ENSURE_STATE(!mEvent->mFlags.mIsBeingDispatched); |
michael@0 | 59 | mData.Put(aKey, aData); |
michael@0 | 60 | return NS_OK; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | void |
michael@0 | 64 | DataContainerEvent::SetData(JSContext* aCx, const nsAString& aKey, |
michael@0 | 65 | JS::Handle<JS::Value> aVal, |
michael@0 | 66 | ErrorResult& aRv) |
michael@0 | 67 | { |
michael@0 | 68 | if (!nsContentUtils::XPConnect()) { |
michael@0 | 69 | aRv = NS_ERROR_FAILURE; |
michael@0 | 70 | return; |
michael@0 | 71 | } |
michael@0 | 72 | nsCOMPtr<nsIVariant> val; |
michael@0 | 73 | nsresult rv = |
michael@0 | 74 | nsContentUtils::XPConnect()->JSToVariant(aCx, aVal, getter_AddRefs(val)); |
michael@0 | 75 | if (NS_FAILED(rv)) { |
michael@0 | 76 | aRv = rv; |
michael@0 | 77 | return; |
michael@0 | 78 | } |
michael@0 | 79 | aRv = SetData(aKey, val); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | PLDHashOperator |
michael@0 | 83 | DataContainerEvent::TraverseEntry(const nsAString& aKey, |
michael@0 | 84 | nsIVariant* aDataItem, |
michael@0 | 85 | void* aUserArg) |
michael@0 | 86 | { |
michael@0 | 87 | nsCycleCollectionTraversalCallback *cb = |
michael@0 | 88 | static_cast<nsCycleCollectionTraversalCallback*>(aUserArg); |
michael@0 | 89 | cb->NoteXPCOMChild(aDataItem); |
michael@0 | 90 | |
michael@0 | 91 | return PL_DHASH_NEXT; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | } // namespace dom |
michael@0 | 95 | } // namespace mozilla |
michael@0 | 96 | |
michael@0 | 97 | using namespace mozilla; |
michael@0 | 98 | using namespace mozilla::dom; |
michael@0 | 99 | |
michael@0 | 100 | nsresult |
michael@0 | 101 | NS_NewDOMDataContainerEvent(nsIDOMEvent** aInstancePtrResult, |
michael@0 | 102 | EventTarget* aOwner, |
michael@0 | 103 | nsPresContext* aPresContext, |
michael@0 | 104 | WidgetEvent* aEvent) |
michael@0 | 105 | { |
michael@0 | 106 | DataContainerEvent* it = new DataContainerEvent(aOwner, aPresContext, aEvent); |
michael@0 | 107 | NS_ADDREF(it); |
michael@0 | 108 | *aInstancePtrResult = static_cast<Event*>(it); |
michael@0 | 109 | return NS_OK; |
michael@0 | 110 | } |
michael@0 | 111 |