Title: [283713] trunk/Source/WebKit
Revision
283713
Author
[email protected]
Date
2021-10-07 08:16:51 -0700 (Thu, 07 Oct 2021)

Log Message

Add the ability to dispatch messages to multiple receiver types in IPC::StreamServerConnection
https://bugs.webkit.org/show_bug.cgi?id=231305

Reviewed by Kimmo Kinnunen.

In preparation for using streamable IPC for display list rendering in the GPU process (i.e. 2D canvas and DOM
rendering), refactor StreamServerConnection such that it is capable of dispatching stream messages to generic
StreamMessageReceivers. This has the disadvantage of performing a vtable lookup with each message dispatch, but
I did not measure this to be a significant performance regression on any of the canvas subtests in MotionMark.

* GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
(WebKit::RemoteGraphicsContextGL::RemoteGraphicsContextGL):
* GPUProcess/graphics/RemoteGraphicsContextGL.h:

Make RemoteGraphicsContextGL subclass StreamMessageReceiver.

* Platform/IPC/StreamMessageReceiver.h: Added.
(IPC::StreamMessageReceiver::~StreamMessageReceiver):
* Platform/IPC/StreamServerConnection.cpp:
(IPC::StreamServerConnection::startReceivingMessages):
(IPC::StreamServerConnection::stopReceivingMessages):
(IPC::StreamServerConnection::dispatchStreamMessages):
(IPC::StreamServerConnection::processSetStreamDestinationID):
(IPC::StreamServerConnection::dispatchStreamMessage):
(IPC::StreamServerConnection::dispatchOutOfStreamMessage):

Now that these methods are no longer templated, we can move their implementations from the header to the
implementation file.

* Platform/IPC/StreamServerConnection.h:

Remove the template argument from StreamServerConnection, and instead make this start and stop receiving
messages for generic StreamMessageReceiver objects.

(IPC::StreamServerConnection<Receiver>::startReceivingMessages): Deleted.
(IPC::StreamServerConnection<Receiver>::stopReceivingMessages): Deleted.
(IPC::StreamServerConnection<Receiver>::dispatchStreamMessages): Deleted.
(IPC::StreamServerConnection<Receiver>::processSetStreamDestinationID): Deleted.
(IPC::StreamServerConnection<Receiver>::dispatchStreamMessage): Deleted.
(IPC::StreamServerConnection<Receiver>::dispatchOutOfStreamMessage): Deleted.
* WebKit.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (283712 => 283713)


--- trunk/Source/WebKit/ChangeLog	2021-10-07 15:02:25 UTC (rev 283712)
+++ trunk/Source/WebKit/ChangeLog	2021-10-07 15:16:51 UTC (rev 283713)
@@ -1,3 +1,47 @@
+2021-10-07  Wenson Hsieh  <[email protected]>
+
+        Add the ability to dispatch messages to multiple receiver types in IPC::StreamServerConnection
+        https://bugs.webkit.org/show_bug.cgi?id=231305
+
+        Reviewed by Kimmo Kinnunen.
+
+        In preparation for using streamable IPC for display list rendering in the GPU process (i.e. 2D canvas and DOM
+        rendering), refactor StreamServerConnection such that it is capable of dispatching stream messages to generic
+        StreamMessageReceivers. This has the disadvantage of performing a vtable lookup with each message dispatch, but
+        I did not measure this to be a significant performance regression on any of the canvas subtests in MotionMark.
+
+        * GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
+        (WebKit::RemoteGraphicsContextGL::RemoteGraphicsContextGL):
+        * GPUProcess/graphics/RemoteGraphicsContextGL.h:
+
+        Make RemoteGraphicsContextGL subclass StreamMessageReceiver.
+
+        * Platform/IPC/StreamMessageReceiver.h: Added.
+        (IPC::StreamMessageReceiver::~StreamMessageReceiver):
+        * Platform/IPC/StreamServerConnection.cpp:
+        (IPC::StreamServerConnection::startReceivingMessages):
+        (IPC::StreamServerConnection::stopReceivingMessages):
+        (IPC::StreamServerConnection::dispatchStreamMessages):
+        (IPC::StreamServerConnection::processSetStreamDestinationID):
+        (IPC::StreamServerConnection::dispatchStreamMessage):
+        (IPC::StreamServerConnection::dispatchOutOfStreamMessage):
+
+        Now that these methods are no longer templated, we can move their implementations from the header to the
+        implementation file.
+
+        * Platform/IPC/StreamServerConnection.h:
+
+        Remove the template argument from StreamServerConnection, and instead make this start and stop receiving
+        messages for generic StreamMessageReceiver objects.
+
+        (IPC::StreamServerConnection<Receiver>::startReceivingMessages): Deleted.
+        (IPC::StreamServerConnection<Receiver>::stopReceivingMessages): Deleted.
+        (IPC::StreamServerConnection<Receiver>::dispatchStreamMessages): Deleted.
+        (IPC::StreamServerConnection<Receiver>::processSetStreamDestinationID): Deleted.
+        (IPC::StreamServerConnection<Receiver>::dispatchStreamMessage): Deleted.
+        (IPC::StreamServerConnection<Receiver>::dispatchOutOfStreamMessage): Deleted.
+        * WebKit.xcodeproj/project.pbxproj:
+
 2021-10-07  Kimmo Kinnunen  <[email protected]>
 
         ScopedEGLDefaultDisplay should be removed

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp (283712 => 283713)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp	2021-10-07 15:02:25 UTC (rev 283712)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp	2021-10-07 15:16:51 UTC (rev 283713)
@@ -64,7 +64,7 @@
 
 RemoteGraphicsContextGL::RemoteGraphicsContextGL(GPUConnectionToWebProcess& gpuConnectionToWebProcess, GraphicsContextGLIdentifier graphicsContextGLIdentifier, RemoteRenderingBackend& renderingBackend, IPC::StreamConnectionBuffer&& stream)
     : m_gpuConnectionToWebProcess(makeWeakPtr(gpuConnectionToWebProcess))
