Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 9fd79b30a635bfa5c6cfebcf0eed889ed9bbdc90
      
https://github.com/WebKit/WebKit/commit/9fd79b30a635bfa5c6cfebcf0eed889ed9bbdc90
  Author: Rupin Mittal <[email protected]>
  Date:   2026-06-10 (Wed, 10 Jun 2026)

  Changed paths:
    A 
LayoutTests/http/tests/resourceLoadStatistics/resources/iframe-with-input.html
    A 
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-keyboard-in-cross-origin-sub-frame-expected.txt
    A 
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-keyboard-in-cross-origin-sub-frame.html
    M LayoutTests/platform/ios/TestExpectations
    M Source/WebCore/page/EventHandler.cpp
    M Source/WebKit/WebProcess/WebCoreSupport/WebResourceLoadObserver.cpp

  Log Message:
  -----------
  [Site Isolation] Make key events attribute user interaction to the top 
frame's origin
https://bugs.webkit.org/show_bug.cgi?id=316465
rdar://178865421

Reviewed by Alex Christensen.

When a key event happens in a cross-site iframe, we record that a user 
interation
happened, but not on the iframe's origin, but rather the top frame's origin. 
This
works with site isolation off (the test this patch adds shows that). But it 
doesn't
work with site isolation on.

EventHandler::keyEvent() only calls 
logUserInteractionWithReducedTimeResolution()
if it finds the main frame's document, which it can't if called from a 
cross-site
iframe. The reason logUserInteractionWithReducedTimeResolution() expects to be
given the main frame's document is so it can extract the top frame's origin.

We fix this by having EventHandler::keyEvent() send in the current document 
(which
could be the cross-site iframe's document) and having
logUserInteractionWithReducedTimeResolution() extract the top frame's origin 
from
it via the documentSyncData stored on the page.

This makes the test pass with site isolation enabled as well.

It looks like logUserInteractionWithReducedTimeResolution() also uses the main
frame's document to call requestStorageAccessUnderOpener(). Since this already
doesn't work with site isolation on, and we aren't fixing it here, we just log
the site isolation error (similiar to other places that check 
mainFrameDocument).

Notes about the test:

Making a keyEvent work in the cross-site iframe meant selecting the iframe. 
This is
a mouse event, which already attributes user interaction to the top frame's 
origin.
So to test this properly, we need to clear this attribution. Two nuances:

1. logUserInteractionWithReducedTimeResolution() reduces the wall-clock time to 
a
   5-second bucket (ResourceLoadStatistics::reduceTimeResolution()). If two
   interactions happen within 5 seconds of each other the second is discarded. 
So
   to test this properly, our key event has to happen at least 5 seconds after 
the
   click (we use a 6 second timeout).

2. We need to clear the attribution stored in the network process (done by 
calling
   TestController::setStatisticsHasHadUserInteraction()).

* 
LayoutTests/http/tests/resourceLoadStatistics/resources/iframe-with-input.html: 
Added.
* 
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-keyboard-in-cross-origin-sub-frame-expected.txt:
 Added.
* 
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-keyboard-in-cross-origin-sub-frame.html:
 Added.
* Source/WebCore/page/EventHandler.cpp:
(WebCore::EventHandler::keyEvent):
* Source/WebKit/WebProcess/WebCoreSupport/WebResourceLoadObserver.cpp:
(WebKit::WebResourceLoadObserver::logUserInteractionWithReducedTimeResolution):

Canonical link: https://commits.webkit.org/314903@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to