In WebKit2, make the MessagePortChannelRegistry live in the UI process.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Jan 2018 18:35:23 +0000 (18:35 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Jan 2018 18:35:23 +0000 (18:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181922

Reviewed by Andy Estes.

Source/WebCore:

No new tests (Refactor, no behavior change)

Add encoder/decoders and EXPORT a whole bunch of stuff.

* WebCore.xcodeproj/project.pbxproj:

* dom/MessagePort.h:

* dom/messageports/MessagePortChannel.cpp:
(WebCore::MessagePortChannel::processForPort):
* dom/messageports/MessagePortChannel.h:

* dom/messageports/MessagePortChannelProvider.h:
* dom/messageports/MessagePortChannelRegistry.h:

* dom/messageports/MessageWithMessagePorts.h:
(WebCore::MessageWithMessagePorts::encode const):
(WebCore::MessageWithMessagePorts::decode):

Source/WebKit:

With all of the work that went into making MessagePorts be fully asynchronous
and to be process-aware, formally moving them out-of-process is just a matter
of adding WebKit IPC layers.

The basic unit of asynchronicity is "MessagePortChannelProvider", and this patch
adds both a WebMessagePortChannelProvider and UIMessagePortChannelProvider for
each side of the process divide.

* UIProcess/UIMessagePortChannelProvider.cpp: Added.
(WebKit::UIMessagePortChannelProvider::singleton):
(WebKit::UIMessagePortChannelProvider::UIMessagePortChannelProvider):
(WebKit::UIMessagePortChannelProvider::~UIMessagePortChannelProvider):
(WebKit::UIMessagePortChannelProvider::createNewMessagePortChannel):
(WebKit::UIMessagePortChannelProvider::entangleLocalPortInThisProcessToRemote):
(WebKit::UIMessagePortChannelProvider::messagePortDisentangled):
(WebKit::UIMessagePortChannelProvider::messagePortClosed):
(WebKit::UIMessagePortChannelProvider::takeAllMessagesForPort):
(WebKit::UIMessagePortChannelProvider::postMessageToRemote):
(WebKit::UIMessagePortChannelProvider::checkRemotePortForActivity):
(WebKit::UIMessagePortChannelProvider::checkProcessLocalPortForActivity):
* UIProcess/UIMessagePortChannelProvider.h: Added.
(WebKit::UIMessagePortChannelProvider::registry):

* UIProcess/WebPageProxy.cpp:
(WebKit::m_configurationPreferenceValues):

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::processForIdentifier):
(WebKit::m_userMediaCaptureManagerProxy):
(WebKit::WebProcessProxy::~WebProcessProxy):
(WebKit::WebProcessProxy::shutDown):
(WebKit::WebProcessProxy::createNewMessagePortChannel):
(WebKit::WebProcessProxy::entangleLocalPortInThisProcessToRemote):
(WebKit::WebProcessProxy::messagePortDisentangled):
(WebKit::WebProcessProxy::messagePortClosed):
(WebKit::WebProcessProxy::takeAllMessagesForPort):
(WebKit::WebProcessProxy::didDeliverMessagePortMessages):
(WebKit::WebProcessProxy::postMessageToRemote):
(WebKit::WebProcessProxy::checkRemotePortForActivity):
(WebKit::WebProcessProxy::checkProcessLocalPortForActivity):
(WebKit::WebProcessProxy::didCheckProcessLocalPortForActivity):
* UIProcess/WebProcessProxy.h:
* UIProcess/WebProcessProxy.messages.in:

* WebKit.xcodeproj/project.pbxproj:

* WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp: Added.
(WebKit::WebMessagePortChannelProvider::singleton):
(WebKit::WebMessagePortChannelProvider::WebMessagePortChannelProvider):
(WebKit::WebMessagePortChannelProvider::~WebMessagePortChannelProvider):
(WebKit::WebMessagePortChannelProvider::createNewMessagePortChannel):
(WebKit::WebMessagePortChannelProvider::entangleLocalPortInThisProcessToRemote):
(WebKit::WebMessagePortChannelProvider::messagePortDisentangled):
(WebKit::WebMessagePortChannelProvider::messagePortClosed):
(WebKit::WebMessagePortChannelProvider::takeAllMessagesForPort):
(WebKit::WebMessagePortChannelProvider::didTakeAllMessagesForPort):
(WebKit::WebMessagePortChannelProvider::didCheckRemotePortForActivity):
(WebKit::WebMessagePortChannelProvider::postMessageToRemote):
(WebKit::WebMessagePortChannelProvider::checkProcessLocalPortForActivity):
(WebKit::WebMessagePortChannelProvider::checkRemotePortForActivity):
* WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h: Added.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeProcess):
(WebKit::WebProcess::didTakeAllMessagesForPort):
(WebKit::WebProcess::checkProcessLocalPortForActivity):
(WebKit::WebProcess::didCheckRemotePortForActivity):
(WebKit::WebProcess::messagesAvailableForPort):
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227340 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/MessagePort.h
Source/WebCore/dom/messageports/MessagePortChannel.cpp
Source/WebCore/dom/messageports/MessagePortChannel.h
Source/WebCore/dom/messageports/MessagePortChannelProvider.h
Source/WebCore/dom/messageports/MessagePortChannelRegistry.h
Source/WebCore/dom/messageports/MessageWithMessagePorts.h
Source/WebKit/CMakeLists.txt
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/UIMessagePortChannelProvider.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/UIMessagePortChannelProvider.h [new file with mode: 0644]
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebProcessProxy.cpp
Source/WebKit/UIProcess/WebProcessProxy.h
Source/WebKit/UIProcess/WebProcessProxy.messages.in
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp [new file with mode: 0644]
Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h [new file with mode: 0644]
Source/WebKit/WebProcess/WebProcess.cpp
Source/WebKit/WebProcess/WebProcess.h
Source/WebKit/WebProcess/WebProcess.messages.in

index 0453a75..1473109 100644 (file)
@@ -1,3 +1,29 @@
+2018-01-22  Brady Eidson  <beidson@apple.com>
+
+        In WebKit2, make the MessagePortChannelRegistry live in the UI process.
+        https://bugs.webkit.org/show_bug.cgi?id=181922
+
+        Reviewed by Andy Estes.
+
+        No new tests (Refactor, no behavior change)
+
+        Add encoder/decoders and EXPORT a whole bunch of stuff.
+        
+        * WebCore.xcodeproj/project.pbxproj:
+
+        * dom/MessagePort.h:
+
+        * dom/messageports/MessagePortChannel.cpp:
+        (WebCore::MessagePortChannel::processForPort):
+        * dom/messageports/MessagePortChannel.h:
+
+        * dom/messageports/MessagePortChannelProvider.h:
+        * dom/messageports/MessagePortChannelRegistry.h:
+
+        * dom/messageports/MessageWithMessagePorts.h:
+        (WebCore::MessageWithMessagePorts::encode const):
+        (WebCore::MessageWithMessagePorts::decode):
+
 2018-01-22  Youenn Fablet  <youenn@apple.com>
 
         Fetch Headers from an Opaque response should be filtered out
index 1ad4944..0e6349d 100644 (file)
                51A052561058874000CC9E95 /* ProtectionSpaceHash.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A052551058874000CC9E95 /* ProtectionSpaceHash.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51A4BB0A1954D61600FA5C2E /* Gamepad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51A4BB071954D61600FA5C2E /* Gamepad.cpp */; };
                51A4BB101954D62700FA5C2E /* NavigatorGamepad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51A4BB0D1954D62700FA5C2E /* NavigatorGamepad.cpp */; };
