Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 21b3626e181e759a3202bdc3248cce2549f39acf
      
https://github.com/WebKit/WebKit/commit/21b3626e181e759a3202bdc3248cce2549f39acf
  Author: Rupin Mittal <[email protected]>
  Date:   2025-12-05 (Fri, 05 Dec 2025)

  Changed paths:
    M Source/WebKit/UIProcess/RemotePageProxy.cpp
    M Source/WebKit/UIProcess/WebPageProxy.cpp
    M Source/WebKit/UIProcess/WebPageProxy.h
    M Source/WebKit/UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.h
    M Source/WebKit/UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.mm
    M Source/WebKit/WebProcess/WebPage/WebPage.cpp
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm
    M Tools/TestWebKitAPI/cocoa/TestUIDelegate.h
    M Tools/TestWebKitAPI/cocoa/TestUIDelegate.mm

  Log Message:
  -----------
  [Site Isolation] Cross-site iframes don't receive DeviceOrientationEvents
https://bugs.webkit.org/show_bug.cgi?id=303618
rdar://165900470

Reviewed by Brady Eidson.

With site isolation on, cross-site iframes don't receive 
DeviceOrientationEvents.
There are mulitple problems we must fix to get this working:

1. Not listening for the events:

    Even if the cross-site iframe is granted permission to receive the events
    and has registered an event listener, WebKit still won't listen for events
    from CoreMotion.

    The Web Process tells the UI Process to listen for events from CoreMotion
    via this call chain:

    1. Event listener is added.
    2. The Web Process sends an IPC to the UI Process in
       WebDeviceOrientationUpdateProvider::startUpdatingDeviceOrientation()
    3. 
WebDeviceOrientationUpdateProviderProxy::StartUpdatingDeviceOrientation().
       is called on the UI Process side, and then the UI Process then starts
       listening for events from CoreMotion.

    In the case of the cross-site iframe, the UI Process never received this
    message. This is because, as we see from it's constructor,
    WebDeviceOrientationUpdateProviderProxy is only set up to receiver messages 
from
    the main frame's Web Process.

    To allow WebDeviceOrientationUpdateProviderProxy to receive messages from 
any
    cross-site Web Process (even those created in the future), we modify
    RemotePageProxy (which is created for every cross-site Web Process) to 
ensure
    that WebDeviceOrientationUpdateProviderProxy can receive messages from the
    Web Process associated with that RemotePageProxy.

2. Not sending the events

    So now the cross-site iframe's Web Process is listening for the events, but
    the UI Process is not sending them. We see in
    WebDeviceOrientationUpdateProviderProxy::orientationChanged that the events
    are sent only to the main frame's Web Process.

    We fix this to ensure that events are sent to all Web Processes.

3. Testing:

    We add a new API test to test this. But testing this required changes as 
well.
    To simulate a device orientation change, we call 
_simulateDeviceOrientationChangeWithAlpha
    on the WebView.

    In order for this simulated change to be noticed by the cross-site iframe,
    we must call simulateDeviceOrientationChange() on that iframe's Document.

    So the first step is ensuring that each Web Process is notified of this 
change.
    For that, we modify WebPageProxy::simulateDeviceOrientationChange().

    Then, within each Web Process, we must ensure that each LocalFrame's 
Document
    is notified of the change (the cross-site iframe will be a LocalFrame in one
    of the WebProcesses). For this, we modify 
WebPage::simulateDeviceOrientationChange.

    The new API test is 
SiteIsolation.CrossSiteIFrameCanReceiveDeviceOrientationEvents

* Source/WebKit/UIProcess/RemotePageProxy.cpp:
(WebKit::RemotePageProxy::RemotePageProxy):

Ensure the associated WebProcess is able to send messages to
WebDeviceOrientationUpdateProviderProxy by adding the Proxy object as a
MessageReceiver.

(WebKit::RemotePageProxy::~RemotePageProxy):

Remove WebDeviceOrientationUpdateProviderProxy as a MessageReceiver of this
WebProcess.

* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::simulateDeviceOrientationChange):

Send the change to every Web Process (for testing).

(WebKit::WebPageProxy::webDeviceOrientationUpdateProviderProxy):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.h:
* Source/WebKit/UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.mm:
(WebKit::WebDeviceOrientationUpdateProviderProxy::addAsMessageReceiverForProcess):
(WebKit::WebDeviceOrientationUpdateProviderProxy::removeAsMessageReceiverForProcess):
(WebKit::WebDeviceOrientationUpdateProviderProxy::orientationChanged):

Send the change to every Web Process.

* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::simulateDeviceOrientationChange):

Send the change to all LocalFrame's documents (for testing).

* Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm:
(TestWebKitAPI::(SiteIsolation, 
CrossSiteIFrameCanReceiveDeviceOrientationEvents)):
* Tools/TestWebKitAPI/cocoa/TestUIDelegate.h:
* Tools/TestWebKitAPI/cocoa/TestUIDelegate.mm:
(-[TestUIDelegate 
webView:requestDeviceOrientationAndMotionPermissionForOrigin:initiatedByFrame:decisionHandler:]):

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



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

Reply via email to