From f1dd75ca22bb8f8378bc35b0ff4b13a0123d5f34 Mon Sep 17 00:00:00 2001 From: Ciure Andrei Date: Mon, 13 May 2019 22:40:22 +0300 Subject: [PATCH] Backed out 3 changesets (bug 1551055) for causing xpcshell localStorage perma failures CLOSED TREE Backed out changeset 21e44ad9c6df (bug 1551055) Backed out changeset 8727e61ab69b (bug 1551055) Backed out changeset d99a6769beb4 (bug 1551055) --HG-- extra : rebase_source : 56f7fe5c54cd7e4109acce5074be1aba12e91086 --- dom/base/nsGlobalWindowInner.cpp | 48 +- .../storage/nsIDOMStorageManager.idl | 6 - dom/localstorage/ActorsParent.cpp | 74 +- dom/localstorage/LSObject.cpp | 65 +- dom/localstorage/LSObject.h | 5 +- dom/localstorage/LocalStorageManager2.cpp | 10 +- .../PBackgroundLSSharedTypes.ipdlh | 3 - dom/storage/LocalStorage.cpp | 11 +- dom/storage/LocalStorage.h | 3 +- dom/storage/LocalStorageManager.cpp | 20 +- dom/storage/LocalStorageManager.h | 1 - dom/storage/PartitionedLocalStorage.cpp | 8 +- dom/storage/PartitionedLocalStorage.h | 4 +- dom/storage/SessionStorage.cpp | 3 +- dom/storage/SessionStorageManager.cpp | 7 +- dom/storage/Storage.cpp | 13 +- dom/storage/Storage.h | 6 +- dom/storage/StorageNotifierService.cpp | 2 +- dom/storage/StorageNotifierService.h | 2 +- .../browser/browser_localStorage_e10s.js | 2 +- .../antitracking/StoragePrincipalHelper.cpp | 85 -- .../antitracking/StoragePrincipalHelper.h | 8 - .../browser_partitionedLocalStorage_events.js | 1062 ++++++++--------- toolkit/components/extensions/Extension.jsm | 2 +- .../sessionstore/SessionStoreUtils.cpp | 14 +- .../windowwatcher/nsWindowWatcher.cpp | 6 +- 26 files changed, 613 insertions(+), 857 deletions(-) diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index b44e0a2fefdc..ad3e3ba9a7b4 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -389,8 +389,8 @@ class nsGlobalWindowObserver final : public nsIObserver, } } - nsIPrincipal* GetEffectiveStoragePrincipal() const override { - return mWindow ? mWindow->GetEffectiveStoragePrincipal() : nullptr; + nsIPrincipal* GetPrincipal() const override { + return mWindow ? mWindow->GetPrincipal() : nullptr; } bool IsPrivateBrowsing() const override { @@ -4354,9 +4354,8 @@ Storage* nsGlobalWindowInner::GetSessionStorage(ErrorResult& aError) { } RefPtr storage; - // No StoragePrincipal for sessions. - aError = storageManager->CreateStorage(this, principal, principal, - documentURI, IsPrivateBrowsing(), + aError = storageManager->CreateStorage(this, principal, documentURI, + IsPrivateBrowsing(), getter_AddRefs(storage)); if (aError.Failed()) { return nullptr; @@ -4407,7 +4406,7 @@ Storage* nsGlobalWindowInner::GetLocalStorage(ErrorResult& aError) { if (access == nsContentUtils::StorageAccess::ePartitionedOrDeny) { if (!mDoc) { access = nsContentUtils::StorageAccess::eDeny; - } else if (!StaticPrefs::privacy_storagePrincipal_enabledForTrackers()) { + } else { nsCOMPtr uri; Unused << mDoc->NodePrincipal()->GetURI(getter_AddRefs(uri)); static const char* kPrefName = @@ -4433,8 +4432,7 @@ Storage* nsGlobalWindowInner::GetLocalStorage(ErrorResult& aError) { // tracker, we pass from the partitioned LocalStorage to the 'normal' // LocalStorage. The previous data is lost and the 2 window.localStorage // objects, before and after the permission granted, will be different. - if ((StaticPrefs::privacy_storagePrincipal_enabledForTrackers() || - access != nsContentUtils::StorageAccess::ePartitionedOrDeny) && + if (access != nsContentUtils::StorageAccess::ePartitionedOrDeny && (!mLocalStorage || mLocalStorage->Type() == Storage::ePartitionedLocalStorage)) { RefPtr storage; @@ -4464,14 +4462,8 @@ Storage* nsGlobalWindowInner::GetLocalStorage(ErrorResult& aError) { return nullptr; } - nsIPrincipal* storagePrincipal = GetEffectiveStoragePrincipal(); - if (!storagePrincipal) { - aError.Throw(NS_ERROR_DOM_SECURITY_ERR); - return nullptr; - } - - aError = storageManager->CreateStorage(this, principal, storagePrincipal, - documentURI, IsPrivateBrowsing(), + aError = storageManager->CreateStorage(this, principal, documentURI, + IsPrivateBrowsing(), getter_AddRefs(storage)); } @@ -4491,20 +4483,11 @@ Storage* nsGlobalWindowInner::GetLocalStorage(ErrorResult& aError) { return nullptr; } - nsIPrincipal* storagePrincipal = GetEffectiveStoragePrincipal(); - if (!storagePrincipal) { - aError.Throw(NS_ERROR_DOM_SECURITY_ERR); - return nullptr; - } - - mLocalStorage = - new PartitionedLocalStorage(this, principal, storagePrincipal); + mLocalStorage = new PartitionedLocalStorage(this, principal); } - MOZ_ASSERT_IF( - !StaticPrefs::privacy_storagePrincipal_enabledForTrackers(), - (access == nsContentUtils::StorageAccess::ePartitionedOrDeny) == - (mLocalStorage->Type() == Storage::ePartitionedLocalStorage)); + MOZ_ASSERT((access == nsContentUtils::StorageAccess::ePartitionedOrDeny) == + (mLocalStorage->Type() == Storage::ePartitionedLocalStorage)); return mLocalStorage; } @@ -4891,11 +4874,6 @@ void nsGlobalWindowInner::ObserveStorageNotification( return; } - nsIPrincipal* storagePrincipal = GetEffectiveStoragePrincipal(); - if (!storagePrincipal) { - return; - } - bool fireMozStorageChanged = false; nsAutoString eventType; eventType.AssignLiteral("storage"); @@ -4936,8 +4914,8 @@ void nsGlobalWindowInner::ObserveStorageNotification( else { MOZ_ASSERT(!NS_strcmp(aStorageType, u"localStorage")); - MOZ_DIAGNOSTIC_ASSERT(StorageUtils::PrincipalsEqual(aEvent->GetPrincipal(), - storagePrincipal)); + MOZ_DIAGNOSTIC_ASSERT( + StorageUtils::PrincipalsEqual(aEvent->GetPrincipal(), principal)); fireMozStorageChanged = mLocalStorage && mLocalStorage == aEvent->GetStorageArea(); diff --git a/dom/interfaces/storage/nsIDOMStorageManager.idl b/dom/interfaces/storage/nsIDOMStorageManager.idl index eda314264969..894995ec9964 100644 --- a/dom/interfaces/storage/nsIDOMStorageManager.idl +++ b/dom/interfaces/storage/nsIDOMStorageManager.idl @@ -39,8 +39,6 @@ interface nsIDOMStorageManager : nsISupports * The parent window. * @param aPrincipal * Principal to bound storage to. - * @param aStoragePrincipal - * StoragePrincipal to bound storage to. * @param aDocumentURI * URL of the demanding document, used for DOM storage event only. * @param aPrivate @@ -48,7 +46,6 @@ interface nsIDOMStorageManager : nsISupports */ Storage createStorage(in mozIDOMWindow aWindow, in nsIPrincipal aPrincipal, - in nsIPrincipal aStoragePrincipal, in AString aDocumentURI, [optional] in bool aPrivate); /** @@ -66,14 +63,11 @@ interface nsIDOMStorageManager : nsISupports * The parent window. * @param aPrincipal * Principal to bound storage to. - * @param aStoragePrincipal - * StoragePrincipal to bound storage to. * @param aPrivate * Whether the demanding document is running in Private Browsing mode or not. */ Storage getStorage(in mozIDOMWindow aWindow, in nsIPrincipal aPrincipal, - in nsIPrincipal aStoragePrincipal, [optional] in bool aPrivate); /** diff --git a/dom/localstorage/ActorsParent.cpp b/dom/localstorage/ActorsParent.cpp index dcaadc2aad0c..21ff65b51d2f 100644 --- a/dom/localstorage/ActorsParent.cpp +++ b/dom/localstorage/ActorsParent.cpp @@ -39,7 +39,6 @@ #include "mozilla/ipc/PBackgroundSharedTypes.h" #include "mozilla/Logging.h" #include "mozilla/storage/Variant.h" -#include "mozilla/StoragePrincipalHelper.h" #include "nsClassHashtable.h" #include "nsDataHashtable.h" #include "nsExceptionHandler.h" @@ -3381,7 +3380,6 @@ bool DeallocPBackgroundLSObserverParent(PBackgroundLSObserverParent* aActor) { bool VerifyPrincipalInfo(const Maybe& aContentParentId, const PrincipalInfo& aPrincipalInfo, - const PrincipalInfo& aStoragePrincipalInfo, const Maybe& aClientId) { AssertIsOnBackgroundThread(); @@ -3399,9 +3397,7 @@ bool VerifyPrincipalInfo(const Maybe& aContentParentId, } } - return StoragePrincipalHelper:: - VerifyValidStoragePrincipalInfoForPrincipalInfo(aStoragePrincipalInfo, - aPrincipalInfo); + return true; } bool VerifyOriginKey(const nsACString& aOriginKey, @@ -3436,9 +3432,8 @@ bool VerifyRequestParams(const Maybe& aContentParentId, const LSRequestCommonParams& params = aParams.get_LSRequestPreloadDatastoreParams().commonParams(); - if (NS_WARN_IF( - !VerifyPrincipalInfo(aContentParentId, params.principalInfo(), - params.storagePrincipalInfo(), Nothing()))) { + if (NS_WARN_IF(!VerifyPrincipalInfo(aContentParentId, + params.principalInfo(), Nothing()))) { ASSERT_UNLESS_FUZZING(); return false; } @@ -3457,9 +3452,9 @@ bool VerifyRequestParams(const Maybe& aContentParentId, const LSRequestCommonParams& commonParams = params.commonParams(); - if (NS_WARN_IF(!VerifyPrincipalInfo( - aContentParentId, commonParams.principalInfo(), - commonParams.storagePrincipalInfo(), params.clientId()))) { + if (NS_WARN_IF(!VerifyPrincipalInfo(aContentParentId, + commonParams.principalInfo(), + params.clientId()))) { ASSERT_UNLESS_FUZZING(); return false; } @@ -3477,8 +3472,7 @@ bool VerifyRequestParams(const Maybe& aContentParentId, aParams.get_LSRequestPrepareObserverParams(); if (NS_WARN_IF(!VerifyPrincipalInfo( - aContentParentId, params.principalInfo(), - params.storagePrincipalInfo(), params.clientId()))) { + aContentParentId, params.principalInfo(), params.clientId()))) { ASSERT_UNLESS_FUZZING(); return false; } @@ -3599,9 +3593,8 @@ bool VerifyRequestParams(const Maybe& aContentParentId, const LSSimpleRequestPreloadedParams& params = aParams.get_LSSimpleRequestPreloadedParams(); - if (NS_WARN_IF( - !VerifyPrincipalInfo(aContentParentId, params.principalInfo(), - params.storagePrincipalInfo(), Nothing()))) { + if (NS_WARN_IF(!VerifyPrincipalInfo(aContentParentId, + params.principalInfo(), Nothing()))) { ASSERT_UNLESS_FUZZING(); return false; } @@ -6611,16 +6604,15 @@ nsresult PrepareDatastoreOp::Open() { return NS_ERROR_FAILURE; } - const PrincipalInfo& storagePrincipalInfo = mParams.storagePrincipalInfo(); + const PrincipalInfo& principalInfo = mParams.principalInfo(); - if (storagePrincipalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) { + if (principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) { QuotaManager::GetInfoForChrome(&mSuffix, &mGroup, &mOrigin); } else { - MOZ_ASSERT(storagePrincipalInfo.type() == - PrincipalInfo::TContentPrincipalInfo); + MOZ_ASSERT(principalInfo.type() == PrincipalInfo::TContentPrincipalInfo); QuotaManager::GetInfoFromValidatedPrincipalInfo( - storagePrincipalInfo, &mSuffix, &mGroup, &mMainThreadOrigin); + principalInfo, &mSuffix, &mGroup, &mMainThreadOrigin); } mState = State::Nesting; @@ -6642,19 +6634,17 @@ nsresult PrepareDatastoreOp::CheckExistingOperations() { return NS_ERROR_FAILURE; } - const PrincipalInfo& storagePrincipalInfo = mParams.storagePrincipalInfo(); + const PrincipalInfo& principalInfo = mParams.principalInfo(); nsCString originAttrSuffix; uint32_t privateBrowsingId; - if (storagePrincipalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) { + if (principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) { privateBrowsingId = 0; } else { - MOZ_ASSERT(storagePrincipalInfo.type() == - PrincipalInfo::TContentPrincipalInfo); + MOZ_ASSERT(principalInfo.type() == PrincipalInfo::TContentPrincipalInfo); - const ContentPrincipalInfo& info = - storagePrincipalInfo.get_ContentPrincipalInfo(); + const ContentPrincipalInfo& info = principalInfo.get_ContentPrincipalInfo(); const OriginAttributes& attrs = info.attrs(); attrs.CreateSuffix(originAttrSuffix); @@ -7920,16 +7910,15 @@ nsresult PrepareObserverOp::Open() { return NS_ERROR_FAILURE; } - const PrincipalInfo& storagePrincipalInfo = mParams.storagePrincipalInfo(); + const PrincipalInfo& principalInfo = mParams.principalInfo(); - if (storagePrincipalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) { + if (principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) { QuotaManager::GetInfoForChrome(nullptr, nullptr, &mOrigin); } else { - MOZ_ASSERT(storagePrincipalInfo.type() == - PrincipalInfo::TContentPrincipalInfo); + MOZ_ASSERT(principalInfo.type() == PrincipalInfo::TContentPrincipalInfo); - QuotaManager::GetInfoFromValidatedPrincipalInfo(storagePrincipalInfo, - nullptr, nullptr, &mOrigin); + QuotaManager::GetInfoFromValidatedPrincipalInfo(principalInfo, nullptr, + nullptr, &mOrigin); } mState = State::SendingReadyMessage; @@ -8062,16 +8051,15 @@ nsresult PreloadedOp::Open() { return NS_ERROR_FAILURE; } - const PrincipalInfo& storagePrincipalInfo = mParams.storagePrincipalInfo(); + const PrincipalInfo& principalInfo = mParams.principalInfo(); - if (storagePrincipalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) { + if (principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) { QuotaManager::GetInfoForChrome(nullptr, nullptr, &mOrigin); } else { - MOZ_ASSERT(storagePrincipalInfo.type() == - PrincipalInfo::TContentPrincipalInfo); + MOZ_ASSERT(principalInfo.type() == PrincipalInfo::TContentPrincipalInfo); - QuotaManager::GetInfoFromValidatedPrincipalInfo(storagePrincipalInfo, - nullptr, nullptr, &mOrigin); + QuotaManager::GetInfoFromValidatedPrincipalInfo(principalInfo, nullptr, + nullptr, &mOrigin); } mState = State::SendingResults; @@ -8982,11 +8970,11 @@ nsresult QuotaClient::CreateArchivedOriginScope( contentPrincipalInfo.attrs() = attrs; contentPrincipalInfo.spec() = spec; - PrincipalInfo storagePrincipalInfo(contentPrincipalInfo); + PrincipalInfo principalInfo(contentPrincipalInfo); nsCString originAttrSuffix; nsCString originKey; - rv = GenerateOriginKey2(storagePrincipalInfo, originAttrSuffix, originKey); + rv = GenerateOriginKey2(principalInfo, originAttrSuffix, originKey); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } @@ -9005,11 +8993,11 @@ nsresult QuotaClient::CreateArchivedOriginScope( contentPrincipalInfo.attrs() = attrs; contentPrincipalInfo.spec() = spec; - PrincipalInfo storagePrincipalInfo(contentPrincipalInfo); + PrincipalInfo principalInfo(contentPrincipalInfo); nsCString originAttrSuffix; nsCString originKey; - rv = GenerateOriginKey2(storagePrincipalInfo, originAttrSuffix, originKey); + rv = GenerateOriginKey2(principalInfo, originAttrSuffix, originKey); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } diff --git a/dom/localstorage/LSObject.cpp b/dom/localstorage/LSObject.cpp index 3356c459aed8..fa2e8502167e 100644 --- a/dom/localstorage/LSObject.cpp +++ b/dom/localstorage/LSObject.cpp @@ -195,9 +195,8 @@ class RequestHelper final : public Runnable, public LSRequestChildCallback { } // namespace -LSObject::LSObject(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal) - : Storage(aWindow, aPrincipal, aStoragePrincipal), +LSObject::LSObject(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal) + : Storage(aWindow, aPrincipal), mPrivateBrowsingId(0), mInExplicitSnapshot(false) { AssertIsOnOwningThread(); @@ -245,7 +244,7 @@ nsresult LSObject::CreateForWindow(nsPIDOMWindowInner* aWindow, MOZ_ASSERT(aWindow); MOZ_ASSERT(aStorage); MOZ_ASSERT(NextGenLocalStorageEnabled()); - MOZ_ASSERT(nsContentUtils::StorageAllowedForWindow(aWindow) != + MOZ_ASSERT(nsContentUtils::StorageAllowedForWindow(aWindow) > nsContentUtils::StorageAccess::eDeny); nsCOMPtr sop = do_QueryInterface(aWindow); @@ -256,11 +255,6 @@ nsresult LSObject::CreateForWindow(nsPIDOMWindowInner* aWindow, return NS_ERROR_FAILURE; } - nsCOMPtr storagePrincipal = sop->GetEffectiveStoragePrincipal(); - if (NS_WARN_IF(!storagePrincipal)) { - return NS_ERROR_FAILURE; - } - if (nsContentUtils::IsSystemPrincipal(principal)) { return NS_ERROR_NOT_AVAILABLE; } @@ -270,8 +264,7 @@ nsresult LSObject::CreateForWindow(nsPIDOMWindowInner* aWindow, // for the check. nsCString originAttrSuffix; nsCString originKey; - nsresult rv = - GenerateOriginKey(storagePrincipal, originAttrSuffix, originKey); + nsresult rv = GenerateOriginKey(principal, originAttrSuffix, originKey); if (NS_FAILED(rv)) { return NS_ERROR_NOT_AVAILABLE; } @@ -284,23 +277,13 @@ nsresult LSObject::CreateForWindow(nsPIDOMWindowInner* aWindow, MOZ_ASSERT(principalInfo->type() == PrincipalInfo::TContentPrincipalInfo); - nsAutoPtr storagePrincipalInfo(new PrincipalInfo()); - rv = PrincipalToPrincipalInfo(storagePrincipal, storagePrincipalInfo); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - MOZ_ASSERT(storagePrincipalInfo->type() == - PrincipalInfo::TContentPrincipalInfo); - - if (NS_WARN_IF(!QuotaManager::IsPrincipalInfoValid(*storagePrincipalInfo))) { + if (NS_WARN_IF(!QuotaManager::IsPrincipalInfoValid(*principalInfo))) { return NS_ERROR_FAILURE; } nsCString suffix; nsCString origin; - rv = QuotaManager::GetInfoFromPrincipal(storagePrincipal, &suffix, nullptr, - &origin); + rv = QuotaManager::GetInfoFromPrincipal(principal, &suffix, nullptr, &origin); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } @@ -308,7 +291,7 @@ nsresult LSObject::CreateForWindow(nsPIDOMWindowInner* aWindow, MOZ_ASSERT(originAttrSuffix == suffix); uint32_t privateBrowsingId; - rv = storagePrincipal->GetPrivateBrowsingId(&privateBrowsingId); + rv = principal->GetPrivateBrowsingId(&privateBrowsingId); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } @@ -328,9 +311,8 @@ nsresult LSObject::CreateForWindow(nsPIDOMWindowInner* aWindow, } } - RefPtr object = new LSObject(aWindow, principal, storagePrincipal); + RefPtr object = new LSObject(aWindow, principal); object->mPrincipalInfo = std::move(principalInfo); - object->mStoragePrincipalInfo = std::move(storagePrincipalInfo); object->mPrivateBrowsingId = privateBrowsingId; object->mClientId = clientId; object->mOrigin = origin; @@ -344,18 +326,15 @@ nsresult LSObject::CreateForWindow(nsPIDOMWindowInner* aWindow, // static nsresult LSObject::CreateForPrincipal(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal, const nsAString& aDocumentURI, bool aPrivate, LSObject** aObject) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aPrincipal); - MOZ_ASSERT(aStoragePrincipal); MOZ_ASSERT(aObject); nsCString originAttrSuffix; nsCString originKey; - nsresult rv = - GenerateOriginKey(aStoragePrincipal, originAttrSuffix, originKey); + nsresult rv = GenerateOriginKey(aPrincipal, originAttrSuffix, originKey); if (NS_FAILED(rv)) { return NS_ERROR_NOT_AVAILABLE; } @@ -369,24 +348,14 @@ nsresult LSObject::CreateForPrincipal(nsPIDOMWindowInner* aWindow, MOZ_ASSERT(principalInfo->type() == PrincipalInfo::TContentPrincipalInfo || principalInfo->type() == PrincipalInfo::TSystemPrincipalInfo); - nsAutoPtr storagePrincipalInfo(new PrincipalInfo()); - rv = PrincipalToPrincipalInfo(aStoragePrincipal, storagePrincipalInfo); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - MOZ_ASSERT( - storagePrincipalInfo->type() == PrincipalInfo::TContentPrincipalInfo || - storagePrincipalInfo->type() == PrincipalInfo::TSystemPrincipalInfo); - - if (NS_WARN_IF(!QuotaManager::IsPrincipalInfoValid(*storagePrincipalInfo))) { + if (NS_WARN_IF(!QuotaManager::IsPrincipalInfoValid(*principalInfo))) { return NS_ERROR_FAILURE; } nsCString suffix; nsCString origin; - if (storagePrincipalInfo->type() == PrincipalInfo::TSystemPrincipalInfo) { + if (principalInfo->type() == PrincipalInfo::TSystemPrincipalInfo) { QuotaManager::GetInfoForChrome(&suffix, nullptr, &origin); } else { rv = QuotaManager::GetInfoFromPrincipal(aPrincipal, &suffix, nullptr, @@ -408,10 +377,8 @@ nsresult LSObject::CreateForPrincipal(nsPIDOMWindowInner* aWindow, clientId = Some(clientInfo.ref().Id()); } - RefPtr object = - new LSObject(aWindow, aPrincipal, aStoragePrincipal); + RefPtr object = new LSObject(aWindow, aPrincipal); object->mPrincipalInfo = std::move(principalInfo); - object->mStoragePrincipalInfo = std::move(storagePrincipalInfo); object->mPrivateBrowsingId = aPrivate ? 1 : 0; object->mClientId = clientId; object->mOrigin = origin; @@ -844,7 +811,6 @@ nsresult LSObject::EnsureDatabase() { LSRequestCommonParams commonParams; commonParams.principalInfo() = *mPrincipalInfo; - commonParams.storagePrincipalInfo() = *mStoragePrincipalInfo; commonParams.originKey() = mOriginKey; LSRequestPrepareDatastoreParams params; @@ -878,7 +844,7 @@ nsresult LSObject::EnsureDatabase() { LSDatabaseChild* actor = new LSDatabaseChild(database); MOZ_ALWAYS_TRUE(backgroundActor->SendPBackgroundLSDatabaseConstructor( - actor, *mStoragePrincipalInfo, mPrivateBrowsingId, datastoreId)); + actor, *mPrincipalInfo, mPrivateBrowsingId, datastoreId)); database->SetActor(actor); @@ -913,7 +879,6 @@ nsresult LSObject::EnsureObserver() { LSRequestPrepareObserverParams params; params.principalInfo() = *mPrincipalInfo; - params.storagePrincipalInfo() = *mStoragePrincipalInfo; params.clientId() = mClientId; LSRequestResponse response; @@ -967,8 +932,8 @@ void LSObject::OnChange(const nsAString& aKey, const nsAString& aOldValue, const nsAString& aNewValue) { AssertIsOnOwningThread(); - NotifyChange(/* aStorage */ this, StoragePrincipal(), aKey, aOldValue, - aNewValue, /* aStorageType */ kLocalStorageType, mDocumentURI, + NotifyChange(/* aStorage */ this, Principal(), aKey, aOldValue, aNewValue, + /* aStorageType */ kLocalStorageType, mDocumentURI, /* aIsPrivate */ !!mPrivateBrowsingId, /* aImmediateDispatch */ false); } diff --git a/dom/localstorage/LSObject.h b/dom/localstorage/LSObject.h index 5b7af8071cbf..8f096cb37da8 100644 --- a/dom/localstorage/LSObject.h +++ b/dom/localstorage/LSObject.h @@ -61,7 +61,6 @@ class LSObject final : public Storage { friend nsGlobalWindowInner; nsAutoPtr mPrincipalInfo; - nsAutoPtr mStoragePrincipalInfo; RefPtr mDatabase; RefPtr mObserver; @@ -93,7 +92,6 @@ class LSObject final : public Storage { */ static nsresult CreateForPrincipal(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal, const nsAString& aDocumentURI, bool aPrivate, LSObject** aObject); @@ -179,8 +177,7 @@ class LSObject final : public Storage { NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(LSObject, Storage) private: - LSObject(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal); + LSObject(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal); ~LSObject(); diff --git a/dom/localstorage/LocalStorageManager2.cpp b/dom/localstorage/LocalStorageManager2.cpp index ac7a7380aa7d..b44ddf3f73c1 100644 --- a/dom/localstorage/LocalStorageManager2.cpp +++ b/dom/localstorage/LocalStorageManager2.cpp @@ -191,19 +191,16 @@ LocalStorageManager2::PrecacheStorage(nsIPrincipal* aPrincipal, NS_IMETHODIMP LocalStorageManager2::CreateStorage(mozIDOMWindow* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal, const nsAString& aDocumentURI, bool aPrivate, Storage** _retval) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aPrincipal); - MOZ_ASSERT(aStoragePrincipal); MOZ_ASSERT(_retval); nsCOMPtr inner = nsPIDOMWindowInner::From(aWindow); RefPtr object; - nsresult rv = LSObject::CreateForPrincipal(inner, aPrincipal, - aStoragePrincipal, aDocumentURI, + nsresult rv = LSObject::CreateForPrincipal(inner, aPrincipal, aDocumentURI, aPrivate, getter_AddRefs(object)); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; @@ -215,12 +212,10 @@ LocalStorageManager2::CreateStorage(mozIDOMWindow* aWindow, NS_IMETHODIMP LocalStorageManager2::GetStorage(mozIDOMWindow* aWindow, - nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal, bool aPrivate, + nsIPrincipal* aPrincipal, bool aPrivate, Storage** _retval) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aPrincipal); - MOZ_ASSERT(aStoragePrincipal); MOZ_ASSERT(_retval); return NS_ERROR_NOT_IMPLEMENTED; @@ -288,7 +283,6 @@ LocalStorageManager2::Preload(nsIPrincipal* aPrincipal, JSContext* aContext, LSRequestCommonParams commonParams; commonParams.principalInfo() = *principalInfo; - commonParams.storagePrincipalInfo() = *principalInfo; commonParams.originKey() = originKey; LSRequestPreloadDatastoreParams params(commonParams); diff --git a/dom/localstorage/PBackgroundLSSharedTypes.ipdlh b/dom/localstorage/PBackgroundLSSharedTypes.ipdlh index e460ebaae033..9e841526b8a6 100644 --- a/dom/localstorage/PBackgroundLSSharedTypes.ipdlh +++ b/dom/localstorage/PBackgroundLSSharedTypes.ipdlh @@ -16,7 +16,6 @@ namespace dom { struct LSRequestCommonParams { PrincipalInfo principalInfo; - PrincipalInfo storagePrincipalInfo; nsCString originKey; }; @@ -34,7 +33,6 @@ struct LSRequestPrepareDatastoreParams struct LSRequestPrepareObserverParams { PrincipalInfo principalInfo; - PrincipalInfo storagePrincipalInfo; nsID? clientId; }; @@ -48,7 +46,6 @@ union LSRequestParams struct LSSimpleRequestPreloadedParams { PrincipalInfo principalInfo; - PrincipalInfo storagePrincipalInfo; }; union LSSimpleRequestParams diff --git a/dom/storage/LocalStorage.cpp b/dom/storage/LocalStorage.cpp index 9908e7d848e0..4ad8616891ec 100644 --- a/dom/storage/LocalStorage.cpp +++ b/dom/storage/LocalStorage.cpp @@ -54,9 +54,8 @@ LocalStorage::LocalStorage(nsPIDOMWindowInner* aWindow, LocalStorageManager* aManager, LocalStorageCache* aCache, const nsAString& aDocumentURI, - nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal, bool aIsPrivate) - : Storage(aWindow, aPrincipal, aStoragePrincipal), + nsIPrincipal* aPrincipal, bool aIsPrivate) + : Storage(aWindow, aPrincipal), mManager(aManager), mCache(aCache), mDocumentURI(aDocumentURI), @@ -164,9 +163,9 @@ void LocalStorage::Clear(nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) { void LocalStorage::OnChange(const nsAString& aKey, const nsAString& aOldValue, const nsAString& aNewValue) { - NotifyChange(/* aStorage */ this, StoragePrincipal(), aKey, aOldValue, - aNewValue, /* aStorageType */ u"localStorage", mDocumentURI, - mIsPrivate, /* aImmediateDispatch */ false); + NotifyChange(/* aStorage */ this, Principal(), aKey, aOldValue, aNewValue, + /* aStorageType */ u"localStorage", mDocumentURI, mIsPrivate, + /* aImmediateDispatch */ false); } void LocalStorage::ApplyEvent(StorageEvent* aStorageEvent) { diff --git a/dom/storage/LocalStorage.h b/dom/storage/LocalStorage.h index 45195640b097..723686cf1bc5 100644 --- a/dom/storage/LocalStorage.h +++ b/dom/storage/LocalStorage.h @@ -32,8 +32,7 @@ class LocalStorage final : public Storage, public nsSupportsWeakReference { LocalStorage(nsPIDOMWindowInner* aWindow, LocalStorageManager* aManager, LocalStorageCache* aCache, const nsAString& aDocumentURI, - nsIPrincipal* aPrincipal, nsIPrincipal* aStoragePrincipal, - bool aIsPrivate); + nsIPrincipal* aPrincipal, bool aIsPrivate); bool IsForkOf(const Storage* aOther) const override; diff --git a/dom/storage/LocalStorageManager.cpp b/dom/storage/LocalStorageManager.cpp index adefc0bf1bdc..1cf2d906f4e5 100644 --- a/dom/storage/LocalStorageManager.cpp +++ b/dom/storage/LocalStorageManager.cpp @@ -198,8 +198,7 @@ void LocalStorageManager::DropCache(LocalStorageCache* aCache) { nsresult LocalStorageManager::GetStorageInternal( CreateMode aCreateMode, mozIDOMWindow* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal, const nsAString& aDocumentURI, - bool aPrivate, Storage** aRetval) { + const nsAString& aDocumentURI, bool aPrivate, Storage** aRetval) { nsAutoCString originAttrSuffix; nsAutoCString originKey; @@ -271,9 +270,8 @@ nsresult LocalStorageManager::GetStorageInternal( if (aRetval) { nsCOMPtr inner = nsPIDOMWindowInner::From(aWindow); - RefPtr storage = - new LocalStorage(inner, this, cache, aDocumentURI, aPrincipal, - aStoragePrincipal, aPrivate); + RefPtr storage = new LocalStorage(inner, this, cache, aDocumentURI, + aPrincipal, aPrivate); storage.forget(aRetval); } @@ -284,28 +282,24 @@ NS_IMETHODIMP LocalStorageManager::PrecacheStorage(nsIPrincipal* aPrincipal, Storage** aRetval) { return GetStorageInternal(CreateMode::CreateIfShouldPreload, nullptr, - aPrincipal, aPrincipal, EmptyString(), false, - aRetval); + aPrincipal, EmptyString(), false, aRetval); } NS_IMETHODIMP LocalStorageManager::CreateStorage(mozIDOMWindow* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal, const nsAString& aDocumentURI, bool aPrivate, Storage** aRetval) { return GetStorageInternal(CreateMode::CreateAlways, aWindow, aPrincipal, - aStoragePrincipal, aDocumentURI, aPrivate, aRetval); + aDocumentURI, aPrivate, aRetval); } NS_IMETHODIMP LocalStorageManager::GetStorage(mozIDOMWindow* aWindow, - nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal, bool aPrivate, + nsIPrincipal* aPrincipal, bool aPrivate, Storage** aRetval) { return GetStorageInternal(CreateMode::UseIfExistsNeverCreate, aWindow, - aPrincipal, aStoragePrincipal, EmptyString(), - aPrivate, aRetval); + aPrincipal, EmptyString(), aPrivate, aRetval); } NS_IMETHODIMP diff --git a/dom/storage/LocalStorageManager.h b/dom/storage/LocalStorageManager.h index 55cb44ea168c..23d60fc9e469 100644 --- a/dom/storage/LocalStorageManager.h +++ b/dom/storage/LocalStorageManager.h @@ -101,7 +101,6 @@ class LocalStorageManager final : public nsIDOMStorageManager, // Helper for creation of DOM storage objects nsresult GetStorageInternal(CreateMode aCreate, mozIDOMWindow* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal, const nsAString& aDocumentURI, bool aPrivate, Storage** aRetval); diff --git a/dom/storage/PartitionedLocalStorage.cpp b/dom/storage/PartitionedLocalStorage.cpp index bfc199b8a77f..c55a29a5be4b 100644 --- a/dom/storage/PartitionedLocalStorage.cpp +++ b/dom/storage/PartitionedLocalStorage.cpp @@ -20,11 +20,9 @@ NS_INTERFACE_MAP_END_INHERITING(Storage) NS_IMPL_ADDREF_INHERITED(PartitionedLocalStorage, Storage) NS_IMPL_RELEASE_INHERITED(PartitionedLocalStorage, Storage) -PartitionedLocalStorage::PartitionedLocalStorage( - nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal) - : Storage(aWindow, aPrincipal, aStoragePrincipal), - mCache(new SessionStorageCache()) {} +PartitionedLocalStorage::PartitionedLocalStorage(nsPIDOMWindowInner* aWindow, + nsIPrincipal* aPrincipal) + : Storage(aWindow, aPrincipal), mCache(new SessionStorageCache()) {} PartitionedLocalStorage::~PartitionedLocalStorage() {} diff --git a/dom/storage/PartitionedLocalStorage.h b/dom/storage/PartitionedLocalStorage.h index d82fb2dc6bdb..91230162c3f4 100644 --- a/dom/storage/PartitionedLocalStorage.h +++ b/dom/storage/PartitionedLocalStorage.h @@ -24,8 +24,8 @@ class PartitionedLocalStorage final : public Storage { NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PartitionedLocalStorage, Storage) - PartitionedLocalStorage(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal); + PartitionedLocalStorage(nsPIDOMWindowInner* aWindow, + nsIPrincipal* aPrincipal); StorageType Type() const override { return ePartitionedLocalStorage; } diff --git a/dom/storage/SessionStorage.cpp b/dom/storage/SessionStorage.cpp index 6d94b5420cd5..0734c17d97ee 100644 --- a/dom/storage/SessionStorage.cpp +++ b/dom/storage/SessionStorage.cpp @@ -35,7 +35,7 @@ SessionStorage::SessionStorage(nsPIDOMWindowInner* aWindow, SessionStorageCache* aCache, SessionStorageManager* aManager, const nsAString& aDocumentURI, bool aIsPrivate) - : Storage(aWindow, aPrincipal, aPrincipal), + : Storage(aWindow, aPrincipal), mCache(aCache), mManager(aManager), mDocumentURI(aDocumentURI), @@ -46,7 +46,6 @@ SessionStorage::SessionStorage(nsPIDOMWindowInner* aWindow, SessionStorage::~SessionStorage() {} already_AddRefed SessionStorage::Clone() const { - MOZ_ASSERT(Principal() == StoragePrincipal()); RefPtr storage = new SessionStorage(GetParentObject(), Principal(), mCache, mManager, mDocumentURI, mIsPrivate); diff --git a/dom/storage/SessionStorageManager.cpp b/dom/storage/SessionStorageManager.cpp index 4bebf07a5285..bf5b5ec1be6c 100644 --- a/dom/storage/SessionStorageManager.cpp +++ b/dom/storage/SessionStorageManager.cpp @@ -71,7 +71,6 @@ SessionStorageManager::PrecacheStorage(nsIPrincipal* aPrincipal, NS_IMETHODIMP SessionStorageManager::CreateStorage(mozIDOMWindow* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal, const nsAString& aDocumentURI, bool aPrivate, Storage** aRetval) { nsAutoCString originKey; @@ -95,7 +94,6 @@ SessionStorageManager::CreateStorage(mozIDOMWindow* aWindow, nsCOMPtr inner = nsPIDOMWindowInner::From(aWindow); - // No StoragePrincipal for sessionStorage. RefPtr storage = new SessionStorage( inner, aPrincipal, cache, this, aDocumentURI, aPrivate); @@ -105,9 +103,8 @@ SessionStorageManager::CreateStorage(mozIDOMWindow* aWindow, NS_IMETHODIMP SessionStorageManager::GetStorage(mozIDOMWindow* aWindow, - nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal, - bool aPrivate, Storage** aRetval) { + nsIPrincipal* aPrincipal, bool aPrivate, + Storage** aRetval) { *aRetval = nullptr; nsAutoCString originKey; diff --git a/dom/storage/Storage.cpp b/dom/storage/Storage.cpp index 62c7656067a2..43788eea7fb9 100644 --- a/dom/storage/Storage.cpp +++ b/dom/storage/Storage.cpp @@ -16,8 +16,7 @@ namespace dom { static const char kStorageEnabled[] = "dom.storage.enabled"; -NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Storage, mWindow, mPrincipal, - mStoragePrincipal) +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Storage, mWindow, mPrincipal) NS_IMPL_CYCLE_COLLECTING_ADDREF(Storage) NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(Storage, LastRelease()) @@ -27,12 +26,8 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Storage) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -Storage::Storage(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal) - : mWindow(aWindow), - mPrincipal(aPrincipal), - mStoragePrincipal(aStoragePrincipal), - mIsSessionOnly(false) { +Storage::Storage(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal) + : mWindow(aWindow), mPrincipal(aPrincipal), mIsSessionOnly(false) { MOZ_ASSERT(aPrincipal); if (nsContentUtils::IsSystemPrincipal(mPrincipal)) { @@ -50,7 +45,7 @@ Storage::Storage(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal, } } -Storage::~Storage() = default; +Storage::~Storage() {} /* static */ bool Storage::StoragePrefIsEnabled() { diff --git a/dom/storage/Storage.h b/dom/storage/Storage.h index e121ac0cc5bb..41433771357f 100644 --- a/dom/storage/Storage.h +++ b/dom/storage/Storage.h @@ -26,8 +26,7 @@ class Storage : public nsISupports, public nsWrapperCache { NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Storage) - Storage(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal, - nsIPrincipal* aStoragePrincipal); + Storage(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal); static bool StoragePrefIsEnabled(); @@ -45,8 +44,6 @@ class Storage : public nsISupports, public nsWrapperCache { nsIPrincipal* Principal() const { return mPrincipal; } - nsIPrincipal* StoragePrincipal() const { return mStoragePrincipal; } - // WebIDL JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; @@ -144,7 +141,6 @@ class Storage : public nsISupports, public nsWrapperCache { private: nsCOMPtr mWindow; nsCOMPtr mPrincipal; - nsCOMPtr mStoragePrincipal; // Whether storage is set to persist data only per session, may change // dynamically and is set by CanUseStorage function that is called diff --git a/dom/storage/StorageNotifierService.cpp b/dom/storage/StorageNotifierService.cpp index c0606355b3e3..380ace4220b6 100644 --- a/dom/storage/StorageNotifierService.cpp +++ b/dom/storage/StorageNotifierService.cpp @@ -76,7 +76,7 @@ void StorageNotifierService::Broadcast(StorageEvent* aEvent, // No reasons to continue if the principal of the event doesn't match with // the window's one. if (!StorageUtils::PrincipalsEqual(aEvent->GetPrincipal(), - observer->GetEffectiveStoragePrincipal())) { + observer->GetPrincipal())) { continue; } diff --git a/dom/storage/StorageNotifierService.h b/dom/storage/StorageNotifierService.h index 9471962037ea..ac4afd07462f 100644 --- a/dom/storage/StorageNotifierService.h +++ b/dom/storage/StorageNotifierService.h @@ -31,7 +31,7 @@ class StorageNotificationObserver { virtual bool IsPrivateBrowsing() const = 0; - virtual nsIPrincipal* GetEffectiveStoragePrincipal() const = 0; + virtual nsIPrincipal* GetPrincipal() const = 0; virtual nsIEventTarget* GetEventTarget() const = 0; }; diff --git a/dom/tests/browser/browser_localStorage_e10s.js b/dom/tests/browser/browser_localStorage_e10s.js index 0cb1a4c1bdf2..5281ea1495aa 100644 --- a/dom/tests/browser/browser_localStorage_e10s.js +++ b/dom/tests/browser/browser_localStorage_e10s.js @@ -107,7 +107,7 @@ async function verifyTabPreload(knownTab, expectStorageExists) { if (Services.lsm.nextGenLocalStorageEnabled) { return Services.lsm.isPreloaded(principal); } - return !!Services.domStorageManager.getStorage(null, principal, principal); + return !!Services.domStorageManager.getStorage(null, principal); }); is(storageExists, expectStorageExists, "Storage existence === preload"); } diff --git a/toolkit/components/antitracking/StoragePrincipalHelper.cpp b/toolkit/components/antitracking/StoragePrincipalHelper.cpp index b5ac53340288..3faad336484f 100644 --- a/toolkit/components/antitracking/StoragePrincipalHelper.cpp +++ b/toolkit/components/antitracking/StoragePrincipalHelper.cpp @@ -6,7 +6,6 @@ #include "StoragePrincipalHelper.h" -#include "mozilla/ipc/PBackgroundSharedTypes.h" #include "mozilla/ScopeExit.h" #include "mozilla/StaticPrefs.h" #include "nsContentUtils.h" @@ -98,88 +97,4 @@ nsresult StoragePrincipalHelper::PrepareOriginAttributes( return NS_OK; } -// static -bool StoragePrincipalHelper::VerifyValidStoragePrincipalInfoForPrincipalInfo( - const mozilla::ipc::PrincipalInfo& aStoragePrincipalInfo, - const mozilla::ipc::PrincipalInfo& aPrincipalInfo) { - if (aStoragePrincipalInfo.type() != aPrincipalInfo.type()) { - return false; - } - - if (aStoragePrincipalInfo.type() == - mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) { - const mozilla::ipc::ContentPrincipalInfo& spInfo = - aStoragePrincipalInfo.get_ContentPrincipalInfo(); - const mozilla::ipc::ContentPrincipalInfo& pInfo = - aPrincipalInfo.get_ContentPrincipalInfo(); - - if (!spInfo.attrs().EqualsIgnoringFPD(pInfo.attrs()) || - spInfo.originNoSuffix() != pInfo.originNoSuffix() || - spInfo.spec() != pInfo.spec() || spInfo.domain() != pInfo.domain() || - spInfo.baseDomain() != pInfo.baseDomain() || - spInfo.securityPolicies().Length() != - pInfo.securityPolicies().Length()) { - return false; - } - - for (uint32_t i = 0; i < spInfo.securityPolicies().Length(); ++i) { - if (spInfo.securityPolicies()[i].policy() != - pInfo.securityPolicies()[i].policy() || - spInfo.securityPolicies()[i].reportOnlyFlag() != - pInfo.securityPolicies()[i].reportOnlyFlag() || - spInfo.securityPolicies()[i].deliveredViaMetaTagFlag() != - pInfo.securityPolicies()[i].deliveredViaMetaTagFlag()) { - return false; - } - } - - return true; - } - - if (aStoragePrincipalInfo.type() == - mozilla::ipc::PrincipalInfo::TSystemPrincipalInfo) { - // Nothing to check here. - return true; - } - - if (aStoragePrincipalInfo.type() == - mozilla::ipc::PrincipalInfo::TNullPrincipalInfo) { - const mozilla::ipc::NullPrincipalInfo& spInfo = - aStoragePrincipalInfo.get_NullPrincipalInfo(); - const mozilla::ipc::NullPrincipalInfo& pInfo = - aPrincipalInfo.get_NullPrincipalInfo(); - - return spInfo.spec() == pInfo.spec() && - spInfo.attrs().EqualsIgnoringFPD(pInfo.attrs()); - } - - if (aStoragePrincipalInfo.type() == - mozilla::ipc::PrincipalInfo::TExpandedPrincipalInfo) { - const mozilla::ipc::ExpandedPrincipalInfo& spInfo = - aStoragePrincipalInfo.get_ExpandedPrincipalInfo(); - const mozilla::ipc::ExpandedPrincipalInfo& pInfo = - aPrincipalInfo.get_ExpandedPrincipalInfo(); - - if (!spInfo.attrs().EqualsIgnoringFPD(pInfo.attrs())) { - return false; - } - - if (spInfo.allowlist().Length() != pInfo.allowlist().Length()) { - return false; - } - - for (uint32_t i = 0; i < spInfo.allowlist().Length(); ++i) { - if (!VerifyValidStoragePrincipalInfoForPrincipalInfo( - spInfo.allowlist()[i], pInfo.allowlist()[i])) { - return false; - } - } - - return true; - } - - MOZ_CRASH("Invalid principalInfo type"); - return false; -} - } // namespace mozilla diff --git a/toolkit/components/antitracking/StoragePrincipalHelper.h b/toolkit/components/antitracking/StoragePrincipalHelper.h index 314bdc05d8c3..f50acb8b0ace 100644 --- a/toolkit/components/antitracking/StoragePrincipalHelper.h +++ b/toolkit/components/antitracking/StoragePrincipalHelper.h @@ -121,10 +121,6 @@ class nsIPrincipal; namespace mozilla { -namespace ipc { -class PrincipalInfo; -} - class OriginAttributes; class StoragePrincipalHelper final { @@ -134,10 +130,6 @@ class StoragePrincipalHelper final { static nsresult PrepareOriginAttributes(nsIChannel* aChannel, OriginAttributes& aOriginAttributes); - - static bool VerifyValidStoragePrincipalInfoForPrincipalInfo( - const mozilla::ipc::PrincipalInfo& aStoragePrincipalInfo, - const mozilla::ipc::PrincipalInfo& aPrincipalInfo); }; } // namespace mozilla diff --git a/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage_events.js b/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage_events.js index f15776b3b991..766c1e003bb3 100644 --- a/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage_events.js +++ b/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage_events.js @@ -1,564 +1,530 @@ -function runAllTests(withStoragePrincipalEnabled, lsngEnabled) { - // A same origin (and same-process via setting "dom.ipc.processCount" to 1) - // top-level window with access to real localStorage does not share storage - // with an ePartitionOrDeny iframe that should have PartitionedLocalStorage and - // no storage events are received in either direction. (Same-process in order - // to avoid having to worry about any e10s propagation issues.) - add_task(async _ => { - await SpecialPowers.pushPrefEnv({"set": [ - ["dom.ipc.processCount", 1], - ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER], - ["privacy.trackingprotection.enabled", false], - ["privacy.trackingprotection.pbmode.enabled", false], - ["privacy.trackingprotection.annotate_channels", true], - ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], - ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled], - ["dom.storage.next_gen", lsngEnabled], - ]}); +// A same origin (and same-process via setting "dom.ipc.processCount" to 1) +// top-level window with access to real localStorage does not share storage +// with an ePartitionOrDeny iframe that should have PartitionedLocalStorage and +// no storage events are received in either direction. (Same-process in order +// to avoid having to worry about any e10s propagation issues.) +add_task(async _ => { + await SpecialPowers.pushPrefEnv({"set": [ + ["dom.ipc.processCount", 1], + ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER], + ["privacy.trackingprotection.enabled", false], + ["privacy.trackingprotection.pbmode.enabled", false], + ["privacy.trackingprotection.annotate_channels", true], + ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], + ]}); - await UrlClassifierTestUtils.addTestTrackers(); + await UrlClassifierTestUtils.addTestTrackers(); - info("Creating a non-tracker top-level context"); - let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); - let normalBrowser = gBrowser.getBrowserForTab(normalTab); - await BrowserTestUtils.browserLoaded(normalBrowser); + info("Creating a non-tracker top-level context"); + let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); + let normalBrowser = gBrowser.getBrowserForTab(normalTab); + await BrowserTestUtils.browserLoaded(normalBrowser); - info("Creating a tracker top-level context"); - let trackerTab = BrowserTestUtils.addTab(gBrowser, TEST_3RD_PARTY_DOMAIN + TEST_PATH + "page.html"); - let trackerBrowser = gBrowser.getBrowserForTab(trackerTab); - await BrowserTestUtils.browserLoaded(trackerBrowser); + info("Creating a tracker top-level context"); + let trackerTab = BrowserTestUtils.addTab(gBrowser, TEST_3RD_PARTY_DOMAIN + TEST_PATH + "page.html"); + let trackerBrowser = gBrowser.getBrowserForTab(trackerTab); + await BrowserTestUtils.browserLoaded(trackerBrowser); - info("The non-tracker page opens a tracker iframe"); - await ContentTask.spawn(normalBrowser, { - page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", - }, async obj => { - let ifr = content.document.createElement("iframe"); - ifr.setAttribute("id", "ifr"); - ifr.setAttribute("src", obj.page); + info("The non-tracker page opens a tracker iframe"); + await ContentTask.spawn(normalBrowser, { + page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", + }, async obj => { + let ifr = content.document.createElement("iframe"); + ifr.setAttribute("id", "ifr"); + ifr.setAttribute("src", obj.page); - info("Iframe loading..."); - await new content.Promise(resolve => { - ifr.onload = resolve; - content.document.body.appendChild(ifr); - }); + info("Iframe loading..."); + await new content.Promise(resolve => { + ifr.onload = resolve; + content.document.body.appendChild(ifr); + }); - info("Setting localStorage value..."); - ifr.contentWindow.postMessage("setValue", "*"); + info("Setting localStorage value..."); + ifr.contentWindow.postMessage("setValue", "*"); - info("Getting the value..."); - let value = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr.contentWindow.postMessage("getValue", "*"); - }); + info("Getting the value..."); + let value = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr.contentWindow.postMessage("getValue", "*"); + }); - ok(value.startsWith("tracker-"), "The value is correctly set by the tracker"); - } - ); + ok(value.startsWith("tracker-"), "The value is correctly set by the tracker"); + } + ); - info("The tracker page should not have received events"); - await ContentTask.spawn(trackerBrowser, null, async _ => { - is(content.localStorage.foo, undefined, "Undefined value!"); - content.localStorage.foo = "normal-" + Math.random(); - } - ); + info("The tracker page should not have received events"); + await ContentTask.spawn(trackerBrowser, null, async _ => { + is(content.localStorage.foo, undefined, "Undefined value!"); + content.localStorage.foo = "normal-" + Math.random(); + } + ); - info("Let's see if non-tracker page has received events"); - await ContentTask.spawn(normalBrowser, null, async _ => { - let ifr = content.document.getElementById("ifr"); + info("Let's see if non-tracker page has received events"); + await ContentTask.spawn(normalBrowser, null, async _ => { + let ifr = content.document.getElementById("ifr"); - info("Getting the value..."); - let value = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr.contentWindow.postMessage("getValue", "*"); - }); + info("Getting the value..."); + let value = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr.contentWindow.postMessage("getValue", "*"); + }); - ok(value.startsWith("tracker-"), "The value is correctly set by the tracker"); + ok(value.startsWith("tracker-"), "The value is correctly set by the tracker"); - info("Getting the events..."); - let events = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr.contentWindow.postMessage("getEvents", "*"); - }); + info("Getting the events..."); + let events = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr.contentWindow.postMessage("getEvents", "*"); + }); - is(events, 0, "No events"); - } - ); + is(events, 0, "No events"); + } + ); - BrowserTestUtils.removeTab(trackerTab); - BrowserTestUtils.removeTab(normalTab); + BrowserTestUtils.removeTab(trackerTab); + BrowserTestUtils.removeTab(normalTab); +}); + +// Two ePartitionOrDeny iframes in the same tab in the same origin don"t see +// the same localStorage values and no storage events are received from each +// other. +add_task(async _ => { + await SpecialPowers.pushPrefEnv({"set": [ + ["dom.ipc.processCount", 1], + ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER], + ["privacy.trackingprotection.enabled", false], + ["privacy.trackingprotection.pbmode.enabled", false], + ["privacy.trackingprotection.annotate_channels", true], + ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], + ]}); + + await UrlClassifierTestUtils.addTestTrackers(); + + info("Creating a non-tracker top-level context"); + let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); + let normalBrowser = gBrowser.getBrowserForTab(normalTab); + await BrowserTestUtils.browserLoaded(normalBrowser); + + info("The non-tracker page opens a tracker iframe"); + await ContentTask.spawn(normalBrowser, { + page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", + }, async obj => { + let ifr1 = content.document.createElement("iframe"); + ifr1.setAttribute("id", "ifr1"); + ifr1.setAttribute("src", obj.page); + + info("Iframe 1 loading..."); + await new content.Promise(resolve => { + ifr1.onload = resolve; + content.document.body.appendChild(ifr1); + }); + + let ifr2 = content.document.createElement("iframe"); + ifr2.setAttribute("id", "ifr2"); + ifr2.setAttribute("src", obj.page); + + info("Iframe 2 loading..."); + await new content.Promise(resolve => { + ifr2.onload = resolve; + content.document.body.appendChild(ifr2); + }); + + info("Setting localStorage value in ifr1..."); + ifr1.contentWindow.postMessage("setValue", "*"); + + info("Getting the value from ifr1..."); + let value = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr1.contentWindow.postMessage("getValue", "*"); + }); + + ok(value.startsWith("tracker-"), "The value is correctly set in ifr1"); + + info("Getting the value from ifr2..."); + value = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr2.contentWindow.postMessage("getValue", "*"); + }); + + is(value, null, "The value is nt set in ifr2"); + + info("Getting the events received by ifr2..."); + let events = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr2.contentWindow.postMessage("getEvents", "*"); + }); + + is(events, 0, "No events"); + } + ); + + BrowserTestUtils.removeTab(normalTab); +}); + +// Same as the previous test but with a cookie behavior of BEHAVIOR_ACCEPT +// instead of BEHAVIOR_REJECT_TRACKER so the iframes get real, persistent +// localStorage instead of partitioned localStorage. +add_task(async _ => { + await SpecialPowers.pushPrefEnv({"set": [ + ["dom.ipc.processCount", 1], + ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_ACCEPT], + ["privacy.trackingprotection.enabled", false], + ["privacy.trackingprotection.pbmode.enabled", false], + ["privacy.trackingprotection.annotate_channels", true], + ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], + ]}); + + await UrlClassifierTestUtils.addTestTrackers(); + + info("Creating a non-tracker top-level context"); + let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); + let normalBrowser = gBrowser.getBrowserForTab(normalTab); + await BrowserTestUtils.browserLoaded(normalBrowser); + + info("The non-tracker page opens a tracker iframe"); + await ContentTask.spawn(normalBrowser, { + page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", + }, async obj => { + let ifr1 = content.document.createElement("iframe"); + ifr1.setAttribute("id", "ifr1"); + ifr1.setAttribute("src", obj.page); + + info("Iframe 1 loading..."); + await new content.Promise(resolve => { + ifr1.onload = resolve; + content.document.body.appendChild(ifr1); + }); + + let ifr2 = content.document.createElement("iframe"); + ifr2.setAttribute("id", "ifr2"); + ifr2.setAttribute("src", obj.page); + + info("Iframe 2 loading..."); + await new content.Promise(resolve => { + ifr2.onload = resolve; + content.document.body.appendChild(ifr2); + }); + + info("Setting localStorage value in ifr1..."); + ifr1.contentWindow.postMessage("setValue", "*"); + + info("Getting the value from ifr1..."); + let value1 = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr1.contentWindow.postMessage("getValue", "*"); + }); + + ok(value1.startsWith("tracker-"), "The value is correctly set in ifr1"); + + info("Getting the value from ifr2..."); + let value2 = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr2.contentWindow.postMessage("getValue", "*"); + }); + + is(value2, value1, "The values match"); + + info("Getting the events received by ifr2..."); + let events = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr2.contentWindow.postMessage("getEvents", "*"); + }); + + is(events, 1, "One event"); + } + ); + + BrowserTestUtils.removeTab(normalTab); +}); + +// An ePartitionOrDeny iframe navigated between two distinct pages on the same +// origin does not see the values stored by the previous iframe. +add_task(async _ => { + await SpecialPowers.pushPrefEnv({"set": [ + ["dom.ipc.processCount", 1], + ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER], + ["privacy.trackingprotection.enabled", false], + ["privacy.trackingprotection.pbmode.enabled", false], + ["privacy.trackingprotection.annotate_channels", true], + ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], + ]}); + + await UrlClassifierTestUtils.addTestTrackers(); + + info("Creating a non-tracker top-level context"); + let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); + let normalBrowser = gBrowser.getBrowserForTab(normalTab); + await BrowserTestUtils.browserLoaded(normalBrowser); + + info("The non-tracker page opens a tracker iframe"); + await ContentTask.spawn(normalBrowser, { + page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", + }, async obj => { + let ifr = content.document.createElement("iframe"); + ifr.setAttribute("id", "ifr"); + ifr.setAttribute("src", obj.page); + + info("Iframe loading..."); + await new content.Promise(resolve => { + ifr.onload = resolve; + content.document.body.appendChild(ifr); + }); + + info("Setting localStorage value in ifr..."); + ifr.contentWindow.postMessage("setValue", "*"); + + info("Getting the value from ifr..."); + let value = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr.contentWindow.postMessage("getValue", "*"); + }); + + ok(value.startsWith("tracker-"), "The value is correctly set in ifr"); + + info("Navigate..."); + await new content.Promise(resolve => { + ifr.onload = resolve; + ifr.setAttribute("src", obj.page + "?" + Math.random()); + }); + + info("Getting the value from ifr..."); + value = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr.contentWindow.postMessage("getValue", "*"); + }); + + is(value, null, "The value is undefined"); + } + ); + + BrowserTestUtils.removeTab(normalTab); +}); + +// Like the previous test, but accepting trackers +add_task(async _ => { + await SpecialPowers.pushPrefEnv({"set": [ + ["dom.ipc.processCount", 1], + ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_ACCEPT], + ["privacy.trackingprotection.enabled", false], + ["privacy.trackingprotection.pbmode.enabled", false], + ["privacy.trackingprotection.annotate_channels", true], + ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], + ]}); + + await UrlClassifierTestUtils.addTestTrackers(); + + info("Creating a non-tracker top-level context"); + let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); + let normalBrowser = gBrowser.getBrowserForTab(normalTab); + await BrowserTestUtils.browserLoaded(normalBrowser); + + info("The non-tracker page opens a tracker iframe"); + await ContentTask.spawn(normalBrowser, { + page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", + }, async obj => { + let ifr = content.document.createElement("iframe"); + ifr.setAttribute("id", "ifr"); + ifr.setAttribute("src", obj.page); + + info("Iframe loading..."); + await new content.Promise(resolve => { + ifr.onload = resolve; + content.document.body.appendChild(ifr); + }); + + info("Setting localStorage value in ifr..."); + ifr.contentWindow.postMessage("setValue", "*"); + + info("Getting the value from ifr..."); + let value = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr.contentWindow.postMessage("getValue", "*"); + }); + + ok(value.startsWith("tracker-"), "The value is correctly set in ifr"); + + info("Navigate..."); + await new content.Promise(resolve => { + ifr.onload = resolve; + ifr.setAttribute("src", obj.page + "?" + Math.random()); + }); + + info("Getting the value from ifr..."); + let value2 = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr.contentWindow.postMessage("getValue", "*"); + }); + + is(value, value2, "The value is undefined"); + } + ); + + BrowserTestUtils.removeTab(normalTab); +}); + +// An ePartitionOrDeny iframe on the same origin that is navigated to itself +// via window.location.reload() or equivalent does not see the values stored by +// its previous self. +add_task(async _ => { + await SpecialPowers.pushPrefEnv({"set": [ + ["dom.ipc.processCount", 1], + ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER], + ["privacy.trackingprotection.enabled", false], + ["privacy.trackingprotection.pbmode.enabled", false], + ["privacy.trackingprotection.annotate_channels", true], + ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], + ]}); + + await UrlClassifierTestUtils.addTestTrackers(); + + info("Creating a non-tracker top-level context"); + let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); + let normalBrowser = gBrowser.getBrowserForTab(normalTab); + await BrowserTestUtils.browserLoaded(normalBrowser); + + info("The non-tracker page opens a tracker iframe"); + await ContentTask.spawn(normalBrowser, { + page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", + }, async obj => { + let ifr = content.document.createElement("iframe"); + ifr.setAttribute("id", "ifr"); + ifr.setAttribute("src", obj.page); + + info("Iframe loading..."); + await new content.Promise(resolve => { + ifr.onload = resolve; + content.document.body.appendChild(ifr); + }); + + info("Setting localStorage value in ifr..."); + ifr.contentWindow.postMessage("setValue", "*"); + + info("Getting the value from ifr..."); + let value = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr.contentWindow.postMessage("getValue", "*"); + }); + + ok(value.startsWith("tracker-"), "The value is correctly set in ifr"); + + info("Reload..."); + await new content.Promise(resolve => { + ifr.onload = resolve; + ifr.contentWindow.postMessage("reload", "*"); + }); + + info("Getting the value from ifr..."); + value = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr.contentWindow.postMessage("getValue", "*"); + }); + + is(value, null, "The value is undefined"); + } + ); + + BrowserTestUtils.removeTab(normalTab); +}); + +// Like the previous test, but accepting trackers +add_task(async _ => { + await SpecialPowers.pushPrefEnv({"set": [ + ["dom.ipc.processCount", 1], + ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_ACCEPT], + ["privacy.trackingprotection.enabled", false], + ["privacy.trackingprotection.pbmode.enabled", false], + ["privacy.trackingprotection.annotate_channels", true], + ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], + ]}); + + await UrlClassifierTestUtils.addTestTrackers(); + + info("Creating a non-tracker top-level context"); + let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); + let normalBrowser = gBrowser.getBrowserForTab(normalTab); + await BrowserTestUtils.browserLoaded(normalBrowser); + + info("The non-tracker page opens a tracker iframe"); + await ContentTask.spawn(normalBrowser, { + page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", + }, async obj => { + let ifr = content.document.createElement("iframe"); + ifr.setAttribute("id", "ifr"); + ifr.setAttribute("src", obj.page); + + info("Iframe loading..."); + await new content.Promise(resolve => { + ifr.onload = resolve; + content.document.body.appendChild(ifr); + }); + + info("Setting localStorage value in ifr..."); + ifr.contentWindow.postMessage("setValue", "*"); + + info("Getting the value from ifr..."); + let value = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr.contentWindow.postMessage("getValue", "*"); + }); + + ok(value.startsWith("tracker-"), "The value is correctly set in ifr"); + + info("Reload..."); + await new content.Promise(resolve => { + ifr.onload = resolve; + ifr.contentWindow.postMessage("reload", "*"); + }); + + info("Getting the value from ifr..."); + let value2 = await new Promise(resolve => { + content.addEventListener("message", e => { + resolve(e.data); + }, {once: true}); + ifr.contentWindow.postMessage("getValue", "*"); + }); + + is(value, value2, "The value is undefined"); + } + ); + + BrowserTestUtils.removeTab(normalTab); +}); + +// Cleanup data. +add_task(async _ => { + await new Promise(resolve => { + Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve()); }); - - // Two ePartitionOrDeny iframes in the same tab in the same origin don't see - // the same localStorage values and no storage events are received from each - // other. - add_task(async _ => { - await SpecialPowers.pushPrefEnv({"set": [ - ["dom.ipc.processCount", 1], - ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER], - ["privacy.trackingprotection.enabled", false], - ["privacy.trackingprotection.pbmode.enabled", false], - ["privacy.trackingprotection.annotate_channels", true], - ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], - ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled], - ]}); - - await UrlClassifierTestUtils.addTestTrackers(); - - info("Creating a non-tracker top-level context"); - let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); - let normalBrowser = gBrowser.getBrowserForTab(normalTab); - await BrowserTestUtils.browserLoaded(normalBrowser); - - info("The non-tracker page opens a tracker iframe"); - await ContentTask.spawn(normalBrowser, { - page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", - withStoragePrincipalEnabled, - }, async obj => { - let ifr1 = content.document.createElement("iframe"); - ifr1.setAttribute("id", "ifr1"); - ifr1.setAttribute("src", obj.page); - - info("Iframe 1 loading..."); - await new content.Promise(resolve => { - ifr1.onload = resolve; - content.document.body.appendChild(ifr1); - }); - - let ifr2 = content.document.createElement("iframe"); - ifr2.setAttribute("id", "ifr2"); - ifr2.setAttribute("src", obj.page); - - info("Iframe 2 loading..."); - await new content.Promise(resolve => { - ifr2.onload = resolve; - content.document.body.appendChild(ifr2); - }); - - info("Setting localStorage value in ifr1..."); - ifr1.contentWindow.postMessage("setValue", "*"); - - info("Getting the value from ifr1..."); - let value = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr1.contentWindow.postMessage("getValue", "*"); - }); - - ok(value.startsWith("tracker-"), "The value is correctly set in ifr1"); - - info("Getting the value from ifr2..."); - value = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr2.contentWindow.postMessage("getValue", "*"); - }); - - if (obj.withStoragePrincipalEnabled) { - ok(value.startsWith("tracker-"), "The value is correctly set in ifr2"); - } else { - is(value, null, "The value is not set in ifr2"); - } - - info("Getting the events received by ifr2..."); - let events = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr2.contentWindow.postMessage("getEvents", "*"); - }); - - if (obj.withStoragePrincipalEnabled) { - is(events, 1, "1 event received"); - } else { - is(events, 0, "No events"); - } - } - ); - - BrowserTestUtils.removeTab(normalTab); - }); - - // Same as the previous test but with a cookie behavior of BEHAVIOR_ACCEPT - // instead of BEHAVIOR_REJECT_TRACKER so the iframes get real, persistent - // localStorage instead of partitioned localStorage. - add_task(async _ => { - await SpecialPowers.pushPrefEnv({"set": [ - ["dom.ipc.processCount", 1], - ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_ACCEPT], - ["privacy.trackingprotection.enabled", false], - ["privacy.trackingprotection.pbmode.enabled", false], - ["privacy.trackingprotection.annotate_channels", true], - ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], - ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled], - ]}); - - await UrlClassifierTestUtils.addTestTrackers(); - - info("Creating a non-tracker top-level context"); - let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); - let normalBrowser = gBrowser.getBrowserForTab(normalTab); - await BrowserTestUtils.browserLoaded(normalBrowser); - - info("The non-tracker page opens a tracker iframe"); - await ContentTask.spawn(normalBrowser, { - page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", - }, async obj => { - let ifr1 = content.document.createElement("iframe"); - ifr1.setAttribute("id", "ifr1"); - ifr1.setAttribute("src", obj.page); - - info("Iframe 1 loading..."); - await new content.Promise(resolve => { - ifr1.onload = resolve; - content.document.body.appendChild(ifr1); - }); - - let ifr2 = content.document.createElement("iframe"); - ifr2.setAttribute("id", "ifr2"); - ifr2.setAttribute("src", obj.page); - - info("Iframe 2 loading..."); - await new content.Promise(resolve => { - ifr2.onload = resolve; - content.document.body.appendChild(ifr2); - }); - - info("Setting localStorage value in ifr1..."); - ifr1.contentWindow.postMessage("setValue", "*"); - - info("Getting the value from ifr1..."); - let value1 = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr1.contentWindow.postMessage("getValue", "*"); - }); - - ok(value1.startsWith("tracker-"), "The value is correctly set in ifr1"); - - info("Getting the value from ifr2..."); - let value2 = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr2.contentWindow.postMessage("getValue", "*"); - }); - - is(value2, value1, "The values match"); - - info("Getting the events received by ifr2..."); - let events = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr2.contentWindow.postMessage("getEvents", "*"); - }); - - is(events, 1, "One event"); - } - ); - - BrowserTestUtils.removeTab(normalTab); - }); - - // An ePartitionOrDeny iframe navigated between two distinct pages on the same - // origin does not see the values stored by the previous iframe. - add_task(async _ => { - await SpecialPowers.pushPrefEnv({"set": [ - ["dom.ipc.processCount", 1], - ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER], - ["privacy.trackingprotection.enabled", false], - ["privacy.trackingprotection.pbmode.enabled", false], - ["privacy.trackingprotection.annotate_channels", true], - ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], - ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled], - ]}); - - await UrlClassifierTestUtils.addTestTrackers(); - - info("Creating a non-tracker top-level context"); - let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); - let normalBrowser = gBrowser.getBrowserForTab(normalTab); - await BrowserTestUtils.browserLoaded(normalBrowser); - - info("The non-tracker page opens a tracker iframe"); - await ContentTask.spawn(normalBrowser, { - page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", - withStoragePrincipalEnabled, - }, async obj => { - let ifr = content.document.createElement("iframe"); - ifr.setAttribute("id", "ifr"); - ifr.setAttribute("src", obj.page); - - info("Iframe loading..."); - await new content.Promise(resolve => { - ifr.onload = resolve; - content.document.body.appendChild(ifr); - }); - - info("Setting localStorage value in ifr..."); - ifr.contentWindow.postMessage("setValue", "*"); - - info("Getting the value from ifr..."); - let value = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr.contentWindow.postMessage("getValue", "*"); - }); - - ok(value.startsWith("tracker-"), "The value is correctly set in ifr"); - - info("Navigate..."); - await new content.Promise(resolve => { - ifr.onload = resolve; - ifr.setAttribute("src", obj.page + "?" + Math.random()); - }); - - info("Getting the value from ifr..."); - let value2 = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr.contentWindow.postMessage("getValue", "*"); - }); - - if (obj.withStoragePrincipalEnabled) { - is(value, value2, "The value is received"); - } else { - is(value2, null, "The value is undefined"); - } - } - ); - - BrowserTestUtils.removeTab(normalTab); - }); - - // Like the previous test, but accepting trackers - add_task(async _ => { - await SpecialPowers.pushPrefEnv({"set": [ - ["dom.ipc.processCount", 1], - ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_ACCEPT], - ["privacy.trackingprotection.enabled", false], - ["privacy.trackingprotection.pbmode.enabled", false], - ["privacy.trackingprotection.annotate_channels", true], - ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], - ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled], - ]}); - - await UrlClassifierTestUtils.addTestTrackers(); - - info("Creating a non-tracker top-level context"); - let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); - let normalBrowser = gBrowser.getBrowserForTab(normalTab); - await BrowserTestUtils.browserLoaded(normalBrowser); - - info("The non-tracker page opens a tracker iframe"); - await ContentTask.spawn(normalBrowser, { - page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", - }, async obj => { - let ifr = content.document.createElement("iframe"); - ifr.setAttribute("id", "ifr"); - ifr.setAttribute("src", obj.page); - - info("Iframe loading..."); - await new content.Promise(resolve => { - ifr.onload = resolve; - content.document.body.appendChild(ifr); - }); - - info("Setting localStorage value in ifr..."); - ifr.contentWindow.postMessage("setValue", "*"); - - info("Getting the value from ifr..."); - let value = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr.contentWindow.postMessage("getValue", "*"); - }); - - ok(value.startsWith("tracker-"), "The value is correctly set in ifr"); - - info("Navigate..."); - await new content.Promise(resolve => { - ifr.onload = resolve; - ifr.setAttribute("src", obj.page + "?" + Math.random()); - }); - - info("Getting the value from ifr..."); - let value2 = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr.contentWindow.postMessage("getValue", "*"); - }); - - is(value, value2, "The value is received"); - } - ); - - BrowserTestUtils.removeTab(normalTab); - }); - - // An ePartitionOrDeny iframe on the same origin that is navigated to itself - // via window.location.reload() or equivalent does not see the values stored - // by its previous self. - add_task(async _ => { - await SpecialPowers.pushPrefEnv({"set": [ - ["dom.ipc.processCount", 1], - ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER], - ["privacy.trackingprotection.enabled", false], - ["privacy.trackingprotection.pbmode.enabled", false], - ["privacy.trackingprotection.annotate_channels", true], - ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], - ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled], - ]}); - - await UrlClassifierTestUtils.addTestTrackers(); - - info("Creating a non-tracker top-level context"); - let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); - let normalBrowser = gBrowser.getBrowserForTab(normalTab); - await BrowserTestUtils.browserLoaded(normalBrowser); - - info("The non-tracker page opens a tracker iframe"); - await ContentTask.spawn(normalBrowser, { - page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", - withStoragePrincipalEnabled, - }, async obj => { - let ifr = content.document.createElement("iframe"); - ifr.setAttribute("id", "ifr"); - ifr.setAttribute("src", obj.page); - - info("Iframe loading..."); - await new content.Promise(resolve => { - ifr.onload = resolve; - content.document.body.appendChild(ifr); - }); - - info("Setting localStorage value in ifr..."); - ifr.contentWindow.postMessage("setValue", "*"); - - info("Getting the value from ifr..."); - let value = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr.contentWindow.postMessage("getValue", "*"); - }); - - ok(value.startsWith("tracker-"), "The value is correctly set in ifr"); - - info("Reload..."); - await new content.Promise(resolve => { - ifr.onload = resolve; - ifr.contentWindow.postMessage("reload", "*"); - }); - - info("Getting the value from ifr..."); - let value2 = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr.contentWindow.postMessage("getValue", "*"); - }); - - if (obj.withStoragePrincipalEnabled) { - is(value, value2, "The value is equal"); - } else { - is(value2, null, "The value is undefined"); - } - } - ); - - BrowserTestUtils.removeTab(normalTab); - }); - - // Like the previous test, but accepting trackers - add_task(async _ => { - await SpecialPowers.pushPrefEnv({"set": [ - ["dom.ipc.processCount", 1], - ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_ACCEPT], - ["privacy.trackingprotection.enabled", false], - ["privacy.trackingprotection.pbmode.enabled", false], - ["privacy.trackingprotection.annotate_channels", true], - ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"], - ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled], - ]}); - - await UrlClassifierTestUtils.addTestTrackers(); - - info("Creating a non-tracker top-level context"); - let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html"); - let normalBrowser = gBrowser.getBrowserForTab(normalTab); - await BrowserTestUtils.browserLoaded(normalBrowser); - - info("The non-tracker page opens a tracker iframe"); - await ContentTask.spawn(normalBrowser, { - page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html", - }, async obj => { - let ifr = content.document.createElement("iframe"); - ifr.setAttribute("id", "ifr"); - ifr.setAttribute("src", obj.page); - - info("Iframe loading..."); - await new content.Promise(resolve => { - ifr.onload = resolve; - content.document.body.appendChild(ifr); - }); - - info("Setting localStorage value in ifr..."); - ifr.contentWindow.postMessage("setValue", "*"); - - info("Getting the value from ifr..."); - let value = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr.contentWindow.postMessage("getValue", "*"); - }); - - ok(value.startsWith("tracker-"), "The value is correctly set in ifr"); - - info("Reload..."); - await new content.Promise(resolve => { - ifr.onload = resolve; - ifr.contentWindow.postMessage("reload", "*"); - }); - - info("Getting the value from ifr..."); - let value2 = await new Promise(resolve => { - content.addEventListener("message", e => { - resolve(e.data); - }, {once: true}); - ifr.contentWindow.postMessage("getValue", "*"); - }); - - is(value, value2, "The value is equal"); - } - ); - - BrowserTestUtils.removeTab(normalTab); - }); - - // Cleanup data. - add_task(async _ => { - await new Promise(resolve => { - Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve()); - }); - }); -} - -runAllTests(false, true); -runAllTests(false, false); -runAllTests(true, true); -runAllTests(true, false); +}); diff --git a/toolkit/components/extensions/Extension.jsm b/toolkit/components/extensions/Extension.jsm index 3462ee1987d1..92e37aaf19fc 100644 --- a/toolkit/components/extensions/Extension.jsm +++ b/toolkit/components/extensions/Extension.jsm @@ -272,7 +272,7 @@ var UninstallObserver = { // the old API. if (!Services.lsm.nextGenLocalStorageEnabled) { // Clear localStorage created by the extension - let storage = Services.domStorageManager.getStorage(null, principal, storagePrincipal); + let storage = Services.domStorageManager.getStorage(null, principal); if (storage) { storage.clear(); } diff --git a/toolkit/components/sessionstore/SessionStoreUtils.cpp b/toolkit/components/sessionstore/SessionStoreUtils.cpp index 60e5d6b08b52..bf0b612aecc6 100644 --- a/toolkit/components/sessionstore/SessionStoreUtils.cpp +++ b/toolkit/components/sessionstore/SessionStoreUtils.cpp @@ -1018,17 +1018,11 @@ static void ReadAllEntriesFromStorage( if (!doc) { return; } - nsCOMPtr principal = doc->NodePrincipal(); if (!principal) { return; } - nsCOMPtr storagePrincipal = doc->EffectiveStoragePrincipal(); - if (!storagePrincipal) { - return; - } - nsAutoCString origin; nsresult rv = principal->GetOrigin(origin); if (NS_FAILED(rv) || aVisitedOrigins.Contains(origin)) { @@ -1042,8 +1036,8 @@ static void ReadAllEntriesFromStorage( return; } RefPtr storage; - storageManager->GetStorage(aWindow->GetCurrentInnerWindow(), principal, - storagePrincipal, false, getter_AddRefs(storage)); + storageManager->GetStorage(aWindow->GetCurrentInnerWindow(), principal, false, + getter_AddRefs(storage)); if (!storage) { return; } @@ -1171,8 +1165,8 @@ void SessionStoreUtils::RestoreSessionStorage( // followup bug to bug 600307. // Null window because the current window doesn't match the principal yet // and loads about:blank. - storageManager->CreateStorage(nullptr, principal, principal, EmptyString(), - false, getter_AddRefs(storage)); + storageManager->CreateStorage(nullptr, principal, EmptyString(), false, + getter_AddRefs(storage)); if (!storage) { continue; } diff --git a/toolkit/components/windowwatcher/nsWindowWatcher.cpp b/toolkit/components/windowwatcher/nsWindowWatcher.cpp index 2ee45293b5e5..30d8da663987 100644 --- a/toolkit/components/windowwatcher/nsWindowWatcher.cpp +++ b/toolkit/components/windowwatcher/nsWindowWatcher.cpp @@ -1184,9 +1184,9 @@ nsresult nsWindowWatcher::OpenWindowInternal( RefPtr storage; nsCOMPtr pInnerWin = parentWindow->GetCurrentInnerWindow(); - parentStorageManager->GetStorage( - pInnerWin, subjectPrincipal, subjectPrincipal, - isPrivateBrowsingWindow, getter_AddRefs(storage)); + parentStorageManager->GetStorage(pInnerWin, subjectPrincipal, + isPrivateBrowsingWindow, + getter_AddRefs(storage)); if (storage) { newStorageManager->CloneStorage(storage); }