Title: [292102] trunk/Source/WebKit
Revision
292102
Author
[email protected]
Date
2022-03-30 02:48:05 -0700 (Wed, 30 Mar 2022)

Log Message

Move AuxiliaryProcess::createIPCConnectionPair to IPC::Connection
https://bugs.webkit.org/show_bug.cgi?id=238504

Patch by Kimmo Kinnunen <[email protected]> on 2022-03-30
Reviewed by Chris Dumez.

Move connection port/socket/pipe pair creation function from AuxiliaryProcess
to IPC::Connection. This way other components than AuxiliaryProcess subclasses
can create and send new connections.

No new tests, refactor.

* GPUProcess/GPUProcess.cpp:
(WebKit::GPUProcess::createGPUConnectionToWebProcess):
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::createNetworkConnectionToWebProcess):
* Platform/IPC/Connection.cpp:
(IPC::Connection::createConnectionIdentifierPair):
* Platform/IPC/Connection.h:
* Platform/IPC/cocoa/ConnectionCocoa.mm:
(IPC::Connection::createConnectionIdentifierPair):
* Platform/IPC/unix/ConnectionUnix.cpp:
(IPC::Connection::createConnectionIdentifierPair):
* Platform/IPC/win/ConnectionWin.cpp:
(IPC::Connection::createConnectionIdentifierPair):
* Shared/AuxiliaryProcess.cpp:
* Shared/AuxiliaryProcess.h:
* WebAuthnProcess/WebAuthnProcess.cpp:
(WebKit::WebAuthnProcess::createWebAuthnConnectionToWebProcess):
* WebProcess/Inspector/WebInspectorUI.cpp:
(WebKit::WebInspectorUI::updateConnection):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (292101 => 292102)


--- trunk/Source/WebKit/ChangeLog	2022-03-30 08:32:00 UTC (rev 292101)
+++ trunk/Source/WebKit/ChangeLog	2022-03-30 09:48:05 UTC (rev 292102)
@@ -1,3 +1,36 @@
+2022-03-30  Kimmo Kinnunen  <[email protected]>
+
+        Move AuxiliaryProcess::createIPCConnectionPair to IPC::Connection
+        https://bugs.webkit.org/show_bug.cgi?id=238504
+
+        Reviewed by Chris Dumez.
+
+        Move connection port/socket/pipe pair creation function from AuxiliaryProcess
+        to IPC::Connection. This way other components than AuxiliaryProcess subclasses
+        can create and send new connections.
+
+        No new tests, refactor.
+
+        * GPUProcess/GPUProcess.cpp:
+        (WebKit::GPUProcess::createGPUConnectionToWebProcess):
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::createNetworkConnectionToWebProcess):
+        * Platform/IPC/Connection.cpp:
+        (IPC::Connection::createConnectionIdentifierPair):
+        * Platform/IPC/Connection.h:
+        * Platform/IPC/cocoa/ConnectionCocoa.mm:
+        (IPC::Connection::createConnectionIdentifierPair):
+        * Platform/IPC/unix/ConnectionUnix.cpp:
+        (IPC::Connection::createConnectionIdentifierPair):
+        * Platform/IPC/win/ConnectionWin.cpp:
+        (IPC::Connection::createConnectionIdentifierPair):
+        * Shared/AuxiliaryProcess.cpp:
+        * Shared/AuxiliaryProcess.h:
+        * WebAuthnProcess/WebAuthnProcess.cpp:
+        (WebKit::WebAuthnProcess::createWebAuthnConnectionToWebProcess):
+        * WebProcess/Inspector/WebInspectorUI.cpp:
+        (WebKit::WebInspectorUI::updateConnection):
+
 2022-03-30  Pablo Saavedra  <[email protected]>
 
         [GTK][WPE] Exit cleanly if Connection to UIProcess severed. Regression (r214307)

Modified: trunk/Source/WebKit/GPUProcess/GPUProcess.cpp (292101 => 292102)


