[webkit-changes] [WebKit/WebKit] a28781: Use object lifetimes to manage message receiver re...

Alex Christensen noreply at github.com
Wed Jul 5 10:33:13 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: a2878138acd817eaa41c98ea75b1bc8e2e830729
      https://github.com/WebKit/WebKit/commit/a2878138acd817eaa41c98ea75b1bc8e2e830729
  Author: Alex Christensen <achristensen at apple.com>
  Date:   2023-07-05 (Wed, 05 Jul 2023)

  Changed paths:
    M Source/WebKit/Sources.txt
    M Source/WebKit/UIProcess/DrawingAreaProxy.cpp
    M Source/WebKit/UIProcess/DrawingAreaProxy.h
    M Source/WebKit/UIProcess/PerActivityStateCPUUsageSampler.cpp
    M Source/WebKit/UIProcess/ProvisionalPageProxy.cpp
    M Source/WebKit/UIProcess/ProvisionalPageProxy.h
    M Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeDrawingAreaProxy.h
    M Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeDrawingAreaProxy.mm
    M Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteScrollingTreeIOS.cpp
    M Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteScrollingTreeIOS.h
    M Source/WebKit/UIProcess/RemoteLayerTree/mac/RemoteLayerTreeEventDispatcher.h
    A Source/WebKit/UIProcess/RemotePageDrawingAreaProxy.cpp
    A Source/WebKit/UIProcess/RemotePageDrawingAreaProxy.h
    M Source/WebKit/UIProcess/RemotePageProxy.cpp
    M Source/WebKit/UIProcess/RemotePageProxy.h
    A Source/WebKit/UIProcess/RemotePageVisitedLinkStoreRegistration.h
    M Source/WebKit/UIProcess/SuspendedPageProxy.cpp
    M Source/WebKit/UIProcess/SuspendedPageProxy.h
    M Source/WebKit/UIProcess/WebPageProxy.cpp
    M Source/WebKit/UIProcess/WebPageProxy.h
    M Source/WebKit/UIProcess/WebPageProxyInternals.h
    A Source/WebKit/UIProcess/WebPageProxyMessageReceiverRegistration.cpp
    A Source/WebKit/UIProcess/WebPageProxyMessageReceiverRegistration.h
    M Source/WebKit/UIProcess/gtk/WebDataListSuggestionsDropdownGtk.cpp
    M Source/WebKit/WebKit.xcodeproj/project.pbxproj
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm

  Log Message:
  -----------
  Use object lifetimes to manage message receiver registrations
https://bugs.webkit.org/show_bug.cgi?id=258829
rdar://111064194

Reviewed by J Pascoe.

The receiving of messages to Messages::WebPageProxy::messageReceiverName
is a tricky thing.  When a RemotePageProxy is created during
ProvisionalPageProxy::didCommitLoadForFrame when the frame is the result of
a cross-site window.open in another process (enabled by an off-by-default
feature flag) then we need to transfer the receiving of the messages from
the WebPageProxy to the RemotePageProxy.  We then don't want the WebPageProxy
to start and stop messages from being received for that name any more.
To do this in the most straightforward way I could think of, I tied the
registrations to the lifetime of a new object WebPageProxyMessageReceiverRegistration
which also has the ability to start/stop/transfer its message receiving.
It's a little like a smart pointer, but with lots of metadata for each operation.
It removes the need for explicit calls to remoteMessageReceiver with
Messages::WebPageProxy::messageReceiverName.

I did something quite similar for the VisitedLinkStore registration of a
RemotePageProxy, which only needs to register and unregister when
RemotePageProxy::injectPageIntoNewProcess is called, which happens if that
RemotePageProxy is used for a remote iframe but not for a cross-site window.open.

I also introduce RemotePageDrawingAreaProxy which is similar for the DrawingAreaProxy
messages.  Its existence makes it so that each DrawingArea has one unique proxy
object it communicates with, which will aid in future development of drawing
with site isolation.  Right now it just forwards all its messages to the DrawingAreaProxy
of the page, but in the future it can have the ability to intercept those messages.
In order to know what message receiver names to register for, I replaced the virtual calls
in RemoteLayerTreeDrawingAreaProxy::startReceivingMessages with a function that returns
a std::span of names.  This is safe because all implementations return pointers to
static std::array's, so their lifetimes are forever.  This saves unnecessary allocations.

