From 2b5b6451335c13dc80ea95b2cfc8142b407a3e60 Mon Sep 17 00:00:00 2001 From: Alexandru Marc Date: Thu, 22 May 2025 10:20:45 +0300 Subject: [PATCH] Revert "Bug 1966658 - Populate the partitionedPrincipal to the SessionHistoryEntry in the parent process. r=smaug,sessionstore-reviewers,core-sessionstore-reviewers,farre" This reverts commit 52c31c4da0149c5ca72b8a1dd37473c01785c484. --- .../components/sessionstore/test/browser.toml | 2 - ...onHistory_partitionedPrincipalToInherit.js | 108 ------------------ docshell/base/BrowsingContext.cpp | 10 +- docshell/base/BrowsingContext.h | 3 +- docshell/base/CanonicalBrowsingContext.cpp | 4 +- docshell/base/CanonicalBrowsingContext.h | 3 +- docshell/base/nsDocShell.cpp | 22 +--- docshell/base/nsDocShell.h | 3 +- docshell/shistory/SessionHistoryEntry.cpp | 15 +-- docshell/shistory/SessionHistoryEntry.h | 1 - dom/ipc/ContentParent.cpp | 10 +- dom/ipc/ContentParent.h | 2 +- dom/ipc/PContent.ipdl | 3 +- netwerk/ipc/DocumentLoadListener.cpp | 3 +- .../sessionstore/SessionHistory.sys.mjs | 13 +++ 15 files changed, 38 insertions(+), 164 deletions(-) delete mode 100644 browser/components/sessionstore/test/browser_sessionHistory_partitionedPrincipalToInherit.js diff --git a/browser/components/sessionstore/test/browser.toml b/browser/components/sessionstore/test/browser.toml index 757868bbedaf..13b55d91e03b 100644 --- a/browser/components/sessionstore/test/browser.toml +++ b/browser/components/sessionstore/test/browser.toml @@ -289,8 +289,6 @@ run-if = ["fission"] ["browser_searchModeSwitcher_restore.js"] -["browser_sessionHistory_partitionedPrincipalToInherit.js"] - ["browser_sessionHistory.js"] https_first_disabled = true support-files = ["file_sessionHistory_hashchange.html"] diff --git a/browser/components/sessionstore/test/browser_sessionHistory_partitionedPrincipalToInherit.js b/browser/components/sessionstore/test/browser_sessionHistory_partitionedPrincipalToInherit.js deleted file mode 100644 index 9fbbc4e2a469..000000000000 --- a/browser/components/sessionstore/test/browser_sessionHistory_partitionedPrincipalToInherit.js +++ /dev/null @@ -1,108 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -add_task(async function test_partitioned_principal_to_inherit() { - if (!Services.appinfo.sessionHistoryInParent) { - ok(true, "sessionHistoryInParent is not enabled, skipping the test."); - return; - } - - // Create a new tab. - let tab = await BrowserTestUtils.openNewForegroundTab( - gBrowser, - "https://example.com" - ); - let browser = tab.linkedBrowser; - - // Get the last entry in the session history. - let sh = browser.browsingContext.sessionHistory; - let entry = sh.getEntryAtIndex(sh.count - 1); - let partitionedPrincipalToInherit = entry.partitionedPrincipalToInherit; - - // Check that the partitioned principal to inherit is properly set. - ok(partitionedPrincipalToInherit, "partitionedPrincipalToInherit is set"); - is( - partitionedPrincipalToInherit.originAttributes.partitionKey, - "(https,example.com)", - "correct partitionKey" - ); - - BrowserTestUtils.removeTab(tab); -}); - -add_task(async function test_partitioned_Principal_to_inherit_in_iframe() { - if (!Services.appinfo.sessionHistoryInParent) { - ok(true, "sessionHistoryInParent is not enabled, skipping the test."); - return; - } - - // Create a new tab. - let tab = await BrowserTestUtils.openNewForegroundTab( - gBrowser, - "https://example.com" - ); - let browser = tab.linkedBrowser; - - // Load a same-origin iframe - await SpecialPowers.spawn(browser, [], async _ => { - let iframe = content.document.createElement("iframe"); - iframe.src = "https://example.com"; - - await new content.Promise(resolve => { - iframe.onload = resolve; - content.document.body.appendChild(iframe); - }); - }); - - // Get the last child entry in the session history for the same-origin iframe. - let sh = browser.browsingContext.sessionHistory; - let entry = sh.getEntryAtIndex(sh.count - 1); - let childEntry = entry.GetChildAt(entry.childCount - 1); - let partitionedPrincipalToInherit = childEntry.partitionedPrincipalToInherit; - - // Check that the partitioned principal to inherit is properly set. - ok(partitionedPrincipalToInherit, "partitionedPrincipalToInherit is set"); - is( - partitionedPrincipalToInherit.originNoSuffix, - "https://example.com", - "correct originNoSuffix in the same-origin iframe" - ); - is( - partitionedPrincipalToInherit.originAttributes.partitionKey, - "(https,example.com)", - "correct partitionKey in the same-origin iframe" - ); - - // Load a cross-site iframe. - await SpecialPowers.spawn(browser, [], async _ => { - let iframe = content.document.createElement("iframe"); - iframe.src = "https://example.net"; - - await new content.Promise(resolve => { - iframe.onload = resolve; - content.document.body.appendChild(iframe); - }); - }); - - // Get the last child entry in the session history for the cross-site iframe. - entry = sh.getEntryAtIndex(sh.count - 1); - childEntry = entry.GetChildAt(entry.childCount - 1); - partitionedPrincipalToInherit = childEntry.partitionedPrincipalToInherit; - - // Check that the partitioned principal to inherit is properly set. - ok(partitionedPrincipalToInherit, "partitionedPrincipalToInherit is set"); - is( - partitionedPrincipalToInherit.originNoSuffix, - "https://example.net", - "correct originNoSuffix in the cross-site iframe" - ); - is( - partitionedPrincipalToInherit.originAttributes.partitionKey, - "(https,example.com)", - "correct partitionKey in the cross-site iframe" - ); - - BrowserTestUtils.removeTab(tab); -}); diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index 7eeaa1ba1d75..df48c8bf0013 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -3791,7 +3791,7 @@ void BrowsingContext::SessionHistoryCommit( const LoadingSessionHistoryInfo& aInfo, uint32_t aLoadType, nsIURI* aPreviousURI, SessionHistoryInfo* aPreviousActiveEntry, bool aPersist, bool aCloneEntryChildren, bool aChannelExpired, - uint32_t aCacheKey, nsIPrincipal* aPartitionedPrincipal) { + uint32_t aCacheKey) { nsID changeID = {}; if (XRE_IsContentProcess()) { RefPtr rootSH = Top()->GetChildSessionHistory(); @@ -3830,11 +3830,11 @@ void BrowsingContext::SessionHistoryCommit( ContentChild* cc = ContentChild::GetSingleton(); mozilla::Unused << cc->SendHistoryCommit( this, aInfo.mLoadId, changeID, aLoadType, aPersist, aCloneEntryChildren, - aChannelExpired, aCacheKey, aPartitionedPrincipal); + aChannelExpired, aCacheKey); } else { - Canonical()->SessionHistoryCommit( - aInfo.mLoadId, changeID, aLoadType, aPersist, aCloneEntryChildren, - aChannelExpired, aCacheKey, aPartitionedPrincipal); + Canonical()->SessionHistoryCommit(aInfo.mLoadId, changeID, aLoadType, + aPersist, aCloneEntryChildren, + aChannelExpired, aCacheKey); } } diff --git a/docshell/base/BrowsingContext.h b/docshell/base/BrowsingContext.h index 284b25ac9b81..cafd925bcb4f 100644 --- a/docshell/base/BrowsingContext.h +++ b/docshell/base/BrowsingContext.h @@ -867,8 +867,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache { uint32_t aLoadType, nsIURI* aCurrentURI, SessionHistoryInfo* aPreviousActiveEntry, bool aPersist, bool aCloneEntryChildren, - bool aChannelExpired, uint32_t aCacheKey, - nsIPrincipal* aPartitionedPrincipal); + bool aChannelExpired, uint32_t aCacheKey); // Set a new active entry on this browsing context. This is used for // implementing history.pushState/replaceState and same document navigations. diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp index 6c35ec730a7a..efcf377f3264 100644 --- a/docshell/base/CanonicalBrowsingContext.cpp +++ b/docshell/base/CanonicalBrowsingContext.cpp @@ -1013,8 +1013,7 @@ void CanonicalBrowsingContext::CallOnTopDescendants( void CanonicalBrowsingContext::SessionHistoryCommit( uint64_t aLoadId, const nsID& aChangeID, uint32_t aLoadType, bool aPersist, - bool aCloneEntryChildren, bool aChannelExpired, uint32_t aCacheKey, - nsIPrincipal* aPartitionedPrincipal) { + bool aCloneEntryChildren, bool aChannelExpired, uint32_t aCacheKey) { MOZ_LOG(gSHLog, LogLevel::Verbose, ("CanonicalBrowsingContext::SessionHistoryCommit %p %" PRIu64, this, aLoadId)); @@ -1038,7 +1037,6 @@ void CanonicalBrowsingContext::SessionHistoryCommit( newActiveEntry->SharedInfo()->mExpired = true; } - newActiveEntry->SetPartitionedPrincipalToInherit(aPartitionedPrincipal); bool loadFromSessionHistory = !newActiveEntry->ForInitialLoad(); newActiveEntry->SetForInitialLoad(false); SessionHistoryEntry::RemoveLoadId(aLoadId); diff --git a/docshell/base/CanonicalBrowsingContext.h b/docshell/base/CanonicalBrowsingContext.h index 6f5948615ca4..fea572d0dc76 100644 --- a/docshell/base/CanonicalBrowsingContext.h +++ b/docshell/base/CanonicalBrowsingContext.h @@ -170,8 +170,7 @@ class CanonicalBrowsingContext final : public BrowsingContext { void SessionHistoryCommit(uint64_t aLoadId, const nsID& aChangeID, uint32_t aLoadType, bool aPersist, bool aCloneEntryChildren, bool aChannelExpired, - uint32_t aCacheKey, - nsIPrincipal* aPartitionedPrincipal); + uint32_t aCacheKey); // Calls the session history listeners' OnHistoryReload, storing the result in // aCanReload. If aCanReload is set to true and we have an active or a loading diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index bc61e4a2bab0..6abc6320bceb 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -9044,7 +9044,7 @@ nsresult nsDocShell::HandleSameDocumentNavigation( *mLoadingEntry, mLoadType, mCurrentURI, previousActiveEntry.get(), true, true, /* No expiration update on the same document loads*/ - false, cacheKey, doc->PartitionedPrincipal()); + false, cacheKey); // FIXME Need to set postdata. // Set the title for the SH entry for this target url so that @@ -9104,9 +9104,6 @@ nsresult nsDocShell::HandleSameDocumentNavigation( // SH menus in go/back/forward buttons won't be empty for this. mActiveEntry->SetTitle(mTitle); - mActiveEntry->SetPartitionedPrincipalToInherit( - doc->PartitionedPrincipal()); - if (scrollRestorationIsManual.isSome()) { mActiveEntry->SetScrollRestorationIsManual( scrollRestorationIsManual.value()); @@ -11612,7 +11609,7 @@ nsresult nsDocShell::UpdateURLAndHistory( /* aReferrerInfo = */ referrerInfo, /* aTriggeringPrincipal = */ aDocument->NodePrincipal(), csp, title, scrollRestorationIsManual, aData, - uriWasModified, aDocument->PartitionedPrincipal()); + uriWasModified); } else { // Since we're not changing which page we have loaded, pass // true for aCloneChildren. @@ -11666,7 +11663,7 @@ nsresult nsDocShell::UpdateURLAndHistory( /* aReferrerInfo = */ referrerInfo, aDocument->NodePrincipal(), aDocument->GetCsp(), title, mActiveEntry && mActiveEntry->GetScrollRestorationIsManual(), aData, - uriWasModified, aDocument->PartitionedPrincipal()); + uriWasModified); } else { // Step 3. newSHEntry = mOSHE; @@ -12115,8 +12112,7 @@ void nsDocShell::UpdateActiveEntry( nsIURI* aOriginalURI, nsIReferrerInfo* aReferrerInfo, nsIPrincipal* aTriggeringPrincipal, nsIContentSecurityPolicy* aCsp, const nsAString& aTitle, bool aScrollRestorationIsManual, - nsIStructuredCloneContainer* aData, bool aURIWasModified, - nsIPrincipal* aPartitionedPrincipal) { + nsIStructuredCloneContainer* aData, bool aURIWasModified) { MOZ_ASSERT(mozilla::SessionHistoryInParent()); MOZ_ASSERT(aURI, "uri is null"); MOZ_ASSERT(mLoadType == LOAD_PUSHSTATE, @@ -12151,7 +12147,6 @@ void nsDocShell::UpdateActiveEntry( mActiveEntry->SetStateData(static_cast(aData)); mActiveEntry->SetURIWasModified(aURIWasModified); mActiveEntry->SetScrollRestorationIsManual(aScrollRestorationIsManual); - mActiveEntry->SetPartitionedPrincipalToInherit(aPartitionedPrincipal); if (replace) { mBrowsingContext->ReplaceActiveSessionHistoryEntry(mActiveEntry.get()); @@ -13892,13 +13887,6 @@ void nsDocShell::MoveLoadingToActiveEntry(bool aPersist, bool aExpired, if (aCacheKey != 0) { mActiveEntry->SetCacheKey(aCacheKey); } - - nsCOMPtr partitionedPrincipal; - RefPtr doc = GetDocument(); - if (doc) { - partitionedPrincipal = doc->PartitionedPrincipal(); - } - mActiveEntry->SetPartitionedPrincipalToInherit(partitionedPrincipal); MOZ_ASSERT(loadingEntry); uint32_t loadType = mLoadType == LOAD_ERROR_PAGE ? mFailedLoadType : mLoadType; @@ -13909,7 +13897,7 @@ void nsDocShell::MoveLoadingToActiveEntry(bool aPersist, bool aExpired, // URI, but in that case mCurrentURI won't be null here. mBrowsingContext->SessionHistoryCommit( *loadingEntry, loadType, aPreviousURI, previousActiveEntry.get(), - aPersist, false, aExpired, aCacheKey, partitionedPrincipal); + aPersist, false, aExpired, aCacheKey); } // Only update navigation if the new entry will be persisted (i.e., is not diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 62bb1dd478ae..32d1673ea09a 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -625,8 +625,7 @@ class nsDocShell final : public nsDocLoader, nsIURI* aURI, nsIURI* aOriginalURI, nsIReferrerInfo* aReferrerInfo, nsIPrincipal* aTriggeringPrincipal, nsIContentSecurityPolicy* aCsp, const nsAString& aTitle, bool aScrollRestorationIsManual, - nsIStructuredCloneContainer* aData, bool aURIWasModified, - nsIPrincipal* aPartitionedPrincipal); + nsIStructuredCloneContainer* aData, bool aURIWasModified); nsresult AddChildSHEntry(nsISHEntry* aCloneRef, nsISHEntry* aNewEntry, int32_t aChildOffset, uint32_t aLoadType, diff --git a/docshell/shistory/SessionHistoryEntry.cpp b/docshell/shistory/SessionHistoryEntry.cpp index 4ab78dc8a2a6..c147e330e413 100644 --- a/docshell/shistory/SessionHistoryEntry.cpp +++ b/docshell/shistory/SessionHistoryEntry.cpp @@ -227,11 +227,6 @@ nsIPrincipal* SessionHistoryInfo::GetPartitionedPrincipalToInherit() const { return mSharedState.Get()->mPartitionedPrincipalToInherit; } -void SessionHistoryInfo::SetPartitionedPrincipalToInherit( - nsIPrincipal* aPartitionedPrincipal) { - mSharedState.Get()->mPartitionedPrincipalToInherit = aPartitionedPrincipal; -} - nsIContentSecurityPolicy* SessionHistoryInfo::GetCsp() const { return mSharedState.Get()->mCsp; } @@ -1670,10 +1665,12 @@ bool IPDLParamTraits::Read( aResult->mSharedState.Get()->mPrincipalToInherit) : !aResult->mSharedState.Get()->mPrincipalToInherit, "We don't expect this to change!"); - MOZ_ASSERT_IF( - aResult->mSharedState.Get()->mPartitionedPrincipalToInherit, - aResult->mSharedState.Get()->mPartitionedPrincipalToInherit->Equals( - partitionedPrincipalToInherit)); + MOZ_ASSERT( + partitionedPrincipalToInherit + ? partitionedPrincipalToInherit->Equals( + aResult->mSharedState.Get()->mPartitionedPrincipalToInherit) + : !aResult->mSharedState.Get()->mPartitionedPrincipalToInherit, + "We don't expect this to change!"); MOZ_ASSERT( csp ? nsCSPContext::Equals(csp, aResult->mSharedState.Get()->mCsp) : !aResult->mSharedState.Get()->mCsp, diff --git a/docshell/shistory/SessionHistoryEntry.h b/docshell/shistory/SessionHistoryEntry.h index 29fefaff6382..4f9f9e3866ff 100644 --- a/docshell/shistory/SessionHistoryEntry.h +++ b/docshell/shistory/SessionHistoryEntry.h @@ -141,7 +141,6 @@ class SessionHistoryInfo { nsIPrincipal* GetPrincipalToInherit() const; nsIPrincipal* GetPartitionedPrincipalToInherit() const; - void SetPartitionedPrincipalToInherit(nsIPrincipal* aPrincipal); nsIContentSecurityPolicy* GetCsp() const; diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index ac19021c895a..61c9bb0a289c 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -7527,13 +7527,7 @@ mozilla::ipc::IPCResult ContentParent::RecvHistoryCommit( const MaybeDiscarded& aContext, const uint64_t& aLoadID, const nsID& aChangeID, const uint32_t& aLoadType, const bool& aPersist, const bool& aCloneEntryChildren, const bool& aChannelExpired, - const uint32_t& aCacheKey, nsIPrincipal* aPartitionedPrincipal) { - if (!ValidatePrincipal(aPartitionedPrincipal, - {ValidatePrincipalOptions::AllowNullPtr, - ValidatePrincipalOptions::AllowSystem})) { - LogAndAssertFailedPrincipalValidationInfo(aPartitionedPrincipal, __func__); - } - + const uint32_t& aCacheKey) { if (!aContext.IsDiscarded()) { CanonicalBrowsingContext* canonical = aContext.get_canonical(); if (!canonical) { @@ -7542,7 +7536,7 @@ mozilla::ipc::IPCResult ContentParent::RecvHistoryCommit( } canonical->SessionHistoryCommit(aLoadID, aChangeID, aLoadType, aPersist, aCloneEntryChildren, aChannelExpired, - aCacheKey, aPartitionedPrincipal); + aCacheKey); } return IPC_OK(); } diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 5c353eb7b496..75ab5336d1b3 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -1304,7 +1304,7 @@ class ContentParent final : public PContentParent, const MaybeDiscarded& aContext, const uint64_t& aLoadID, const nsID& aChangeID, const uint32_t& aLoadType, const bool& aPersist, const bool& aCloneEntryChildren, const bool& aChannelExpired, - const uint32_t& aCacheKey, nsIPrincipal* aPartitionedPrincipal); + const uint32_t& aCacheKey); MOZ_CAN_RUN_SCRIPT_BOUNDARY mozilla::ipc::IPCResult RecvHistoryGo( diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index ff743cdfd36d..da9b374e515a 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -1784,8 +1784,7 @@ parent: async HistoryCommit(MaybeDiscardedBrowsingContext aContext, uint64_t aLoadID, nsID aChangeID, uint32_t aLoadType, bool aPersist, bool aCloneEntryChildren, - bool aChannelExpired, uint32_t aCacheKey, - nullable nsIPrincipal aPartitionedPrincipal); + bool aChannelExpired, uint32_t aCacheKey); async HistoryGo(MaybeDiscardedBrowsingContext aContext, int32_t aOffset, uint64_t aHistoryEpoch, bool aRequireUserInteraction, diff --git a/netwerk/ipc/DocumentLoadListener.cpp b/netwerk/ipc/DocumentLoadListener.cpp index 642916adb4bd..c486793f79e2 100644 --- a/netwerk/ipc/DocumentLoadListener.cpp +++ b/netwerk/ipc/DocumentLoadListener.cpp @@ -662,8 +662,7 @@ static Result ValidateHistoryLoad( aLoadState->PrincipalToInherit())) { return Err("PrincipalToInherit"); } - if (snapshot->GetPartitionedPrincipalToInherit() && - !principalEq(snapshot->GetPartitionedPrincipalToInherit(), + if (!principalEq(snapshot->GetPartitionedPrincipalToInherit(), aLoadState->PartitionedPrincipalToInherit())) { return Err("PartitionedPrincipalToInherit"); } diff --git a/toolkit/modules/sessionstore/SessionHistory.sys.mjs b/toolkit/modules/sessionstore/SessionHistory.sys.mjs index 55d780c71db5..19f6210fba08 100644 --- a/toolkit/modules/sessionstore/SessionHistory.sys.mjs +++ b/toolkit/modules/sessionstore/SessionHistory.sys.mjs @@ -277,6 +277,13 @@ var SessionHistoryInternal = { ); } + if (shEntry.partitionedPrincipalToInherit) { + entry.partitionedPrincipalToInherit_base64 = + lazy.E10SUtils.serializePrincipal( + shEntry.partitionedPrincipalToInherit + ); + } + entry.hasUserInteraction = shEntry.hasUserInteraction; if (shEntry.triggeringPrincipal) { @@ -563,6 +570,12 @@ var SessionHistoryInternal = { ); // As both partitionedPrincipal and principalToInherit are both not required to load // it's ok to keep these undefined when we don't have a previously defined principal. + if (entry.partitionedPrincipalToInherit_base64) { + shEntry.partitionedPrincipalToInherit = + lazy.E10SUtils.deserializePrincipal( + entry.partitionedPrincipalToInherit_base64 + ); + } if (entry.principalToInherit_base64) { shEntry.principalToInherit = lazy.E10SUtils.deserializePrincipal( entry.principalToInherit_base64