diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index dc7ddfa13b72..7ca49bbd6452 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -2089,7 +2089,7 @@ nsDocShell::FindItemWithName(const PRUnichar * aName, // This may fail, but comparing against null serves the same purpose nsCOMPtr - reqAsTreeOwner(do_GetInterface(aRequestor)); + reqAsTreeOwner(do_QueryInterface(aRequestor)); if (mTreeOwner && mTreeOwner != reqAsTreeOwner) { return mTreeOwner-> diff --git a/xpfe/appshell/src/nsChromeTreeOwner.cpp b/xpfe/appshell/src/nsChromeTreeOwner.cpp index fb0bbf6e23e0..764968bd2112 100644 --- a/xpfe/appshell/src/nsChromeTreeOwner.cpp +++ b/xpfe/appshell/src/nsChromeTreeOwner.cpp @@ -214,16 +214,21 @@ NS_IMETHODIMP nsChromeTreeOwner::FindItemWithName(const PRUnichar* aName, if(fIs_Content) { - xulWindow->GetPrimaryContentShell(getter_AddRefs(shellAsTreeItem)); - if(shellAsTreeItem) - *aFoundItem = shellAsTreeItem; + xulWindow->GetPrimaryContentShell(aFoundItem); } else { nsCOMPtr shell; xulWindow->GetDocShell(getter_AddRefs(shell)); shellAsTreeItem = do_QueryInterface(shell); - if(shellAsTreeItem && (aRequestor != shellAsTreeItem.get())) + if (shellAsTreeItem) { + // Get the root tree item of same type, since roots are the only + // things that call into the treeowner to look for named items. + nsCOMPtr root; + shellAsTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(root)); + shellAsTreeItem = root; + } + if(shellAsTreeItem && aRequestor != shellAsTreeItem) { // Do this so we can pass in the tree owner as the requestor so the child knows not // to call back up. diff --git a/xpfe/appshell/src/nsContentTreeOwner.cpp b/xpfe/appshell/src/nsContentTreeOwner.cpp index 66f3640d8c83..bc61e0bafdae 100644 --- a/xpfe/appshell/src/nsContentTreeOwner.cpp +++ b/xpfe/appshell/src/nsContentTreeOwner.cpp @@ -221,16 +221,26 @@ NS_IMETHODIMP nsContentTreeOwner::FindItemWithName(const PRUnichar* aName, *aFoundItem = shellAsTreeItem; NS_ADDREF(*aFoundItem); } - else if(aRequestor != shellAsTreeItem.get()) + else { - // Do this so we can pass in the tree owner as the requestor so the child knows not - // to call back up. - nsCOMPtr shellOwner; - shellAsTreeItem->GetTreeOwner(getter_AddRefs(shellOwner)); - nsCOMPtr shellOwnerSupports(do_QueryInterface(shellOwner)); + // Get the root tree item of same type, since roots are the only + // things that call into the treeowner to look for named items. + nsCOMPtr root; + shellAsTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(root)); + NS_ASSERTION(root, "Must have root tree item of same type"); + shellAsTreeItem = root; + if(aRequestor != shellAsTreeItem) + { + // Do this so we can pass in the tree owner as the + // requestor so the child knows not to call back up. + nsCOMPtr shellOwner; + shellAsTreeItem->GetTreeOwner(getter_AddRefs(shellOwner)); + nsCOMPtr shellOwnerSupports(do_QueryInterface(shellOwner)); - shellAsTreeItem->FindItemWithName(aName, shellOwnerSupports, - aOriginalRequestor, aFoundItem); + shellAsTreeItem->FindItemWithName(aName, shellOwnerSupports, + aOriginalRequestor, + aFoundItem); + } } if(*aFoundItem) return NS_OK;