diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 6ecddd25ff42..4434e6dd2edf 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -4594,9 +4594,9 @@ already_AddRefed nsGlobalWindowInner::GetCaches( if (!mCacheStorage) { bool forceTrustedOrigin = GetOuterWindow()->GetServiceWorkersTestingEnabled(); - mCacheStorage = CacheStorage::CreateOnMainThread(cache::DEFAULT_NAMESPACE, - this, GetPrincipal(), - forceTrustedOrigin, aRv); + mCacheStorage = CacheStorage::CreateOnMainThread( + cache::DEFAULT_NAMESPACE, this, GetEffectiveStoragePrincipal(), + forceTrustedOrigin, aRv); } RefPtr ref = mCacheStorage; @@ -6984,6 +6984,9 @@ void nsGlobalWindowInner::StorageAccessGranted() { // Reset the IndexedDB factory. mIndexedDB = nullptr; + + // Reset DOM Cache + mCacheStorage = nullptr; } mozilla::dom::TabGroup* nsPIDOMWindowInner::TabGroup() { diff --git a/dom/cache/CacheStorage.cpp b/dom/cache/CacheStorage.cpp index 38e41b5af218..3912a99ae639 100644 --- a/dom/cache/CacheStorage.cpp +++ b/dom/cache/CacheStorage.cpp @@ -197,7 +197,8 @@ already_AddRefed CacheStorage::CreateOnWorker( return nullptr; } - const PrincipalInfo& principalInfo = aWorkerPrivate->GetPrincipalInfo(); + const PrincipalInfo& principalInfo = + aWorkerPrivate->GetEffectiveStoragePrincipalInfo(); if (NS_WARN_IF(!QuotaManager::IsPrincipalInfoValid(principalInfo))) { aRv.Throw(NS_ERROR_FAILURE); diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index 16785538a606..34a9240cd421 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -507,7 +507,11 @@ WorkerGlobalScope::GetOrCreateServiceWorkerRegistration( } void WorkerGlobalScope::FirstPartyStorageAccessGranted() { + // Reset the IndexedDB factory. mIndexedDB = nullptr; + + // Reset DOM Cache + mCacheStorage = nullptr; } DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope( diff --git a/toolkit/components/antitracking/test/browser/browser_partitionedDOMCache.js b/toolkit/components/antitracking/test/browser/browser_partitionedDOMCache.js index e4bf7cfc1279..e2212e8a63f7 100644 --- a/toolkit/components/antitracking/test/browser/browser_partitionedDOMCache.js +++ b/toolkit/components/antitracking/test/browser/browser_partitionedDOMCache.js @@ -1,6 +1,6 @@ -/* import-globals-from storageprincipal_head.js */ +/* import-globals-from partitionedstorage_head.js */ -StoragePrincipalHelper.runTest("DOMCache", +PartitionedStorageHelper.runTest("DOMCache", async (win3rdParty, win1stParty, allowed) => { // DOM Cache is not supported. Always blocked. await win3rdParty.caches.open("wow").then( @@ -9,8 +9,8 @@ StoragePrincipalHelper.runTest("DOMCache", ); await win1stParty.caches.open("wow").then( - _ => { ok(true, "DOM Cache shoulw be available"); }, - _ => { ok(false, "DOM Cache shoulw be available"); }, + _ => { ok(true, "DOM Cache should be available"); }, + _ => { ok(false, "DOM Cache should be available"); }, ); }, @@ -18,4 +18,8 @@ StoragePrincipalHelper.runTest("DOMCache", await new Promise(resolve => { Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve()); }); - }); + }, + + [ + ["dom.caches.testing.enabled", true], + ]);