From 091c1ba3aab834f19740e4ff26e0d00bc4951c3c Mon Sep 17 00:00:00 2001 From: Jan-Niklas Jaeschke Date: Wed, 26 Jun 2024 14:24:32 +0000 Subject: [PATCH] Bug 1888756, part 3 - Text Fragments: Preserve information if a load is a same-document load in `nsILoadInfo`. r=farre,dom-core,necko-reviewers,kershaw,peterv This commit is a prerequisite for part 5 of this patch set. There is no changed behavior in this commit. Differential Revision: https://phabricator.services.mozilla.com/D212818 --- docshell/base/nsDocShell.cpp | 6 +++++- ipc/glue/BackgroundUtils.cpp | 3 +++ netwerk/base/LoadInfo.cpp | 17 +++++++++++++++-- netwerk/base/LoadInfo.h | 5 +++-- netwerk/base/TRRLoadInfo.cpp | 10 ++++++++++ netwerk/base/nsILoadInfo.idl | 15 +++++++++++++++ 6 files changed, 51 insertions(+), 5 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 812e88e0ebf1..cc2408f368e1 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -8693,7 +8693,11 @@ nsresult nsDocShell::HandleSameDocumentNavigation( MOZ_ASSERT(sameExceptHashes); } #endif - + const nsCOMPtr loadInfo = + doc->GetChannel() ? doc->GetChannel()->LoadInfo() : nullptr; + if (loadInfo) { + loadInfo->SetIsSameDocumentNavigation(true); + } // Save the position of the scrollers. nsPoint scrollPos = GetCurScrollPos(); diff --git a/ipc/glue/BackgroundUtils.cpp b/ipc/glue/BackgroundUtils.cpp index d11a7ec4e761..e5b6535b8e64 100644 --- a/ipc/glue/BackgroundUtils.cpp +++ b/ipc/glue/BackgroundUtils.cpp @@ -879,6 +879,9 @@ nsresult LoadInfoArgsToLoadInfo(const LoadInfoArgs& loadInfoArgs, loadInfoArgs.skipContentSniffing(), loadInfoArgs.httpsOnlyStatus(), loadInfoArgs.hstsStatus(), loadInfoArgs.hasValidUserGestureActivation(), loadInfoArgs.textDirectiveUserActivation(), + // This function is only called for moving LoadInfo across processes. + // Same-document navigation won't cross process boundaries. + /* aIsSameDocumentNavigation */ false, loadInfoArgs.allowDeprecatedSystemRequests(), loadInfoArgs.isInDevToolsContext(), loadInfoArgs.parserCreatedScript(), loadInfoArgs.storagePermission(), overriddenFingerprintingSettings, diff --git a/netwerk/base/LoadInfo.cpp b/netwerk/base/LoadInfo.cpp index d78a06b871db..21d5a5e1b419 100644 --- a/netwerk/base/LoadInfo.cpp +++ b/netwerk/base/LoadInfo.cpp @@ -732,8 +732,8 @@ LoadInfo::LoadInfo( const nsAString& aIntegrityMetadata, bool aSkipContentSniffing, uint32_t aHttpsOnlyStatus, bool aHstsStatus, bool aHasValidUserGestureActivation, bool aTextDirectiveUserActivation, - bool aAllowDeprecatedSystemRequests, bool aIsInDevToolsContext, - bool aParserCreatedScript, + bool aIsSameDocumentNavigation, bool aAllowDeprecatedSystemRequests, + bool aIsInDevToolsContext, bool aParserCreatedScript, nsILoadInfo::StoragePermissionState aStoragePermission, const Maybe& aOverriddenFingerprintingSettings, bool aIsMetaRefresh, uint32_t aRequestBlockingReason, @@ -808,6 +808,7 @@ LoadInfo::LoadInfo( mHstsStatus(aHstsStatus), mHasValidUserGestureActivation(aHasValidUserGestureActivation), mTextDirectiveUserActivation(aTextDirectiveUserActivation), + mIsSameDocumentNavigation(aIsSameDocumentNavigation), mAllowDeprecatedSystemRequests(aAllowDeprecatedSystemRequests), mIsInDevToolsContext(aIsInDevToolsContext), mParserCreatedScript(aParserCreatedScript), @@ -2000,6 +2001,18 @@ LoadInfo::SetTextDirectiveUserActivation(bool aTextDirectiveUserActivation) { return NS_OK; } +NS_IMETHODIMP +LoadInfo::GetIsSameDocumentNavigation(bool* aIsSameDocumentNavigation) { + *aIsSameDocumentNavigation = mIsSameDocumentNavigation; + return NS_OK; +} + +NS_IMETHODIMP +LoadInfo::SetIsSameDocumentNavigation(bool aIsSameDocumentNavigation) { + mIsSameDocumentNavigation = aIsSameDocumentNavigation; + return NS_OK; +} + NS_IMETHODIMP LoadInfo::GetAllowDeprecatedSystemRequests( bool* aAllowDeprecatedSystemRequests) { diff --git a/netwerk/base/LoadInfo.h b/netwerk/base/LoadInfo.h index 684cb955fca4..52d867196a45 100644 --- a/netwerk/base/LoadInfo.h +++ b/netwerk/base/LoadInfo.h @@ -250,8 +250,8 @@ class LoadInfo final : public nsILoadInfo { const nsAString& aIntegrityMetadata, bool aSkipContentSniffing, uint32_t aHttpsOnlyStatus, bool aHstsStatus, bool aHasValidUserGestureActivation, bool aTextDirectiveUserActivation, - bool aAllowDeprecatedSystemRequests, bool aIsInDevToolsContext, - bool aParserCreatedScript, + bool aIsSameDocumentNavigation, bool aAllowDeprecatedSystemRequests, + bool aIsInDevToolsContext, bool aParserCreatedScript, nsILoadInfo::StoragePermissionState aStoragePermission, const Maybe& aOverriddenFingerprintingSettings, bool aIsMetaRefresh, uint32_t aRequestBlockingReason, @@ -369,6 +369,7 @@ class LoadInfo final : public nsILoadInfo { bool mHstsStatus = false; bool mHasValidUserGestureActivation = false; bool mTextDirectiveUserActivation = false; + bool mIsSameDocumentNavigation = false; bool mAllowDeprecatedSystemRequests = false; bool mIsUserTriggeredSave = false; bool mIsInDevToolsContext = false; diff --git a/netwerk/base/TRRLoadInfo.cpp b/netwerk/base/TRRLoadInfo.cpp index bf725db386bb..9dc2bb0da687 100644 --- a/netwerk/base/TRRLoadInfo.cpp +++ b/netwerk/base/TRRLoadInfo.cpp @@ -776,6 +776,16 @@ TRRLoadInfo::SetTextDirectiveUserActivation(bool aTextDirectiveUserActivation) { return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP +TRRLoadInfo::GetIsSameDocumentNavigation(bool* aTextDirectiveUserActivation) { + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +TRRLoadInfo::SetIsSameDocumentNavigation(bool aTextDirectiveUserActivation) { + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP TRRLoadInfo::GetInternalContentPolicyType(nsContentPolicyType* aResult) { *aResult = mInternalContentPolicyType; diff --git a/netwerk/base/nsILoadInfo.idl b/netwerk/base/nsILoadInfo.idl index 917523405089..12f43b911006 100644 --- a/netwerk/base/nsILoadInfo.idl +++ b/netwerk/base/nsILoadInfo.idl @@ -554,6 +554,21 @@ interface nsILoadInfo : nsISupports */ [infallible] attribute boolean textDirectiveUserActivation; + /** + * Returns true if the current load is a same-document navigation. + * + * Note: There exists no IPC plumbing for this field. If this object crosses + * a process boundary, it is not same-document, and the value defaults + * to false. + * Also note: This flag is only meant to be used for a specific case when + * scrolling to a text fragment: If a same-doc load is triggered + * during the initial document load, and the target text has not + * been parsed. + * The flag is not being reset. If you want to use this flag for + * another reason, don't. Check Bug 1777171 for a stable solution. + */ + [infallible] attribute boolean isSameDocumentNavigation; + /** * We disallow the SystemPrincipal to initiate requests to * the public web. This flag is to allow exceptions.