Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test SPI to see the entire frame trees in all processes for site isolation #13679

Conversation

achristensen07
Copy link
Contributor

@achristensen07 achristensen07 commented May 10, 2023

538b503

Add test SPI to see the entire frame trees in all processes for site isolation
https://bugs.webkit.org/show_bug.cgi?id=256574
rdar://109134755

Reviewed by J Pascoe and Youenn Fablet.

WKWebView._frames gets info about the frame tree from whatever process each frame is in.
In order to add tests that verifies the whole frame tree state in multiple process during
operations like frame destruction, we need to get the whole frame tree state from each
process and inspect all of it.  This introduces such SPI and uses it for tests.

* Source/WebKit/Shared/FrameInfoData.h:
* Source/WebKit/Shared/FrameInfoData.serialization.in:
* Source/WebKit/UIProcess/API/APIFrameInfo.h:
* Source/WebKit/UIProcess/API/APIFrameTreeNode.h:
* Source/WebKit/UIProcess/API/Cocoa/WKFrameInfo.mm:
(-[WKFrameInfo _isLocalFrame]):
* Source/WebKit/UIProcess/API/Cocoa/WKFrameInfoPrivate.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _frames:]):
(-[WKWebView _frameTrees:]):
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKFrameTreeNode.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKFrameTreeNode.mm:
(-[_WKFrameTreeNode info]):
(-[_WKFrameTreeNode _isLocalFrame]):
* Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::UIClient::promptForDisplayCapturePermission):
(WebKit::UIDelegate::UIClient::decidePolicyForUserMediaPermissionRequest):
* Source/WebKit/UIProcess/ProvisionalPageProxy.cpp:
(WebKit::ProvisionalPageProxy::cancel):
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::getAllFrameTrees):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction):
* Source/WebKit/WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::info const):
(WebKit::WebFrame::frameTreeData const):
* Source/WebKit/WebProcess/WebPage/WebFrame.h:
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::getFrameTree):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm:
(TestWebKitAPI::nullTerminatedIndentation):
(TestWebKitAPI::debugPrint):
(TestWebKitAPI::frameTreesMatch):
(TestWebKitAPI::checkFrameTreesInProcesses):
(TestWebKitAPI::TEST):

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

6c383b3

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe   πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug   πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2   πŸ§ͺ api-mac βœ… πŸ›  gtk
  πŸ§ͺ ios-wk2-wpt   πŸ§ͺ mac-wk1   πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios   πŸ§ͺ mac-wk2   πŸ§ͺ api-gtk
βœ… πŸ›  tv   πŸ§ͺ mac-AS-debug-wk2
  πŸ›  tv-sim
  πŸ›  πŸ§ͺ merge βœ… πŸ›  watch
βœ… πŸ›  πŸ§ͺ unsafe-merge   πŸ›  watch-sim

@achristensen07 achristensen07 self-assigned this May 10, 2023
@achristensen07 achristensen07 added the WebKit Process Model Bugs related to WebKit's multi-process architecture label May 10, 2023
Copy link
Member

@pascoej pascoej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor comment

@@ -31,8 +31,11 @@

