From 67f68a06ad7e3b72b89f9f8ce903affc707f9a38 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 7 Sep 2016 19:30:36 -0400 Subject: [PATCH] Bug 1300851 - Don't use expanded principals when creating the about:blank content viewer eagerly; r=bzbarsky --- dom/base/nsGlobalWindow.cpp | 1 + xpfe/appshell/nsWebShellWindow.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 31a23a6ddd58..d0ebdfc5df65 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -2162,6 +2162,7 @@ nsGlobalWindow::SetInitialPrincipalToSubject() // We should never create windows with an expanded principal. // If we have a system principal, make sure we're not using it for a content // docshell. + // NOTE: Please keep this logic in sync with nsWebShellWindow::Initialize(). if (nsContentUtils::IsExpandedPrincipal(newWindowPrincipal) || (nsContentUtils::IsSystemPrincipal(newWindowPrincipal) && GetDocShell()->ItemType() != nsIDocShellTreeItem::typeChrome)) { diff --git a/xpfe/appshell/nsWebShellWindow.cpp b/xpfe/appshell/nsWebShellWindow.cpp index 2596f0d255d3..4bc8cf1731f5 100644 --- a/xpfe/appshell/nsWebShellWindow.cpp +++ b/xpfe/appshell/nsWebShellWindow.cpp @@ -214,8 +214,15 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent, // SetInitialPrincipalToSubject. This avoids creating the about:blank document // and then blowing it away with a second one, which can cause problems for the // top-level chrome window case. See bug 789773. + // Note that we don't accept expanded principals here, similar to + // SetInitialPrincipalToSubject. if (nsContentUtils::IsInitialized()) { // Sometimes this happens really early See bug 793370. - rv = mDocShell->CreateAboutBlankContentViewer(nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller()); + MOZ_ASSERT(mDocShell->ItemType() == nsIDocShellTreeItem::typeChrome); + nsCOMPtr principal = nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller(); + if (nsContentUtils::IsExpandedPrincipal(principal)) { + principal = nullptr; + } + rv = mDocShell->CreateAboutBlankContentViewer(principal); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr doc = mDocShell ? mDocShell->GetDocument() : nullptr; NS_ENSURE_TRUE(!!doc, NS_ERROR_FAILURE);