Bug 1743236 - Part 1: Add StoragePrincipalHelper::ShouldUsePartitionPrincipalForServiceWorker() for WorkerPrivate. r=dimi

Differential Revision: https://phabricator.services.mozilla.com/D132369
This commit is contained in:
Tim Huang 2021-11-30 13:40:32 +00:00
Родитель e892676b4e
Коммит 82984ed40f
2 изменённых файлов: 29 добавлений и 1 удалений

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

@ -8,6 +8,7 @@
#include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/StaticPrefs_privacy.h"
#include "mozilla/StorageAccess.h"
@ -406,6 +407,29 @@ bool StoragePrincipalHelper::ShouldUsePartitionPrincipalForServiceWorker(
: aDocShell->GetBrowsingContext());
}
// static
bool StoragePrincipalHelper::ShouldUsePartitionPrincipalForServiceWorker(
dom::WorkerPrivate* aWorkerPrivate) {
MOZ_ASSERT(aWorkerPrivate);
// We don't use the partitioned principal for service workers if it's
// disabled.
if (!StaticPrefs::privacy_partition_serviceWorkers()) {
return false;
}
nsCOMPtr<nsICookieJarSettings> cookieJarSettings =
aWorkerPrivate->CookieJarSettings();
// We only support partitioned service workers when dFPI is enabled.
if (cookieJarSettings->GetCookieBehavior() !=
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN) {
return false;
}
return aWorkerPrivate->IsThirdPartyContextToTopWindow();
}
// static
bool StoragePrincipalHelper::GetOriginAttributes(
nsIChannel* aChannel, mozilla::OriginAttributes& aAttributes,

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

@ -222,7 +222,8 @@ namespace mozilla {
namespace dom {
class Document;
}
class WorkerPrivate;
} // namespace dom
namespace ipc {
class PrincipalInfo;
@ -301,6 +302,9 @@ class StoragePrincipalHelper final {
static bool ShouldUsePartitionPrincipalForServiceWorker(
nsIDocShell* aDocShell);
static bool ShouldUsePartitionPrincipalForServiceWorker(
dom::WorkerPrivate* aWorkerPrivate);
/**
* Extract the right OriginAttributes from the channel's triggering
* principal.