From 0890b51845b7045d3da7d134c8d5d17ee014af87 Mon Sep 17 00:00:00 2001 From: hsingh Date: Fri, 27 Oct 2023 14:10:07 +0000 Subject: [PATCH] Bug 1835300: Allow CacheAPI in PBM if pref is toggled. r=dom-storage-reviewers,asuth Depends on D180295 Differential Revision: https://phabricator.services.mozilla.com/D180296 --- dom/cache/CacheStorage.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dom/cache/CacheStorage.cpp b/dom/cache/CacheStorage.cpp index c1a1ead48aa7..6407708c7ca6 100644 --- a/dom/cache/CacheStorage.cpp +++ b/dom/cache/CacheStorage.cpp @@ -175,7 +175,8 @@ already_AddRefed CacheStorage::CreateOnWorker( MOZ_DIAGNOSTIC_ASSERT(aWorkerPrivate); aWorkerPrivate->AssertIsOnWorkerThread(); - if (aWorkerPrivate->GetOriginAttributes().mPrivateBrowsingId > 0) { + if (aWorkerPrivate->GetOriginAttributes().mPrivateBrowsingId > 0 && + !StaticPrefs::dom_cache_privateBrowsing_enabled()) { NS_WARNING("CacheStorage not supported during private browsing."); RefPtr ref = new CacheStorage(NS_ERROR_DOM_SECURITY_ERR); return ref.forget(); @@ -574,16 +575,17 @@ bool CacheStorage::HasStorageAccess(UseCounter aLabel, } } - // Deny storage access for private browsing. + // Deny storage access for private browsing unless pref is toggled on. if (nsIPrincipal* principal = mGlobal->PrincipalOrNull()) { if (!principal->IsSystemPrincipal() && principal->GetPrivateBrowsingId() != - nsIScriptSecurityManager::DEFAULT_PRIVATE_BROWSING_ID) { + nsIScriptSecurityManager::DEFAULT_PRIVATE_BROWSING_ID && + !StaticPrefs::dom_cache_privateBrowsing_enabled()) { return false; } } - return access > StorageAccess::ePrivateBrowsing || + return access > StorageAccess::eDeny || (StaticPrefs:: privacy_partition_always_partition_third_party_non_cookie_storage() && ShouldPartitionStorage(access));