Bug 1731982 - Part 3: Use partitioned principal for creating initial client source if needed in nsDocShell. r=asuth

Currently, we are using the regular principal and inherited regular
principal to create clientSource in nsDocShell. This patch makes the
nsDocshell to use the partitioned principal if needed.

Differential Revision: https://phabricator.services.mozilla.com/D127629
This commit is contained in:
Tim Huang
2021-10-19 06:33:07 +00:00
parent d58ca230d0
commit 1c3e8c28ab

View File

@@ -2445,8 +2445,14 @@ void nsDocShell::MaybeCreateInitialClientSource(nsIPrincipal* aPrincipal) {
return;
}
// We cannot get inherited foreign partitioned principal here. Instead, we
// directly check which principal we want to inherit for the service worker.
nsIPrincipal* principal =
aPrincipal ? aPrincipal : GetInheritedPrincipal(false);
aPrincipal
? aPrincipal
: GetInheritedPrincipal(
false, StoragePrincipalHelper::
ShouldUsePartitionPrincipalForServiceWorker(this));
// Sometimes there is no principal available when we are called from
// CreateAboutBlankContentViewer. For example, sometimes the principal
@@ -6618,7 +6624,14 @@ nsresult nsDocShell::CreateAboutBlankContentViewer(
partitionedPrincipal = aPartitionedPrincipal;
}
MaybeCreateInitialClientSource(principal);
// We cannot get the foreign partitioned prinicpal for the initial
// about:blank page. So, we change to check if we need to use the
// partitioned principal for the service worker here.
MaybeCreateInitialClientSource(
StoragePrincipalHelper::ShouldUsePartitionPrincipalForServiceWorker(
this)
? partitionedPrincipal
: principal);
// generate (about:blank) document to load
blankDoc = nsContentDLF::CreateBlankDocument(mLoadGroup, principal,