-    , m_streamConnection(IPC::StreamServerConnection<RemoteGraphicsContextGL>::create(gpuConnectionToWebProcess.connection(), WTFMove(stream), remoteGraphicsContextGLStreamWorkQueue()))
+    , m_streamConnection(IPC::StreamServerConnection::create(gpuConnectionToWebProcess.connection(), WTFMove(stream), remoteGraphicsContextGLStreamWorkQueue()))
     , m_graphicsContextGLIdentifier(graphicsContextGLIdentifier)
     , m_renderingBackend(renderingBackend)
     , m_renderingResourcesRequest(ScopedWebGLRenderingResourcesRequest::acquire())

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h (283712 => 283713)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h	2021-10-07 15:02:25 UTC (rev 283712)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h	2021-10-07 15:16:51 UTC (rev 283713)
@@ -32,6 +32,7 @@
 #include "GraphicsContextGLIdentifier.h"
 #include "RemoteRenderingBackend.h"
 #include "ScopedWebGLRenderingResourcesRequest.h"
+#include "StreamMessageReceiver.h"
 #include "StreamServerConnection.h"
 #include <WebCore/ExtensionsGL.h>
 #include <WebCore/GraphicsContextGLOpenGL.h>
@@ -58,7 +59,7 @@
 // GPU process side implementation of that receives messages about GraphicsContextGL calls
 // and issues real GraphicsContextGL calls based on the received messages.
 // The implementation is largely generated by running Tools/Scripts/generate-gpup-webgl.
