Make nsIDocShellTreeItem inherit from nsIDocShellTreeNode. Bug 377303,r=bsmedberg, sr=biesi
authorbzbarsky@mit.edu
Sun, 06 May 2007 14:06:28 -0700
changeset 1160 47bf169af285a4d76a59d05a8977546bc95b1cf5
parent 1159 d514e74fae38ff0e323d420d5c5d6827d4e2a17b
child 1161 9bea6e3fef1bca28961c0001f248c0dd65d979c0
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg, biesi
bugs377303
milestone1.9a5pre
Make nsIDocShellTreeItem inherit from nsIDocShellTreeNode. Bug 377303,r=bsmedberg, sr=biesi
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
docshell/base/nsDocShellEnumerator.cpp
docshell/base/nsIDocShellTreeItem.idl
docshell/base/nsIDocShellTreeNode.idl
embedding/browser/webBrowser/nsWebBrowser.cpp
embedding/browser/webBrowser/nsWebBrowser.h
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -2075,26 +2075,25 @@ nsDocShell::GetTreeOwner(nsIDocShellTree
 
     *aTreeOwner = mTreeOwner;
     NS_IF_ADDREF(*aTreeOwner);
     return NS_OK;
 }
 
 #ifdef DEBUG_DOCSHELL_FOCUS
 static void 
