From b249c3278f049c2aedd07989fba6d27080635e00 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Wed, 3 May 2023 19:49:32 +0000 Subject: [PATCH] Bug 1829819: Use persistenceType 'private' for private origins.r=janv,dom-storage-reviewers Differential Revision: https://phabricator.services.mozilla.com/D175916 --- dom/base/nsDOMWindowUtils.cpp | 6 ++++-- dom/indexedDB/IDBFactory.cpp | 7 +++++++ dom/indexedDB/test/marionette/test_IDB_encryption_PBM.py | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 379522af538e..c264bf511caa 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -3460,8 +3460,10 @@ nsDOMWindowUtils::GetFileReferences(const nsAString& aDatabaseName, int64_t aId, RefPtr mgr = IndexedDatabaseManager::Get(); if (mgr) { nsresult rv = mgr->BlockAndGetFileReferences( - quota::PERSISTENCE_TYPE_DEFAULT, principalMetadata.mOrigin, - aDatabaseName, aId, aRefCnt, aDBRefCnt, aResult); + principalMetadata.mIsPrivate ? quota::PERSISTENCE_TYPE_PRIVATE + : quota::PERSISTENCE_TYPE_DEFAULT, + principalMetadata.mOrigin, aDatabaseName, aId, aRefCnt, aDBRefCnt, + aResult); NS_ENSURE_SUCCESS(rv, rv); } else { diff --git a/dom/indexedDB/IDBFactory.cpp b/dom/indexedDB/IDBFactory.cpp index 39b859124227..9bc3864c3053 100644 --- a/dom/indexedDB/IDBFactory.cpp +++ b/dom/indexedDB/IDBFactory.cpp @@ -15,6 +15,7 @@ #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/Document.h" #include "mozilla/dom/IDBFactoryBinding.h" +#include "mozilla/dom/quota/PersistenceType.h" #include "mozilla/dom/quota/QuotaManager.h" #include "mozilla/dom/BrowserChild.h" #include "mozilla/dom/WorkerPrivate.h" @@ -581,9 +582,15 @@ RefPtr IDBFactory::OpenInternal( isInternal = QuotaManager::IsOriginInternal(origin); } + const bool isPrivate = + principalInfo.type() == PrincipalInfo::TContentPrincipalInfo && + principalInfo.get_ContentPrincipalInfo().attrs().mPrivateBrowsingId > 0; + if (isInternal) { // Chrome privilege and internal origins always get persistent storage. persistenceType = PERSISTENCE_TYPE_PERSISTENT; + } else if (isPrivate) { + persistenceType = PERSISTENCE_TYPE_PRIVATE; } else { persistenceType = PERSISTENCE_TYPE_DEFAULT; } diff --git a/dom/indexedDB/test/marionette/test_IDB_encryption_PBM.py b/dom/indexedDB/test/marionette/test_IDB_encryption_PBM.py index c7b2ee6cef9e..6fb7b253d537 100644 --- a/dom/indexedDB/test/marionette/test_IDB_encryption_PBM.py +++ b/dom/indexedDB/test/marionette/test_IDB_encryption_PBM.py @@ -121,7 +121,7 @@ class IDBEncryptionPBM(MarionetteTestCase): sanitizedOrigin = origin.replace(":", "+").replace("/", "+") storagePath = os.path.join( - self.profilePath, "storage", "default", sanitizedOrigin, "idb" + self.profilePath, "storage", "private", sanitizedOrigin, "idb" ) self.idbStoragePath = storagePath @@ -137,7 +137,7 @@ class IDBEncryptionPBM(MarionetteTestCase): function getOrigin() { return new Promise((resolve, reject) => { - let context = "default" + let context = "private" let principal = Services.scriptSecurityManager. createContentPrincipalFromOrigin(url);