--- trunk/Source/WebKit/GPUProcess/GPUProcess.cpp	2022-03-30 08:32:00 UTC (rev 292101)
+++ trunk/Source/WebKit/GPUProcess/GPUProcess.cpp	2022-03-30 09:48:05 UTC (rev 292102)
@@ -118,13 +118,13 @@
 void GPUProcess::createGPUConnectionToWebProcess(WebCore::ProcessIdentifier identifier, PAL::SessionID sessionID, GPUProcessConnectionParameters&& parameters, CompletionHandler<void(std::optional<IPC::Attachment>&&, GPUProcessConnectionInitializationParameters&&)>&& completionHandler)
 {
     RELEASE_LOG(Process, "%p - GPUProcess::createGPUConnectionToWebProcess: processIdentifier=%" PRIu64, this, identifier.toUInt64());
-    auto ipcConnection = createIPCConnectionPair();
-    if (!ipcConnection) {
+    auto connectionIdentifiers = IPC::Connection::createConnectionIdentifierPair();
+    if (!connectionIdentifiers) {
         completionHandler({ }, { });
         return;
     }
 
-    auto newConnection = GPUConnectionToWebProcess::create(*this, identifier, ipcConnection->first, sessionID, WTFMove(parameters));
+    auto newConnection = GPUConnectionToWebProcess::create(*this, identifier, connectionIdentifiers->server, sessionID, WTFMove(parameters));
 
 #if ENABLE(MEDIA_STREAM)
     // FIXME: We should refactor code to go from WebProcess -> GPUProcess -> UIProcess when getUserMedia is called instead of going from WebProcess -> UIProcess directly.
@@ -145,7 +145,7 @@
 #if ENABLE(VP9)
     connectionParameters.hasVP9HardwareDecoder = WebCore::vp9HardwareDecoderAvailable();
 #endif
-    completionHandler(WTFMove(ipcConnection->second), WTFMove(connectionParameters));
+    completionHandler(WTFMove(connectionIdentifiers->client), WTFMove(connectionParameters));
 }
 
 void GPUProcess::removeGPUConnectionToWebProcess(GPUConnectionToWebProcess& connection)

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (292101 => 292102)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2022-03-30 08:32:00 UTC (rev 292101)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2022-03-30 09:48:05 UTC (rev 292102)
@@ -368,13 +368,13 @@
 
 void NetworkProcess::createNetworkConnectionToWebProcess(ProcessIdentifier identifier, PAL::SessionID sessionID, CompletionHandler<void(std::optional<IPC::Attachment>&&, HTTPCookieAcceptPolicy)>&& completionHandler)
 {
-    auto ipcConnection = createIPCConnectionPair();
-    if (!ipcConnection) {
+    auto connectionIdentifiers = IPC::Connection::createConnectionIdentifierPair();
+    if (!connectionIdentifiers) {
         completionHandler({ }, HTTPCookieAcceptPolicy::Never);
         return;
     }
 
-    auto newConnection = NetworkConnectionToWebProcess::create(*this, identifier, sessionID, ipcConnection->first);
+    auto newConnection = NetworkConnectionToWebProcess::create(*this, identifier, sessionID, connectionIdentifiers->server);
     auto& connection = newConnection.get();
 
     ASSERT(!m_webProcessConnections.contains(identifier));
@@ -381,7 +381,7 @@
     m_webProcessConnections.add(identifier, WTFMove(newConnection));
 
     auto* storage = storageSession(sessionID);
-    completionHandler(WTFMove(ipcConnection->second), storage ? storage->cookieAcceptPolicy() : HTTPCookieAcceptPolicy::Never);
+    completionHandler(WTFMove(connectionIdentifiers->client), storage ? storage->cookieAcceptPolicy() : HTTPCookieAcceptPolicy::Never);
 
     connection.setOnLineState(NetworkStateNotifier::singleton().onLine());
 

Modified: trunk/Source/WebKit/Platform/IPC/Connection.cpp (292101 => 292102)


--- trunk/Source/WebKit/Platform/IPC/Connection.cpp	2022-03-30 08:32:00 UTC (rev 292101)
+++ trunk/Source/WebKit/Platform/IPC/Connection.cpp	2022-03-30 09:48:05 UTC (rev 292102)
@@ -1301,4 +1301,12 @@
     RunLoop::main().wakeUp();
 }
 
+#if !USE(UNIX_DOMAIN_SOCKETS) && !OS(DARWIN) && !OS(WINDOWS)
+std::optional<Connection::ConnectionIdentifierPair> Connection::createConnectionIdentifierPair()
+{
+    notImplemented();
+    return std::nullopt;
+}
+#endif
+
 } // namespace IPC

Modified: trunk/Source/WebKit/Platform/IPC/Connection.h (292101 => 292102)


--- trunk/Source/WebKit/Platform/IPC/Connection.h	2022-03-30 08:32:00 UTC (rev 292101)
+++ trunk/Source/WebKit/Platform/IPC/Connection.h	2022-03-30 09:48:05 UTC (rev 292102)
@@ -205,6 +205,13 @@
 
     static Ref<Connection> createServerConnection(Identifier, Client&);
     static Ref<Connection> createClientConnection(Identifier, Client&);
+
+    struct ConnectionIdentifierPair {
+        IPC::Connection::Identifier server;
+        IPC::Attachment client;
+    };
+    static std::optional<ConnectionIdentifierPair> createConnectionIdentifierPair();
+
     ~Connection();
 
     Client& client() const { return m_client; }

Modified: trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm (292101 => 292102)


--- trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm	2022-03-30 08:32:00 UTC (rev 292101)
+++ trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm	2022-03-30 09:48:05 UTC (rev 292102)
@@ -657,5 +657,20 @@
 
     return xpc_connection_get_pid(m_xpcConnection.get());
 }
