Skip to content

Commit

Permalink
RemotePageProxy should handle all messages from site-isolated iframes
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265416
rdar://116202187

Reviewed by Pascoe.

During the initial development we skipped a few messages, but the time has come to handle them all correctly.

* LayoutTests/http/tests/site-isolation/post-message-expected.txt:
* Source/WebKit/UIProcess/RemotePageProxy.cpp:
(WebKit::RemotePageProxy::didReceiveMessage):
(WebKit::RemotePageProxy::handleMessage):
(WebKit::RemotePageProxy::didCommitLoadForFrame):
* Source/WebKit/UIProcess/RemotePageProxy.h:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleMessage):
(WebKit::WebPageProxy::handleMessageShared):
* Source/WebKit/UIProcess/WebPageProxy.h:

Canonical link: https://commits.webkit.org/271241@main
  • Loading branch information
achristensen07 committed Nov 28, 2023
1 parent 166abf6 commit b81b211
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
CONSOLE MESSAGE: Unable to post message to http://webkit.org. Recipient has origin http://localhost:8000.

PASS posting a message to about:blank threw an exception: SyntaxError: The string did not match the expected pattern.
PASS posting a non-serializable message threw an exception: DataCloneError: The object can not be cloned.
PASS successfullyParsed is true
Expand Down
27 changes: 15 additions & 12 deletions Source/WebKit/UIProcess/RemotePageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ RemotePageProxy::~RemotePageProxy()

void RemotePageProxy::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder)
{
#if HAVE(VISIBILITY_PROPAGATION_VIEW)
// FIXME: This needs to be handled correctly in a way that doesn't cause assertions or crashes. <rdar://116202187>
if (decoder.messageName() == Messages::WebPageProxy::DidCreateContextInWebProcessForVisibilityPropagation::name())
return;
#endif

// FIXME: Removing this will be necessary to getting layout tests to work with site isolation. <rdar://116202187>
if (decoder.messageName() == Messages::WebPageProxy::HandleMessage::name())
return;

if (decoder.messageName() == Messages::WebPageProxy::DecidePolicyForResponse::name()) {
IPC::handleMessageAsync<Messages::WebPageProxy::DecidePolicyForResponse>(connection, decoder, this, &RemotePageProxy::decidePolicyForResponse);
return;
Expand All @@ -133,10 +123,22 @@ void RemotePageProxy::didReceiveMessage(IPC::Connection& connection, IPC::Decode
return;
}

if (decoder.messageName() == Messages::WebPageProxy::HandleMessage::name()) {
IPC::handleMessage<Messages::WebPageProxy::HandleMessage>(connection, decoder, this, &RemotePageProxy::handleMessage);
return;
}

if (m_page)
m_page->didReceiveMessage(connection, decoder);
}

void RemotePageProxy::handleMessage(const String& messageName, const WebKit::UserData& messageBody)
{
if (!m_page)
return;
m_page->handleMessageShared(m_process, messageName, messageBody);
}

void RemotePageProxy::decidePolicyForResponse(FrameInfoData&& frameInfo, uint64_t navigationID, const WebCore::ResourceResponse& response, const WebCore::ResourceRequest& request, bool canShowMIMEType, const String& downloadAttribute, CompletionHandler<void(PolicyDecision&&)>&& completionHandler)
{
if (!m_page)
Expand All @@ -148,8 +150,9 @@ void RemotePageProxy::didCommitLoadForFrame(WebCore::FrameIdentifier frameID, Fr
{
m_process->didCommitProvisionalLoad();
RefPtr frame = WebFrameProxy::webFrame(frameID);
if (frame)
frame->commitProvisionalFrame(frameID, WTFMove(frameInfo), WTFMove(request), navigationID, mimeType, frameHasCustomContentProvider, frameLoadType, certificateInfo, usedLegacyTLS, privateRelayed, containsPluginDocument, hasInsecureContent, mouseEventPolicy, userData); // Will delete |this|.
if (!frame)
return;
frame->commitProvisionalFrame(frameID, WTFMove(frameInfo), WTFMove(request), navigationID, mimeType, frameHasCustomContentProvider, frameLoadType, certificateInfo, usedLegacyTLS, privateRelayed, containsPluginDocument, hasInsecureContent, mouseEventPolicy, userData); // Will delete |this|.
}

void RemotePageProxy::decidePolicyForNavigationActionAsync(FrameInfoData&& frameInfo, uint64_t navigationID, NavigationActionData&& navigationActionData, FrameInfoData&& originatingFrameInfo, std::optional<WebPageProxyIdentifier> originatingPageID, const WebCore::ResourceRequest& originalRequest, WebCore::ResourceRequest&& request, IPC::FormDataReference&& requestBody, CompletionHandler<void(PolicyDecision&&)>&& completionHandler)
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/UIProcess/RemotePageProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class RemotePageProxy : public RefCounted<RemotePageProxy>, public IPC::MessageR
void decidePolicyForNavigationActionSync(FrameInfoData&&, uint64_t navigationID, NavigationActionData&&, FrameInfoData&& originatingFrameInfo, std::optional<WebPageProxyIdentifier> originatingPageID, const WebCore::ResourceRequest& originalRequest, WebCore::ResourceRequest&&, IPC::FormDataReference&& requestBody, CompletionHandler<void(PolicyDecision&&)>&&);
void didFailProvisionalLoadForFrame(FrameInfoData&&, WebCore::ResourceRequest&&, uint64_t navigationID, const String& provisionalURL, const WebCore::ResourceError&, WebCore::WillContinueLoading, const UserData&, WebCore::WillInternallyHandleFailure);
void didChangeProvisionalURLForFrame(WebCore::FrameIdentifier, uint64_t, URL&&);
void handleMessage(const String& messageName, const UserData& messageBody);

const WebCore::PageIdentifier m_webPageID;
const Ref<WebProcessProxy> m_process;
Expand Down
6 changes: 5 additions & 1 deletion Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,11 +1016,15 @@ void WebPageProxy::setResourceLoadClient(std::unique_ptr<API::ResourceLoadClient
void WebPageProxy::handleMessage(IPC::Connection& connection, const String& messageName, const WebKit::UserData& messageBody)
{
ASSERT(m_process->connection() == &connection);
handleMessageShared(m_process, messageName, messageBody);
}

void WebPageProxy::handleMessageShared(const Ref<WebProcessProxy>& process, const String& messageName, const WebKit::UserData& messageBody)
{
if (!m_injectedBundleClient)
return;

m_injectedBundleClient->didReceiveMessageFromInjectedBundle(this, messageName, m_process->transformHandlesToObjects(messageBody.protectedObject().get()).get());
m_injectedBundleClient->didReceiveMessageFromInjectedBundle(this, messageName, process->transformHandlesToObjects(messageBody.protectedObject().get()).get());
}

void WebPageProxy::handleSynchronousMessage(IPC::Connection& connection, const String& messageName, const UserData& messageBody, CompletionHandler<void(UserData&&)>&& completionHandler)
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/UIProcess/WebPageProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1925,6 +1925,7 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>, publ
#if ENABLE(CONTENT_FILTERING)
void contentFilterDidBlockLoadForFrameShared(Ref<WebProcessProxy>&&, const WebCore::ContentFilterUnblockHandler&, WebCore::FrameIdentifier);
#endif
void handleMessageShared(const Ref<WebProcessProxy>&, const String& messageName, const WebKit::UserData&);

void dumpPrivateClickMeasurement(CompletionHandler<void(const String&)>&&);
void clearPrivateClickMeasurement(CompletionHandler<void()>&&);
Expand Down

0 comments on commit b81b211

Please sign in to comment.