From 03ab2bf22955b20c141c326d10d9391ff48b19ce Mon Sep 17 00:00:00 2001 From: Blink WPT Bot Date: Mon, 3 Feb 2025 11:37:33 -0800 Subject: [PATCH] Fix selectURL() loaded iframes not getting window.fence. (#50394) We are temporarily allowing APIs like Protected Audience and Shared Storage selectURL() to load into iframes as part of the fenced frame transition process. As part of this, we expose the fenced frame window.fence call to these kinds of iframes. This was launched as part of the fenced frames launch. See: https://chromestatus.com/feature/5699388062040064 A restriction currently exists where the config created by the API must have some kind of reporting metadata to give the iframe access to window.fence. This is a legacy restriction and is no longer necessary, and it results in selectURL()-created iframes without reporting metadata supplied from accessing window.fence. This CL fixes that by removing the restriction. It also adds a test to check the selectURL() without reporting path. It also updates the fenced frame WPT infrastructure to allow selectURL() to be invoked with or without reporting metadata. As part of this change, the renderer is no longer being told whether the fenced frame has reporting metadata. This is information that can be determined in the browser rather than calculating it on the renderer-side and then verifying the calculation in the browser, so having the renderer be part of this check is unnecessary. Change-Id: Ieec3cdaa31cd62bfe6fdb1993e13d68f00f00f28 Bug: 392650252 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6197762 Reviewed-by: Shivani Sharma Commit-Queue: Liam Brady Reviewed-by: Arthur Sonzogni Reviewed-by: Daniel Cheng Reviewed-by: Xiaochen Zhou Cr-Commit-Position: refs/heads/main@{#1413688} Co-authored-by: Liam Brady --- ...automatic-beacon-shared-storage.https.html | 3 +- .../fence-object-urn-iframe.https.html | 31 +++++++++++++++++++ ...ce-report-event-sub-fencedframe.https.html | 3 +- fenced-frame/resources/utils.js | 27 +++++++++------- 4 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 fenced-frame/fence-object-urn-iframe.https.html diff --git a/fenced-frame/automatic-beacon-shared-storage.https.html b/fenced-frame/automatic-beacon-shared-storage.https.html index 56ca40b9e928ca..157210a786cf6d 100644 --- a/fenced-frame/automatic-beacon-shared-storage.https.html +++ b/fenced-frame/automatic-beacon-shared-storage.https.html @@ -18,7 +18,8 @@ const actions = new test_driver.Actions(); const fencedframe = await attachFencedFrameContext( {generator_api: 'sharedstorage', - origin: get_host_info().HTTPS_REMOTE_ORIGIN}); + origin: get_host_info().HTTPS_REMOTE_ORIGIN, + register_beacon: true}); let start_event = { eventType: "reserved.top_navigation_start", diff --git a/fenced-frame/fence-object-urn-iframe.https.html b/fenced-frame/fence-object-urn-iframe.https.html new file mode 100644 index 00000000000000..91268bd561676a --- /dev/null +++ b/fenced-frame/fence-object-urn-iframe.https.html @@ -0,0 +1,31 @@ + +Test window.fence exists in URN iframes. + + + + + + + + + diff --git a/fenced-frame/fence-report-event-sub-fencedframe.https.html b/fenced-frame/fence-report-event-sub-fencedframe.https.html index b3516acf4bd452..53000101dfb55b 100644 --- a/fenced-frame/fence-report-event-sub-fencedframe.https.html +++ b/fenced-frame/fence-report-event-sub-fencedframe.https.html @@ -20,7 +20,8 @@ }); await fencedframe.execute(async () => { const fencedframe = await attachFencedFrameContext({ - generator_api: 'sharedstorage' + generator_api: 'sharedstorage', + register_beacon: true }); await fencedframe.execute(() => { const destination_url = new URL(BEACON_URL + "?type=url", diff --git a/fenced-frame/resources/utils.js b/fenced-frame/resources/utils.js index bf0cb2f53c51a4..f26ebd82acc388 100644 --- a/fenced-frame/resources/utils.js +++ b/fenced-frame/resources/utils.js @@ -24,7 +24,8 @@ function getRemoteContextURL(origin) { return new URL(REMOTE_EXECUTOR_URL, origin); } -async function runSelectRawURL(href, resolve_to_config = false) { +async function runSelectRawURL( + href, resolve_to_config = false, register_beacon = false) { try { await sharedStorage.worklet.addModule( "/shared-storage/resources/simple-module.js"); @@ -35,14 +36,17 @@ async function runSelectRawURL(href, resolve_to_config = false) { // in a try/catch so that if it runs a second time in a test, it will // gracefully fail rather than bring the whole test down. } + let operation = {url: href}; + if (register_beacon) { + operation.reportingMetadata = { + 'reserved.top_navigation_start': + BEACON_URL + '?type=reserved.top_navigation_start', + 'reserved.top_navigation_commit': + BEACON_URL + '?type=reserved.top_navigation_commit', + }; + } return await sharedStorage.selectURL( - 'test-url-selection-operation', [{url: href, - reportingMetadata: { - 'reserved.top_navigation_start': BEACON_URL + - "?type=reserved.top_navigation_start", - 'reserved.top_navigation_commit': BEACON_URL + - "?type=reserved.top_navigation_commit", - }}], { + 'test-url-selection-operation', [operation], { data: {'mockResult': 0}, resolveToConfig: resolve_to_config, keepAlive: true, @@ -71,9 +75,10 @@ async function runSelectRawURL(href, resolve_to_config = false) { // needs to be enabled for `selectURL()` to return a fenced frame config. // Otherwise `selectURL()` will fall back to the old behavior that returns an // urn:uuid. -async function runSelectURL(href, keylist = [], resolve_to_config = false) { +async function runSelectURL( + href, keylist = [], resolve_to_config = false, register_beacon = false) { const full_url = generateURL(href, keylist); - return await runSelectRawURL(full_url, resolve_to_config); + return await runSelectRawURL(full_url, resolve_to_config, register_beacon); } async function generateURNFromFledgeRawURL( @@ -302,7 +307,7 @@ async function attachOpaqueContext( generateURNFromFledge( url, [], components_list, resolve_to_config, ad_with_size, requested_size, register_beacon) : - runSelectURL(url, [], resolve_to_config)); + runSelectURL(url, [], resolve_to_config, register_beacon)); const object = object_constructor(id); return buildRemoteContextForObject(object, uuid, html); }