-               51A748E32005D0E80075BA68 /* MessageWithMessagePorts.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A748E02005D0E00075BA68 /* MessageWithMessagePorts.h */; };
+               51A748E32005D0E80075BA68 /* MessageWithMessagePorts.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A748E02005D0E00075BA68 /* MessageWithMessagePorts.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51A748E62006004F0075BA68 /* MessagePortChannelProviderImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A748E5200600210075BA68 /* MessagePortChannelProviderImpl.h */; };
                51A9D9E9195B931F001B2B5C /* GamepadManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51A9D9E7195B931F001B2B5C /* GamepadManager.cpp */; };
                51A9D9EA195B931F001B2B5C /* GamepadManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A9D9E8195B931F001B2B5C /* GamepadManager.h */; };
                51E399021D6E4750009C8831 /* GameControllerGamepadProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E398FE1D6E474B009C8831 /* GameControllerGamepadProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51E3AA0B1B98BCAB0036AD81 /* SecurityOriginData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E3AA091B98BC9A0036AD81 /* SecurityOriginData.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51E6821016387302003BBF3C /* LoaderStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E6820F16387302003BBF3C /* LoaderStrategy.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               51ECC3F6200587BF00483EAE /* MessagePortChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ECC3F4200587B700483EAE /* MessagePortChannel.h */; };
-               51ECC3F8200587BF00483EAE /* MessagePortChannelRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ECC3F1200587B500483EAE /* MessagePortChannelRegistry.h */; };
-               51ECC3FD2005930D00483EAE /* MessagePortChannelProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ECC3FB2005930100483EAE /* MessagePortChannelProvider.h */; };
+               51ECC3F6200587BF00483EAE /* MessagePortChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ECC3F4200587B700483EAE /* MessagePortChannel.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               51ECC3F8200587BF00483EAE /* MessagePortChannelRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ECC3F1200587B500483EAE /* MessagePortChannelRegistry.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               51ECC3FD2005930D00483EAE /* MessagePortChannelProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ECC3FB2005930100483EAE /* MessagePortChannelProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51EE7B381AA50B0500F92B21 /* ResourceLoadInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 51EE7B371AA50B0500F92B21 /* ResourceLoadInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51EEAA741BEFFAB100218008 /* IndexValueEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 51EEAA721BEFFA7900218008 /* IndexValueEntry.h */; };
                51F174FE1F35899200C74950 /* WorkerType.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F174FC1F35898800C74950 /* WorkerType.h */; settings = {ATTRIBUTES = (Private, ); }; };
index 245ba82..d835816 100644 (file)
@@ -57,9 +57,9 @@ public:
     // Returns nullptr if the passed-in vector is empty.
     static ExceptionOr<TransferredMessagePortArray> disentanglePorts(Vector<RefPtr<MessagePort>>&&);
     static Vector<RefPtr<MessagePort>> entanglePorts(ScriptExecutionContext&, TransferredMessagePortArray&&);
-    static RefPtr<MessagePort> existingMessagePortForIdentifier(const MessagePortIdentifier&);
+    WEBCORE_EXPORT static RefPtr<MessagePort> existingMessagePortForIdentifier(const MessagePortIdentifier&);
 
-    void messageAvailable();
+    WEBCORE_EXPORT void messageAvailable();
     bool started() const { return m_started; }
     bool closed() const { return m_closed; }
 
@@ -73,8 +73,8 @@ public:
     const MessagePortIdentifier& identifier() const { return m_identifier; }
     const MessagePortIdentifier& remoteIdentifier() const { return m_remoteIdentifier; }
 
-    void ref() const;
-    void deref() const;
+    WEBCORE_EXPORT void ref() const;
+    WEBCORE_EXPORT void deref() const;
 
     // ActiveDOMObject
     const char* activeDOMObjectName() const final;
@@ -83,7 +83,7 @@ public:
     void stop() final { close(); }
     bool hasPendingActivity() const final;
 
-    bool isLocallyReachable() const;
+    WEBCORE_EXPORT bool isLocallyReachable() const;
 
     // EventTargetWithInlineData.
     EventTargetInterface eventTargetInterface() const final { return MessagePortEventTargetInterfaceType; }
index 4dcac0f..6fcb999 100644 (file)
@@ -60,6 +60,14 @@ MessagePortChannel::~MessagePortChannel()
     m_registry.messagePortChannelDestroyed(*this);
 }
 
