Bug 771273 - Part 1: Make nsDocShell::GetSameTypeParent and friends respect <iframe mozbrowser> boundaries. r=bz

This commit is contained in:
Justin Lebar 2012-07-23 11:24:14 -04:00
parent 6c36bf164e
commit ddcc540395
3 changed files with 52 additions and 26 deletions

View File

@ -2747,6 +2747,10 @@ nsDocShell::GetSameTypeParent(nsIDocShellTreeItem ** aParent)
NS_ENSURE_ARG_POINTER(aParent);
*aParent = nsnull;
if (mIsBrowserFrame) {
return NS_OK;
}
nsCOMPtr<nsIDocShellTreeItem> parent =
do_QueryInterface(GetAsSupports(mParent));
if (!parent)
@ -2761,6 +2765,27 @@ nsDocShell::GetSameTypeParent(nsIDocShellTreeItem ** aParent)
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetParentIgnoreBrowserFrame(nsIDocShell** aParent)
{
NS_ENSURE_ARG_POINTER(aParent);
*aParent = nsnull;
nsCOMPtr<nsIDocShellTreeItem> parent =
do_QueryInterface(GetAsSupports(mParent));
if (!parent)
return NS_OK;
PRInt32 parentType;
NS_ENSURE_SUCCESS(parent->GetItemType(&parentType), NS_ERROR_FAILURE);
if (parentType == mItemType) {
nsCOMPtr<nsIDocShell> parentDS = do_QueryInterface(parent);
parentDS.forget(aParent);
}
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetRootTreeItem(nsIDocShellTreeItem ** aRootTreeItem)
{
@ -11093,16 +11118,9 @@ NS_IMETHODIMP nsDocShell::EnsureFind()
bool
nsDocShell::IsFrame()
{
nsCOMPtr<nsIDocShellTreeItem> parent =
do_QueryInterface(GetAsSupports(mParent));
if (parent) {
PRInt32 parentType = ~mItemType; // Not us
parent->GetItemType(&parentType);
if (parentType == mItemType) // This is a frame
return true;
}
return false;
nsCOMPtr<nsIDocShellTreeItem> parent;
GetSameTypeParent(getter_AddRefs(parent));
return !!parent;
}
/* boolean IsBeingDestroyed (); */

View File

@ -39,7 +39,7 @@ interface nsIWebBrowserPrint;
interface nsIVariant;
interface nsIPrivacyTransitionObserver;
[scriptable, builtinclass, uuid(be5a675b-b675-4443-af75-510530eab5fa)]
[scriptable, builtinclass, uuid(51f2b7f0-6435-40ec-b315-588f52be7eea)]
interface nsIDocShell : nsISupports
{
/**
@ -644,4 +644,10 @@ interface nsIDocShell : nsISupports
* docshell.
*/
readonly attribute bool asyncPanZoomEnabled;
/**
* Like GetSameTypeParent, except this ignores <iframe mozbrowser>
* boundaries.
*/
nsIDocShell getParentIgnoreBrowserFrame();
};

View File

@ -2990,11 +2990,8 @@ nsGlobalWindow::GetRealParent(nsIDOMWindow** aParent)
return NS_OK;
}
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell));
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShellTreeItem> parent;
docShellAsItem->GetSameTypeParent(getter_AddRefs(parent));
nsCOMPtr<nsIDocShell> parent;
mDocShell->GetParentIgnoreBrowserFrame(getter_AddRefs(parent));
if (parent) {
nsCOMPtr<nsIScriptGlobalObject> globalObject(do_GetInterface(parent));
@ -3073,11 +3070,19 @@ NS_IMETHODIMP
nsGlobalWindow::GetContent(nsIDOMWindow** aContent)
{
FORWARD_TO_OUTER(GetContent, (aContent), NS_ERROR_NOT_INITIALIZED);
*aContent = nsnull;
nsCOMPtr<nsIDocShellTreeItem> primaryContent;
// If we're contained in <iframe mozbrowser>, then GetContent is the same as
// window.top.
if (mDocShell) {
bool inBrowserFrame = false;
mDocShell->GetContainedInBrowserFrame(&inBrowserFrame);
if (inBrowserFrame) {
return GetScriptableTop(aContent);
}
}
nsCOMPtr<nsIDocShellTreeItem> primaryContent;
if (!nsContentUtils::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
@ -3091,7 +3096,6 @@ nsGlobalWindow::GetContent(nsIDOMWindow** aContent)
if (!visible) {
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(mDocShell));
treeItem->GetSameTypeRootTreeItem(getter_AddRefs(primaryContent));
}
}
@ -3111,6 +3115,7 @@ nsGlobalWindow::GetContent(nsIDOMWindow** aContent)
return NS_OK;
}
NS_IMETHODIMP
nsGlobalWindow::GetPrompter(nsIPrompt** aPrompt)
{
@ -7030,19 +7035,16 @@ nsGlobalWindow::GetRealFrameElement(nsIDOMElement** aFrameElement)
*aFrameElement = NULL;
nsCOMPtr<nsIDocShellTreeItem> docShellTI(do_QueryInterface(mDocShell));
if (!docShellTI) {
if (!mDocShell) {
return NS_OK;
}
nsCOMPtr<nsIDocShellTreeItem> parent;
docShellTI->GetSameTypeParent(getter_AddRefs(parent));
nsCOMPtr<nsIDocShell> parent;
mDocShell->GetParentIgnoreBrowserFrame(getter_AddRefs(parent));
if (!parent || parent == docShellTI) {
if (!parent || parent == mDocShell) {
// We're at a chrome boundary, don't expose the chrome iframe
// element to content code.
return NS_OK;
}