-class RemoteGraphicsContextGL : public ThreadSafeRefCounted<RemoteGraphicsContextGL>, private WebCore::GraphicsContextGL::Client {
+class RemoteGraphicsContextGL : private WebCore::GraphicsContextGL::Client, public IPC::StreamMessageReceiver {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     static Ref<RemoteGraphicsContextGL> create(GPUConnectionToWebProcess&, WebCore::GraphicsContextGLAttributes&&, GraphicsContextGLIdentifier, RemoteRenderingBackend&, IPC::StreamConnectionBuffer&&);
@@ -65,8 +66,7 @@
     ~RemoteGraphicsContextGL() override;
     void stopListeningForIPC(Ref<RemoteGraphicsContextGL>&& refFromConnection);
 
-    // IPC::StreamServerConnection<RemoteGraphicsContextGL> template contract implementation.
-    void didReceiveStreamMessage(IPC::StreamServerConnectionBase&, IPC::Decoder&);
+    void didReceiveStreamMessage(IPC::StreamServerConnectionBase&, IPC::Decoder&) final;
 #if PLATFORM(MAC)
     void displayWasReconfigured();
 #endif
@@ -108,7 +108,7 @@
     void paintPixelBufferToImageBuffer(std::optional<WebCore::PixelBuffer>&&, WebCore::RenderingResourceIdentifier, CompletionHandler<void()>&&);
 
     WeakPtr<GPUConnectionToWebProcess> m_gpuConnectionToWebProcess;
-    RefPtr<IPC::StreamServerConnection<RemoteGraphicsContextGL>> m_streamConnection;
+    RefPtr<IPC::StreamServerConnection> m_streamConnection;
     RefPtr<WebCore::GraphicsContextGLOpenGL> m_context WTF_GUARDED_BY_LOCK(m_streamThread);
     GraphicsContextGLIdentifier m_graphicsContextGLIdentifier;
     Ref<RemoteRenderingBackend> m_renderingBackend;

Added: trunk/Source/WebKit/Platform/IPC/StreamMessageReceiver.h (0 => 283713)


--- trunk/Source/WebKit/Platform/IPC/StreamMessageReceiver.h	                        (rev 0)
+++ trunk/Source/WebKit/Platform/IPC/StreamMessageReceiver.h	2021-10-07 15:16:51 UTC (rev 283713)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2021 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 <wtf/ThreadSafeRefCounted.h>
+
+namespace IPC {
+
+class StreamServerConnectionBase;
+class Decoder;
+
+class StreamMessageReceiver : public ThreadSafeRefCounted<StreamMessageReceiver> {
+public:
+    virtual ~StreamMessageReceiver() { }
+
+    virtual void didReceiveStreamMessage(StreamServerConnectionBase&, Decoder&) = 0;
+};
+
+} // namespace IPC

Modified: trunk/Source/WebKit/Platform/IPC/StreamServerConnection.cpp (283712 => 283713)


--- trunk/Source/WebKit/Platform/IPC/StreamServerConnection.cpp	2021-10-07 15:02:25 UTC (rev 283712)
+++ trunk/Source/WebKit/Platform/IPC/StreamServerConnection.cpp	2021-10-07 15:16:51 UTC (rev 283713)
@@ -141,4 +141,142 @@
     return std::min(limit, dataSize() - 1);
 }
 
+void StreamServerConnection::startReceivingMessages(StreamMessageReceiver& receiver, ReceiverName receiverName, uint64_t destinationID)
+{
+    {
+        auto key = std::make_pair(static_cast<uint8_t>(receiverName), destinationID);
+        Locker locker { m_receiversLock };
+        ASSERT(!m_receivers.contains(key));
+        m_receivers.add(key, receiver);
+    }
+    StreamServerConnectionBase::startReceivingMessagesImpl(receiverName, destinationID);
 }
+
+void StreamServerConnection::stopReceivingMessages(ReceiverName receiverName, uint64_t destinationID)
+{
+    StreamServerConnectionBase::stopReceivingMessagesImpl(receiverName, destinationID);
+    auto key = std::make_pair(static_cast<uint8_t>(receiverName), destinationID);
+    Locker locker { m_receiversLock };
+    ASSERT(m_receivers.contains(key));
+    m_receivers.remove(key);
+}
+
+StreamServerConnectionBase::DispatchResult StreamServerConnection::dispatchStreamMessages(size_t messageLimit)
+{
+    RefPtr<StreamMessageReceiver> currentReceiver;
+    // FIXME: Implement WTF::isValid(ReceiverName).
+    uint8_t currentReceiverName = static_cast<uint8_t>(ReceiverName::Invalid);
+
+    for (size_t i = 0; i < messageLimit; ++i) {
+        auto span = tryAcquire();
+        if (!span)
+            return DispatchResult::HasNoMessages;
+        IPC::Decoder decoder { span->data, span->size, m_currentDestinationID };
+        if (!decoder.isValid()) {
+            m_connection->dispatchDidReceiveInvalidMessage(decoder.messageName());
+            return DispatchResult::HasNoMessages;
+        }
+        if (decoder.messageName() == MessageName::SetStreamDestinationID) {
+            if (!processSetStreamDestinationID(WTFMove(decoder), currentReceiver))
+                return DispatchResult::HasNoMessages;
+            continue;
+        }
+        if (decoder.messageName() == MessageName::ProcessOutOfStreamMessage) {
+            if (!dispatchOutOfStreamMessage(WTFMove(decoder)))
+                return DispatchResult::HasNoMessages;
+            continue;
+        }
+        if (currentReceiverName != static_cast<uint8_t>(decoder.messageReceiverName())) {
+            currentReceiverName = static_cast<uint8_t>(decoder.messageReceiverName());
+            currentReceiver = nullptr;
+        }
+        if (!currentReceiver) {
+            auto key = std::make_pair(static_cast<uint8_t>(currentReceiverName), m_currentDestinationID);
+            if (!ReceiversMap::isValidKey(key)) {
+                m_connection->dispatchDidReceiveInvalidMessage(decoder.messageName());
+                return DispatchResult::HasNoMessages;
+            }
+            Locker locker { m_receiversLock };
+            currentReceiver = m_receivers.get(key);
+        }
+        if (!currentReceiver) {
+            // Valid scenario is when receiver has been removed, but there are messages for it in the buffer.
+            // FIXME: Since we do not have a receiver, we don't know how to decode the message.
+            // This means we must timeout every receiver in the stream connection.
+            // Currently we assert that the receivers are empty, as we only have up to one receiver in
+            // a stream connection until possibility of skipping is implemented properly.
+            Locker locker { m_receiversLock };
+            ASSERT(m_receivers.isEmpty());
+            return DispatchResult::HasNoMessages;
+        }
+        if (!dispatchStreamMessage(WTFMove(decoder), *currentReceiver))
+            return DispatchResult::HasNoMessages;
+    }
+    return DispatchResult::HasMoreMessages;
+}
+
+bool StreamServerConnection::processSetStreamDestinationID(Decoder&& decoder, RefPtr<StreamMessageReceiver>& currentReceiver)
+{
+    uint64_t destinationID = 0;
+    if (!decoder.decode(destinationID)) {
+        m_connection->dispatchDidReceiveInvalidMessage(decoder.messageName());
+        return false;
+    }
+    if (m_currentDestinationID != destinationID) {
+        m_currentDestinationID = destinationID;
+        currentReceiver = nullptr;
+    }
+    release(decoder.currentBufferPosition());
+    return true;
+}
+
+bool StreamServerConnection::dispatchStreamMessage(Decoder&& decoder, StreamMessageReceiver& receiver)
+{
+    ASSERT(!m_isDispatchingStreamMessage);
+    m_isDispatchingStreamMessage = true;
+    receiver.didReceiveStreamMessage(*this, decoder);
+    m_isDispatchingStreamMessage = false;
+    if (!decoder.isValid()) {
+        m_connection->dispatchDidReceiveInvalidMessage(decoder.messageName());
+        return false;
+    }
+    if (decoder.isSyncMessage())
+        releaseAll();
+    else
+        release(decoder.currentBufferPosition());
+    return true;
+}
+
+bool StreamServerConnection::dispatchOutOfStreamMessage(Decoder&& decoder)
+{
+    std::unique_ptr<Decoder> message;
+    {
+        Locker locker { m_outOfStreamMessagesLock };
+        if (m_outOfStreamMessages.isEmpty())
+            return false;
+        message = m_outOfStreamMessages.takeFirst();
+    }
+    if (!message)
+        return false;
+
+    RefPtr<StreamMessageReceiver> receiver;
+    {
+        auto key = std::make_pair(static_cast<uint8_t>(message->messageReceiverName()), message->destinationID());
+        Locker locker { m_receiversLock };
+        receiver = m_receivers.get(key);
+    }
+    if (receiver) {
+        receiver->didReceiveStreamMessage(*this, *message);
+        if (!message->isValid()) {
+            m_connection->dispatchDidReceiveInvalidMessage(message->messageName());
+            return false;
+        }
+    }
+    // If receiver does not exist if it has been removed but messages are still pending to be
+    // processed. It's ok to skip such messages.
+    // FIXME: Note, corresponding skip is not possible at the moment for stream messages.
+    release(decoder.currentBufferPosition());
+    return true;
+}
+
+}

