Title: [276733] trunk
Revision
276733
Author
[email protected]
Date
2021-04-28 14:54:44 -0700 (Wed, 28 Apr 2021)

Log Message

When IPC testing API is enabled, GPU process shouldn't kill Web Process
https://bugs.webkit.org/show_bug.cgi?id=225143
<rdar://70692277>

Reviewed by Chris Dumez.

Source/WebKit:

Set Connection::g_ignoreInvalidMessageForTesting on createGPUConnectionToWebProcess
when the IPC testing API is enabled.

Tests: IPCTestingAPI.CanSendSyncMessageToGPUProcess
       IPCTestingAPI.CanSendAsyncMessageToGPUProcess
       IPCTestingAPI.CanSendInvalidAsyncMessageToGPUProcessWithoutTermination

* GPUProcess/GPUConnectionToWebProcess.cpp:
(WebKit::GPUConnectionToWebProcess::didReceiveInvalidMessage): Exit early without
killing the Web process if IPC testing API is enabled.
* GPUProcess/GPUProcess.cpp:
(WebKit::GPUProcess::createGPUConnectionToWebProcess): Set the aforementioned flag
on the IPC connection.
* Shared/GPUProcessConnectionParameters.h:
(WebKit::GPUProcessConnectionParameters): Added ignoreInvalidMessageForTesting.
(WebKit::GPUProcessConnectionParameters::encode const):
(WebKit::GPUProcessConnectionParameters::decode):
* UIProcess/WebPageProxy.cpp:
(WebKit::m_limitsNavigationsToAppBoundDomains): Cleanup. Use a helper function.
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::getGPUProcessConnection): Set the value of
GPUProcessConnectionParameters::ignoreInvalidMessageForTesting based on the value
of WebProcessProxy::m_ignoreInvalidMessageForTesting.
* UIProcess/WebProcessProxy.h:
(WebKit::WebProcessProxy::ignoreInvalidMessageForTesting const): Added.

Tools:

Added tests for sending IPC messages to GPU process via IPC testing API.

* TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm:
(IPCTestingAPI.CanSendInvalidAsyncMessageToUIProcessWithoutTermination): Renamed from
CanSendInvalidAsyncMessageWithoutTermination.
(IPCTestingAPI.CanSendInvalidSyncMessageToUIProcessWithoutTermination): Renamed from
CanSendInvalidMessageWithoutTermination.
(IPCTestingAPI.CanSendSyncMessageToGPUProcess): Added.
(IPCTestingAPI.CanSendAsyncMessageToGPUProcess): Added.
(IPCTestingAPI.CanSendInvalidAsyncMessageToGPUProcessWithoutTermination): Added.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (276732 => 276733)


--- trunk/Source/WebKit/ChangeLog	2021-04-28 20:07:16 UTC (rev 276732)
+++ trunk/Source/WebKit/ChangeLog	2021-04-28 21:54:44 UTC (rev 276733)
@@ -1,3 +1,37 @@
+2021-04-28  Ryosuke Niwa  <[email protected]>
+
+        When IPC testing API is enabled, GPU process shouldn't kill Web Process
+        https://bugs.webkit.org/show_bug.cgi?id=225143
+        <rdar://70692277>
+
+        Reviewed by Chris Dumez.
+
+        Set Connection::g_ignoreInvalidMessageForTesting on createGPUConnectionToWebProcess
+        when the IPC testing API is enabled.
+
+        Tests: IPCTestingAPI.CanSendSyncMessageToGPUProcess
+               IPCTestingAPI.CanSendAsyncMessageToGPUProcess
+               IPCTestingAPI.CanSendInvalidAsyncMessageToGPUProcessWithoutTermination
+
+        * GPUProcess/GPUConnectionToWebProcess.cpp:
+        (WebKit::GPUConnectionToWebProcess::didReceiveInvalidMessage): Exit early without
+        killing the Web process if IPC testing API is enabled.
+        * GPUProcess/GPUProcess.cpp:
+        (WebKit::GPUProcess::createGPUConnectionToWebProcess): Set the aforementioned flag
+        on the IPC connection.
+        * Shared/GPUProcessConnectionParameters.h:
+        (WebKit::GPUProcessConnectionParameters): Added ignoreInvalidMessageForTesting.
+        (WebKit::GPUProcessConnectionParameters::encode const):
+        (WebKit::GPUProcessConnectionParameters::decode):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::m_limitsNavigationsToAppBoundDomains): Cleanup. Use a helper function.
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::getGPUProcessConnection): Set the value of
+        GPUProcessConnectionParameters::ignoreInvalidMessageForTesting based on the value
+        of WebProcessProxy::m_ignoreInvalidMessageForTesting.
+        * UIProcess/WebProcessProxy.h:
+        (WebKit::WebProcessProxy::ignoreInvalidMessageForTesting const): Added.
+
 2021-04-28  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r276658.