+std::optional<ProcessIdentifier> MessagePortChannel::processForPort(const MessagePortIdentifier& port)
+{
+    ASSERT(isMainThread());
+    ASSERT(port == m_ports[0] || port == m_ports[1]);
+    size_t i = port == m_ports[0] ? 0 : 1;
+    return m_processes[i];
+}
+
 bool MessagePortChannel::includesPort(const MessagePortIdentifier& port)
 {
     ASSERT(isMainThread());
index 4f2e999..25f16f5 100644 (file)
@@ -46,6 +46,7 @@ public:
     const MessagePortIdentifier& port1() const { return m_ports[0]; }
     const MessagePortIdentifier& port2() const { return m_ports[1]; }
 
+    WEBCORE_EXPORT std::optional<ProcessIdentifier> processForPort(const MessagePortIdentifier&);
     bool includesPort(const MessagePortIdentifier&);
     void entanglePortWithProcess(const MessagePortIdentifier&, ProcessIdentifier);
     void disentanglePort(const MessagePortIdentifier&);
index 38984da..f71effb 100644 (file)
@@ -37,7 +37,7 @@ struct MessageWithMessagePorts;
 class MessagePortChannelProvider {
 public:
     static MessagePortChannelProvider& singleton();
-    static void setSharedProvider(MessagePortChannelProvider&);
+    WEBCORE_EXPORT static void setSharedProvider(MessagePortChannelProvider&);
 
     virtual ~MessagePortChannelProvider() { }
 
index f10ecb5..a5108b0 100644 (file)
@@ -35,20 +35,20 @@ namespace WebCore {
 
 class MessagePortChannelRegistry {
 public:
-    ~MessagePortChannelRegistry();
+    WEBCORE_EXPORT ~MessagePortChannelRegistry();
     
-    void didCreateMessagePortChannel(const MessagePortIdentifier& port1, const MessagePortIdentifier& port2);
-    void didEntangleLocalToRemote(const MessagePortIdentifier& local, const MessagePortIdentifier& remote, ProcessIdentifier);
-    void didDisentangleMessagePort(const MessagePortIdentifier& local);
-    void didCloseMessagePort(const MessagePortIdentifier& local);
-    bool didPostMessageToRemote(MessageWithMessagePorts&&, const MessagePortIdentifier& remoteTarget);
-    void takeAllMessagesForPort(const MessagePortIdentifier&, Function<void(Vector<MessageWithMessagePorts>&&, Function<void()>&&)>&&);
-    void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(MessagePortChannelProvider::HasActivity)>&& callback);
-
-    MessagePortChannel* existingChannelContainingPort(const MessagePortIdentifier&);
-
-    void messagePortChannelCreated(MessagePortChannel&);
-    void messagePortChannelDestroyed(MessagePortChannel&);
+    WEBCORE_EXPORT void didCreateMessagePortChannel(const MessagePortIdentifier& port1, const MessagePortIdentifier& port2);
+    WEBCORE_EXPORT void didEntangleLocalToRemote(const MessagePortIdentifier& local, const MessagePortIdentifier& remote, ProcessIdentifier);
+    WEBCORE_EXPORT void didDisentangleMessagePort(const MessagePortIdentifier& local);
+    WEBCORE_EXPORT void didCloseMessagePort(const MessagePortIdentifier& local);
+    WEBCORE_EXPORT bool didPostMessageToRemote(MessageWithMessagePorts&&, const MessagePortIdentifier& remoteTarget);
+    WEBCORE_EXPORT void takeAllMessagesForPort(const MessagePortIdentifier&, Function<void(Vector<MessageWithMessagePorts>&&, Function<void()>&&)>&&);
+    WEBCORE_EXPORT void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(MessagePortChannelProvider::HasActivity)>&& callback);
+
+    WEBCORE_EXPORT MessagePortChannel* existingChannelContainingPort(const MessagePortIdentifier&);
+
+    WEBCORE_EXPORT void messagePortChannelCreated(MessagePortChannel&);
+    WEBCORE_EXPORT void messagePortChannelDestroyed(MessagePortChannel&);
 
 private:
     HashMap<MessagePortIdentifier, MessagePortChannel*> m_openChannels;
index 969a62a..7cd6068 100644 (file)
 
 #pragma once
 
+#include "MessagePortIdentifier.h"
 #include "SerializedScriptValue.h"
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
 
-struct MessagePortIdentifier;
-
 // When a message port is transferred, it is represented by a pair of identifiers.
 // The first identifier is the port being transferred and the second is its remote port.
 typedef Vector<std::pair<WebCore::MessagePortIdentifier, WebCore::MessagePortIdentifier>> TransferredMessagePortArray;
@@ -39,6 +38,33 @@ typedef Vector<std::pair<WebCore::MessagePortIdentifier, WebCore::MessagePortIde
 struct MessageWithMessagePorts {
     RefPtr<SerializedScriptValue> message;
     TransferredMessagePortArray transferredPorts;
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static std::optional<MessageWithMessagePorts> decode(Decoder&);
 };
 
+
+template<class Encoder>
+void MessageWithMessagePorts::encode(Encoder& encoder) const
+{
+    ASSERT(message);
+    encoder << message->toWireBytes() << transferredPorts;
+}
+
+template<class Decoder>
+std::optional<MessageWithMessagePorts> MessageWithMessagePorts::decode(Decoder& decoder)
+{
+    MessageWithMessagePorts result;
+
+    Vector<uint8_t> wireBytes;
+    if (!decoder.decode(wireBytes))
+        return std::nullopt;
+
+    if (!decoder.decode(result.transferredPorts))
+        return std::nullopt;
+
+    result.message = SerializedScriptValue::createFromWireBytes(WTFMove(wireBytes));
+    return result;
+}
+
 } // namespace WebCore
index 719367e..b6d9d4d 100644 (file)
@@ -302,6 +302,7 @@ set(WebKit_SOURCES
     UIProcess/ResponsivenessTimer.cpp
     UIProcess/StatisticsRequest.cpp
     UIProcess/TextCheckerCompletion.cpp
+    UIProcess/UIMessagePortChannelProvider.cpp
     UIProcess/UserMediaPermissionCheckProxy.cpp
     UIProcess/UserMediaPermissionRequestManagerProxy.cpp
     UIProcess/UserMediaPermissionRequestProxy.cpp
@@ -561,6 +562,7 @@ set(WebKit_SOURCES
     WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
     WebProcess/WebCoreSupport/WebGeolocationClient.cpp
     WebProcess/WebCoreSupport/WebInspectorClient.cpp
+    WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp
     WebProcess/WebCoreSupport/WebNotificationClient.cpp
     WebProcess/WebCoreSupport/WebPerformanceLoggingClient.cpp
     WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
index d0e2740..08c240f 100644 (file)
@@ -1,3 +1,81 @@
+2018-01-22  Brady Eidson  <beidson@apple.com>
+
+        In WebKit2, make the MessagePortChannelRegistry live in the UI process.
+        https://bugs.webkit.org/show_bug.cgi?id=181922
+
+        Reviewed by Andy Estes.
+
+        With all of the work that went into making MessagePorts be fully asynchronous
+        and to be process-aware, formally moving them out-of-process is just a matter
+        of adding WebKit IPC layers.
+        
+        The basic unit of asynchronicity is "MessagePortChannelProvider", and this patch
+        adds both a WebMessagePortChannelProvider and UIMessagePortChannelProvider for
+        each side of the process divide.
+        
+        * UIProcess/UIMessagePortChannelProvider.cpp: Added.
+        (WebKit::UIMessagePortChannelProvider::singleton):
+        (WebKit::UIMessagePortChannelProvider::UIMessagePortChannelProvider):
+        (WebKit::UIMessagePortChannelProvider::~UIMessagePortChannelProvider):
+        (WebKit::UIMessagePortChannelProvider::createNewMessagePortChannel):
+        (WebKit::UIMessagePortChannelProvider::entangleLocalPortInThisProcessToRemote):
+        (WebKit::UIMessagePortChannelProvider::messagePortDisentangled):
+        (WebKit::UIMessagePortChannelProvider::messagePortClosed):
+        (WebKit::UIMessagePortChannelProvider::takeAllMessagesForPort):
+        (WebKit::UIMessagePortChannelProvider::postMessageToRemote):
+        (WebKit::UIMessagePortChannelProvider::checkRemotePortForActivity):
+        (WebKit::UIMessagePortChannelProvider::checkProcessLocalPortForActivity):
+        * UIProcess/UIMessagePortChannelProvider.h: Added.
+        (WebKit::UIMessagePortChannelProvider::registry):
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::m_configurationPreferenceValues):
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::processForIdentifier):
+        (WebKit::m_userMediaCaptureManagerProxy):
+        (WebKit::WebProcessProxy::~WebProcessProxy):
+        (WebKit::WebProcessProxy::shutDown):
+        (WebKit::WebProcessProxy::createNewMessagePortChannel):
+        (WebKit::WebProcessProxy::entangleLocalPortInThisProcessToRemote):
+        (WebKit::WebProcessProxy::messagePortDisentangled):
+        (WebKit::WebProcessProxy::messagePortClosed):
+        (WebKit::WebProcessProxy::takeAllMessagesForPort):
+        (WebKit::WebProcessProxy::didDeliverMessagePortMessages):
+        (WebKit::WebProcessProxy::postMessageToRemote):
+        (WebKit::WebProcessProxy::checkRemotePortForActivity):
+        (WebKit::WebProcessProxy::checkProcessLocalPortForActivity):
+        (WebKit::WebProcessProxy::didCheckProcessLocalPortForActivity):
+        * UIProcess/WebProcessProxy.h:
+        * UIProcess/WebProcessProxy.messages.in:
+
+        * WebKit.xcodeproj/project.pbxproj:
+
+        * WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp: Added.
+        (WebKit::WebMessagePortChannelProvider::singleton):
+        (WebKit::WebMessagePortChannelProvider::WebMessagePortChannelProvider):
+        (WebKit::WebMessagePortChannelProvider::~WebMessagePortChannelProvider):
+        (WebKit::WebMessagePortChannelProvider::createNewMessagePortChannel):
+        (WebKit::WebMessagePortChannelProvider::entangleLocalPortInThisProcessToRemote):
+        (WebKit::WebMessagePortChannelProvider::messagePortDisentangled):
+        (WebKit::WebMessagePortChannelProvider::messagePortClosed):
+        (WebKit::WebMessagePortChannelProvider::takeAllMessagesForPort):
+        (WebKit::WebMessagePortChannelProvider::didTakeAllMessagesForPort):
+        (WebKit::WebMessagePortChannelProvider::didCheckRemotePortForActivity):
+        (WebKit::WebMessagePortChannelProvider::postMessageToRemote):
+        (WebKit::WebMessagePortChannelProvider::checkProcessLocalPortForActivity):
+        (WebKit::WebMessagePortChannelProvider::checkRemotePortForActivity):
+        * WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h: Added.
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeProcess):
+        (WebKit::WebProcess::didTakeAllMessagesForPort):
+        (WebKit::WebProcess::checkProcessLocalPortForActivity):
+        (WebKit::WebProcess::didCheckRemotePortForActivity):
+        (WebKit::WebProcess::messagesAvailableForPort):
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+
 2018-01-22  Youenn Fablet  <youenn@apple.com>
 
         Bump default cache storage quota to 50MB