-    
+
+std::optional<Connection::ConnectionIdentifierPair> Connection::createConnectionIdentifierPair()
+{
+    // Create the listening port.
+    mach_port_t listeningPort = MACH_PORT_NULL;
+    auto kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort);
+    if (kr != KERN_SUCCESS) {
+        RELEASE_LOG_ERROR(Process, "Connection::createConnectionIdentifierPair: Could not allocate mach port, error %x", kr);
+        return std::nullopt;
+    }
+    if (!MACH_PORT_VALID(listeningPort)) {
+        RELEASE_LOG_ERROR(Process, "Connection::createConnectionIdentifierPair: Could not allocate mach port, returned port was invalid");
+        return std::nullopt;
+    }
+    return ConnectionIdentifierPair { Connection::Identifier { listeningPort }, Attachment { listeningPort, MACH_MSG_TYPE_MAKE_SEND } };
+}
 } // namespace IPC

Modified: trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp (292101 => 292102)


--- trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp	2022-03-30 08:32:00 UTC (rev 292101)
+++ trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp	2022-03-30 09:48:05 UTC (rev 292102)
@@ -635,4 +635,9 @@
 {
 }
 
+std::optional<Connection::ConnectionIdentifierPair> Connection::createConnectionIdentifierPair()
+{
+    Connection::SocketPair socketPair = Connection::createPlatformConnection();
+    return ConnectionIdentifierPair { socketPair.server, Attachment { socketPair.client } };
+}
 } // namespace IPC

Modified: trunk/Source/WebKit/Platform/IPC/win/ConnectionWin.cpp (292101 => 292102)


--- trunk/Source/WebKit/Platform/IPC/win/ConnectionWin.cpp	2022-03-30 08:32:00 UTC (rev 292101)
+++ trunk/Source/WebKit/Platform/IPC/win/ConnectionWin.cpp	2022-03-30 09:48:05 UTC (rev 292102)
@@ -360,4 +360,14 @@
     m_handler = Function<void()>();
 }
 
+std::optional<Connection::ConnectionIdentifierPair> Connection::createConnectionIdentifierPair()
+{
+    Connection::Identifier serverIdentifier, clientIdentifier;
+    if (!Connection::createServerAndClientIdentifiers(serverIdentifier, clientIdentifier)) {
+        LOG_ERROR("Failed to create server and client identifiers");
+        return std::nullopt;
+    }
+    return ConnectionIdentifierPair { serverIdentifier, Attachment { clientIdentifier } };
+}
+
 } // namespace IPC

Modified: trunk/Source/WebKit/Shared/AuxiliaryProcess.cpp (292101 => 292102)


--- trunk/Source/WebKit/Shared/AuxiliaryProcess.cpp	2022-03-30 08:32:00 UTC (rev 292101)
+++ trunk/Source/WebKit/Shared/AuxiliaryProcess.cpp	2022-03-30 09:48:05 UTC (rev 292102)
@@ -209,37 +209,6 @@
     terminate();
 }
 