Modified: trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp (276732 => 276733)


--- trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp	2021-04-28 20:07:16 UTC (rev 276732)
+++ trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp	2021-04-28 21:54:44 UTC (rev 276733)
@@ -331,6 +331,10 @@
 
 void GPUConnectionToWebProcess::didReceiveInvalidMessage(IPC::Connection& connection, IPC::MessageName messageName)
 {
+#if ENABLE(IPC_TESTING_API)
+    if (connection.ignoreInvalidMessageForTesting())
+        return;
+#endif
     RELEASE_LOG_FAULT(IPC, "Received an invalid message '%" PUBLIC_LOG_STRING "' from WebContent process %" PRIu64 ", requesting for it to be terminated.", description(messageName), m_webProcessIdentifier.toUInt64());
     terminateWebProcess();
 }

Modified: trunk/Source/WebKit/GPUProcess/GPUProcess.cpp (276732 => 276733)


--- trunk/Source/WebKit/GPUProcess/GPUProcess.cpp	2021-04-28 20:07:16 UTC (rev 276732)
+++ trunk/Source/WebKit/GPUProcess/GPUProcess.cpp	2021-04-28 21:54:44 UTC (rev 276733)
@@ -109,6 +109,11 @@
     newConnection->setOrientationForMediaCapture(m_orientation);
 #endif
 
+#if ENABLE(IPC_TESTING_API)
+    if (parameters.ignoreInvalidMessageForTesting)
+        newConnection->connection().setIgnoreInvalidMessageForTesting();
+#endif
+
     ASSERT(!m_webProcessConnections.contains(identifier));
     m_webProcessConnections.add(identifier, WTFMove(newConnection));
 

Modified: trunk/Source/WebKit/Shared/GPUProcessConnectionParameters.h (276732 => 276733)


--- trunk/Source/WebKit/Shared/GPUProcessConnectionParameters.h	2021-04-28 20:07:16 UTC (rev 276732)
+++ trunk/Source/WebKit/Shared/GPUProcessConnectionParameters.h	2021-04-28 21:54:44 UTC (rev 276733)
@@ -36,6 +36,9 @@
     MachSendRight webProcessIdentityToken;
 #endif
     Vector<String> overrideLanguages;
+#if ENABLE(IPC_TESTING_API)
+    bool ignoreInvalidMessageForTesting { false };
+#endif
 
     void encode(IPC::Encoder& encoder) const
     {
@@ -43,6 +46,9 @@
         encoder << webProcessIdentityToken;
 #endif
         encoder << overrideLanguages;
+#if ENABLE(IPC_TESTING_API)
+        encoder << ignoreInvalidMessageForTesting;
+#endif
     }
 
     static Optional<GPUProcessConnectionParameters> decode(IPC::Decoder& decoder)
@@ -59,11 +65,21 @@
         if (!overrideLanguages)
             return WTF::nullopt;
 