diff --git a/Source/WebKit/UIProcess/UIMessagePortChannelProvider.cpp b/Source/WebKit/UIProcess/UIMessagePortChannelProvider.cpp
new file mode 100644 (file)
index 0000000..3d6ca1e
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#include "config.h"
+#include "UIMessagePortChannelProvider.h"
+
+#include "WebProcessMessages.h"
+#include "WebProcessProxy.h"
+#include <wtf/CompletionHandler.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+UIMessagePortChannelProvider& UIMessagePortChannelProvider::singleton()
+{
+    static UIMessagePortChannelProvider* provider = new UIMessagePortChannelProvider;
+    return *provider;
+}
+
+UIMessagePortChannelProvider::UIMessagePortChannelProvider()
+{
+}
+
+UIMessagePortChannelProvider::~UIMessagePortChannelProvider()
+{
+    ASSERT_NOT_REACHED();
+}
+
+void UIMessagePortChannelProvider::createNewMessagePortChannel(const MessagePortIdentifier&, const MessagePortIdentifier&)
+{
+    // Should never be called in the UI process provider.
+    ASSERT_NOT_REACHED();
+}
+
+void UIMessagePortChannelProvider::entangleLocalPortInThisProcessToRemote(const MessagePortIdentifier&, const MessagePortIdentifier&)
+{
+    // Should never be called in the UI process provider.
+    ASSERT_NOT_REACHED();
+}
+
+void UIMessagePortChannelProvider::messagePortDisentangled(const MessagePortIdentifier&)
+{
+    // Should never be called in the UI process provider.
+    ASSERT_NOT_REACHED();
+}
+
+void UIMessagePortChannelProvider::messagePortClosed(const MessagePortIdentifier&)
+{
+    // Should never be called in the UI process provider.
+    ASSERT_NOT_REACHED();
+}
+
+void UIMessagePortChannelProvider::takeAllMessagesForPort(const MessagePortIdentifier&, Function<void(Vector<MessageWithMessagePorts>&&, Function<void()>&&)>&&)
+{
+    // Should never be called in the UI process provider.
+    ASSERT_NOT_REACHED();
+}
+
+void UIMessagePortChannelProvider::postMessageToRemote(MessageWithMessagePorts&&, const MessagePortIdentifier&)
+{
+    // Should never be called in the UI process provider.
+    ASSERT_NOT_REACHED();
+}
+
+void UIMessagePortChannelProvider::checkRemotePortForActivity(const MessagePortIdentifier&, CompletionHandler<void(HasActivity)>&&)
+{
+    // Should never be called in the UI process provider.
+    ASSERT_NOT_REACHED();
+}
+
+void UIMessagePortChannelProvider::checkProcessLocalPortForActivity(const MessagePortIdentifier& port, ProcessIdentifier processIdentifier, CompletionHandler<void(HasActivity)>&& completionHandler)
+{
+    auto* process = WebProcessProxy::processForIdentifier(processIdentifier);
+    if (!process) {
+        completionHandler(HasActivity::No);
+        return;
+    }
+
+    process->checkProcessLocalPortForActivity(port, WTFMove(completionHandler));
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit/UIProcess/UIMessagePortChannelProvider.h b/Source/WebKit/UIProcess/UIMessagePortChannelProvider.h
new file mode 100644 (file)
index 0000000..f1e0c49
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2018 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 <WebCore/MessagePortChannelProvider.h>
+#include <WebCore/MessagePortChannelRegistry.h>
+
+namespace WebKit {
+
+class UIMessagePortChannelProvider : public WebCore::MessagePortChannelProvider {
+public:
+    static UIMessagePortChannelProvider& singleton();
+    WebCore::MessagePortChannelRegistry& registry() { return m_registry; }
+
+private:
+    UIMessagePortChannelProvider();
+    ~UIMessagePortChannelProvider() final;
+
+    void createNewMessagePortChannel(const WebCore::MessagePortIdentifier& local, const WebCore::MessagePortIdentifier& remote) final;
+    void entangleLocalPortInThisProcessToRemote(const WebCore::MessagePortIdentifier& local, const WebCore::MessagePortIdentifier& remote) final;
+    void messagePortDisentangled(const WebCore::MessagePortIdentifier& local) final;
+    void messagePortClosed(const WebCore::MessagePortIdentifier& local) final;
+    void takeAllMessagesForPort(const WebCore::MessagePortIdentifier&, Function<void(Vector<WebCore::MessageWithMessagePorts>&&, Function<void()>&&)>&&) final;
+    void postMessageToRemote(WebCore::MessageWithMessagePorts&&, const WebCore::MessagePortIdentifier& remoteTarget) final;
+    void checkRemotePortForActivity(const WebCore::MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& callback) final;
+    void checkProcessLocalPortForActivity(const WebCore::MessagePortIdentifier&, WebCore::ProcessIdentifier, CompletionHandler<void(HasActivity)>&&) final;
+
+    WebCore::MessagePortChannelRegistry m_registry;
+};
+
+} // namespace WebKit
index dee0aad..ef57e10 100644 (file)
@@ -77,6 +77,7 @@
 #include "PrintInfo.h"
 #include "TextChecker.h"
 #include "TextCheckerState.h"
+#include "UIMessagePortChannelProvider.h"
 #include "URLSchemeTaskParameters.h"
 #include "UserMediaPermissionRequestProxy.h"
 #include "UserMediaProcessManager.h"
@@ -414,6 +415,11 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uin
         this->dispatchActivityStateChange();
     });
 #endif
+
+    static std::once_flag once;
+    std::call_once(once, [] {
+        MessagePortChannelProvider::setSharedProvider(UIMessagePortChannelProvider::singleton());
+    });
 }
 
 WebPageProxy::~WebPageProxy()
index 59b2e17..db669d6 100644 (file)
@@ -36,6 +36,7 @@
 #include "PluginProcessManager.h"
 #include "TextChecker.h"
 #include "TextCheckerState.h"
+#include "UIMessagePortChannelProvider.h"
 #include "UserData.h"
 #include "WebBackForwardListItem.h"
 #include "WebInspectorUtilities.h"
