Bug 774633 - Fold SetOpenerScriptPrincipal into SetInitialPrincipalToSubject, and make it indempotent and callable without an existing document. r=jst

There's no reason it has to fail if there's no mDoc, since any document is promptly
blown away with the new about:blank document.

The indempotence is important because we want to be able to call this method
unconditionally in OpenJSWindowInternal (since we may not have gone through
RegisterTopLevelWindow) without worrying about whether we've called it already.
This commit is contained in:
Bobby Holley 2012-08-23 16:44:52 -07:00
parent dc08b52980
commit bdfc1a194e
3 changed files with 36 additions and 45 deletions

View File

@ -1509,45 +1509,11 @@ nsGlobalWindow::WouldReuseInnerWindow(nsIDocument *aNewDocument)
return false;
}
void
nsGlobalWindow::SetOpenerScriptPrincipal(nsIPrincipal* aPrincipal)
{
FORWARD_TO_OUTER_VOID(SetOpenerScriptPrincipal, (aPrincipal));
if (mDoc) {
if (!mDoc->IsInitialDocument()) {
// We have a document already, and it's not the original one. Bail out.
return;
}
#ifdef DEBUG
// We better have an about:blank document loaded at this point. Otherwise,
// something is really weird.
nsCOMPtr<nsIURI> uri;
mDoc->NodePrincipal()->GetURI(getter_AddRefs(uri));
NS_ASSERTION(uri && NS_IsAboutBlank(uri) &&
NS_IsAboutBlank(mDoc->GetDocumentURI()),
"Unexpected original document");
#endif
GetDocShell()->CreateAboutBlankContentViewer(aPrincipal);
mDoc->SetIsInitialDocument(true);
nsCOMPtr<nsIPresShell> shell;
GetDocShell()->GetPresShell(getter_AddRefs(shell));
if (shell && !shell->DidInitialReflow()) {
// Ensure that if someone plays with this document they will get
// layout happening.
nsRect r = shell->GetPresContext()->GetVisibleArea();
shell->InitialReflow(r.width, r.height);
}
}
}
void
nsGlobalWindow::SetInitialPrincipalToSubject()
{
FORWARD_TO_OUTER_VOID(SetInitialPrincipalToSubject, ());
// First, grab the subject principal. These methods never fail.
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
nsCOMPtr<nsIPrincipal> newWindowPrincipal, systemPrincipal;
@ -1568,8 +1534,38 @@ nsGlobalWindow::SetInitialPrincipalToSubject()
}
}
// Set the initial about:blank document up with the correct principal.
SetOpenerScriptPrincipal(newWindowPrincipal);
// If there's an existing document, bail if it either:
if (mDoc) {
// (a) is not an initial about:blank document, or
if (!mDoc->IsInitialDocument())
return;
// (b) already has the correct principal.
if (mDoc->NodePrincipal() == newWindowPrincipal)
return;
#ifdef DEBUG
// If we have a document loaded at this point, it had better be about:blank.
// Otherwise, something is really weird.
nsCOMPtr<nsIURI> uri;
mDoc->NodePrincipal()->GetURI(getter_AddRefs(uri));
NS_ASSERTION(uri && NS_IsAboutBlank(uri) &&
NS_IsAboutBlank(mDoc->GetDocumentURI()),
"Unexpected original document");
#endif
}
GetDocShell()->CreateAboutBlankContentViewer(newWindowPrincipal);
mDoc->SetIsInitialDocument(true);
nsCOMPtr<nsIPresShell> shell;
GetDocShell()->GetPresShell(getter_AddRefs(shell));
if (shell && !shell->DidInitialReflow()) {
// Ensure that if someone plays with this document they will get
// layout happening.
nsRect r = shell->GetPresContext()->GetVisibleArea();
shell->InitialReflow(r.width, r.height);
}
}
PopupControlState

View File

@ -342,7 +342,6 @@ public:
virtual NS_HIDDEN_(void) SetIsBackground(bool aIsBackground);
virtual NS_HIDDEN_(void) SetChromeEventHandler(nsIDOMEventTarget* aChromeEventHandler);
virtual NS_HIDDEN_(void) SetOpenerScriptPrincipal(nsIPrincipal* aPrincipal);
virtual NS_HIDDEN_(void) SetInitialPrincipalToSubject();
virtual NS_HIDDEN_(PopupControlState) PushPopupControlState(PopupControlState state, bool aForce) const;

View File

@ -280,12 +280,8 @@ public:
return win->mIsHandlingResizeEvent;
}
// Tell this window who opened it. This only has an effect if there is
// either no document currently in the window or if the document is the
// original document this window came with (an about:blank document either
// preloaded into it when it was created, or created by
// CreateAboutBlankContentViewer()).
virtual void SetOpenerScriptPrincipal(nsIPrincipal* aPrincipal) = 0;
// Set the window up with an about:blank document with the current subject
// principal.
virtual void SetInitialPrincipalToSubject() = 0;
virtual PopupControlState PushPopupControlState(PopupControlState aState,