Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 9fd70490c75d5f5af1675ef73bfb7988687d2bc3
      
https://github.com/WebKit/WebKit/commit/9fd70490c75d5f5af1675ef73bfb7988687d2bc3
  Author: Ryosuke Niwa <[email protected]>
  Date:   2026-08-06 (Thu, 06 Aug 2026)

  Changed paths:
    M LayoutTests/http/tests/site-isolation/resources/text-input.html
    A 
LayoutTests/http/tests/site-isolation/tap-main-frame-clears-caret-in-cross-origin-iframe-expected.txt
    A 
LayoutTests/http/tests/site-isolation/tap-main-frame-clears-caret-in-cross-origin-iframe.html
    M Source/WebKit/UIProcess/WebPageProxy.h
    M Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
    M Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm
    M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/SiteIsolation.mm

  Log Message:
  -----------
  [Site Isolation] [iOS] Tapping on a text field does not move the caret from a 
cross-site iframe
https://bugs.webkit.org/show_bug.cgi?id=321125

Reviewed by Wenson Hsieh and Megan Gardner.

When a text field inside a cross-origin (site-isolated) iframe has a caret, two 
related
iOS behaviors were broken:

1. Tapping empty (non-click-target) content in the main frame did not clear the 
caret in
   the cross-origin subframe's field. commitPotentialTap()'s reportFailedTap() 
clears focus
   via setFocusedElement(nullptr) only under 
ENABLE(FOCUS_ADJUSTMENT_IN_SYNTHETIC_CLICK),
   which is disabled on iOS; and even when enabled, localFocusedFrame() is null 
while a
   remote frame holds focus, so nothing defocused the subframe. As a result the 
subframe
   stayed focused and its caret persisted.

2. Focusing a text field in the main frame (after a cross-origin subframe's 
field was
   focused) left the main-frame field with no caret. Focus moves in the main 
frame's
   process first (ElementDidFocus), then the subframe process blurs its 
now-defocused
   field and sends ElementDidBlur. That blur arrives after the main-frame field 
was
   focused, and the UI process blurred it unconditionally -- wiping the new 
caret.

Fix (1) by having reportFailedTap() move focus to the local root frame when a 
remote frame
currently holds focus, which broadcasts the focus change and defocuses the 
subframe
(scoped to the remote case so local behavior, intentionally untouched when 
synthetic-click
focus adjustment is off, is unchanged).

Fix (2) by tracking, in the UI process, which web process reported the 
currently-focused
element (from ElementDidFocus, which already carries the connection) and 
ignoring an
ElementDidBlur from a different process. This is a no-op for the single-process 
case and
for focus moving to nothing (no newer ElementDidFocus, so the process still 
matches).

Add a regression test for (2). It focuses a cross-origin iframe field, then 
focuses a
main-frame field, and verifies (via a new _hasFocusedElementForTesting hook) 
that the
main-frame field remains focused after the subframe's stale blur has been 
delivered.
(1) is verified manually; TestWebKitAPI has no way to synthesize a real tap on 
iOS.

Test: 
http/tests/site-isolation/tap-main-frame-clears-caret-in-cross-origin-iframe.html
      
TestWebKitAPI.SiteIsolation.FocusingMainFrameFieldKeepsFocusAfterCrossOriginIframeField

* LayoutTests/http/tests/site-isolation/resources/text-input.html:
* 
LayoutTests/http/tests/site-isolation/tap-main-frame-clears-caret-in-cross-origin-iframe-expected.txt:
 Added.
* 
LayoutTests/http/tests/site-isolation/tap-main-frame-clears-caret-in-cross-origin-iframe.html:
 Added.
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::elementDidFocus): Record the reporting process.
(WebKit::WebPageProxy::elementDidBlur): Ignore a stale blur from another 
process.
* Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::commitPotentialTap): In reportFailedTap(), defocus a 
cross-origin subframe
that holds focus by moving focus to the local root frame.
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/SiteIsolation.mm:
(-[SiteIsolationInputSessionWebView hasActiveInputSession]):
(-[SiteIsolationInputSessionWebView didStartFormControlInteraction]):
(-[SiteIsolationInputSessionWebView didEndFormControlInteraction]):
(TestWebKitAPI::(SiteIsolation, 
FocusingMainFrameFieldKeepsFocusAfterCrossOriginIframeField)):

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



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

Reply via email to