@@ -78,6 +79,18 @@ using namespace WebCore;
 
 namespace WebKit {
 
+static HashMap<ProcessIdentifier, WebProcessProxy*>& allProcesses()
+{
+    ASSERT(isMainThread());
+    static NeverDestroyed<HashMap<ProcessIdentifier, WebProcessProxy*>> map;
+    return map;
+}
+
+WebProcessProxy* WebProcessProxy::processForIdentifier(ProcessIdentifier identifier)
+{
+    return allProcesses().get(identifier);
+}
+
 uint64_t WebProcessProxy::generatePageID()
 {
     static uint64_t uniquePageID;
@@ -113,13 +126,19 @@ WebProcessProxy::WebProcessProxy(WebProcessPool& processPool, WebsiteDataStore&
     , m_userMediaCaptureManagerProxy(std::make_unique<UserMediaCaptureManagerProxy>(*this))
 #endif
 {
+    auto result = allProcesses().add(coreProcessIdentifier(), this);
+    ASSERT_UNUSED(result, result.isNewEntry);
+
     WebPasteboardProxy::singleton().addWebProcessProxy(*this);
 }
 
 WebProcessProxy::~WebProcessProxy()
 {
     ASSERT(m_pageURLRetainCountMap.isEmpty());
-    
+
+    auto result = allProcesses().remove(coreProcessIdentifier());
+    ASSERT_UNUSED(result, result);
+
     WebPasteboardProxy::singleton().removeWebProcessProxy(*this);
 
     if (m_webConnection)
@@ -197,6 +216,9 @@ void WebProcessProxy::shutDown()
 
     m_userInitiatedActionMap.clear();
 
+    for (auto& port : m_processEntangledPorts)
+        UIMessagePortChannelProvider::singleton().registry().didCloseMessagePort(port);
+
     m_processPool->disconnectProcess(this);
 }
 
@@ -1229,4 +1251,90 @@ const HashSet<String>& WebProcessProxy::platformPathsWithAssumedReadAccess()
 }
 #endif
 
+void WebProcessProxy::createNewMessagePortChannel(const MessagePortIdentifier& port1, const MessagePortIdentifier& port2)
+{
+    m_processEntangledPorts.add(port1);
+    m_processEntangledPorts.add(port2);
+    UIMessagePortChannelProvider::singleton().registry().didCreateMessagePortChannel(port1, port2);
+}
+
+void WebProcessProxy::entangleLocalPortInThisProcessToRemote(const MessagePortIdentifier& local, const MessagePortIdentifier& remote)
+{
+    m_processEntangledPorts.add(local);
+    UIMessagePortChannelProvider::singleton().registry().didEntangleLocalToRemote(local, remote, coreProcessIdentifier());
+}
+
+void WebProcessProxy::messagePortDisentangled(const MessagePortIdentifier& port)
+{
+    auto result = m_processEntangledPorts.remove(port);
+    ASSERT_UNUSED(result, result);
+
+    UIMessagePortChannelProvider::singleton().registry().didDisentangleMessagePort(port);
+}
+
+void WebProcessProxy::messagePortClosed(const MessagePortIdentifier& port)
+{
+    UIMessagePortChannelProvider::singleton().registry().didCloseMessagePort(port);
+}
+
+void WebProcessProxy::takeAllMessagesForPort(const MessagePortIdentifier& port, uint64_t messagesCallbackIdentifier)
+{
+    UIMessagePortChannelProvider::singleton().registry().takeAllMessagesForPort(port, [this, protectedThis = makeRef(*this), messagesCallbackIdentifier](Vector<MessageWithMessagePorts>&& messages, Function<void()>&& deliveryCallback) {
+
+        static uint64_t currentMessageBatchIdentifier;
+        auto result = m_messageBatchDeliveryCompletionHandlers.ensure(++currentMessageBatchIdentifier, [deliveryCallback = WTFMove(deliveryCallback)]() mutable {
+            return WTFMove(deliveryCallback);
+        });
+        ASSERT_UNUSED(result, result.isNewEntry);
+
+        send(Messages::WebProcess::DidTakeAllMessagesForPort(WTFMove(messages), messagesCallbackIdentifier, currentMessageBatchIdentifier), 0);
+    });
+}
+
+void WebProcessProxy::didDeliverMessagePortMessages(uint64_t messageBatchIdentifier)
+{
+    auto callback = m_messageBatchDeliveryCompletionHandlers.take(messageBatchIdentifier);
+    ASSERT(callback);
+    callback();
+}
+
+void WebProcessProxy::postMessageToRemote(MessageWithMessagePorts&& message, const MessagePortIdentifier& port)
+{
+    if (UIMessagePortChannelProvider::singleton().registry().didPostMessageToRemote(WTFMove(message), port)) {
+        // Look up the process for that port
+        auto* channel = UIMessagePortChannelProvider::singleton().registry().existingChannelContainingPort(port);
+        ASSERT(channel);
+        auto process = channel->processForPort(port);
+        if (process)
+            send(Messages::WebProcess::MessagesAvailableForPort(port), 0);
+    }
+}
+
+void WebProcessProxy::checkRemotePortForActivity(const WebCore::MessagePortIdentifier port, uint64_t callbackIdentifier)
+{
+    UIMessagePortChannelProvider::singleton().registry().checkRemotePortForActivity(port, [this, protectedThis = makeRef(*this), callbackIdentifier](MessagePortChannelProvider::HasActivity hasActivity) {
+        send(Messages::WebProcess::DidCheckRemotePortForActivity(callbackIdentifier, hasActivity == MessagePortChannelProvider::HasActivity::Yes), 0);
+    });
+}
+
+void WebProcessProxy::checkProcessLocalPortForActivity(const MessagePortIdentifier& port, CompletionHandler<void(MessagePortChannelProvider::HasActivity)>&& callback)
+{
+    static uint64_t currentCallbackIdentifier;
+    auto result = m_localPortActivityCompletionHandlers.ensure(++currentCallbackIdentifier, [callback = WTFMove(callback)]() mutable {
+        return WTFMove(callback);
+    });
+    ASSERT_UNUSED(result, result.isNewEntry);
+
+    send(Messages::WebProcess::CheckProcessLocalPortForActivity(port, currentCallbackIdentifier), 0);
+}
+
+void WebProcessProxy::didCheckProcessLocalPortForActivity(uint64_t callbackIdentifier, bool isLocallyReachable)
+{
+    auto callback = m_localPortActivityCompletionHandlers.take(callbackIdentifier);
+    if (!callback)
+        return;
+
+    callback(isLocallyReachable ? MessagePortChannelProvider::HasActivity::Yes : MessagePortChannelProvider::HasActivity::No);
+}
+
 } // namespace WebKit
index 0a5821e..e59d758 100644 (file)
@@ -38,6 +38,9 @@
 #include "VisibleWebPageCounter.h"
 #include "WebConnectionToWebProcess.h"
 #include "WebProcessProxyMessages.h"
+#include <WebCore/MessagePortChannelProvider.h>
+#include <WebCore/MessagePortIdentifier.h>
+#include <WebCore/Process.h>
 #include <WebCore/SharedStringHash.h>
 #include <memory>
 #include <pal/SessionID.h>
@@ -103,6 +106,7 @@ public:
     // FIXME: WebsiteDataStores should be made per-WebPageProxy throughout WebKit2
     WebsiteDataStore& websiteDataStore() const { return m_websiteDataStore.get(); }
 
+    static WebProcessProxy* processForIdentifier(WebCore::ProcessIdentifier);
     static WebPageProxy* webPage(uint64_t pageID);
     Ref<WebPageProxy> createWebPage(PageClient&, Ref<API::PageConfiguration>&&);
     void addExistingWebPage(WebPageProxy&, uint64_t pageID);
@@ -197,6 +201,8 @@ public:
     void didExceedActiveMemoryLimit();
     void didExceedInactiveMemoryLimit();
 
+    void checkProcessLocalPortForActivity(const WebCore::MessagePortIdentifier&, CompletionHandler<void(WebCore::MessagePortChannelProvider::HasActivity)>&&);
+
 protected:
     static uint64_t generatePageID();
     WebProcessProxy(WebProcessPool&, WebsiteDataStore&);
@@ -219,6 +225,16 @@ private:
     void shouldTerminate(bool& shouldTerminate);
     void testIncomingSyncIPCMessageWhileWaitingForSyncReply(bool& handled);
 
+    void createNewMessagePortChannel(const WebCore::MessagePortIdentifier& port1, const WebCore::MessagePortIdentifier& port2);
+    void entangleLocalPortInThisProcessToRemote(const WebCore::MessagePortIdentifier& local, const WebCore::MessagePortIdentifier& remote);
+    void messagePortDisentangled(const WebCore::MessagePortIdentifier&);
+    void messagePortClosed(const WebCore::MessagePortIdentifier&);
+    void takeAllMessagesForPort(const WebCore::MessagePortIdentifier&, uint64_t messagesCallbackIdentifier);
+    void postMessageToRemote(WebCore::MessageWithMessagePorts&&, const WebCore::MessagePortIdentifier&);
+    void checkRemotePortForActivity(const WebCore::MessagePortIdentifier, uint64_t callbackIdentifier);
+    void didDeliverMessagePortMessages(uint64_t messageBatchIdentifier);
+    void didCheckProcessLocalPortForActivity(uint64_t callbackIdentifier, bool isLocallyReachable);
+
     // Plugins
 #if ENABLE(NETSCAPE_PLUGIN_API)
     void getPlugins(bool refresh, Vector<WebCore::PluginInfo>& plugins, Vector<WebCore::PluginInfo>& applicationPlugins);
@@ -307,6 +323,10 @@ private:
 #if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
     std::unique_ptr<UserMediaCaptureManagerProxy> m_userMediaCaptureManagerProxy;
 #endif
+
+    HashSet<WebCore::MessagePortIdentifier> m_processEntangledPorts;
+    HashMap<uint64_t, CompletionHandler<void()>> m_messageBatchDeliveryCompletionHandlers;
+    HashMap<uint64_t, CompletionHandler<void(WebCore::MessagePortChannelProvider::HasActivity)>> m_localPortActivityCompletionHandlers;
 };
 
 } // namespace WebKit
index e73d884..2ffbd5c 100644 (file)
@@ -56,4 +56,14 @@ messages -> WebProcessProxy LegacyReceiver {
     DidExceedInactiveMemoryLimitWhileActive()
 
     TestIncomingSyncIPCMessageWhileWaitingForSyncReply() -> (bool handled)
+
+    CreateNewMessagePortChannel(struct WebCore::MessagePortIdentifier port1, struct WebCore::MessagePortIdentifier port2)
+    EntangleLocalPortInThisProcessToRemote(struct WebCore::MessagePortIdentifier local, struct WebCore::MessagePortIdentifier remote)
+    MessagePortDisentangled(struct WebCore::MessagePortIdentifier local)
+    MessagePortClosed(struct WebCore::MessagePortIdentifier local)
+    TakeAllMessagesForPort(struct WebCore::MessagePortIdentifier port, uint64_t messagesCallbackIdentifier)
+    PostMessageToRemote(struct WebCore::MessageWithMessagePorts message, struct WebCore::MessagePortIdentifier remote)
+    CheckRemotePortForActivity(struct WebCore::MessagePortIdentifier port, uint64_t callbackIdentifier)
+    DidDeliverMessagePortMessages(uint64_t messageBatchIdentifier)
+    DidCheckProcessLocalPortForActivity(uint64_t callbackIdentifier, bool isLocallyReachable)
 }