Modified: trunk/Source/WebKit/Platform/IPC/StreamServerConnection.h (283712 => 283713)


--- trunk/Source/WebKit/Platform/IPC/StreamServerConnection.h	2021-10-07 15:02:25 UTC (rev 283712)
+++ trunk/Source/WebKit/Platform/IPC/StreamServerConnection.h	2021-10-07 15:16:51 UTC (rev 283713)
@@ -31,6 +31,7 @@
 #include "MessageNames.h"
 #include "StreamConnectionBuffer.h"
 #include "StreamConnectionEncoder.h"
+#include "StreamMessageReceiver.h"
 #include <wtf/Deque.h>
 #include <wtf/Lock.h>
 #include <wtf/Threading.h>
@@ -131,7 +132,6 @@
 //   void didReceiveStreamMessage(StreamServerConnectionBase&, Decoder&);
 //
 // The StreamServerConnection does not trust the StreamClientConnection.
-template<typename Receiver>
 class StreamServerConnection final : public StreamServerConnectionBase {
 public:
     static Ref<StreamServerConnection> create(Connection& connection, StreamConnectionBuffer&& streamBuffer, StreamConnectionWorkQueue& workQueue)
@@ -140,7 +140,7 @@
     }
     ~StreamServerConnection() final = default;
 
