diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 2c8871b6b2b1..7e7c2815cd05 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -1507,45 +1507,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 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 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 newWindowPrincipal, systemPrincipal; @@ -1566,8 +1532,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 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 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 diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 060e4d12561e..47e2d99ad65b 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -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; diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 40345f956d61..ae484cf55a23 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -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,