index a2bc58f..bd20e3c 100644 (file)
@@ -64,8 +64,8 @@
                076E884E1A13CADF005E90FC /* APIContextMenuClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 076E884D1A13CADF005E90FC /* APIContextMenuClient.h */; };
                07A5EBBB1C7BA43E00B9CA69 /* WKFrameHandleRef.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07A5EBB91C7BA43E00B9CA69 /* WKFrameHandleRef.cpp */; };
                07A5EBBC1C7BA43E00B9CA69 /* WKFrameHandleRef.h in Headers */ = {isa = PBXBuildFile; fileRef = 07A5EBBA1C7BA43E00B9CA69 /* WKFrameHandleRef.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               0EDE85032004E75D00030560 /* WebsitePopUpPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 0EDE85022004E74900030560 /* WebsitePopUpPolicy.h */; };
                0E97D74D200E900400BF6643 /* SafeBrowsingSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E97D74C200E8FF300BF6643 /* SafeBrowsingSPI.h */; };
+               0EDE85032004E75D00030560 /* WebsitePopUpPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 0EDE85022004E74900030560 /* WebsitePopUpPolicy.h */; };
                0F08CF521D63C13A00B48DF1 /* WKFormSelectPicker.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F08CF511D63C13A00B48DF1 /* WKFormSelectPicker.h */; };
                0F08CF541D63C14000B48DF1 /* WKFormSelectPopover.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F08CF531D63C14000B48DF1 /* WKFormSelectPopover.h */; };
                0F0C365818C051BA00F607D7 /* RemoteLayerTreeHostIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F0C365718C051BA00F607D7 /* RemoteLayerTreeHostIOS.mm */; };
                513A164D1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h in Headers */ = {isa = PBXBuildFile; fileRef = 513A164A1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h */; };
                513E462D1AD837560016234A /* WKSharingServicePickerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 513E462B1AD837560016234A /* WKSharingServicePickerDelegate.h */; };
                513E462E1AD837560016234A /* WKSharingServicePickerDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 513E462C1AD837560016234A /* WKSharingServicePickerDelegate.mm */; };
+               513FFB8C201459B0002596EA /* UIMessagePortChannelProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 513FFB8A201459A7002596EA /* UIMessagePortChannelProvider.cpp */; };
+               513FFB8D201459B0002596EA /* UIMessagePortChannelProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 513FFB8B201459A7002596EA /* UIMessagePortChannelProvider.h */; };
+               513FFB90201459C6002596EA /* WebMessagePortChannelProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 513FFB8E201459C2002596EA /* WebMessagePortChannelProvider.cpp */; };
+               513FFB91201459C6002596EA /* WebMessagePortChannelProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 513FFB8F201459C2002596EA /* WebMessagePortChannelProvider.h */; };
                514129941C6428BB0059E714 /* WebIDBConnectionToServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 514129921C6428100059E714 /* WebIDBConnectionToServer.h */; };
                514129951C6428C20059E714 /* WebIDBConnectionToServer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 514129911C6428100059E714 /* WebIDBConnectionToServer.cpp */; };
                514BDED316C98EDD00E4E25E /* StatisticsRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 514BDED216C98EDD00E4E25E /* StatisticsRequest.h */; };
                07A8F3861E64A8F900B668E8 /* CelestialSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CelestialSPI.h; sourceTree = "<group>"; };
                0867D6A5FE840307C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
                089C1667FE841158C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
-               0EDE85022004E74900030560 /* WebsitePopUpPolicy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebsitePopUpPolicy.h; sourceTree = "<group>"; };
                0E97D74C200E8FF300BF6643 /* SafeBrowsingSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SafeBrowsingSPI.h; sourceTree = "<group>"; };
+               0EDE85022004E74900030560 /* WebsitePopUpPolicy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebsitePopUpPolicy.h; sourceTree = "<group>"; };
                0F08CF511D63C13A00B48DF1 /* WKFormSelectPicker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKFormSelectPicker.h; path = ios/forms/WKFormSelectPicker.h; sourceTree = "<group>"; };
                0F08CF531D63C14000B48DF1 /* WKFormSelectPopover.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKFormSelectPopover.h; path = ios/forms/WKFormSelectPopover.h; sourceTree = "<group>"; };
                0F0C365718C051BA00F607D7 /* RemoteLayerTreeHostIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteLayerTreeHostIOS.mm; sourceTree = "<group>"; };
                513A164B1630A9BF005D7D22 /* NetworkConnectionToWebProcess.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = NetworkConnectionToWebProcess.messages.in; path = NetworkProcess/NetworkConnectionToWebProcess.messages.in; sourceTree = "<group>"; };
                513E462B1AD837560016234A /* WKSharingServicePickerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKSharingServicePickerDelegate.h; sourceTree = "<group>"; };
                513E462C1AD837560016234A /* WKSharingServicePickerDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKSharingServicePickerDelegate.mm; sourceTree = "<group>"; };
+               513FFB8A201459A7002596EA /* UIMessagePortChannelProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIMessagePortChannelProvider.cpp; sourceTree = "<group>"; };
+               513FFB8B201459A7002596EA /* UIMessagePortChannelProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIMessagePortChannelProvider.h; sourceTree = "<group>"; };
+               513FFB8E201459C2002596EA /* WebMessagePortChannelProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebMessagePortChannelProvider.cpp; sourceTree = "<group>"; };
+               513FFB8F201459C2002596EA /* WebMessagePortChannelProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebMessagePortChannelProvider.h; sourceTree = "<group>"; };
                514129911C6428100059E714 /* WebIDBConnectionToServer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebIDBConnectionToServer.cpp; sourceTree = "<group>"; };
                514129921C6428100059E714 /* WebIDBConnectionToServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebIDBConnectionToServer.h; sourceTree = "<group>"; };
                5143B25E1DDCDFD10014FAC6 /* _WKIconLoadingDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKIconLoadingDelegate.h; sourceTree = "<group>"; };
                                37C21CAD1E994C0C0029D5F9 /* CorePredictionSPI.h */,
                                A1FB68261F6E51C100C43F9F /* CrashReporterClientSPI.h */,
                                3754D5441B3A29FD003A4C7F /* NSInvocationSPI.h */,
-                               0E97D74C200E8FF300BF6643 /* SafeBrowsingSPI.h */,
                                37B47E2C1D64DB76005F4EFF /* objcSPI.h */,
+                               0E97D74C200E8FF300BF6643 /* SafeBrowsingSPI.h */,
                        );
                        path = Cocoa;
                        sourceTree = "<group>";
                                BC1BE1DE12D54A410004A228 /* WebGeolocationClient.h */,
                                BC111A59112F4FBB00337BAB /* WebInspectorClient.cpp */,
                                BC032D6D10F4378D0058C15A /* WebInspectorClient.h */,
+                               513FFB8E201459C2002596EA /* WebMessagePortChannelProvider.cpp */,
+                               513FFB8F201459C2002596EA /* WebMessagePortChannelProvider.h */,
                                31099971146C759B0029DEB9 /* WebNotificationClient.cpp */,
                                31099968146C71F50029DEB9 /* WebNotificationClient.h */,
                                512127C11908239A00DAF35C /* WebPasteboardOverrides.cpp */,
                                1AA417C912C00CCA002BE67B /* TextChecker.h */,
                                1BB417C912C00CCA002BE67B /* TextCheckerCompletion.cpp */,
                                1CC417C912C00CCA002BE67B /* TextCheckerCompletion.h */,
+                               513FFB8A201459A7002596EA /* UIMessagePortChannelProvider.cpp */,
+                               513FFB8B201459A7002596EA /* UIMessagePortChannelProvider.h */,
                                07297F9C1C17BBEA003F0735 /* UserMediaPermissionCheckProxy.cpp */,
                                07297F9D1C17BBEA003F0735 /* UserMediaPermissionCheckProxy.h */,
                                4A410F3919AF7B04002EBAB5 /* UserMediaPermissionRequestManagerProxy.cpp */,
                                51E6C1641F2935DD00FD3437 /* ResourceLoadStatisticsPersistentStorage.h in Headers */,
                                1A30066E1110F4F70031937C /* ResponsivenessTimer.h in Headers */,
                                410482CE1DDD324F00F006D0 /* RTCNetwork.h in Headers */,