-    void startReceivingMessages(Receiver&, ReceiverName, uint64_t destinationID);
+    void startReceivingMessages(StreamMessageReceiver&, ReceiverName, uint64_t destinationID);
     // Stops the message receipt. Note: already received messages might still be delivered.
     void stopReceivingMessages(ReceiverName, uint64_t destinationID);
 
@@ -152,157 +152,13 @@
         : StreamServerConnectionBase(connection, WTFMove(streamBuffer), workQueue)
     {
     }
-    bool processSetStreamDestinationID(Decoder&&, RefPtr<Receiver>& currentReceiver);
-    bool dispatchStreamMessage(Decoder&&, Receiver&);
+    bool processSetStreamDestinationID(Decoder&&, RefPtr<StreamMessageReceiver>& currentReceiver);
+    bool dispatchStreamMessage(Decoder&&, StreamMessageReceiver&);
     bool dispatchOutOfStreamMessage(Decoder&&);
     Lock m_receiversLock;
-    using ReceiversMap = HashMap<std::pair<uint8_t, uint64_t>, Ref<Receiver>>;
+    using ReceiversMap = HashMap<std::pair<uint8_t, uint64_t>, Ref<StreamMessageReceiver>>;
     ReceiversMap m_receivers WTF_GUARDED_BY_LOCK(m_receiversLock);
     uint64_t m_currentDestinationID { 0 };
 };
 
-template<typename Receiver>
-void StreamServerConnection<Receiver>::startReceivingMessages(Receiver& receiver, ReceiverName receiverName, uint64_t destinationID)
-{
-    {
-        auto key = std::make_pair(static_cast<uint8_t>(receiverName), destinationID);
-        Locker locker { m_receiversLock };
-        ASSERT(!m_receivers.contains(key));
-        m_receivers.add(key, receiver);
-    }
-    StreamServerConnectionBase::startReceivingMessagesImpl(receiverName, destinationID);
 }
