Bug 1888756, part 2 - Text Fragments: Implement setting the textDirectiveUserActivation flag in the document loading algorithm. r=edgar,dom-core

This commit is a prerequisite for part 5 of this patch set.

This flag is set in the docshell, based on `user gesture activation`.
This is not necessarily sufficient,
as the text fragments spec bases the value of
this flag also on User Involvement, which is not
implemented in Gecko yet.

The flag is then plumbed through the parent process
(`DocumentLoadListener::CreateDocumentLoadInfo()`)
to the document, where it can be consumed.
This includes client-side redirects as described in [0].

There is no changed behavior in this commit.

[0] https://wicg.github.io/scroll-to-text-fragment/#restricting-the-text-fragment

Differential Revision: https://phabricator.services.mozilla.com/D212817
This commit is contained in:
Jan-Niklas Jaeschke
2024-06-26 14:24:32 +00:00
parent 04c0ffe9aa
commit 4835874f4b
7 changed files with 67 additions and 4 deletions

View File

@@ -4110,6 +4110,11 @@ nsresult nsDocShell::ReloadDocument(nsDocShell* aDocShell, Document* aDocument,
loadState->SetBaseURI(baseURI);
loadState->SetHasValidUserGestureActivation(
context && context->HasValidTransientUserGestureActivation());
loadState->SetTextDirectiveUserActivation(
aDocument->ConsumeTextDirectiveUserActivation() ||
loadState->HasValidUserGestureActivation());
loadState->SetNotifiedBeforeUnloadListeners(aNotifiedBeforeUnloadListeners);
return aDocShell->InternalLoad(loadState);
}
@@ -5082,6 +5087,10 @@ nsDocShell::ForceRefreshURI(nsIURI* aURI, nsIPrincipal* aPrincipal,
loadState->SetCsp(doc->GetCsp());
loadState->SetHasValidUserGestureActivation(
doc->HasValidTransientUserGestureActivation());
loadState->SetTextDirectiveUserActivation(
doc->ConsumeTextDirectiveUserActivation() ||
loadState->HasValidUserGestureActivation());
loadState->SetTriggeringSandboxFlags(doc->GetSandboxFlags());
loadState->SetTriggeringWindowId(doc->InnerWindowID());
loadState->SetTriggeringStorageAccess(doc->UsingStorageAccess());
@@ -8390,6 +8399,9 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState) {
loadState->SetHasValidUserGestureActivation(
aLoadState->HasValidUserGestureActivation());
loadState->SetTextDirectiveUserActivation(
aLoadState->GetTextDirectiveUserActivation());
// Propagate POST data to the new load.
loadState->SetPostDataStream(aLoadState->PostDataStream());
loadState->SetIsFormSubmission(aLoadState->IsFormSubmission());
@@ -10377,6 +10389,7 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
if (mLoadType != LOAD_ERROR_PAGE && context && context->IsInProcess()) {
if (context->HasValidTransientUserGestureActivation()) {
aLoadState->SetHasValidUserGestureActivation(true);
aLoadState->SetTextDirectiveUserActivation(true);
}
if (!aLoadState->TriggeringWindowId()) {
aLoadState->SetTriggeringWindowId(context->Id());
@@ -10396,8 +10409,12 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
if (aLoadState->HasValidUserGestureActivation() ||
aLoadState->HasLoadFlags(LOAD_FLAGS_FROM_EXTERNAL)) {
loadInfo->SetHasValidUserGestureActivation(true);
aLoadState->SetTextDirectiveUserActivation(true);
}
loadInfo->SetTextDirectiveUserActivation(
aLoadState->GetTextDirectiveUserActivation());
loadInfo->SetTriggeringWindowId(aLoadState->TriggeringWindowId());
loadInfo->SetTriggeringStorageAccess(aLoadState->TriggeringStorageAccess());
loadInfo->SetTriggeringSandboxFlags(aLoadState->TriggeringSandboxFlags());
@@ -11938,6 +11955,9 @@ nsresult nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry, uint32_t aLoadType,
loadState->SetHasValidUserGestureActivation(
loadState->HasValidUserGestureActivation() || aUserActivation);
loadState->SetTextDirectiveUserActivation(
loadState->GetTextDirectiveUserActivation() || aUserActivation);
return LoadHistoryEntry(loadState, aLoadType, aEntry == mOSHE);
}
@@ -11948,6 +11968,9 @@ nsresult nsDocShell::LoadHistoryEntry(const LoadingSessionHistoryInfo& aEntry,
loadState->SetHasValidUserGestureActivation(
loadState->HasValidUserGestureActivation() || aUserActivation);
loadState->SetTextDirectiveUserActivation(
loadState->GetTextDirectiveUserActivation() || aUserActivation);
return LoadHistoryEntry(loadState, aLoadType, aEntry.mLoadingCurrentEntry);
}
@@ -12793,6 +12816,13 @@ nsresult nsDocShell::OnLinkClick(
loadState->SetCsp(aCsp ? aCsp : aContent->GetCsp());
loadState->SetAllowFocusMove(UserActivation::IsHandlingUserInput());
const bool hasValidUserGestureActivation =
ownerDoc->HasValidTransientUserGestureActivation();
loadState->SetHasValidUserGestureActivation(hasValidUserGestureActivation);
loadState->SetTextDirectiveUserActivation(
ownerDoc->ConsumeTextDirectiveUserActivation() ||
hasValidUserGestureActivation);
nsCOMPtr<nsIRunnable> ev =
new OnLinkClickEvent(this, aContent, loadState, noOpenerImplied,
aIsTrusted, aTriggeringPrincipal);
@@ -13028,7 +13058,6 @@ nsresult nsDocShell::OnLinkClickSync(nsIContent* aContent,
nsCOMPtr<nsIReferrerInfo> referrerInfo =
elementCanHaveNoopener ? new ReferrerInfo(*aContent->AsElement())
: new ReferrerInfo(*referrerDoc);
RefPtr<WindowContext> context = mBrowsingContext->GetCurrentWindowContext();
aLoadState->SetTriggeringSandboxFlags(triggeringSandboxFlags);
aLoadState->SetTriggeringWindowId(triggeringWindowId);
@@ -13038,8 +13067,6 @@ nsresult nsDocShell::OnLinkClickSync(nsIContent* aContent,
aLoadState->SetTypeHint(NS_ConvertUTF16toUTF8(typeHint));
aLoadState->SetLoadType(loadType);
aLoadState->SetSourceBrowsingContext(mBrowsingContext);
aLoadState->SetHasValidUserGestureActivation(
context && context->HasValidTransientUserGestureActivation());
nsresult rv = InternalLoad(aLoadState);