Fix bug 406900 by doing a better job of unbinding XBL default content. r=smaug, sr=sicking

This commit is contained in:
bzbarsky@mit.edu 2008-01-28 15:34:28 -08:00
parent 7f6c0e2289
commit 6ea80e5213
4 changed files with 28 additions and 12 deletions

View File

@ -448,10 +448,7 @@ RemoveInsertionParentForNodeList(nsIDOMNodeList* aList, nsIContent* aParent)
PRInt32 count = list->GetInsertionPointCount();
for (PRInt32 i = 0; i < count; ++i) {
nsRefPtr<nsXBLInsertionPoint> currPoint = list->GetInsertionPointAt(i);
nsCOMPtr<nsIContent> defContent = currPoint->GetDefaultContent();
if (defContent) {
defContent->UnbindFromTree();
}
currPoint->UnbindDefaultContent();
#ifdef DEBUG
nsCOMPtr<nsIContent> parent = currPoint->GetInsertionParent();
NS_ASSERTION(!parent || parent == aParent, "Wrong insertion parent!");

View File

@ -565,10 +565,7 @@ ChangeDocumentForDefaultContent(nsISupports* aKey,
{
PRInt32 count = aData->Length();
for (PRInt32 i = 0; i < count; i++) {
nsXBLInsertionPoint* currPoint = aData->ElementAt(i);
nsCOMPtr<nsIContent> defContent = currPoint->GetDefaultContent();
if (defContent)
defContent->UnbindFromTree();
aData->ElementAt(i)->UnbindDefaultContent();
}
return PL_DHASH_NEXT;
@ -1402,10 +1399,7 @@ nsXBLBinding::RemoveInsertionParent(nsIContent* aParent)
PRInt32 count = list->Length();
for (PRInt32 i = 0; i < count; ++i) {
nsRefPtr<nsXBLInsertionPoint> currPoint = list->ElementAt(i);
nsCOMPtr<nsIContent> defContent = currPoint->GetDefaultContent();
if (defContent) {
defContent->UnbindFromTree();
}
currPoint->UnbindDefaultContent();
#ifdef DEBUG
nsCOMPtr<nsIContent> parent = currPoint->GetInsertionParent();
NS_ASSERTION(!parent || parent == aParent, "Wrong insertion parent!");

View File

@ -114,3 +114,24 @@ nsXBLInsertionPoint::Matches(nsIContent* aContent, PRUint32 aIndex)
{
return (aContent == mParentElement && mIndex != -1 && ((PRInt32)aIndex) == mIndex);
}
void
nsXBLInsertionPoint::UnbindDefaultContent()
{
if (!mDefaultContent) {
return;
}
// Hold a strong ref while doing this, just in case
nsCOMPtr<nsIContent> defContent = mDefaultContent;
// Unbind the _kids_ of the default content, not just the default content
// itself, since they are bound to some other parent. Basically we want to
// undo the mess that InstallAnonymousContent created.
PRUint32 childCount = mDefaultContent->GetChildCount();
for (PRUint32 i = 0; i < childCount; i++) {
defContent->GetChildAt(i)->UnbindFromTree();
}
defContent->UnbindFromTree();
}

View File

@ -83,6 +83,10 @@ public:
PRBool Matches(nsIContent* aContent, PRUint32 aIndex);
// Unbind all the default content in this insertion point. Used
// when the insertion parent is going away.
void UnbindDefaultContent();
protected:
nsAutoRefCnt mRefCnt;
nsIContent* mParentElement; // This ref is weak. The parent of the <children> element.