-
-template<typename Receiver>
-void StreamServerConnection<Receiver>::stopReceivingMessages(ReceiverName receiverName, uint64_t destinationID)
-{
-    StreamServerConnectionBase::stopReceivingMessagesImpl(receiverName, destinationID);
-    auto key = std::make_pair(static_cast<uint8_t>(receiverName), destinationID);
-    Locker locker { m_receiversLock };
-    ASSERT(m_receivers.contains(key));
-    m_receivers.remove(key);
-}
-
-template<typename Receiver>
-StreamServerConnectionBase::DispatchResult StreamServerConnection<Receiver>::dispatchStreamMessages(size_t messageLimit)
-{
-    RefPtr<Receiver> currentReceiver;
-    // FIXME: Implement WTF::isValid(ReceiverName).
-    uint8_t currentReceiverName = static_cast<uint8_t>(ReceiverName::Invalid);
-
-    for (size_t i = 0; i < messageLimit; ++i) {
-        auto span = tryAcquire();
-        if (!span)
-            return DispatchResult::HasNoMessages;
-        IPC::Decoder decoder { span->data, span->size, m_currentDestinationID };
-        if (!decoder.isValid()) {
-            m_connection->dispatchDidReceiveInvalidMessage(decoder.messageName());
-            return DispatchResult::HasNoMessages;
-        }
-        if (decoder.messageName() == MessageName::SetStreamDestinationID) {
-            if (!processSetStreamDestinationID(WTFMove(decoder), currentReceiver))
-                return DispatchResult::HasNoMessages;
-            continue;
-        }
-        if (decoder.messageName() == MessageName::ProcessOutOfStreamMessage) {
-            if (!dispatchOutOfStreamMessage(WTFMove(decoder)))
-                return DispatchResult::HasNoMessages;
-            continue;
-        }
-        if (currentReceiverName != static_cast<uint8_t>(decoder.messageReceiverName())) {
-            currentReceiverName = static_cast<uint8_t>(decoder.messageReceiverName());
-            currentReceiver = nullptr;
-        }
-        if (!currentReceiver) {
-            auto key = std::make_pair(static_cast<uint8_t>(currentReceiverName), m_currentDestinationID);
-            if (!ReceiversMap::isValidKey(key)) {
-                m_connection->dispatchDidReceiveInvalidMessage(decoder.messageName());
-                return DispatchResult::HasNoMessages;
-            }
-            Locker locker { m_receiversLock };
-            currentReceiver = m_receivers.get(key);
-        }
-        if (!currentReceiver) {
-            // Valid scenario is when receiver has been removed, but there are messages for it in the buffer.
-            // FIXME: Since we do not have a receiver, we don't know how to decode the message.
-            // This means we must timeout every receiver in the stream connection.
-            // Currently we assert that the receivers are empty, as we only have up to one receiver in
-            // a stream connection until possibility of skipping is implemented properly.
-            Locker locker { m_receiversLock };
-            ASSERT(m_receivers.isEmpty());
-            return DispatchResult::HasNoMessages;
-        }
-        if (!dispatchStreamMessage(WTFMove(decoder), *currentReceiver))
-            return DispatchResult::HasNoMessages;
-    }
-    return DispatchResult::HasMoreMessages;
-}
-
-template<typename Receiver>
-bool StreamServerConnection<Receiver>::processSetStreamDestinationID(Decoder&& decoder, RefPtr<Receiver>& currentReceiver)
-{
-    uint64_t destinationID = 0;
-    if (!decoder.decode(destinationID)) {
-        m_connection->dispatchDidReceiveInvalidMessage(decoder.messageName());
-        return false;
-    }
-    if (m_currentDestinationID != destinationID) {
-        m_currentDestinationID = destinationID;
-        currentReceiver = nullptr;
-    }
-    release(decoder.currentBufferPosition());
-    return true;
-}
-
-template<typename Receiver>
-bool StreamServerConnection<Receiver>::dispatchStreamMessage(Decoder&& decoder, Receiver& receiver)
-{
-    ASSERT(!m_isDispatchingStreamMessage);
-    m_isDispatchingStreamMessage = true;
-    receiver.didReceiveStreamMessage(*this, decoder);
-    m_isDispatchingStreamMessage = false;
-    if (!decoder.isValid()) {
-        m_connection->dispatchDidReceiveInvalidMessage(decoder.messageName());
-        return false;
-    }
-    if (decoder.isSyncMessage())
-        releaseAll();
-    else
-        release(decoder.currentBufferPosition());
-    return true;
-}
-
-template<typename Receiver>
-bool StreamServerConnection<Receiver>::dispatchOutOfStreamMessage(Decoder&& decoder)
-{
-    std::unique_ptr<Decoder> message;
-    {
-        Locker locker { m_outOfStreamMessagesLock };
-        if (m_outOfStreamMessages.isEmpty())
-            return false;
-        message = m_outOfStreamMessages.takeFirst();
-    }
-    if (!message)
-        return false;
-
-    RefPtr<Receiver> receiver;
-    {
-        auto key = std::make_pair(static_cast<uint8_t>(message->messageReceiverName()), message->destinationID());
-        Locker locker { m_receiversLock };
-        receiver = m_receivers.get(key);
-    }
-    if (receiver) {
-        receiver->didReceiveStreamMessage(*this, *message);
-        if (!message->isValid()) {
-            m_connection->dispatchDidReceiveInvalidMessage(message->messageName());
-            return false;
-        }
-    }
-    // If receiver does not exist if it has been removed but messages are still pending to be
-    // processed. It's ok to skip such messages.
-    // FIXME: Note, corresponding skip is not possible at the moment for stream messages.
-    release(decoder.currentBufferPosition());
-    return true;
-}
-
-}

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (283712 => 283713)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-10-07 15:02:25 UTC (rev 283712)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-10-07 15:16:51 UTC (rev 283713)
@@ -2040,6 +2040,7 @@
 		F409BA181E6E64BC009DA28E /* WKDragDestinationAction.h in Headers */ = {isa = PBXBuildFile; fileRef = F409BA171E6E64B3009DA28E /* WKDragDestinationAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		F40BBB41257FF46E0067463A /* GPUProcessWakeupMessageArguments.h in Headers */ = {isa = PBXBuildFile; fileRef = F40BBB40257FF46E0067463A /* GPUProcessWakeupMessageArguments.h */; };
 		F414CE2D269DE6EA00BD216A /* RemoteRenderingBackendState.h in Headers */ = {isa = PBXBuildFile; fileRef = F414CE2C269DE6EA00BD216A /* RemoteRenderingBackendState.h */; };
+		F4299507270E234D0032298B /* StreamMessageReceiver.h in Headers */ = {isa = PBXBuildFile; fileRef = F4299506270E234C0032298B /* StreamMessageReceiver.h */; };
 		F42D634122A0EFDF00D2FB3A /* WebAutocorrectionData.h in Headers */ = {isa = PBXBuildFile; fileRef = F42D633F22A0EFD300D2FB3A /* WebAutocorrectionData.h */; };
 		F430E9422247335F005FE053 /* WebsiteMetaViewportPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = F430E941224732A9005FE053 /* WebsiteMetaViewportPolicy.h */; };
 		F430E94422473DFF005FE053 /* WebContentMode.h in Headers */ = {isa = PBXBuildFile; fileRef = F430E94322473DB8005FE053 /* WebContentMode.h */; };