+                               0E97D74D200E900400BF6643 /* SafeBrowsingSPI.h in Headers */,
                                BC2D021712AC41CB00E732A3 /* SameDocumentNavigationType.h in Headers */,
                                1AAB4A8D1296F0A20023952F /* SandboxExtension.h in Headers */,
                                E1E552C516AE065F004ED653 /* SandboxInitializationParameters.h in Headers */,
                                515BE1B51D5917FF00DD7C68 /* UIGamepad.h in Headers */,
                                515BE1A91D55293400DD7C68 /* UIGamepadProvider.h in Headers */,
                                CEE4AE2B1A5DCF430002F49B /* UIKitSPI.h in Headers */,
+                               513FFB8D201459B0002596EA /* UIMessagePortChannelProvider.h in Headers */,
                                1A64245E12DE29A100CAAE2C /* UpdateInfo.h in Headers */,
                                5C19A5201FD0B29500EEA323 /* URLSchemeTaskParameters.h in Headers */,
                                1AC1336818565B5700F3EC05 /* UserData.h in Headers */,
                                C9CD43981B4B001D00239E33 /* WebMediaSessionMetadata.h in Headers */,
                                2D3EF4431917646300034184 /* WebMemoryPressureHandlerIOS.h in Headers */,
                                909854ED12BC4E18000AD080 /* WebMemorySampler.h in Headers */,
+                               513FFB91201459C6002596EA /* WebMessagePortChannelProvider.h in Headers */,
                                BCF69F9A1176CED600471A52 /* WebNavigationDataStore.h in Headers */,
                                7CCCC8FB1A5F50FD008FB0DA /* WebNavigationState.h in Headers */,
                                31A2EC49148997C200810D71 /* WebNotification.h in Headers */,
                                BC5C75C814954DA600BC4775 /* WKConnectionInternal.h in Headers */,
                                BC4A6297147313A0006C681A /* WKConnectionRef.h in Headers */,
                                5CD286541E7235B10094FDC8 /* WKContentRuleList.h in Headers */,
-                               0E97D74D200E900400BF6643 /* SafeBrowsingSPI.h in Headers */,
                                5CD286551E7235B80094FDC8 /* WKContentRuleListInternal.h in Headers */,
                                5CD286511E7235990094FDC8 /* WKContentRuleListStore.h in Headers */,
                                5CD286571E7235C90094FDC8 /* WKContentRuleListStoreInternal.h in Headers */,
                                51E399061D6F54C7009C8831 /* UIGamepadProviderCocoa.mm in Sources */,
                                51E949971D76211300EC9EB9 /* UIGamepadProviderIOS.mm in Sources */,
                                515BE1B71D5A94FD00DD7C68 /* UIGamepadProviderMac.mm in Sources */,
+                               513FFB8C201459B0002596EA /* UIMessagePortChannelProvider.cpp in Sources */,
                                1A64245F12DE29A100CAAE2C /* UpdateInfo.cpp in Sources */,
                                5C19A5211FD0B29A00EEA323 /* URLSchemeTaskParameters.cpp in Sources */,
                                1AC1336718565B5700F3EC05 /* UserData.cpp in Sources */,
                                2D3EF4421917646300034184 /* WebMemoryPressureHandlerIOS.mm in Sources */,
                                909854EC12BC4E17000AD080 /* WebMemorySampler.cpp in Sources */,
                                909854EE12BC4E18000AD080 /* WebMemorySampler.mac.mm in Sources */,
+                               513FFB90201459C6002596EA /* WebMessagePortChannelProvider.cpp in Sources */,
                                C0337DB0127A28D0008FF4F4 /* WebMouseEvent.cpp in Sources */,
                                7CCCC8FA1A5F50FD008FB0DA /* WebNavigationState.cpp in Sources */,
                                31A2EC48148997C200810D71 /* WebNotification.cpp in Sources */,
diff --git a/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp b/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp
new file mode 100644 (file)
index 0000000..fca188a
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#include "config.h"
+#include "WebMessagePortChannelProvider.h"
+
+#include "WebProcess.h"
+#include "WebProcessProxyMessages.h"
+#include <WebCore/MessagePort.h>
+#include <WebCore/MessagePortIdentifier.h>
+#include <WebCore/MessageWithMessagePorts.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebMessagePortChannelProvider& WebMessagePortChannelProvider::singleton()
+{
+    static WebMessagePortChannelProvider* provider = new WebMessagePortChannelProvider;
+    return *provider;
+}
+
+WebMessagePortChannelProvider::WebMessagePortChannelProvider()
+{
+}
+
+WebMessagePortChannelProvider::~WebMessagePortChannelProvider()
+{
+    ASSERT_NOT_REACHED();
+}
+
+void WebMessagePortChannelProvider::createNewMessagePortChannel(const MessagePortIdentifier& port1, const MessagePortIdentifier& port2)
+{
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::CreateNewMessagePortChannel(port1, port2), 0);
+}
+
+void WebMessagePortChannelProvider::entangleLocalPortInThisProcessToRemote(const MessagePortIdentifier& local, const MessagePortIdentifier& remote)
+{
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::EntangleLocalPortInThisProcessToRemote(local, remote), 0);
+}
+
+void WebMessagePortChannelProvider::messagePortDisentangled(const MessagePortIdentifier& port)
+{
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::MessagePortDisentangled(port), 0);
+}
+
+void WebMessagePortChannelProvider::messagePortClosed(const MessagePortIdentifier& port)
+{
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::MessagePortClosed(port), 0);
+}
+
+void WebMessagePortChannelProvider::takeAllMessagesForPort(const MessagePortIdentifier& port, Function<void(Vector<MessageWithMessagePorts>&&, Function<void()>&&)>&& completionHandler)
+{
+    static std::atomic<uint64_t> currentHandlerIdentifier;
+    uint64_t identifier = ++currentHandlerIdentifier;
+
+    {
+        Locker<Lock> locker(m_takeAllMessagesCallbackLock);
+        auto result = m_takeAllMessagesCallbacks.ensure(identifier, [completionHandler = WTFMove(completionHandler)]() mutable {
+            return WTFMove(completionHandler);
+        });
+        ASSERT_UNUSED(result, result.isNewEntry);
+    }
+
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::TakeAllMessagesForPort(port, identifier), 0);
+}
+
+void WebMessagePortChannelProvider::didTakeAllMessagesForPort(Vector<MessageWithMessagePorts>&& messages, uint64_t messageCallbackIdentifier, uint64_t messageBatchIdentifier)
+{
+    ASSERT(isMainThread());
+
+    Locker<Lock> locker(m_takeAllMessagesCallbackLock);
+    auto callback = m_takeAllMessagesCallbacks.take(messageCallbackIdentifier);
+    locker.unlockEarly();
+
+    ASSERT(callback);
+    callback(WTFMove(messages), [messageBatchIdentifier] {
+        WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DidDeliverMessagePortMessages(messageBatchIdentifier), 0);
+    });
+}
+
+void WebMessagePortChannelProvider::didCheckRemotePortForActivity(uint64_t callbackIdentifier, bool hasActivity)
+{
+    ASSERT(isMainThread());
+
+    Locker<Lock> locker(m_remoteActivityCallbackLock);
+    auto callback = m_remoteActivityCallbacks.take(callbackIdentifier);
+    locker.unlockEarly();
+
+    ASSERT(callback);
+    callback(hasActivity ? HasActivity::Yes : HasActivity::No);
+}
+
+void WebMessagePortChannelProvider::postMessageToRemote(MessageWithMessagePorts&& message, const MessagePortIdentifier& remoteTarget)
+{
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::PostMessageToRemote(WTFMove(message), remoteTarget), 0);
+}
+
+void WebMessagePortChannelProvider::checkProcessLocalPortForActivity(const MessagePortIdentifier& identifier, uint64_t callbackIdentifier)
+{
+    auto port = MessagePort::existingMessagePortForIdentifier(identifier);
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DidCheckProcessLocalPortForActivity(callbackIdentifier, port && port->isLocallyReachable()), 0);
+}
+
+void WebMessagePortChannelProvider::checkProcessLocalPortForActivity(const MessagePortIdentifier&, ProcessIdentifier, CompletionHandler<void(HasActivity)>&&)
+{
+    // To be called only in the UI process provider, not the Web process provider.
+    ASSERT_NOT_REACHED();
+}
+
+void WebMessagePortChannelProvider::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& completionHandler)
+{
+    static std::atomic<uint64_t> currentHandlerIdentifier;
+    uint64_t identifier = ++currentHandlerIdentifier;
+
+    {
+        Locker<Lock> locker(m_remoteActivityCallbackLock);
+        auto result = m_remoteActivityCallbacks.ensure(identifier, [completionHandler = WTFMove(completionHandler)]() mutable {
+            return WTFMove(completionHandler);
+        });
+        ASSERT_UNUSED(result, result.isNewEntry);
+    }
+
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::CheckRemotePortForActivity(remoteTarget, identifier), 0);
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h b/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h
new file mode 100644 (file)
index 0000000..6c9cf86
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2018 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 <WebCore/MessagePortChannelProvider.h>
+#include <wtf/CompletionHandler.h>
+#include <wtf/HashMap.h>
+
+namespace WebKit {
+
+class WebMessagePortChannelProvider : public WebCore::MessagePortChannelProvider {
+public:
+    static WebMessagePortChannelProvider& singleton();
+
+    void didTakeAllMessagesForPort(Vector<WebCore::MessageWithMessagePorts>&& messages, uint64_t messageCallbackIdentifier, uint64_t messageBatchIdentifier);
+    void checkProcessLocalPortForActivity(const WebCore::MessagePortIdentifier&, uint64_t callbackIdentifier);
+    void didCheckRemotePortForActivity(uint64_t callbackIdentifier, bool hasActivity);
+    
+private:
+    WebMessagePortChannelProvider();
+    ~WebMessagePortChannelProvider() final;
+
+    void createNewMessagePortChannel(const WebCore::MessagePortIdentifier& local, const WebCore::MessagePortIdentifier& remote) final;
+    void entangleLocalPortInThisProcessToRemote(const WebCore::MessagePortIdentifier& local, const WebCore::MessagePortIdentifier& remote) final;
+    void messagePortDisentangled(const WebCore::MessagePortIdentifier& local) final;
+    void messagePortClosed(const WebCore::MessagePortIdentifier& local) final;
+    void takeAllMessagesForPort(const WebCore::MessagePortIdentifier&, Function<void(Vector<WebCore::MessageWithMessagePorts>&&, Function<void()>&&)>&&) final;
+    void postMessageToRemote(WebCore::MessageWithMessagePorts&&, const WebCore::MessagePortIdentifier& remoteTarget) final;
+    void checkProcessLocalPortForActivity(const WebCore::MessagePortIdentifier&, WebCore::ProcessIdentifier, CompletionHandler<void(HasActivity)>&&) final;
+
+    // To be called only in the UI process
+    void checkRemotePortForActivity(const WebCore::MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& callback) final;
+
+    Lock m_takeAllMessagesCallbackLock;
+    HashMap<uint64_t, CompletionHandler<void(Vector<WebCore::MessageWithMessagePorts>&&, Function<void()>&&)>> m_takeAllMessagesCallbacks;
+    Lock m_remoteActivityCallbackLock;
+    HashMap<uint64_t, CompletionHandler<void(HasActivity)>> m_remoteActivityCallbacks;
+};
+
+} // namespace WebKit
index 0265a9c..8c3bf10 100644 (file)
@@ -57,6 +57,7 @@
 #include "WebLoaderStrategy.h"
 #include "WebMediaKeyStorageManager.h"
 #include "WebMemorySampler.h"
