diff options
Diffstat (limited to 'dom/base/FragmentOrElement.cpp')
-rw-r--r-- | dom/base/FragmentOrElement.cpp | 165 |
1 files changed, 90 insertions, 75 deletions
diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index 9106778df..526c3c9d4 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -530,8 +530,7 @@ nsNodeSupportsWeakRefTearoff::GetWeakReference(nsIWeakReference** aInstancePtr) //---------------------------------------------------------------------- FragmentOrElement::nsDOMSlots::nsDOMSlots() : nsINode::nsSlots(), - mDataset(nullptr), - mBindingParent(nullptr) + mDataset(nullptr) { } @@ -543,84 +542,104 @@ FragmentOrElement::nsDOMSlots::~nsDOMSlots() } void -FragmentOrElement::nsDOMSlots::Traverse(nsCycleCollectionTraversalCallback &cb, bool aIsXUL) +FragmentOrElement::nsDOMSlots::Traverse(nsCycleCollectionTraversalCallback &cb) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mStyle"); cb.NoteXPCOMChild(mStyle.get()); - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mSMILOverrideStyle"); - cb.NoteXPCOMChild(mSMILOverrideStyle.get()); - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mAttributeMap"); cb.NoteXPCOMChild(mAttributeMap.get()); - if (aIsXUL) { - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mControllers"); - cb.NoteXPCOMChild(mControllers); + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mChildrenList"); + cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMNodeList*, mChildrenList)); + + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mClassList"); + cb.NoteXPCOMChild(mClassList.get()); + + if (!mExtendedSlots) { + return; } - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mXBLBinding"); - cb.NoteNativeChild(mXBLBinding, NS_CYCLE_COLLECTION_PARTICIPANT(nsXBLBinding)); + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mExtendedSlots->mSMILOverrideStyle"); + cb.NoteXPCOMChild(mExtendedSlots->mSMILOverrideStyle.get()); - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mXBLInsertionParent"); - cb.NoteXPCOMChild(mXBLInsertionParent.get()); + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mExtendedSlots->mControllers"); + cb.NoteXPCOMChild(mExtendedSlots->mControllers); - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mShadowRoot"); - cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIContent*, mShadowRoot)); + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mExtendedSlots->mLabelsList"); + cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMNodeList*,mExtendedSlots-> mLabelsList)); - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mContainingShadow"); - cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIContent*, mContainingShadow)); + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mExtendedSlots->mShadowRoot"); + cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIContent*, mExtendedSlots->mShadowRoot)); - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mChildrenList"); - cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMNodeList*, mChildrenList)); + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mExtendedSlots->mContainingShadow"); + cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIContent*, mExtendedSlots->mContainingShadow)); - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mLabelsList"); - cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMNodeList*, mLabelsList)); + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mExtendedSlots->mXBLBinding"); + cb.NoteNativeChild(mExtendedSlots->mXBLBinding, + NS_CYCLE_COLLECTION_PARTICIPANT(nsXBLBinding)); - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mClassList"); - cb.NoteXPCOMChild(mClassList.get()); + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mExtendedSlots->mXBLInsertionParent"); + cb.NoteXPCOMChild(mExtendedSlots->mXBLInsertionParent.get()); - if (mCustomElementData) { - for (uint32_t i = 0; i < mCustomElementData->mCallbackQueue.Length(); i++) { - mCustomElementData->mCallbackQueue[i]->Traverse(cb); - } + if (mExtendedSlots->mCustomElementData) { + mExtendedSlots->mCustomElementData->Traverse(cb); } - for (auto iter = mRegisteredIntersectionObservers.Iter(); !iter.Done(); iter.Next()) { + for (auto iter = mExtendedSlots->mRegisteredIntersectionObservers.Iter(); + !iter.Done(); iter.Next()) { DOMIntersectionObserver* observer = iter.Key(); - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mRegisteredIntersectionObservers[i]"); + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, + "mExtendedSlots->mRegisteredIntersectionObservers[i]"); cb.NoteXPCOMChild(observer); } + + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mExtendedSlots->mFrameLoaderOrOpener"); + cb.NoteXPCOMChild(mExtendedSlots->mFrameLoaderOrOpener); } void -FragmentOrElement::nsDOMSlots::Unlink(bool aIsXUL) +FragmentOrElement::nsDOMSlots::Unlink() { mStyle = nullptr; - mSMILOverrideStyle = nullptr; if (mAttributeMap) { mAttributeMap->DropReference(); mAttributeMap = nullptr; } - if (aIsXUL) - NS_IF_RELEASE(mControllers); - - MOZ_ASSERT(!mXBLBinding); - - mXBLInsertionParent = nullptr; - mShadowRoot = nullptr; - mContainingShadow = nullptr; mChildrenList = nullptr; - mLabelsList = nullptr; - mCustomElementData = nullptr; mClassList = nullptr; - mRegisteredIntersectionObservers.Clear(); + + if (!mExtendedSlots) { + return; + } + + mExtendedSlots->mSMILOverrideStyle = nullptr; + mExtendedSlots->mControllers = nullptr; + mExtendedSlots->mLabelsList = nullptr; + mExtendedSlots->mShadowRoot = nullptr; + mExtendedSlots->mContainingShadow = nullptr; + MOZ_ASSERT(!(mExtendedSlots->mXBLBinding)); + mExtendedSlots->mXBLInsertionParent = nullptr; + if (mExtendedSlots->mCustomElementData) { + mExtendedSlots->mCustomElementData->Unlink(); + mExtendedSlots->mCustomElementData = nullptr; + } + mExtendedSlots->mRegisteredIntersectionObservers.Clear(); + nsCOMPtr<nsIFrameLoader> frameLoader = + do_QueryInterface(mExtendedSlots->mFrameLoaderOrOpener); + if (frameLoader) { + static_cast<nsFrameLoader*>(frameLoader.get())->Destroy(); + } + mExtendedSlots->mFrameLoaderOrOpener = nullptr; } size_t FragmentOrElement::nsDOMSlots::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { size_t n = aMallocSizeOf(this); + if (mExtendedSlots) { + n += aMallocSizeOf(mExtendedSlots.get()); + } if (mAttributeMap) { n += mAttributeMap->SizeOfIncludingThis(aMallocSizeOf); @@ -641,6 +660,19 @@ FragmentOrElement::nsDOMSlots::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) c return n; } +FragmentOrElement::nsExtendedDOMSlots::nsExtendedDOMSlots() + : mBindingParent(nullptr) +{ +} + +FragmentOrElement::nsExtendedDOMSlots::~nsExtendedDOMSlots() +{ + nsCOMPtr<nsIFrameLoader> frameLoader = do_QueryInterface(mFrameLoaderOrOpener); + if (frameLoader) { + static_cast<nsFrameLoader*>(frameLoader.get())->Destroy(); + } +} + FragmentOrElement::FragmentOrElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo) : nsIContent(aNodeInfo) { @@ -962,7 +994,7 @@ FragmentOrElement::IsLink(nsIURI** aURI) const nsIContent* FragmentOrElement::GetBindingParent() const { - nsDOMSlots *slots = GetExistingDOMSlots(); + nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); if (slots) { return slots->mBindingParent; @@ -974,7 +1006,7 @@ nsXBLBinding* FragmentOrElement::GetXBLBinding() const { if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) { - nsDOMSlots *slots = GetExistingDOMSlots(); + nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); if (slots) { return slots->mXBLBinding; } @@ -1009,11 +1041,11 @@ FragmentOrElement::SetXBLBinding(nsXBLBinding* aBinding, if (aBinding) { SetFlags(NODE_MAY_BE_IN_BINDING_MNGR); - nsDOMSlots *slots = DOMSlots(); + nsExtendedDOMSlots* slots = ExtendedDOMSlots(); slots->mXBLBinding = aBinding; bindingManager->AddBoundContent(this); } else { - nsDOMSlots *slots = GetExistingDOMSlots(); + nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); if (slots) { slots->mXBLBinding = nullptr; } @@ -1028,7 +1060,7 @@ nsIContent* FragmentOrElement::GetXBLInsertionParent() const { if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) { - nsDOMSlots *slots = GetExistingDOMSlots(); + nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); if (slots) { return slots->mXBLInsertionParent; } @@ -1040,7 +1072,7 @@ FragmentOrElement::GetXBLInsertionParent() const ShadowRoot* FragmentOrElement::GetContainingShadow() const { - nsDOMSlots *slots = GetExistingDOMSlots(); + nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); if (slots) { return slots->mContainingShadow; } @@ -1050,21 +1082,21 @@ FragmentOrElement::GetContainingShadow() const void FragmentOrElement::SetShadowRoot(ShadowRoot* aShadowRoot) { - nsDOMSlots *slots = DOMSlots(); + nsExtendedDOMSlots* slots = ExtendedDOMSlots(); slots->mShadowRoot = aShadowRoot; } nsTArray<nsIContent*>& FragmentOrElement::DestInsertionPoints() { - nsDOMSlots *slots = DOMSlots(); + nsExtendedDOMSlots* slots = ExtendedDOMSlots(); return slots->mDestInsertionPoints; } nsTArray<nsIContent*>* FragmentOrElement::GetExistingDestInsertionPoints() const { - nsDOMSlots *slots = GetExistingDOMSlots(); + nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); if (slots) { return &slots->mDestInsertionPoints; } @@ -1075,35 +1107,17 @@ void FragmentOrElement::SetXBLInsertionParent(nsIContent* aContent) { if (aContent) { - nsDOMSlots *slots = DOMSlots(); + nsExtendedDOMSlots* slots = ExtendedDOMSlots(); SetFlags(NODE_MAY_BE_IN_BINDING_MNGR); slots->mXBLInsertionParent = aContent; } else { - nsDOMSlots *slots = GetExistingDOMSlots(); + nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); if (slots) { slots->mXBLInsertionParent = nullptr; } } } -CustomElementData* -FragmentOrElement::GetCustomElementData() const -{ - nsDOMSlots *slots = GetExistingDOMSlots(); - if (slots) { - return slots->mCustomElementData; - } - return nullptr; -} - -void -FragmentOrElement::SetCustomElementData(CustomElementData* aData) -{ - nsDOMSlots *slots = DOMSlots(); - MOZ_ASSERT(!slots->mCustomElementData, "Custom element data may not be changed once set."); - slots->mCustomElementData = aData; -} - nsresult FragmentOrElement::InsertChildAt(nsIContent* aKid, uint32_t aIndex, @@ -1366,14 +1380,15 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(FragmentOrElement) { nsDOMSlots *slots = tmp->GetExistingDOMSlots(); if (slots) { - if (tmp->IsElement()) { + if (slots->mExtendedSlots && tmp->IsElement()) { Element* elem = tmp->AsElement(); - for (auto iter = slots->mRegisteredIntersectionObservers.Iter(); !iter.Done(); iter.Next()) { + for (auto iter = slots->mExtendedSlots->mRegisteredIntersectionObservers.Iter(); + !iter.Done(); iter.Next()) { DOMIntersectionObserver* observer = iter.Key(); observer->UnlinkTarget(*elem); } } - slots->Unlink(tmp->IsXULElement()); + slots->Unlink(); } } @@ -1938,7 +1953,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(FragmentOrElement) { nsDOMSlots *slots = tmp->GetExistingDOMSlots(); if (slots) { - slots->Traverse(cb, tmp->IsXULElement()); + slots->Traverse(cb); } } NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |