Bug 1911339 - Text Fragments: Preserve user activation when opening a link in a new tab or window. r=dom-core,tabbrowser-reviewers,dao,farre

Differential Revision: https://phabricator.services.mozilla.com/D218655
This commit is contained in:
Jan-Niklas Jaeschke 2024-08-20 08:47:49 +00:00
parent cd9132d86e
commit 81eef3ca60
5 changed files with 42 additions and 0 deletions

View File

@ -119,6 +119,7 @@ export class ClickHandlerParent extends JSWindowActorParent {
openerBrowser: browser,
// The child ensures that untrusted events have a valid user activation.
hasValidUserGestureActivation: true,
textDirectiveUserActivation: true,
triggeringRemoteType: this.manager.domProcess?.remoteType,
};

View File

@ -2692,6 +2692,8 @@
globalHistoryOptions,
triggeringRemoteType,
wasSchemelessInput,
hasValidUserGestureActivation = false,
textDirectiveUserActivation = false,
} = {}
) {
// all callers of addTab that pass a params object need to pass
@ -2880,8 +2882,10 @@
triggeringRemoteType,
wasSchemelessInput,
hasValidUserGestureActivation:
hasValidUserGestureActivation ||
!!openWindowInfo?.hasValidUserGestureActivation,
textDirectiveUserActivation:
textDirectiveUserActivation ||
!!openWindowInfo?.textDirectiveUserActivation,
});
}

View File

@ -445,6 +445,8 @@ export const URILoadingHelper = {
resolveOnNewTabCreated,
resolveOnContentBrowserCreated,
globalHistoryOptions,
hasValidUserGestureActivation,
textDirectiveUserActivation,
} = params;
// We want to overwrite some things for convenience when passing it to other
@ -588,6 +590,8 @@ export const URILoadingHelper = {
fromExternal: params.fromExternal,
globalHistoryOptions,
wasSchemelessInput: params.wasSchemelessInput,
hasValidUserGestureActivation,
textDirectiveUserActivation,
});
targetBrowser = tabUsedForLoad.linkedBrowser;

View File

@ -0,0 +1,5 @@
[scroll-to-text-fragment-open-link-in-new-tab-desktop.html]
expected:
if os == "android": TIMEOUT
[Test that the text fragment directive requires a user activation when invoked by clicking a link in the same or a new tab]
expected: if os == "android": TIMEOUT

View File

@ -0,0 +1,28 @@
<!doctype html>
<title>Navigating to a text fragment directive in a new tab</title>
<meta charset=utf-8>
<link rel="help" href="https://wicg.github.io/ScrollToTextFragment/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/common/utils.js"></script>
<script src="stash.js"></script>
<body></body>
<script>
promise_test(async t => new Promise((resolve, reject) =>{
let key = token();
document.body.innerHTML = `<a href="scroll-to-text-fragment-target.html?key=${key}#:~:text=test">Click me</a>`;
const link = document.querySelector("a");
test_driver.bless('Open a URL with a text directive in a new tab', () => {
test_driver.send_keys(document.body, '\uE004'); // TAB to focus the link
test_driver.send_keys(link, '\uE009\uE007'); // CTRL + ENTER
});
fetchResults(key, resolve, reject);
}).then(data => {
assert_equals(data.scrollPosition, 'text', 'Expected ctrl+click on a link to be user activated.');
}), `Test that the text fragment directive requires a user activation when invoked by clicking a link in the same or a new tab`);
</script>