+#include "WebMessagePortChannelProvider.h"
 #include "WebPage.h"
 #include "WebPageGroupProxy.h"
 #include "WebPlatformStrategies.h"
 #include <WebCore/MainFrame.h>
 #include <WebCore/MemoryCache.h>
 #include <WebCore/MemoryRelease.h>
+#include <WebCore/MessagePort.h>
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/Page.h>
 #include <WebCore/PageCache.h>
@@ -216,6 +218,8 @@ WebProcess::~WebProcess()
 
 void WebProcess::initializeProcess(const ChildProcessInitializationParameters& parameters)
 {
+    MessagePortChannelProvider::setSharedProvider(WebMessagePortChannelProvider::singleton());
+    
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
     // This call is needed when the WebProcess is not running the NSApplication event loop.
     // Otherwise, calling enableSandboxStyleFileQuarantine() will fail.
@@ -1054,6 +1058,28 @@ void WebProcess::syncIPCMessageWhileWaitingForSyncReplyForTesting()
 {
 }
 
+void WebProcess::didTakeAllMessagesForPort(Vector<MessageWithMessagePorts>&& messages, uint64_t messageCallbackIdentifier, uint64_t messageBatchIdentifier)
+{
+    WebMessagePortChannelProvider::singleton().didTakeAllMessagesForPort(WTFMove(messages), messageCallbackIdentifier, messageBatchIdentifier);
+}
+
+void WebProcess::checkProcessLocalPortForActivity(const MessagePortIdentifier& port, uint64_t callbackIdentifier)
+{
+    WebMessagePortChannelProvider::singleton().checkProcessLocalPortForActivity(port, callbackIdentifier);
+}
+
+void WebProcess::didCheckRemotePortForActivity(uint64_t callbackIdentifier, bool hasActivity)
+{
+    WebMessagePortChannelProvider::singleton().didCheckRemotePortForActivity(callbackIdentifier, hasActivity);
+}
+
+void WebProcess::messagesAvailableForPort(const MessagePortIdentifier& identifier)
+{
+    auto port = MessagePort::existingMessagePortForIdentifier(identifier);
+    if (port)
+        port->messageAvailable();
+}
+
 #if ENABLE(GAMEPAD)
 
 void WebProcess::setInitialGamepads(const Vector<WebKit::GamepadData>& gamepadDatas)
index 01d225a..94cbd75 100644 (file)
@@ -68,6 +68,8 @@ class CertificateInfo;
 class PageGroup;
 class ResourceRequest;
 class UserGestureToken;
+struct MessagePortIdentifier;
+struct MessageWithMessagePorts;
 struct PluginInfo;
 struct SecurityOriginData;
 struct SoupNetworkProxySettings;
@@ -293,6 +295,10 @@ private:
     void backgroundResponsivenessPing();
 
     void syncIPCMessageWhileWaitingForSyncReplyForTesting();
+    void didTakeAllMessagesForPort(Vector<WebCore::MessageWithMessagePorts>&& messages, uint64_t messageCallbackIdentifier, uint64_t messageBatchIdentifier);
+    void checkProcessLocalPortForActivity(const WebCore::MessagePortIdentifier&, uint64_t callbackIdentifier);
+    void didCheckRemotePortForActivity(uint64_t callbackIdentifier, bool hasActivity);
+    void messagesAvailableForPort(const WebCore::MessagePortIdentifier&);
 
 #if ENABLE(GAMEPAD)
     void setInitialGamepads(const Vector<GamepadData>&);
index be57fdc..11ffab9 100644 (file)
@@ -119,4 +119,9 @@ messages -> WebProcess LegacyReceiver {
     EstablishWorkerContextConnectionToStorageProcess(uint64_t pageID, struct WebKit::WebPreferencesStore store, PAL::SessionID initialSessionID)
     RegisterServiceWorkerClients(PAL::SessionID sessionID)
 #endif
+
+    DidTakeAllMessagesForPort(Vector<WebCore::MessageWithMessagePorts> messages, uint64_t messageCallbackIdentifier, uint64_t messageBatchIdentifier)
+    DidCheckRemotePortForActivity(uint64_t callbackIdentifier, bool hasActivity)
+    CheckProcessLocalPortForActivity(struct WebCore::MessagePortIdentifier port, uint64_t callbackIdentifier)
+    MessagesAvailableForPort(struct WebCore::MessagePortIdentifier port)
 }