Bug 1639807 - Isolate image cache per first-party when privacy.partition.network_state is set to true - part 2 - Implementation, r=timhuang

Differential Revision: https://phabricator.services.mozilla.com/D76283
This commit is contained in:
Andrea Marchesini 2020-05-21 11:28:12 +00:00
parent 55807d2b15
commit fd1027ec66
2 changed files with 26 additions and 1 deletions

View File

@ -170,6 +170,17 @@ nsCString ImageCacheKey::GetIsolationKey(Document* aDocument, nsIURI* aURI) {
return EmptyCString();
}
// Network-state isolation
if (StaticPrefs::privacy_partition_network_state()) {
OriginAttributes oa;
StoragePrincipalHelper::GetOriginAttributesForNetworkState(aDocument, oa);
nsAutoCString suffix;
oa.CreateSuffix(suffix);
return std::move(suffix);
}
// If the window is 3rd party resource, let's see if first-party storage
// access is granted for this image.
if (nsContentUtils::IsThirdPartyWindowOrChannel(aDocument->GetInnerWindow(),

View File

@ -277,8 +277,22 @@ bool StoragePrincipalHelper::GetOriginAttributesForNetworkState(
// static
void StoragePrincipalHelper::GetOriginAttributesForNetworkState(
Document* aDocument, OriginAttributes& aAttributes) {
aAttributes = aDocument->NodePrincipal()->OriginAttributesRef();
if (!StaticPrefs::privacy_partition_network_state()) {
aAttributes = aDocument->NodePrincipal()->OriginAttributesRef();
return;
}
// This part is required because the intrisicStoragePrincipal is not always
// partitioned. This should probably change. TODO - bug 1639833.
nsCOMPtr<nsICookieJarSettings> cjs = aDocument->CookieJarSettings();
MOZ_ASSERT(cjs);
nsAutoString domain;
Unused << cjs->GetFirstPartyDomain(domain);
if (!domain.IsEmpty()) {
aAttributes.SetFirstPartyDomain(false, domain, true /* aForced */);
return;
}