Fix for bug 5850:

1) Add a RemoveChild() method to nsIWebshell.
2) nsWebshell::Destroy() calls this method on its parent to remove itself from the parent's child list.
3) Call nsWebshell::Destroy() from nsHTMLFrameInnerFrame's detructor.
This commit is contained in:
nisheeth%netscape.com 1999-05-05 00:23:51 +00:00
parent 3c41d4b24d
commit 18e8cf2a70
4 changed files with 42 additions and 4 deletions

View File

@ -171,6 +171,7 @@ public:
NS_IMETHOD GetParentEvenIfChrome(nsIWebShell*& aParent);
NS_IMETHOD GetChildCount(PRInt32& aResult);
NS_IMETHOD AddChild(nsIWebShell* aChild);
NS_IMETHOD RemoveChild(nsIWebShell* aChild);
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIWebShell*& aResult);
NS_IMETHOD GetName(const PRUnichar** aName);
NS_IMETHOD SetName(const PRUnichar* aName);
@ -888,6 +889,11 @@ nsWebShell::Destroy()
SetObserver(nsnull);
SetDocLoaderObserver(nsnull);
// Remove this webshell from its parent's child list
if (nsnull != mParent) {
mParent->RemoveChild(this);
}
if (nsnull != mDocLoader) {
mDocLoader->SetContainer(nsnull);
}
@ -1214,6 +1220,20 @@ nsWebShell::AddChild(nsIWebShell* aChild)
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::RemoveChild(nsIWebShell* aChild)
{
NS_PRECONDITION(nsnull != aChild, "nsWebShell::RemoveChild(): null ptr");
if (nsnull == aChild) {
return NS_ERROR_NULL_POINTER;
}
mChildren.RemoveElement(aChild);
aChild->SetParent(nsnull);
NS_RELEASE(aChild);
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::ChildAt(PRInt32 aIndex, nsIWebShell*& aResult)
{

View File

@ -432,8 +432,7 @@ nsHTMLFrameInnerFrame::~nsHTMLFrameInnerFrame()
{
//printf("nsHTMLFrameInnerFrame destructor %X \n", this);
if (nsnull != mWebShell) {
//XXX Let mWebShell's parent destroy it because now may not be a good time
// mWebShell->Destroy();
mWebShell->Destroy();
NS_RELEASE(mWebShell);
}
NS_RELEASE(mTempObserver);

View File

@ -432,8 +432,7 @@ nsHTMLFrameInnerFrame::~nsHTMLFrameInnerFrame()
{
//printf("nsHTMLFrameInnerFrame destructor %X \n", this);
if (nsnull != mWebShell) {
//XXX Let mWebShell's parent destroy it because now may not be a good time
// mWebShell->Destroy();
mWebShell->Destroy();
NS_RELEASE(mWebShell);
}
NS_RELEASE(mTempObserver);

View File

@ -171,6 +171,7 @@ public:
NS_IMETHOD GetParentEvenIfChrome(nsIWebShell*& aParent);
NS_IMETHOD GetChildCount(PRInt32& aResult);
NS_IMETHOD AddChild(nsIWebShell* aChild);
NS_IMETHOD RemoveChild(nsIWebShell* aChild);
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIWebShell*& aResult);
NS_IMETHOD GetName(const PRUnichar** aName);
NS_IMETHOD SetName(const PRUnichar* aName);
@ -888,6 +889,11 @@ nsWebShell::Destroy()
SetObserver(nsnull);
SetDocLoaderObserver(nsnull);
// Remove this webshell from its parent's child list
if (nsnull != mParent) {
mParent->RemoveChild(this);
}
if (nsnull != mDocLoader) {
mDocLoader->SetContainer(nsnull);
}
@ -1214,6 +1220,20 @@ nsWebShell::AddChild(nsIWebShell* aChild)
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::RemoveChild(nsIWebShell* aChild)
{
NS_PRECONDITION(nsnull != aChild, "nsWebShell::RemoveChild(): null ptr");
if (nsnull == aChild) {
return NS_ERROR_NULL_POINTER;
}
mChildren.RemoveElement(aChild);
aChild->SetParent(nsnull);
NS_RELEASE(aChild);
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::ChildAt(PRInt32 aIndex, nsIWebShell*& aResult)
{