Skip to content

Commit

Permalink
IPC::Connection declaration has unrelated platform implementation dec…
Browse files Browse the repository at this point in the history
…larations

https://bugs.webkit.org/show_bug.cgi?id=245178
rdar://problem/99916528

Reviewed by Antti Koivisto.

Move inner-classes to standalone classes in their own headers:
 - MessageObserver
 - WorkQueueMessageReceiver

Move platform-specific pipe and socket creation functions to
IPCtilities.h.

This way IPC::Connection declaration is easier to understand.

* Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h:
* Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h:
* Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayerManager.h:
* Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h:
* Source/WebKit/NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy.h:
* Source/WebKit/Platform/IPC/Connection.cpp:
* Source/WebKit/Platform/IPC/Connection.h:
* Source/WebKit/Platform/IPC/IPCUtilities.h:
* Source/WebKit/Platform/IPC/MessageObserver.h: Copied from Source/WebKit/Platform/IPC/IPCUtilities.h.
* Source/WebKit/Platform/IPC/MessageReceiveQueues.h:
* Source/WebKit/Platform/IPC/WorkQueueMessageReceiver.h: Copied from Source/WebKit/Platform/IPC/IPCUtilities.h.
* Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp:
(IPC::createPlatformConnection):
(IPC::Connection::createConnectionIdentifierPair):
(IPC::Connection::createPlatformConnection): Deleted.
* Source/WebKit/Platform/IPC/win/ConnectionWin.cpp:
(IPC::createServerAndClientIdentifiers):
(IPC::Connection::createConnectionIdentifierPair):
(IPC::Connection::createServerAndClientIdentifiers): Deleted.
* Source/WebKit/UIProcess/Launcher/glib/ProcessLauncherGLib.cpp:
(WebKit::ProcessLauncher::launchProcess):
* Source/WebKit/UIProcess/Launcher/playstation/ProcessLauncherPlayStation.cpp:
(WebKit::ProcessLauncher::launchProcess):
* Source/WebKit/UIProcess/Launcher/win/ProcessLauncherWin.cpp:
(WebKit::ProcessLauncher::launchProcess):
* Source/WebKit/UIProcess/mac/SecItemShimProxy.h:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/GPU/media/RemoteAudioSourceProviderManager.h:
* Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h:
* Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.h:
* Source/WebKit/WebProcess/Inspector/WebInspectorInterruptDispatcher.h:
* Source/WebKit/WebProcess/Network/webrtc/RTCDataChannelRemoteManager.h:
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h:
* Source/WebKit/WebProcess/WebPage/EventDispatcher.h:
* Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp:
* Source/WebKit/WebProcess/WebPage/ViewUpdateDispatcher.h:
* Source/WebKit/WebProcess/cocoa/RemoteCaptureSampleManager.h:

Canonical link: https://commits.webkit.org/254728@main
  • Loading branch information
kkinnunen-apple committed Sep 21, 2022
1 parent 021fa34 commit 3f576a1
Show file tree
Hide file tree
Showing 28 changed files with 177 additions and 65 deletions.
3 changes: 2 additions & 1 deletion Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h
Expand Up @@ -29,6 +29,7 @@
#include "Connection.h"
#include "RemoteVideoFrameProxy.h"
#include "ThreadSafeObjectHeap.h"
#include "WorkQueueMessageReceiver.h"
#include <WebCore/DestinationColorSpace.h>
#include <WebCore/VideoFrame.h>