namespace WebKit {

enum class FrameType : bool { Local, Remote };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse the enum class FrameType in Frame.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but then we'd need to include Frame.h in many more places, which would hurt our build time.

class FrameTreeCallbackAggregator : public RefCounted<FrameTreeCallbackAggregator> {
public:
static Ref<FrameTreeCallbackAggregator> create(CompletionHandler<void(Vector<FrameTreeNodeData>&&)>&& completionHandler, size_t processCount) { return adoptRef(*new FrameTreeCallbackAggregator(WTFMove(completionHandler), processCount)); }
void addFrameTree(FrameTreeNodeData&& data) { m_data.uncheckedAppend(WTFMove(data)); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it private? It seems uncheckedAppend as a public method is not great.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it needs to be public. But I can make the append a checked append call.

};

auto& internals = this->internals();
size_t processCount = !!m_mainFrame + internals.domainToSubframePageProxyMap.size();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no main frame, why should there be any sub frame?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There wouldn't be. I'll make an early return if m_mainFrame is null.

size_t processCount = !!m_mainFrame + internals.domainToSubframePageProxyMap.size();
auto aggregator = FrameTreeCallbackAggregator::create(WTFMove(completionHandler), processCount);
if (m_mainFrame) {
m_mainFrame->process().sendWithAsyncReply(Messages::WebPage::GetFrameTree(), [aggregator] (FrameTreeNodeData&& data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto&&?

}, webPageID());
}
for (auto& subframePageProxy : internals.domainToSubframePageProxyMap.values()) {
subframePageProxy->process().sendWithAsyncReply(Messages::WebPage::GetFrameTree(), [aggregator] (FrameTreeNodeData&& data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto&&

debugPrint(child, indentation + 2);
}

void debugPrint(const ExpectedFrameTree& node, size_t indentation = 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all these debug prints routines really needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were quite useful for looking for what went wrong. I guess they don't need to be checked in.

Util::run(&done);
checkFrameTreesInProcesses(webView.get(), {
{ "https://example.com"_s,
{ { RemoteFrame } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect the top level main frame to be local

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is. This is its child.

@achristensen07 achristensen07 force-pushed the eng/Add-test-SPI-to-see-the-entire-frame-trees-in-all-processes-for-site-isolation branch from c5a0621 to a53600d Compare May 10, 2023 15:24
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 10, 2023
@achristensen07 achristensen07 force-pushed the eng/Add-test-SPI-to-see-the-entire-frame-trees-in-all-processes-for-site-isolation branch from a53600d to 6c383b3 Compare May 10, 2023 17:26
@achristensen07 achristensen07 added merge-queue Applied to send a pull request to merge-queue unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed merging-blocked Applied to prevent a change from being merged merge-queue Applied to send a pull request to merge-queue labels May 10, 2023
…isolation

https://bugs.webkit.org/show_bug.cgi?id=256574
rdar://109134755

Reviewed by J Pascoe and Youenn Fablet.

WKWebView._frames gets info about the frame tree from whatever process each frame is in.
In order to add tests that verifies the whole frame tree state in multiple process during
operations like frame destruction, we need to get the whole frame tree state from each
process and inspect all of it.  This introduces such SPI and uses it for tests.

* Source/WebKit/Shared/FrameInfoData.h:
* Source/WebKit/Shared/FrameInfoData.serialization.in:
* Source/WebKit/UIProcess/API/APIFrameInfo.h:
* Source/WebKit/UIProcess/API/APIFrameTreeNode.h:
* Source/WebKit/UIProcess/API/Cocoa/WKFrameInfo.mm:
(-[WKFrameInfo _isLocalFrame]):
* Source/WebKit/UIProcess/API/Cocoa/WKFrameInfoPrivate.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _frames:]):
(-[WKWebView _frameTrees:]):
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKFrameTreeNode.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKFrameTreeNode.mm:
(-[_WKFrameTreeNode info]):
(-[_WKFrameTreeNode _isLocalFrame]):
* Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::UIClient::promptForDisplayCapturePermission):
(WebKit::UIDelegate::UIClient::decidePolicyForUserMediaPermissionRequest):
* Source/WebKit/UIProcess/ProvisionalPageProxy.cpp:
(WebKit::ProvisionalPageProxy::cancel):
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::getAllFrameTrees):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction):
* Source/WebKit/WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::info const):
(WebKit::WebFrame::frameTreeData const):
* Source/WebKit/WebProcess/WebPage/WebFrame.h:
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::getFrameTree):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm:
(TestWebKitAPI::nullTerminatedIndentation):
(TestWebKitAPI::debugPrint):
(TestWebKitAPI::frameTreesMatch):
(TestWebKitAPI::checkFrameTreesInProcesses):
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/263912@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Add-test-SPI-to-see-the-entire-frame-trees-in-all-processes-for-site-isolation branch from 6c383b3 to 538b503 Compare May 10, 2023 17:45
@webkit-commit-queue
Copy link
Collaborator

Committed 263912@main (538b503): https://commits.webkit.org/263912@main

Reviewed commits have been landed. Closing PR #13679 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 538b503 into WebKit:main May 10, 2023
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebKit Process Model Bugs related to WebKit's multi-process architecture
Projects
None yet
6 participants