@@ -6105,6 +6106,7 @@
 		F40D1B68220BDC0F00B49A01 /* WebAutocorrectionContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WebAutocorrectionContext.h; path = ios/WebAutocorrectionContext.h; sourceTree = "<group>"; };
 		F41056612130699A0092281D /* APIAttachmentCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = APIAttachmentCocoa.mm; sourceTree = "<group>"; };
 		F414CE2C269DE6EA00BD216A /* RemoteRenderingBackendState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteRenderingBackendState.h; sourceTree = "<group>"; };
+		F4299506270E234C0032298B /* StreamMessageReceiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamMessageReceiver.h; sourceTree = "<group>"; };
 		F42D633F22A0EFD300D2FB3A /* WebAutocorrectionData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebAutocorrectionData.h; path = ios/WebAutocorrectionData.h; sourceTree = "<group>"; };
 		F42D634022A0EFD300D2FB3A /* WebAutocorrectionData.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebAutocorrectionData.mm; path = ios/WebAutocorrectionData.mm; sourceTree = "<group>"; };
 		F430E941224732A9005FE053 /* WebsiteMetaViewportPolicy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebsiteMetaViewportPolicy.h; sourceTree = "<group>"; };
@@ -7350,6 +7352,7 @@
 				7B73123925CC8525003B2796 /* StreamConnectionEncoder.h */,
 				7B73123225CC8523003B2796 /* StreamConnectionWorkQueue.cpp */,
 				7B73123525CC8524003B2796 /* StreamConnectionWorkQueue.h */,
+				F4299506270E234C0032298B /* StreamMessageReceiver.h */,
 				7B73123725CC8524003B2796 /* StreamServerConnection.cpp */,
 				7B73123825CC8524003B2796 /* StreamServerConnection.h */,
 				1AE00D6918327C1200087DD7 /* StringReference.cpp */,
@@ -12659,6 +12662,7 @@
 				7B73123A25CC8525003B2796 /* StreamConnectionBuffer.h in Headers */,
 				7B73124225CC8525003B2796 /* StreamConnectionEncoder.h in Headers */,
 				7B73123E25CC8525003B2796 /* StreamConnectionWorkQueue.h in Headers */,
+				F4299507270E234D0032298B /* StreamMessageReceiver.h in Headers */,
 				7B73124125CC8525003B2796 /* StreamServerConnection.h in Headers */,
 				1AE00D6C18327C1200087DD7 /* StringReference.h in Headers */,
 				296BD85D15019BC30071F424 /* StringUtilities.h in Headers */,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to