+#if ENABLE(IPC_TESTING_API)
+        Optional<bool> ignoreInvalidMessageForTesting;
+        decoder >> ignoreInvalidMessageForTesting;
+        if (!ignoreInvalidMessageForTesting)
+            return WTF::nullopt;
+#endif
+
         return GPUProcessConnectionParameters {
 #if HAVE(TASK_IDENTITY_TOKEN)
             WTFMove(*webProcessIdentityToken),
 #endif
             WTFMove(*overrideLanguages),
+#if ENABLE(IPC_TESTING_API)
+            *ignoreInvalidMessageForTesting,
+#endif
         };
     }
 };

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (276732 => 276733)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-04-28 20:07:16 UTC (rev 276732)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-04-28 21:54:44 UTC (rev 276733)
@@ -562,7 +562,7 @@
     m_inspectorController->init();
 
 #if ENABLE(IPC_TESTING_API)
-    if (m_preferences->store().getBoolValueForKey(WebPreferencesKey::ipcTestingAPIEnabledKey()))
+    if (m_preferences->ipcTestingAPIEnabled())
         process.setIgnoreInvalidMessageForTesting();
 #endif
 

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (276732 => 276733)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2021-04-28 20:07:16 UTC (rev 276732)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2021-04-28 21:54:44 UTC (rev 276733)
@@ -524,6 +524,9 @@
 
 void WebProcessPool::getGPUProcessConnection(WebProcessProxy& webProcessProxy, GPUProcessConnectionParameters&& parameters, Messages::WebProcessProxy::GetGPUProcessConnection::DelayedReply&& reply)
 {
+#if ENABLE(IPC_TESTING_API)
+    parameters.ignoreInvalidMessageForTesting = webProcessProxy.ignoreInvalidMessageForTesting();
+#endif
     ensureGPUProcess().getGPUProcessConnection(webProcessProxy, parameters, [this, protectedThis = makeRef(*this), parameters, webProcessProxy = makeWeakPtr(webProcessProxy), reply = WTFMove(reply)] (auto& connectionInfo) mutable {
         if (UNLIKELY(!IPC::Connection::identifierIsValid(connectionInfo.identifier()) && webProcessProxy)) {
             WEBPROCESSPOOL_RELEASE_LOG_ERROR(Process, "getGPUProcessConnection: Failed first attempt, retrying");

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.h (276732 => 276733)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2021-04-28 20:07:16 UTC (rev 276732)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2021-04-28 21:54:44 UTC (rev 276733)
@@ -395,6 +395,7 @@
 #endif
 
 #if ENABLE(IPC_TESTING_API)
+    bool ignoreInvalidMessageForTesting() const { return m_ignoreInvalidMessageForTesting; }
     void setIgnoreInvalidMessageForTesting();
 #endif
 

Modified: trunk/Tools/ChangeLog (276732 => 276733)


--- trunk/Tools/ChangeLog	2021-04-28 20:07:16 UTC (rev 276732)
+++ trunk/Tools/ChangeLog	2021-04-28 21:54:44 UTC (rev 276733)
@@ -1,3 +1,22 @@
+2021-04-28  Ryosuke Niwa  <[email protected]>
+
+        When IPC testing API is enabled, GPU process shouldn't kill Web Process
+        https://bugs.webkit.org/show_bug.cgi?id=225143
+        <rdar://70692277>
+
+        Reviewed by Chris Dumez.
+
+        Added tests for sending IPC messages to GPU process via IPC testing API.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm:
+        (IPCTestingAPI.CanSendInvalidAsyncMessageToUIProcessWithoutTermination): Renamed from
+        CanSendInvalidAsyncMessageWithoutTermination.
+        (IPCTestingAPI.CanSendInvalidSyncMessageToUIProcessWithoutTermination): Renamed from
+        CanSendInvalidMessageWithoutTermination.
+        (IPCTestingAPI.CanSendSyncMessageToGPUProcess): Added.
+        (IPCTestingAPI.CanSendAsyncMessageToGPUProcess): Added.
+        (IPCTestingAPI.CanSendInvalidAsyncMessageToGPUProcessWithoutTermination): Added.
+
 2021-04-28  Wenson Hsieh  <[email protected]>
 
         Fine-tune some more selection behaviors in image overlays

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm (276732 => 276733)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm	2021-04-28 20:07:16 UTC (rev 276732)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm	2021-04-28 21:54:44 UTC (rev 276733)
@@ -122,7 +122,7 @@
     EXPECT_STREQ([alertMessage UTF8String], "true");
 }
 
-TEST(IPCTestingAPI, CanSendInvalidAsyncMessageWithoutTermination)
+TEST(IPCTestingAPI, CanSendInvalidAsyncMessageToUIProcessWithoutTermination)
 {
     auto webView = createWebViewWithIPCTestingAPI();
 
@@ -138,7 +138,7 @@
     EXPECT_STREQ([alertMessage UTF8String], "hi");
 }
 
-TEST(IPCTestingAPI, CanSendInvalidMessageWithoutTermination)
+TEST(IPCTestingAPI, CanSendInvalidSyncMessageToUIProcessWithoutTermination)
 {
     auto webView = createWebViewWithIPCTestingAPI();
 
@@ -154,6 +154,63 @@
     EXPECT_STREQ([alertMessage UTF8String], "hi");
 }
 
+#if ENABLE(GPU_PROCESS)
+TEST(IPCTestingAPI, CanSendSyncMessageToGPUProcess)
+{
+    auto webView = createWebViewWithIPCTestingAPI();
+
+    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
+    [webView setUIDelegate:delegate.get()];
+
+    done = false;
+    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><script>"
+        "result = !!IPC.sendSyncMessage('GPU', 0, IPC.messages.GPUConnectionToWebProcess_EnsureAudioSession.name, 100, []);"
+        "alert(result)</script>"];
+    TestWebKitAPI::Util::run(&done);
+
+    EXPECT_TRUE([alertMessage boolValue]);
+}
+
+TEST(IPCTestingAPI, CanSendAsyncMessageToGPUProcess)
+{
+    auto webView = createWebViewWithIPCTestingAPI();
+
+    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
+    [webView setUIDelegate:delegate.get()];
+
+    done = false;
+    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><script>(async function test() {"
+        "window.result = await IPC.sendMessage('GPU', 0, IPC.messages.RemoteAudioDestinationManager_StartAudioDestination.name, [{type: 'uint64_t', value: 12345}]);"
+        "alert(!!result)"
+        "})();</script>"];
+    TestWebKitAPI::Util::run(&done);
+
+    EXPECT_TRUE([alertMessage boolValue]);
+    EXPECT_STREQ([webView stringByEvaluatingJavaScript:@"result.arguments[0].type"].UTF8String, "bool");
+    EXPECT_FALSE([webView stringByEvaluatingJavaScript:@"result.arguments[0].value"].boolValue);
+}
+
+TEST(IPCTestingAPI, CanSendInvalidAsyncMessageToGPUProcessWithoutTermination)
+{
+    auto webView = createWebViewWithIPCTestingAPI();
+
+    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
+    [webView setUIDelegate:delegate.get()];
+
+    done = false;
+    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><script>(async function test() {"
+        "IPC.sendMessage('GPU', 0, IPC.messages.GPUConnectionToWebProcess_CreateRenderingBackend.name, []);"
+        "window.result = await IPC.sendMessage('GPU', 0, IPC.messages.RemoteAudioDestinationManager_StartAudioDestination.name, [{type: 'uint64_t', value: 12345}]);"
+        "alert(!!result)"
+        "})();</script>"];
+    TestWebKitAPI::Util::run(&done);
+
+    EXPECT_TRUE([alertMessage boolValue]);
+    EXPECT_STREQ([webView stringByEvaluatingJavaScript:@"result.arguments[0].type"].UTF8String, "bool");
+    EXPECT_FALSE([webView stringByEvaluatingJavaScript:@"result.arguments[0].value"].boolValue);
+}
+#endif
+
 TEST(IPCTestingAPI, DecodesReplyArgumentsForPrompt)
 {
     auto webView = createWebViewWithIPCTestingAPI();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to