A few other changes are needed to fix the build after adding new files.
Aren't unified builds fun?

* Source/WebKit/Sources.txt:
* Source/WebKit/UIProcess/DrawingAreaProxy.cpp:
(WebKit::DrawingAreaProxy::startReceivingMessages):
(WebKit::DrawingAreaProxy::stopReceivingMessages):
(WebKit::DrawingAreaProxy::messageReceiverNames const):
* Source/WebKit/UIProcess/DrawingAreaProxy.h:
* Source/WebKit/UIProcess/PerActivityStateCPUUsageSampler.cpp:
* Source/WebKit/UIProcess/ProvisionalPageProxy.cpp:
(WebKit::ProvisionalPageProxy::ProvisionalPageProxy):
(WebKit::ProvisionalPageProxy::~ProvisionalPageProxy):
(WebKit::ProvisionalPageProxy::didCommitLoadForFrame):
* Source/WebKit/UIProcess/ProvisionalPageProxy.h:
* Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeDrawingAreaProxy.h:
* Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeDrawingAreaProxy.mm:
(WebKit::RemoteLayerTreeDrawingAreaProxy::messageReceiverNames const):
(WebKit::RemoteLayerTreeDrawingAreaProxy::startReceivingMessages): Deleted.
(WebKit::RemoteLayerTreeDrawingAreaProxy::stopReceivingMessages): Deleted.
* Source/WebKit/UIProcess/RemoteLayerTree/mac/RemoteLayerTreeEventDispatcher.h:
* Source/WebKit/UIProcess/RemotePageDrawingAreaProxy.cpp: Added.
(WebKit::RemotePageDrawingAreaProxy::RemotePageDrawingAreaProxy):
(WebKit::RemotePageDrawingAreaProxy::~RemotePageDrawingAreaProxy):
(WebKit::RemotePageDrawingAreaProxy::didReceiveMessage):
(WebKit::RemotePageDrawingAreaProxy::didReceiveSyncMessage):
* Source/WebKit/UIProcess/RemotePageDrawingAreaProxy.h: Added.
* Source/WebKit/UIProcess/RemotePageProxy.cpp:
(WebKit::RemotePageProxy::RemotePageProxy):
(WebKit::RemotePageProxy::injectPageIntoNewProcess):
(WebKit::RemotePageProxy::~RemotePageProxy):
* Source/WebKit/UIProcess/RemotePageProxy.h:
(WebKit::RemotePageProxy::create):
(WebKit::RemotePageProxy::messageReceiverRegistration):
* Source/WebKit/UIProcess/RemotePageVisitedLinkStoreRegistration.h: Added.
(WebKit::RemotePageVisitedLinkStoreRegistration::RemotePageVisitedLinkStoreRegistration):
(WebKit::RemotePageVisitedLinkStoreRegistration::~RemotePageVisitedLinkStoreRegistration):
* Source/WebKit/UIProcess/SuspendedPageProxy.cpp:
(WebKit::SuspendedPageProxy::SuspendedPageProxy):
(WebKit::SuspendedPageProxy::~SuspendedPageProxy):
(WebKit::SuspendedPageProxy::didProcessRequestToSuspend):
* Source/WebKit/UIProcess/SuspendedPageProxy.h:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::~WebPageProxy):
(WebKit::WebPageProxy::addAllMessageReceivers):
(WebKit::WebPageProxy::removeAllMessageReceivers):
(WebKit::WebPageProxy::messageReceiverRegistration):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/WebPageProxyInternals.h:
* Source/WebKit/UIProcess/WebPageProxyMessageReceiverRegistration.cpp: Added.
(WebKit::WebPageProxyMessageReceiverRegistration::~WebPageProxyMessageReceiverRegistration):
(WebKit::WebPageProxyMessageReceiverRegistration::startReceivingMessages):
(WebKit::WebPageProxyMessageReceiverRegistration::stopReceivingMessages):
(WebKit::WebPageProxyMessageReceiverRegistration::transferMessageReceivingFrom):
* Source/WebKit/UIProcess/WebPageProxyMessageReceiverRegistration.h: Added.
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:

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




More information about the webkit-changes mailing list