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-12 18:55:19 +00:00
Родитель ff5bc38481
Коммит 7075341260
1 изменённых файлов: 15 добавлений и 2 удалений

Просмотреть файл

@ -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
@ -6605,7 +6611,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,