From 18e8cf2a70668304ad4bd99ed8961832152ff101 Mon Sep 17 00:00:00 2001 From: "nisheeth%netscape.com" Date: Wed, 5 May 1999 00:23:51 +0000 Subject: [PATCH] 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. --- docshell/base/nsWebShell.cpp | 20 ++++++++++++++++++++ layout/generic/nsFrameFrame.cpp | 3 +-- layout/html/document/src/nsFrameFrame.cpp | 3 +-- webshell/src/nsWebShell.cpp | 20 ++++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp index 774568f72736..711571baf016 100644 --- a/docshell/base/nsWebShell.cpp +++ b/docshell/base/nsWebShell.cpp @@ -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) { diff --git a/layout/generic/nsFrameFrame.cpp b/layout/generic/nsFrameFrame.cpp index 3088e3cb87af..883529598e34 100644 --- a/layout/generic/nsFrameFrame.cpp +++ b/layout/generic/nsFrameFrame.cpp @@ -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); diff --git a/layout/html/document/src/nsFrameFrame.cpp b/layout/html/document/src/nsFrameFrame.cpp index 3088e3cb87af..883529598e34 100644 --- a/layout/html/document/src/nsFrameFrame.cpp +++ b/layout/html/document/src/nsFrameFrame.cpp @@ -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); diff --git a/webshell/src/nsWebShell.cpp b/webshell/src/nsWebShell.cpp index 774568f72736..711571baf016 100644 --- a/webshell/src/nsWebShell.cpp +++ b/webshell/src/nsWebShell.cpp @@ -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) {