Expand All @@ -43,7 +44,7 @@ class PixelBufferConformerCV;
namespace WebKit {

// Holds references to all VideoFrame instances that are mapped from GPU process to Web process.
class RemoteVideoFrameObjectHeap final : public IPC::Connection::WorkQueueMessageReceiver {
class RemoteVideoFrameObjectHeap final : public IPC::WorkQueueMessageReceiver {
public:
static Ref<RemoteVideoFrameObjectHeap> create(Ref<IPC::Connection>&&);
~RemoteVideoFrameObjectHeap();
Expand Down
5 changes: 3 additions & 2 deletions Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h
Expand Up @@ -34,6 +34,7 @@
#include "RemoteVideoFrameIdentifier.h"
#include "SharedMemory.h"
#include "SharedVideoFrame.h"
#include "WorkQueueMessageReceiver.h"
#include <WebCore/ProcessIdentity.h>
#include <atomic>
#include <wtf/ThreadAssertions.h>
Expand All @@ -60,7 +61,7 @@ class RemoteVideoFrameObjectHeap;
struct SharedVideoFrame;
class SharedVideoFrameReader;

class LibWebRTCCodecsProxy final : public IPC::Connection::WorkQueueMessageReceiver {
class LibWebRTCCodecsProxy final : public IPC::WorkQueueMessageReceiver {
WTF_MAKE_FAST_ALLOCATED;
public:
static Ref<LibWebRTCCodecsProxy> create(GPUConnectionToWebProcess&);
Expand All @@ -74,7 +75,7 @@ class LibWebRTCCodecsProxy final : public IPC::Connection::WorkQueueMessageRecei
auto createDecoderCallback(RTCDecoderIdentifier, bool useRemoteFrames);
WorkQueue& workQueue() const { return m_queue; }

// IPC::Connection::WorkQueueMessageReceiver overrides.
// IPC::WorkQueueMessageReceiver overrides.
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;

void createH264Decoder(RTCDecoderIdentifier, bool useRemoteFrames);
Expand Down
Expand Up @@ -30,6 +30,7 @@
#include "Connection.h"
#include "RemoteSampleBufferDisplayLayerManagerMessagesReplies.h"
#include "SampleBufferDisplayLayerIdentifier.h"
#include "WorkQueueMessageReceiver.h"
#include <WebCore/IntSize.h>
#include <wtf/HashMap.h>

Expand All @@ -46,7 +47,7 @@ namespace WebKit {
class GPUConnectionToWebProcess;
class RemoteSampleBufferDisplayLayer;

class RemoteSampleBufferDisplayLayerManager final : public IPC::Connection::WorkQueueMessageReceiver {
class RemoteSampleBufferDisplayLayerManager final : public IPC::WorkQueueMessageReceiver {
WTF_MAKE_FAST_ALLOCATED;
public:
static Ref<RemoteSampleBufferDisplayLayerManager> create(GPUConnectionToWebProcess& connection)
Expand All @@ -65,7 +66,7 @@ class RemoteSampleBufferDisplayLayerManager final : public IPC::Connection::Work
explicit RemoteSampleBufferDisplayLayerManager(GPUConnectionToWebProcess&);
void startListeningForIPC();

// IPC::Connection::WorkQueueMessageReceiver overrides.
// IPC::WorkQueueMessageReceiver overrides.
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;

bool dispatchMessage(IPC::Connection&, IPC::Decoder&);
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h
Expand Up @@ -34,6 +34,7 @@
#include "StorageNamespaceIdentifier.h"
#include "WebPageProxyIdentifier.h"
#include "WebsiteData.h"
#include "WorkQueueMessageReceiver.h"
#include <WebCore/ClientOrigin.h>
#include <WebCore/FileSystemHandleIdentifier.h>
#include <WebCore/FileSystemSyncAccessHandleIdentifier.h>
Expand Down Expand Up @@ -70,7 +71,7 @@ class IDBStorageRegistry;
class StorageAreaBase;
class StorageAreaRegistry;

class NetworkStorageManager final : public IPC::Connection::WorkQueueMessageReceiver {
class NetworkStorageManager final : public IPC::WorkQueueMessageReceiver {
public:
static void forEach(const Function<void(NetworkStorageManager&)>&);
static Ref<NetworkStorageManager> create(PAL::SessionID, IPC::Connection::UniqueID, const String& path, const String& customLocalStoragePath, const String& customIDBStoragePath, const String& customCacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyOriginQuota, bool shouldUseCustomPaths);
Expand Down
Expand Up @@ -28,6 +28,7 @@

#include "Connection.h"
#include "DataReference.h"
#include "WorkQueueMessageReceiver.h"
#include <WebCore/RTCDataChannelRemoteHandlerConnection.h>
#include <WebCore/RTCDataChannelRemoteSourceConnection.h>
#include <wtf/WorkQueue.h>
Expand All @@ -36,7 +37,7 @@ namespace WebKit {

class NetworkConnectionToWebProcess;

class RTCDataChannelRemoteManagerProxy final : public IPC::Connection::WorkQueueMessageReceiver {
class RTCDataChannelRemoteManagerProxy final : public IPC::WorkQueueMessageReceiver {
public:
static Ref<RTCDataChannelRemoteManagerProxy> create() { return adoptRef(*new RTCDataChannelRemoteManagerProxy); }

Expand All @@ -46,7 +47,7 @@ class RTCDataChannelRemoteManagerProxy final : public IPC::Connection::WorkQueue
private:
RTCDataChannelRemoteManagerProxy();

// IPC::Connection::WorkQueueMessageReceiver
// IPC::WorkQueueMessageReceiver overrides.
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;

// To source
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/Platform/IPC/Connection.cpp
Expand Up @@ -29,6 +29,7 @@
#include "Logging.h"
#include "MessageFlags.h"
#include "MessageReceiveQueues.h"
#include "WorkQueueMessageReceiver.h"
#include <memory>
#include <wtf/ArgumentCoder.h>
#include <wtf/HashSet.h>
Expand Down
34 changes: 6 additions & 28 deletions Source/WebKit/Platform/IPC/Connection.h
Expand Up @@ -66,10 +66,13 @@
#include <wtf/glib/GSocketMonitor.h>
#endif

#if ENABLE(IPC_TESTING_API)
#include "MessageObserver.h"
#endif

namespace IPC {

enum class SendOption {
enum class SendOption : uint8_t {
// Whether this message should be dispatched when waiting for a sync reply.
// This is the default for synchronous messages.
DispatchMessageEvenWhenWaitingForSyncReply = 1 << 0,
Expand Down Expand Up @@ -114,6 +117,7 @@ template<typename AsyncReplyResult> struct AsyncReplyError {

class MachMessage;
class UnixMessage;
class WorkQueueMessageReceiver;

class Connection : public ThreadSafeRefCounted<Connection, WTF::DestructionThread::MainRunLoop>, public CanMakeWeakPtr<Connection> {
public:
Expand All @@ -129,18 +133,6 @@ class Connection : public ThreadSafeRefCounted<Connection, WTF::DestructionThrea
virtual ~Client() { }
};

class WorkQueueMessageReceiver : public MessageReceiver, public ThreadSafeRefCounted<WorkQueueMessageReceiver> {
};

#if ENABLE(IPC_TESTING_API)
class MessageObserver : public CanMakeWeakPtr<MessageObserver> {
public:
virtual ~MessageObserver() = default;
virtual void willSendMessage(const Encoder&, OptionSet<SendOption>) = 0;
virtual void didReceiveMessage(const Decoder&) = 0;
};
#endif

#if USE(UNIX_DOMAIN_SOCKETS)
using Handle = UnixFileDescriptor;
#elif OS(WINDOWS)
Expand Down Expand Up @@ -193,24 +185,10 @@ class Connection : public ThreadSafeRefCounted<Connection, WTF::DestructionThrea
#endif
};

#if USE(UNIX_DOMAIN_SOCKETS)
struct SocketPair {
int client;
int server;
};

enum ConnectionOptions {
SetCloexecOnClient = 1 << 0,
SetCloexecOnServer = 1 << 1,
};

static Connection::SocketPair createPlatformConnection(unsigned options = SetCloexecOnClient | SetCloexecOnServer);
#elif OS(DARWIN)
#if OS(DARWIN)
xpc_connection_t xpcConnection() const { return m_xpcConnection.get(); }
std::optional<audit_token_t> getAuditToken();
pid_t remoteProcessID() const;
#elif OS(WINDOWS)
static bool createServerAndClientIdentifiers(HANDLE& serverIdentifier, HANDLE& clientIdentifier);
#endif

static Ref<Connection> createServerConnection(Identifier);
Expand Down
18 changes: 18 additions & 0 deletions Source/WebKit/Platform/IPC/IPCUtilities.h
Expand Up @@ -43,4 +43,22 @@ inline bool isTestingIPC()
}
#endif

#if USE(UNIX_DOMAIN_SOCKETS)
struct SocketPair {
int client;
int server;
};

enum PlatformConnectionOptions {
SetCloexecOnClient = 1 << 0,
SetCloexecOnServer = 1 << 1,
};

SocketPair createPlatformConnection(unsigned options = SetCloexecOnClient | SetCloexecOnServer);
#endif

#if OS(WINDOWS)
bool createServerAndClientIdentifiers(HANDLE& serverIdentifier, HANDLE& clientIdentifier);
#endif

}
49 changes: 49 additions & 0 deletions Source/WebKit/Platform/IPC/MessageObserver.h
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if ENABLE(IPC_TESTING_API)

#include <wtf/OptionSet.h>
#include <wtf/WeakPtr.h>

namespace IPC {

class Decoder;
class Encoder;

enum class SendOption : uint8_t;

class MessageObserver : public CanMakeWeakPtr<MessageObserver> {
public:
virtual ~MessageObserver() = default;
virtual void willSendMessage(const Encoder&, OptionSet<SendOption>) = 0;
virtual void didReceiveMessage(const Decoder&) = 0;
};

}

#endif
5 changes: 3 additions & 2 deletions Source/WebKit/Platform/IPC/MessageReceiveQueues.h
Expand Up @@ -27,6 +27,7 @@

#include "Connection.h"
#include "MessageReceiveQueue.h"
#include "WorkQueueMessageReceiver.h"

namespace IPC {

Expand Down Expand Up @@ -54,7 +55,7 @@ class FunctionDispatcherQueue final : public MessageReceiveQueue {
class WorkQueueMessageReceiverQueue final : public MessageReceiveQueue {
WTF_MAKE_FAST_ALLOCATED;
public:
WorkQueueMessageReceiverQueue(WorkQueue& queue, Connection::WorkQueueMessageReceiver& receiver)
WorkQueueMessageReceiverQueue(WorkQueue& queue, WorkQueueMessageReceiver& receiver)
: m_queue(queue)
, m_receiver(receiver)
{
Expand All @@ -69,7 +70,7 @@ class WorkQueueMessageReceiverQueue final : public MessageReceiveQueue {
}
private:
Ref<WorkQueue> m_queue;
Ref<Connection::WorkQueueMessageReceiver> m_receiver;
Ref<WorkQueueMessageReceiver> m_receiver;
};

} // namespace IPC
37 changes: 37 additions & 0 deletions Source/WebKit/Platform/IPC/WorkQueueMessageReceiver.h
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "MessageReceiver.h"
#include <wtf/ThreadSafeRefCounted.h>

namespace IPC {

class WorkQueueMessageReceiver : public MessageReceiver, public ThreadSafeRefCounted<WorkQueueMessageReceiver> {

};

}
5 changes: 3 additions & 2 deletions Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp
Expand Up @@ -29,6 +29,7 @@
#include "Connection.h"

#include "DataReference.h"
#include "IPCUtilities.h"
#include "SharedMemory.h"
#include "UnixMessage.h"
#include <sys/socket.h>
Expand Down Expand Up @@ -588,7 +589,7 @@ bool Connection::sendOutputMessage(UnixMessage& outputMessage)
return true;
}

Connection::SocketPair Connection::createPlatformConnection(unsigned options)
SocketPair createPlatformConnection(unsigned options)
{
int sockets[2];
RELEASE_ASSERT(socketpair(AF_UNIX, SOCKET_TYPE, 0, sockets) != -1);
Expand Down Expand Up @@ -619,7 +620,7 @@ void Connection::didReceiveSyncReply(OptionSet<SendSyncOption>)

std::optional<Connection::ConnectionIdentifierPair> Connection::createConnectionIdentifierPair()
{
Connection::SocketPair socketPair = Connection::createPlatformConnection();
SocketPair socketPair = createPlatformConnection();
return ConnectionIdentifierPair { Identifier { UnixFileDescriptor { socketPair.server, UnixFileDescriptor::Adopt } }, UnixFileDescriptor { socketPair.client, UnixFileDescriptor::Adopt } };
}
} // namespace IPC
5 changes: 3 additions & 2 deletions Source/WebKit/Platform/IPC/win/ConnectionWin.cpp
Expand Up @@ -29,6 +29,7 @@
#include "DataReference.h"
#include "Decoder.h"
#include "Encoder.h"
#include "IPCUtilities.h"
#include <wtf/ArgumentCoder.h>
#include <wtf/HexNumber.h>
#include <wtf/RandomNumber.h>
Expand All @@ -38,7 +39,7 @@ namespace IPC {
// FIXME: Rename this or use a different constant on windows.
static const size_t inlineMessageMaxSize = 4096;

bool Connection::createServerAndClientIdentifiers(HANDLE& serverIdentifier, HANDLE& clientIdentifier)
bool createServerAndClientIdentifiers(HANDLE& serverIdentifier, HANDLE& clientIdentifier)
{
String pipeName;

Expand Down Expand Up @@ -370,7 +371,7 @@ std::optional<Connection::ConnectionIdentifierPair> Connection::createConnection
{
HANDLE serverIdentifier;
HANDLE clientIdentifier;
if (!Connection::createServerAndClientIdentifiers(serverIdentifier, clientIdentifier)) {
if (!createServerAndClientIdentifiers(serverIdentifier, clientIdentifier)) {
LOG_ERROR("Failed to create server and client identifiers");
return std::nullopt;
}
Expand Down
Expand Up @@ -30,6 +30,7 @@
#include "BubblewrapLauncher.h"
#include "Connection.h"
#include "FlatpakLauncher.h"
#include "IPCUtilities.h"
#include "ProcessExecutablePath.h"
#include <errno.h>
#include <fcntl.h>
Expand Down Expand Up @@ -70,7 +71,7 @@ static bool isFlatpakSpawnUsable()

void ProcessLauncher::launchProcess()
{
IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection(IPC::Connection::ConnectionOptions::SetCloexecOnServer);
IPC::SocketPair socketPair = IPC::createPlatformConnection(IPC::PlatformConnectionOptions::SetCloexecOnServer);

String executablePath;
CString realExecutablePath;
Expand Down

0 comments on commit 3f576a1

Please sign in to comment.