Fixing bug 265987. Don't expose the current content window to hidden tabs. r=bryner@brianryner.com, sr=brendan@mozilla.org

This commit is contained in:
jst%mozilla.jstenback.com 2004-11-19 22:39:04 +00:00
Родитель 12867e8208
Коммит 111121310b
1 изменённых файлов: 27 добавлений и 5 удалений

Просмотреть файл

@ -1191,12 +1191,34 @@ GlobalWindowImpl::GetContent(nsIDOMWindow** aContent)
{
*aContent = nsnull;
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
GetTreeOwner(getter_AddRefs(treeOwner));
NS_ENSURE_TRUE(treeOwner, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShellTreeItem> primaryContent;
treeOwner->GetPrimaryContentShell(getter_AddRefs(primaryContent));
if (!IsCallerChrome()) {
// If we're called by non-chrome code, make sure we don't return
// the primary content window if the calling tab is hidden. In
// such a case we return the same-type root in the hidden tab,
// which is "good enough", for now.
nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(mDocShell));
if (baseWin) {
PRBool visible = PR_FALSE;
baseWin->GetVisibility(&visible);
if (!visible) {
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(mDocShell));
treeItem->GetSameTypeRootTreeItem(getter_AddRefs(primaryContent));
}
}
}
if (!primaryContent) {
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
GetTreeOwner(getter_AddRefs(treeOwner));
NS_ENSURE_TRUE(treeOwner, NS_ERROR_FAILURE);
treeOwner->GetPrimaryContentShell(getter_AddRefs(primaryContent));
}
nsCOMPtr<nsIDOMWindowInternal> domWindow(do_GetInterface(primaryContent));
NS_IF_ADDREF(*aContent = domWindow);