-PrintDocTree(nsIDocShellTreeNode * aParentNode, int aLevel)
+PrintDocTree(nsIDocShellTreeItem * aParentNode, int aLevel)
 {
   for (PRInt32 i=0;i<aLevel;i++) printf("  ");
 
   PRInt32 childWebshellCount;
   aParentNode->GetChildCount(&childWebshellCount);
   nsCOMPtr<nsIDocShell> parentAsDocShell(do_QueryInterface(aParentNode));
-  nsCOMPtr<nsIDocShellTreeItem> parentAsItem(do_QueryInterface(aParentNode));
   PRInt32 type;
-  parentAsItem->GetItemType(&type);
+  aParentNode->GetItemType(&type);
   nsCOMPtr<nsIPresShell> presShell;
   parentAsDocShell->GetPresShell(getter_AddRefs(presShell));
   nsCOMPtr<nsPresContext> presContext;
   parentAsDocShell->GetPresContext(getter_AddRefs(presContext));
   nsIDocument *doc = presShell->GetDocument();
 
   nsCOMPtr<nsIDOMWindowInternal> domwin(doc->GetWindow());
 
@@ -2110,57 +2109,52 @@ PrintDocTree(nsIDocShellTreeNode * aPare
     type==nsIDocShellTreeItem::typeChrome?"Chr":"Con", 
      (void*)doc, (void*)domwin.get(),
      (void*)presContext->EventStateManager(), (void*)rootContent);
 
   if (childWebshellCount > 0) {
     for (PRInt32 i=0;i<childWebshellCount;i++) {
       nsCOMPtr<nsIDocShellTreeItem> child;
       aParentNode->GetChildAt(i, getter_AddRefs(child));
-      nsCOMPtr<nsIDocShellTreeNode> 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<nsIDocShellTreeItem> item(do_QueryInterface(aParentNode));
   nsCOMPtr<nsIDocShellTreeItem> parentItem;
-  item->GetParent(getter_AddRefs(parentItem));
+  aParentNode->GetParent(getter_AddRefs(parentItem));
   while (parentItem) {
     nsCOMPtr<nsIDocShellTreeItem>tmp;
     parentItem->GetParent(getter_AddRefs(tmp));
     if (!tmp) {
       break;
     }
     parentItem = tmp;
   }
 
   if (!parentItem) {
-    parentItem = do_QueryInterface(aParentNode);
+    parentItem = aParentNode;
   }
 
-  if (parentItem) {
-    nsCOMPtr<nsIDocShellTreeNode> parentAsNode(do_QueryInterface(parentItem));
-    PrintDocTree(parentAsNode, 0);
-  }
+  PrintDocTree(parentItem, 0);
 }
 #endif
 
 NS_IMETHODIMP
 nsDocShell::SetTreeOwner(nsIDocShellTreeOwner * aTreeOwner)
 {
 #ifdef DEBUG_DOCSHELL_FOCUS
-    nsCOMPtr<nsIDocShellTreeNode> node(do_QueryInterface(aTreeOwner));
-    if (node) {
-      PrintDocTree(node);
+    nsCOMPtr<nsIDocShellTreeItem> item(do_QueryInterface(aTreeOwner));
+    if (item) {
+      PrintDocTree(item);
     }
 #endif
 
     // Don't automatically set the progress based on the tree owner for frames
     if (!IsFrame()) {
         nsCOMPtr<nsIWebProgress> webProgress =
             do_QueryInterface(GetAsSupports(this));
 
@@ -2415,33 +2409,29 @@ nsDocShell::FindChildWithName(const PRUn
         }
 
         if (childType != mItemType)     //Only ask it to check children if it is same type
             continue;
 
         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<nsIDocShellTreeNode>
-                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;
 }
 
 //*****************************************************************************
 // nsDocShell::nsIDocShellHistory
 //*****************************************************************************   
@@ -3486,20 +3476,20 @@ nsDocShell::Destroy()
     mTransferableHookData = nsnull;
 
     // Save the state of the current document, before destroying the window.
     // This is needed to capture the state of a frameset when the new document
     // causes the frameset to be destroyed...
     PersistLayoutHistoryState();
 
     // Remove this docshell from its parent's child list
-    nsCOMPtr<nsIDocShellTreeNode> docShellParentAsNode =
+    nsCOMPtr<nsIDocShellTreeItem> docShellParentAsItem =
         do_QueryInterface(GetAsSupports(mParent));
-    if (docShellParentAsNode)
-        docShellParentAsNode->RemoveChild(this);
+    if (docShellParentAsItem)
+        docShellParentAsItem->RemoveChild(this);
 
     if (mContentViewer) {
         mContentViewer->Close(nsnull);
         mContentViewer->Destroy();
         mContentViewer = nsnull;
     }
 
     nsDocLoader::Destroy();
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -143,17 +143,16 @@ protected:
 
 //*****************************************************************************
 //***    nsDocShell
 //*****************************************************************************
 
 class nsDocShell : public nsDocLoader,
                    public nsIDocShell,
                    public nsIDocShellTreeItem, 
-                   public nsIDocShellTreeNode,
                    public nsIDocShellHistory,
                    public nsIWebNavigation,
                    public nsIBaseWindow, 
                    public nsIScrollable, 
                    public nsITextScroll, 
                    public nsIDocCharset, 
                    public nsIContentViewerContainer,
                    public nsIScriptGlobalObjectOwner,
--- a/docshell/base/nsDocShellEnumerator.cpp
+++ b/docshell/base/nsDocShellEnumerator.cpp
@@ -34,16 +34,17 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 
 #include "nsDocShellEnumerator.h"
 
+#include "nsIDocShellTreeItem.h"
 #include "nsIDocShellTreeNode.h"
 
 nsDocShellEnumerator::nsDocShellEnumerator(PRInt32 inEnumerationDirection)
 : mRootItem(nsnull)
 , mItemArray(nsnull)
 , mCurIndex(0)
 , mDocShellType(nsIDocShellTreeItem::typeAll)
 , mEnumerationDirection(inEnumerationDirection)
--- a/docshell/base/nsIDocShellTreeItem.idl
+++ b/docshell/base/nsIDocShellTreeItem.idl
@@ -32,29 +32,29 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsISupports.idl"
+#include "nsIDocShellTreeNode.idl"
 
 interface nsIDocShellTreeOwner;
 
 
 /**
  * The nsIDocShellTreeItem supplies the methods that are required of any item
  * that wishes to be able to live within the docshell tree either as a middle
  * 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
 	*/
 	attribute wstring name;
 
         /**
          * Compares the provided name against the item's name and
--- a/docshell/base/nsIDocShellTreeNode.idl
+++ b/docshell/base/nsIDocShellTreeNode.idl
@@ -34,69 +34,76 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
-#include "nsIDocShellTreeItem.idl"
+
+interface nsIDocShellTreeItem;
 
 /**
  * The nsIDocShellTreeNode supplies the methods for interacting with children
  * of a docshell.  These are essentially the methods that turn a single docshell
  * 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
 {
 	/*
 	The current number of DocShells which are immediate children of the 
 	this object.
 	*/
 	readonly attribute long childCount;
 
 	/*
 	Add a new child DocShellTreeItem.  Adds to the end of the list.
 	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);
 
 	/*
 	Return the child DocShellTreeItem with the specified name.
 	aName - This is the name of the item that is trying to be found.
 	aRecurse - Is used to tell the function to recurse through children.
 		Note, recursion will only happen through items of the same type.
 	aSameType - If this is set only children of the same type will be returned.
 	aRequestor - This is the docshellTreeItem that is requesting the find.  This
 		parameter is used when recursion is being used to avoid searching the same
 		tree again when a child has asked a parent to search for children.
 	aOriginalRequestor - The original treeitem that made the request, if any.
     	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,
 	                                      in boolean aSameType,
 	                                      in nsIDocShellTreeItem aRequestor,
 	                                      in nsIDocShellTreeItem aOriginalRequestor);
 };
 
--- a/embedding/browser/webBrowser/nsWebBrowser.cpp
+++ b/embedding/browser/webBrowser/nsWebBrowser.cpp
@@ -621,16 +621,56 @@ NS_IMETHODIMP nsWebBrowser::SetChildOffs
 
 NS_IMETHODIMP nsWebBrowser::GetChildOffset(PRInt32 *aChildOffset)
 {
   // Not implemented
   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
 //*****************************************************************************
 
 NS_IMETHODIMP nsWebBrowser::GetCanGoBack(PRBool* aCanGoBack)
 {
    NS_ENSURE_STATE(mDocShell);
 
    return mDocShellAsNav->GetCanGoBack(aCanGoBack);
--- a/embedding/browser/webBrowser/nsWebBrowser.h
+++ b/embedding/browser/webBrowser/nsWebBrowser.h
@@ -46,16 +46,17 @@
 // Core Includes
 #include "nsCOMPtr.h"
 
 // Interfaces needed
 #include "nsCWebBrowser.h"
 #include "nsIBaseWindow.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
+#include "nsIDocShellTreeNode.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIScrollable.h"
 #include "nsISHistory.h"
 #include "nsITextScroll.h"
 #include "nsIWidget.h"
 #include "nsIWebProgress.h"
 #include "nsISecureBrowserUI.h"
@@ -121,16 +122,17 @@ class nsWebBrowser : public nsIWebBrowse
 friend class nsDocShellTreeOwner;
 public:
     nsWebBrowser();
 
     NS_DECL_ISUPPORTS
 
     NS_DECL_NSIBASEWINDOW
     NS_DECL_NSIDOCSHELLTREEITEM
+    NS_DECL_NSIDOCSHELLTREENODE
     NS_DECL_NSIINTERFACEREQUESTOR
     NS_DECL_NSISCROLLABLE   
     NS_DECL_NSITEXTSCROLL
     NS_DECL_NSIWEBBROWSER
     NS_DECL_NSIWEBNAVIGATION
     NS_DECL_NSIWEBBROWSERSETUP
     NS_DECL_NSIWEBBROWSERPERSIST
     NS_DECL_NSICANCELABLE