forked from mirrors/gecko-dev
Bug 1557887 - Part 3: Extend nsIDocShell.createAboutBlankContentViewer() to accept a storage principal argument; r=baku
Differential Revision: https://phabricator.services.mozilla.com/D34457 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
2287617cbc
commit
4a71ba49f8
5 changed files with 37 additions and 14 deletions
|
|
@ -7009,6 +7009,7 @@ nsresult nsDocShell::EnsureContentViewer() {
|
|||
nsCOMPtr<nsIContentSecurityPolicy> cspToInheritForAboutBlank;
|
||||
nsCOMPtr<nsIURI> baseURI;
|
||||
nsIPrincipal* principal = GetInheritedPrincipal(false);
|
||||
nsIPrincipal* storagePrincipal = GetInheritedPrincipal(false, true);
|
||||
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
||||
GetSameTypeParent(getter_AddRefs(parentItem));
|
||||
if (parentItem) {
|
||||
|
|
@ -7022,7 +7023,7 @@ nsresult nsDocShell::EnsureContentViewer() {
|
|||
}
|
||||
|
||||
nsresult rv = CreateAboutBlankContentViewer(
|
||||
principal, cspToInheritForAboutBlank, baseURI);
|
||||
principal, storagePrincipal, cspToInheritForAboutBlank, baseURI);
|
||||
|
||||
NS_ENSURE_STATE(mContentViewer);
|
||||
|
||||
|
|
@ -7048,7 +7049,8 @@ nsresult nsDocShell::EnsureContentViewer() {
|
|||
}
|
||||
|
||||
nsresult nsDocShell::CreateAboutBlankContentViewer(
|
||||
nsIPrincipal* aPrincipal, nsIContentSecurityPolicy* aCSP, nsIURI* aBaseURI,
|
||||
nsIPrincipal* aPrincipal, nsIPrincipal* aStoragePrincipal,
|
||||
nsIContentSecurityPolicy* aCSP, nsIURI* aBaseURI,
|
||||
bool aTryToSaveOldPresentation, bool aCheckPermitUnload) {
|
||||
RefPtr<Document> blankDoc;
|
||||
nsCOMPtr<nsIContentViewer> viewer;
|
||||
|
|
@ -7137,7 +7139,7 @@ nsresult nsDocShell::CreateAboutBlankContentViewer(
|
|||
NS_LITERAL_CSTRING("text/html"));
|
||||
|
||||
if (docFactory) {
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
nsCOMPtr<nsIPrincipal> principal, storagePrincipal;
|
||||
if (mSandboxFlags & SANDBOXED_ORIGIN) {
|
||||
if (aPrincipal) {
|
||||
principal = NullPrincipal::CreateWithInheritedAttributes(aPrincipal);
|
||||
|
|
@ -7203,8 +7205,10 @@ nsresult nsDocShell::CreateAboutBlankContentViewer(
|
|||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,
|
||||
nsIPrincipal* aStoragePrincipal,
|
||||
nsIContentSecurityPolicy* aCSP) {
|
||||
return CreateAboutBlankContentViewer(aPrincipal, aCSP, nullptr);
|
||||
return CreateAboutBlankContentViewer(aPrincipal, aStoragePrincipal, aCSP,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
bool nsDocShell::CanSavePresentation(uint32_t aLoadType,
|
||||
|
|
@ -9437,7 +9441,7 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
|
|||
}
|
||||
|
||||
// clear the decks to prevent context bleed-through (bug 298255)
|
||||
rv = CreateAboutBlankContentViewer(nullptr, nullptr, nullptr);
|
||||
rv = CreateAboutBlankContentViewer(nullptr, nullptr, nullptr, nullptr);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
|
@ -9666,7 +9670,8 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsIPrincipal* nsDocShell::GetInheritedPrincipal(bool aConsiderCurrentDocument) {
|
||||
nsIPrincipal* nsDocShell::GetInheritedPrincipal(
|
||||
bool aConsiderCurrentDocument, bool aConsiderStoragePrincipal) {
|
||||
RefPtr<Document> document;
|
||||
bool inheritedFromCurrent = false;
|
||||
|
||||
|
|
@ -9699,7 +9704,9 @@ nsIPrincipal* nsDocShell::GetInheritedPrincipal(bool aConsiderCurrentDocument) {
|
|||
|
||||
//-- Get the document's principal
|
||||
if (document) {
|
||||
nsIPrincipal* docPrincipal = document->NodePrincipal();
|
||||
nsIPrincipal* docPrincipal = aConsiderStoragePrincipal
|
||||
? document->EffectiveStoragePrincipal()
|
||||
: document->NodePrincipal();
|
||||
|
||||
// Don't allow loads in typeContent docShells to inherit the system
|
||||
// principal from existing documents.
|
||||
|
|
@ -11680,6 +11687,8 @@ nsresult nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry, uint32_t aLoadType) {
|
|||
aEntry->GetContentType(contentType);
|
||||
nsCOMPtr<nsIPrincipal> triggeringPrincipal = aEntry->GetTriggeringPrincipal();
|
||||
nsCOMPtr<nsIPrincipal> principalToInherit = aEntry->GetPrincipalToInherit();
|
||||
nsCOMPtr<nsIPrincipal> storagePrincipalToInherit =
|
||||
aEntry->GetStoragePrincipalToInherit();
|
||||
nsCOMPtr<nsIContentSecurityPolicy> csp = aEntry->GetCsp();
|
||||
nsCOMPtr<nsIReferrerInfo> referrerInfo = aEntry->GetReferrerInfo();
|
||||
|
||||
|
|
@ -11697,8 +11706,9 @@ nsresult nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry, uint32_t aLoadType) {
|
|||
// Don't cache the presentation if we're going to just reload the
|
||||
// current entry. Caching would lead to trying to save the different
|
||||
// content viewers in the same nsISHEntry object.
|
||||
rv = CreateAboutBlankContentViewer(principalToInherit, nullptr, nullptr,
|
||||
aEntry != mOSHE);
|
||||
rv = CreateAboutBlankContentViewer(principalToInherit,
|
||||
storagePrincipalToInherit, nullptr,
|
||||
nullptr, aEntry != mOSHE);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
// The creation of the intermittent about:blank content
|
||||
|
|
@ -12998,8 +13008,10 @@ nsDocShell::InitOrReusePrintPreviewViewer(nsIWebBrowserPrint** aPrintPreview) {
|
|||
NullPrincipal::CreateWithInheritedAttributes(this);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:printpreview"));
|
||||
nsresult rv =
|
||||
CreateAboutBlankContentViewer(principal, /* aCsp = */ nullptr, uri);
|
||||
// Reuse the null principal for the storage principal.
|
||||
// XXXehsan is that the right principal to use here?
|
||||
nsresult rv = CreateAboutBlankContentViewer(principal, principal,
|
||||
/* aCsp = */ nullptr, uri);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// Here we manually set current URI since we have just created a
|
||||
// brand new content viewer (about:blank) to host preview.
|
||||
|
|
|
|||
|
|
@ -498,6 +498,7 @@ class nsDocShell final : public nsDocLoader,
|
|||
// passed in, the about:blank principal will end up being used.
|
||||
// aCSP, if any, will be used for the new about:blank load.
|
||||
nsresult CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,
|
||||
nsIPrincipal* aStoragePrincipal,
|
||||
nsIContentSecurityPolicy* aCSP,
|
||||
nsIURI* aBaseURI,
|
||||
bool aTryToSaveOldPresentation = true,
|
||||
|
|
@ -649,7 +650,10 @@ class nsDocShell final : public nsDocLoader,
|
|||
// If that fails too, we force creation of a content viewer and use the
|
||||
// resulting principal. If aConsiderCurrentDocument is false, we just look
|
||||
// at the parent.
|
||||
nsIPrincipal* GetInheritedPrincipal(bool aConsiderCurrentDocument);
|
||||
// If aConsiderStoragePrincipal is true, we consider the storage principal
|
||||
// instead of the node principal.
|
||||
nsIPrincipal* GetInheritedPrincipal(bool aConsiderCurrentDocument,
|
||||
bool aConsiderStoragePrincipal = false);
|
||||
|
||||
/**
|
||||
* Helper function that determines if channel is an HTTP POST.
|
||||
|
|
|
|||
|
|
@ -613,9 +613,11 @@ interface nsIDocShell : nsIDocShellTreeItem
|
|||
/**
|
||||
* Create a new about:blank document and content viewer.
|
||||
* @param aPrincipal the principal to use for the new document.
|
||||
* @param aStoragePrincipal the storage principal to use for the new document.
|
||||
* @param aCsp the CSP to use for the new document.
|
||||
*/
|
||||
void createAboutBlankContentViewer(in nsIPrincipal aPrincipal,
|
||||
in nsIPrincipal aStoragePrincipal,
|
||||
[optional] in nsIContentSecurityPolicy aCSP);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1580,7 +1580,10 @@ void nsGlobalWindowOuter::SetInitialPrincipalToSubject(
|
|||
#endif
|
||||
}
|
||||
|
||||
GetDocShell()->CreateAboutBlankContentViewer(newWindowPrincipal, aCSP);
|
||||
// Use the subject (or system) principal as the storage principal too until
|
||||
// the new window finishes navigating and gets a real storage principal.
|
||||
GetDocShell()->CreateAboutBlankContentViewer(newWindowPrincipal,
|
||||
newWindowPrincipal, aCSP);
|
||||
|
||||
if (mDoc) {
|
||||
mDoc->SetIsInitialDocument(true);
|
||||
|
|
|
|||
|
|
@ -230,7 +230,9 @@ nsresult nsWebShellWindow::Initialize(
|
|||
if (nsContentUtils::IsExpandedPrincipal(principal)) {
|
||||
principal = nullptr;
|
||||
}
|
||||
rv = mDocShell->CreateAboutBlankContentViewer(principal,
|
||||
// Use the subject (or system) principal as the storage principal too until
|
||||
// the new window finishes navigating and gets a real storage principal.
|
||||
rv = mDocShell->CreateAboutBlankContentViewer(principal, principal,
|
||||
/* aCsp = */ nullptr);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
RefPtr<Document> doc = mDocShell->GetDocument();
|
||||
|
|
|
|||
Loading…
Reference in a new issue