From 7e3d62ddea1cdc86e092e80da2e53175c83bbebf Mon Sep 17 00:00:00 2001 From: "bzbarsky@mit.edu" Date: Sun, 6 May 2007 14:06:28 -0700 Subject: [PATCH] Make nsIDocShellTreeItem inherit from nsIDocShellTreeNode. Bug 377303,r=bsmedberg, sr=biesi --- docshell/base/nsDocShell.cpp | 58 ++++++++----------- docshell/base/nsDocShell.h | 1 - docshell/base/nsDocShellEnumerator.cpp | 1 + docshell/base/nsIDocShellTreeItem.idl | 6 +- docshell/base/nsIDocShellTreeNode.idl | 23 +++++--- embedding/browser/webBrowser/nsWebBrowser.cpp | 40 +++++++++++++ embedding/browser/webBrowser/nsWebBrowser.h | 2 + 7 files changed, 85 insertions(+), 46 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 14d53fa91ccc..2aa6de406fa0 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -2080,16 +2080,15 @@ nsDocShell::GetTreeOwner(nsIDocShellTreeOwner ** aTreeOwner) #ifdef DEBUG_DOCSHELL_FOCUS static void -PrintDocTree(nsIDocShellTreeNode * aParentNode, int aLevel) +PrintDocTree(nsIDocShellTreeItem * aParentNode, int aLevel) { for (PRInt32 i=0;iGetChildCount(&childWebshellCount); nsCOMPtr parentAsDocShell(do_QueryInterface(aParentNode)); - nsCOMPtr parentAsItem(do_QueryInterface(aParentNode)); PRInt32 type; - parentAsItem->GetItemType(&type); + aParentNode->GetItemType(&type); nsCOMPtr presShell; parentAsDocShell->GetPresShell(getter_AddRefs(presShell)); nsCOMPtr presContext; @@ -2115,20 +2114,18 @@ PrintDocTree(nsIDocShellTreeNode * aParentNode, int aLevel) for (PRInt32 i=0;i child; aParentNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsNode(do_QueryInterface(child)); - PrintDocTree(childAsNode, aLevel+1); + PrintDocTree(child, aLevel+1); } } } static void -PrintDocTree(nsIDocShellTreeNode * aParentNode) +PrintDocTree(nsIDocShellTreeItem * aParentNode) { NS_ASSERTION(aParentNode, "Pointer is null!"); - nsCOMPtr item(do_QueryInterface(aParentNode)); nsCOMPtr parentItem; - item->GetParent(getter_AddRefs(parentItem)); + aParentNode->GetParent(getter_AddRefs(parentItem)); while (parentItem) { nsCOMPtrtmp; parentItem->GetParent(getter_AddRefs(tmp)); @@ -2139,13 +2136,10 @@ PrintDocTree(nsIDocShellTreeNode * aParentNode) } if (!parentItem) { - parentItem = do_QueryInterface(aParentNode); + parentItem = aParentNode; } - if (parentItem) { - nsCOMPtr parentAsNode(do_QueryInterface(parentItem)); - PrintDocTree(parentAsNode, 0); - } + PrintDocTree(parentItem, 0); } #endif @@ -2153,9 +2147,9 @@ NS_IMETHODIMP nsDocShell::SetTreeOwner(nsIDocShellTreeOwner * aTreeOwner) { #ifdef DEBUG_DOCSHELL_FOCUS - nsCOMPtr node(do_QueryInterface(aTreeOwner)); - if (node) { - PrintDocTree(node); + nsCOMPtr item(do_QueryInterface(aTreeOwner)); + if (item) { + PrintDocTree(item); } #endif @@ -2420,23 +2414,19 @@ nsDocShell::FindChildWithName(const PRUnichar * aName, if (aRecurse && (aRequestor != child)) // Only ask the child if it isn't the requestor { // See if child contains the shell with the given name - nsCOMPtr - childAsNode(do_QueryInterface(child)); - if (childAsNode) { #ifdef DEBUG - nsresult rv = + nsresult rv = #endif - childAsNode->FindChildWithName(aName, PR_TRUE, - aSameType, - NS_STATIC_CAST(nsIDocShellTreeItem*, - this), - aOriginalRequestor, - _retval); - NS_ASSERTION(NS_SUCCEEDED(rv), - "FindChildWithName should not fail here"); - if (*_retval) // found it - return NS_OK; - } + child->FindChildWithName(aName, PR_TRUE, + aSameType, + NS_STATIC_CAST(nsIDocShellTreeItem*, + this), + aOriginalRequestor, + _retval); + NS_ASSERTION(NS_SUCCEEDED(rv), + "FindChildWithName should not fail here"); + if (*_retval) // found it + return NS_OK; } } return NS_OK; @@ -3491,10 +3481,10 @@ nsDocShell::Destroy() PersistLayoutHistoryState(); // Remove this docshell from its parent's child list - nsCOMPtr docShellParentAsNode = + nsCOMPtr docShellParentAsItem = do_QueryInterface(GetAsSupports(mParent)); - if (docShellParentAsNode) - docShellParentAsNode->RemoveChild(this); + if (docShellParentAsItem) + docShellParentAsItem->RemoveChild(this); if (mContentViewer) { mContentViewer->Close(nsnull); diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index cac77158e46b..5bb4cd1822cc 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -148,7 +148,6 @@ protected: class nsDocShell : public nsDocLoader, public nsIDocShell, public nsIDocShellTreeItem, - public nsIDocShellTreeNode, public nsIDocShellHistory, public nsIWebNavigation, public nsIBaseWindow, diff --git a/docshell/base/nsDocShellEnumerator.cpp b/docshell/base/nsDocShellEnumerator.cpp index 2eb60d3dea9b..d7e9c9687ebb 100644 --- a/docshell/base/nsDocShellEnumerator.cpp +++ b/docshell/base/nsDocShellEnumerator.cpp @@ -39,6 +39,7 @@ #include "nsDocShellEnumerator.h" +#include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeNode.h" nsDocShellEnumerator::nsDocShellEnumerator(PRInt32 inEnumerationDirection) diff --git a/docshell/base/nsIDocShellTreeItem.idl b/docshell/base/nsIDocShellTreeItem.idl index 31f238899546..ab92d935e86e 100644 --- a/docshell/base/nsIDocShellTreeItem.idl +++ b/docshell/base/nsIDocShellTreeItem.idl @@ -37,7 +37,7 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsISupports.idl" +#include "nsIDocShellTreeNode.idl" interface nsIDocShellTreeOwner; @@ -48,8 +48,8 @@ interface nsIDocShellTreeOwner; * node or a leaf. */ -[scriptable, uuid(7d935d63-6d2a-4600-afb5-9a4f7d68b825)] -interface nsIDocShellTreeItem : nsISupports +[scriptable, uuid(377d6996-c703-497d-9330-536562fcfff5)] +interface nsIDocShellTreeItem : nsIDocShellTreeNode { /* name of the DocShellTreeItem diff --git a/docshell/base/nsIDocShellTreeNode.idl b/docshell/base/nsIDocShellTreeNode.idl index 01d67240c59b..c095b15697ee 100644 --- a/docshell/base/nsIDocShellTreeNode.idl +++ b/docshell/base/nsIDocShellTreeNode.idl @@ -39,7 +39,8 @@ * ***** END LICENSE BLOCK ***** */ #include "nsISupports.idl" -#include "nsIDocShellTreeItem.idl" + +interface nsIDocShellTreeItem; /** * The nsIDocShellTreeNode supplies the methods for interacting with children @@ -47,8 +48,11 @@ * into a docshell tree. */ -// XXXbz this interface should probably inherit from nsIDocShellTreeItem, and -// some methods should move from there to here... +/* + * Long-term, we probably want to merge this interface into + * nsIDocShellTreeItem. Need to eliminate uses of this interface + * first. + */ [scriptable, uuid(37f1ab73-f224-44b1-82f0-d2834ab1cec0)] interface nsIDocShellTreeNode : nsISupports @@ -64,18 +68,22 @@ interface nsIDocShellTreeNode : nsISupports Note that this does NOT take a reference to the child. The child stays alive only as long as it's referenced from outside the docshell tree. @throws NS_ERROR_ILLEGAL_VALUE if child corresponds to the same - object as this treenode or an ancestor of this treenode. - // XXXbz this should take an nsIDocShellTreeNode, I think. + object as this treenode or an ancestor of this treenode + @throws NS_ERROR_UNEXPECTED if this node is a leaf in the tree. */ void addChild(in nsIDocShellTreeItem child); /* Removes a child DocShellTreeItem. - // XXXbz this should take an nsIDocShellTreeNode, I think. + @throws NS_ERROR_UNEXPECTED if this node is a leaf in the tree. */ void removeChild(in nsIDocShellTreeItem child); - /* Return the child at the index requested. This is 0-based.*/ + /** + * Return the child at the index requested. This is 0-based. + * + * @throws NS_ERROR_UNEXPECTED if the index is out of range + */ nsIDocShellTreeItem getChildAt(in long index); /* @@ -91,7 +99,6 @@ interface nsIDocShellTreeNode : nsISupports This is used to ensure that we don't run into cross-site issues. Note the search is depth first when recursing. - // XXXbz this should return an nsIDocShellTreeNode, I think. */ nsIDocShellTreeItem findChildWithName(in wstring aName, in boolean aRecurse, diff --git a/embedding/browser/webBrowser/nsWebBrowser.cpp b/embedding/browser/webBrowser/nsWebBrowser.cpp index caf6e151c90e..4a1008c038e2 100644 --- a/embedding/browser/webBrowser/nsWebBrowser.cpp +++ b/embedding/browser/webBrowser/nsWebBrowser.cpp @@ -625,6 +625,46 @@ NS_IMETHODIMP nsWebBrowser::GetChildOffset(PRInt32 *aChildOffset) return NS_OK; } +//***************************************************************************** +// nsWebBrowser::nsIDocShellTreeItem +//***************************************************************************** + +NS_IMETHODIMP nsWebBrowser::GetChildCount(PRInt32 * aChildCount) +{ + NS_ENSURE_ARG_POINTER(aChildCount); + *aChildCount = 0; + return NS_OK; +} + +NS_IMETHODIMP nsWebBrowser::AddChild(nsIDocShellTreeItem * aChild) +{ + return NS_ERROR_UNEXPECTED; +} + +NS_IMETHODIMP nsWebBrowser::RemoveChild(nsIDocShellTreeItem * aChild) +{ + return NS_ERROR_UNEXPECTED; +} + +NS_IMETHODIMP nsWebBrowser::GetChildAt(PRInt32 aIndex, + nsIDocShellTreeItem ** aChild) +{ + return NS_ERROR_UNEXPECTED; +} + +NS_IMETHODIMP nsWebBrowser::FindChildWithName( + const PRUnichar * aName, + PRBool aRecurse, PRBool aSameType, + nsIDocShellTreeItem * aRequestor, + nsIDocShellTreeItem * aOriginalRequestor, + nsIDocShellTreeItem ** _retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + + *_retval = nsnull; + return NS_OK; +} + //***************************************************************************** // nsWebBrowser::nsIWebNavigation //***************************************************************************** diff --git a/embedding/browser/webBrowser/nsWebBrowser.h b/embedding/browser/webBrowser/nsWebBrowser.h index 4b3df13d29dc..b5a036295420 100644 --- a/embedding/browser/webBrowser/nsWebBrowser.h +++ b/embedding/browser/webBrowser/nsWebBrowser.h @@ -51,6 +51,7 @@ #include "nsIBaseWindow.h" #include "nsIDocShell.h" #include "nsIDocShellTreeItem.h" +#include "nsIDocShellTreeNode.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "nsIScrollable.h" @@ -126,6 +127,7 @@ public: NS_DECL_NSIBASEWINDOW NS_DECL_NSIDOCSHELLTREEITEM + NS_DECL_NSIDOCSHELLTREENODE NS_DECL_NSIINTERFACEREQUESTOR NS_DECL_NSISCROLLABLE NS_DECL_NSITEXTSCROLL