-std::optional<std::pair<IPC::Connection::Identifier, IPC::Attachment>> AuxiliaryProcess::createIPCConnectionPair()
-{
-#if USE(UNIX_DOMAIN_SOCKETS)
-    IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection();
-    return std::make_pair(socketPair.server, IPC::Attachment { socketPair.client });
-#elif OS(DARWIN)
-    // Create the listening port.
-    mach_port_t listeningPort = MACH_PORT_NULL;
-    auto kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort);
-    if (kr != KERN_SUCCESS) {
-        RELEASE_LOG_ERROR(Process, "AuxiliaryProcess::createIPCConnectionPair: Could not allocate mach port, error %x", kr);
-        CRASH();
-    }
-    if (!MACH_PORT_VALID(listeningPort)) {
-        RELEASE_LOG_ERROR(Process, "AuxiliaryProcess::createIPCConnectionPair: Could not allocate mach port, returned port was invalid");
-        CRASH();
-    }
-    return std::make_pair(IPC::Connection::Identifier { listeningPort }, IPC::Attachment { listeningPort, MACH_MSG_TYPE_MAKE_SEND });
-#elif OS(WINDOWS)
-    IPC::Connection::Identifier serverIdentifier, clientIdentifier;
-    if (!IPC::Connection::createServerAndClientIdentifiers(serverIdentifier, clientIdentifier)) {
-        LOG_ERROR("Failed to create server and client identifiers");
-        CRASH();
-    }
-    return std::make_pair(serverIdentifier, IPC::Attachment { clientIdentifier });
-#else
-    notImplemented();
-    return { };
-#endif
-}
-
 void AuxiliaryProcess::applyProcessCreationParameters(const AuxiliaryProcessCreationParameters& parameters)
 {
 #if !LOG_DISABLED || !RELEASE_LOG_DISABLED

Modified: trunk/Source/WebKit/Shared/AuxiliaryProcess.h (292101 => 292102)


--- trunk/Source/WebKit/Shared/AuxiliaryProcess.h	2022-03-30 08:32:00 UTC (rev 292101)
+++ trunk/Source/WebKit/Shared/AuxiliaryProcess.h	2022-03-30 09:48:05 UTC (rev 292102)
@@ -134,8 +134,6 @@
     void didReceiveMemoryPressureEvent(bool isCritical);
 #endif
 
-    static std::optional<std::pair<IPC::Connection::Identifier, IPC::Attachment>> createIPCConnectionPair();
-
 protected:
 #if ENABLE(CFPREFS_DIRECT_MODE)
     static id decodePreferenceValue(const std::optional<String>& encodedValue);

Modified: trunk/Source/WebKit/WebAuthnProcess/WebAuthnProcess.cpp (292101 => 292102)


--- trunk/Source/WebKit/WebAuthnProcess/WebAuthnProcess.cpp	2022-03-30 08:32:00 UTC (rev 292101)
+++ trunk/Source/WebKit/WebAuthnProcess/WebAuthnProcess.cpp	2022-03-30 09:48:05 UTC (rev 292102)
@@ -51,18 +51,18 @@
 
 void WebAuthnProcess::createWebAuthnConnectionToWebProcess(ProcessIdentifier identifier, CompletionHandler<void(std::optional<IPC::Attachment>&&)>&& completionHandler)
 {
-    auto ipcConnection = createIPCConnectionPair();
-    if (!ipcConnection) {
+    auto connectionIdentifiers = IPC::Connection::createConnectionIdentifierPair();
+    if (!connectionIdentifiers) {
         completionHandler({ });
         return;
     }
 
-    auto newConnection = WebAuthnConnectionToWebProcess::create(*this, identifier, ipcConnection->first);
+    auto newConnection = WebAuthnConnectionToWebProcess::create(*this, identifier, connectionIdentifiers->server);
 
     ASSERT(!m_webProcessConnections.contains(identifier));
     m_webProcessConnections.add(identifier, WTFMove(newConnection));
 
-    completionHandler(WTFMove(ipcConnection->second));
+    completionHandler(WTFMove(connectionIdentifiers->client));
 }
 
 void WebAuthnProcess::removeWebAuthnConnectionToWebProcess(WebAuthnConnectionToWebProcess& connection)

Modified: trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp (292101 => 292102)


--- trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp	2022-03-30 08:32:00 UTC (rev 292101)
+++ trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp	2022-03-30 09:48:05 UTC (rev 292102)
@@ -98,38 +98,14 @@
         m_backendConnection->invalidate();
         m_backendConnection = nullptr;
     }
+    auto connectionIdentifiers = IPC::Connection::createConnectionIdentifierPair();
+    if (!connectionIdentifiers)
+        return;
 
-#if USE(UNIX_DOMAIN_SOCKETS)
-    IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection();
-    IPC::Connection::Identifier connectionIdentifier(socketPair.server);
-    UNUSED_PARAM(connectionIdentifier);
-    IPC::Attachment connectionClientPort(socketPair.client);
-#elif OS(DARWIN)
-    mach_port_t listeningPort = MACH_PORT_NULL;
-    if (mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort) != KERN_SUCCESS)
-        CRASH();
-
-    if (mach_port_insert_right(mach_task_self(), listeningPort, listeningPort, MACH_MSG_TYPE_MAKE_SEND) != KERN_SUCCESS)
-        CRASH();
-
-    IPC::Connection::Identifier connectionIdentifier(listeningPort);
-    UNUSED_PARAM(connectionIdentifier);
-    IPC::Attachment connectionClientPort(listeningPort, MACH_MSG_TYPE_MOVE_SEND);
-#elif PLATFORM(WIN)
-    IPC::Connection::Identifier connectionIdentifier, connClient;
-    IPC::Connection::createServerAndClientIdentifiers(connectionIdentifier, connClient);
-    IPC::Attachment connectionClientPort(connClient);
-#else
-    notImplemented();
-    return;
-#endif
-
-#if USE(UNIX_DOMAIN_SOCKETS) || OS(DARWIN) || PLATFORM(WIN)
-    m_backendConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
+    m_backendConnection = IPC::Connection::createServerConnection(connectionIdentifiers->server, *this);
     m_backendConnection->open();
-#endif
 
-    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorUIProxy::SetFrontendConnection(connectionClientPort), m_inspectedPageIdentifier);
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorUIProxy::SetFrontendConnection(connectionIdentifiers->client), m_inspectedPageIdentifier);
 }
 
 void WebInspectorUI::windowObjectCleared()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to