Title: [289000] trunk/Source/WebCore
Revision
289000
Author
[email protected]
Date
2022-02-02 15:25:43 -0800 (Wed, 02 Feb 2022)

Log Message

Move TransferredMessagePort to its own header
https://bugs.webkit.org/show_bug.cgi?id=236028

Reviewed by Geoffrey Garen.

Move TransferredMessagePort to its own header so that Shared Worker doesn't need to include the whole MessageWithMessagePorts.h header.
It also facilitates passing a TransferredMessagePort in IPC, which will be needed.

* Headers.cmake:
* WebCore.xcodeproj/project.pbxproj:
* dom/MessagePort.cpp:
(WebCore::MessagePort::postMessage):
(WebCore::MessagePort::disentanglePorts):
(WebCore::MessagePort::entanglePorts):
* dom/MessagePort.h:
* dom/messageports/MessageWithMessagePorts.h:
* dom/messageports/TransferredMessagePort.h: Copied from Source/WebCore/dom/messageports/MessageWithMessagePorts.h.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288999 => 289000)


--- trunk/Source/WebCore/ChangeLog	2022-02-02 23:04:09 UTC (rev 288999)
+++ trunk/Source/WebCore/ChangeLog	2022-02-02 23:25:43 UTC (rev 289000)
@@ -1,3 +1,23 @@
+2022-02-02  Chris Dumez  <[email protected]>
+
+        Move TransferredMessagePort to its own header
+        https://bugs.webkit.org/show_bug.cgi?id=236028
+
+        Reviewed by Geoffrey Garen.
+
+        Move TransferredMessagePort to its own header so that Shared Worker doesn't need to include the whole MessageWithMessagePorts.h header.
+        It also facilitates passing a TransferredMessagePort in IPC, which will be needed.
+
+        * Headers.cmake:
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/MessagePort.cpp:
+        (WebCore::MessagePort::postMessage):
+        (WebCore::MessagePort::disentanglePorts):
+        (WebCore::MessagePort::entanglePorts):
+        * dom/MessagePort.h:
+        * dom/messageports/MessageWithMessagePorts.h:
+        * dom/messageports/TransferredMessagePort.h: Copied from Source/WebCore/dom/messageports/MessageWithMessagePorts.h.
+
 2022-02-02  Timothy Hatcher  <[email protected]>
 
         Web Inspector: didShowExtensionTab needs to pass the frameID of the tab

Modified: trunk/Source/WebCore/Headers.cmake (288999 => 289000)


--- trunk/Source/WebCore/Headers.cmake	2022-02-02 23:04:09 UTC (rev 288999)
+++ trunk/Source/WebCore/Headers.cmake	2022-02-02 23:25:43 UTC (rev 289000)
@@ -738,6 +738,7 @@
     dom/messageports/MessagePortChannelProvider.h
     dom/messageports/MessagePortChannelRegistry.h
     dom/messageports/MessageWithMessagePorts.h
+    dom/messageports/TransferredMessagePort.h
 
     editing/CharacterRange.h
     editing/ClipboardAccessPolicy.h

Modified: trunk/Source/WebCore/Sources.txt (288999 => 289000)


--- trunk/Source/WebCore/Sources.txt	2022-02-02 23:04:09 UTC (rev 288999)
+++ trunk/Source/WebCore/Sources.txt	2022-02-02 23:25:43 UTC (rev 289000)
@@ -1077,7 +1077,6 @@
 dom/messageports/MessagePortChannelProvider.cpp
 dom/messageports/MessagePortChannelProviderImpl.cpp
 dom/messageports/MessagePortChannelRegistry.cpp
-dom/messageports/MessageWithMessagePorts.cpp
 dom/messageports/WorkerMessagePortChannelProvider.cpp
 domjit/DOMJITHelpers.cpp
 domjit/JSDocumentDOMJIT.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (288999 => 289000)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-02-02 23:04:09 UTC (rev 288999)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-02-02 23:25:43 UTC (rev 289000)
@@ -1374,6 +1374,7 @@
 		46C83EFE1A9BBE2900A79A41 /* GeoNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C83EFC1A9BBE2900A79A41 /* GeoNotifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		46CA9C441F97BBE9004CFC3A /* VisibilityState.h in Headers */ = {isa = PBXBuildFile; fileRef = 46CA9C411F97BBE7004CFC3A /* VisibilityState.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		46D0004026A0FEB300D1BF1E /* SubmitEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 46D0003E26A0FE6F00D1BF1E /* SubmitEvent.h */; };
+		46DA4A0227AB039300E375A8 /* TransferredMessagePort.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DA4A0027AB038D00E375A8 /* TransferredMessagePort.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		46DBB6501AB8C96F00D9A813 /* PowerObserverMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DBB64E1AB8C96F00D9A813 /* PowerObserverMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		46DD93D7269DE756001AFD88 /* BroadcastChannelIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DD93D5269DE74B001AFD88 /* BroadcastChannelIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		46DE9BB5269DF93E0024C5A6 /* BroadcastChannelRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DE9BB4269DF9320024C5A6 /* BroadcastChannelRegistry.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -9297,6 +9298,7 @@
 		46D0003C26A0FE6F00D1BF1E /* SubmitEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SubmitEvent.cpp; sourceTree = "<group>"; };
 		46D0003E26A0FE6F00D1BF1E /* SubmitEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SubmitEvent.h; sourceTree = "<group>"; };
 		46D0003F26A0FE7000D1BF1E /* SubmitEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SubmitEvent.idl; sourceTree = "<group>"; };
+		46DA4A0027AB038D00E375A8 /* TransferredMessagePort.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TransferredMessagePort.h; sourceTree = "<group>"; };
 		46DBB64E1AB8C96F00D9A813 /* PowerObserverMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PowerObserverMac.h; sourceTree = "<group>"; };
 		46DD93D5269DE74B001AFD88 /* BroadcastChannelIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BroadcastChannelIdentifier.h; sourceTree = "<group>"; };
 		46DE9BB4269DF9320024C5A6 /* BroadcastChannelRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BroadcastChannelRegistry.h; sourceTree = "<group>"; };
@@ -9871,7 +9873,6 @@
 		51A4BB0E1954D62700FA5C2E /* NavigatorGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigatorGamepad.h; sourceTree = "<group>"; };
 		51A4BB0F1954D62700FA5C2E /* Navigator+Gamepad.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "Navigator+Gamepad.idl"; sourceTree = "<group>"; };
 		51A748E02005D0E00075BA68 /* MessageWithMessagePorts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageWithMessagePorts.h; sourceTree = "<group>"; };
-		51A748E12005D0E00075BA68 /* MessageWithMessagePorts.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MessageWithMessagePorts.cpp; sourceTree = "<group>"; };
 		51A748E4200600210075BA68 /* MessagePortChannelProviderImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MessagePortChannelProviderImpl.cpp; sourceTree = "<group>"; };
 		51A748E5200600210075BA68 /* MessagePortChannelProviderImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessagePortChannelProviderImpl.h; sourceTree = "<group>"; };
 		51A9D9E7195B931F001B2B5C /* GamepadManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GamepadManager.cpp; sourceTree = "<group>"; };
@@ -22370,8 +22371,8 @@
 				51A748E5200600210075BA68 /* MessagePortChannelProviderImpl.h */,
 				51ECC3F5200587B700483EAE /* MessagePortChannelRegistry.cpp */,
 				51ECC3F1200587B500483EAE /* MessagePortChannelRegistry.h */,
-				51A748E12005D0E00075BA68 /* MessageWithMessagePorts.cpp */,
 				51A748E02005D0E00075BA68 /* MessageWithMessagePorts.h */,
+				46DA4A0027AB038D00E375A8 /* TransferredMessagePort.h */,
 				41114A7C2317B39E00B56007 /* WorkerMessagePortChannelProvider.cpp */,
 				41114A7A2317B39E00B56007 /* WorkerMessagePortChannelProvider.h */,
 			);
@@ -37700,6 +37701,7 @@
 				FFAC30FE184FB145008C4F1E /* TrailingObjects.h in Headers */,
 				516071321BD8308B00DBC4F2 /* TransactionOperation.h in Headers */,
 				CD3EEF4125799FD9006563BB /* TransferFunction.h in Headers */,
+				46DA4A0227AB039300E375A8 /* TransferredMessagePort.h in Headers */,
 				49E911C40EF86D47009D0CAF /* TransformationMatrix.h in Headers */,
 				FB484F4D171F821E00040755 /* TransformFunctions.h in Headers */,
 				49E911CE0EF86D47009D0CAF /* TransformOperation.h in Headers */,

Modified: trunk/Source/WebCore/dom/MessagePort.cpp (288999 => 289000)


--- trunk/Source/WebCore/dom/MessagePort.cpp	2022-02-02 23:04:09 UTC (rev 288999)
+++ trunk/Source/WebCore/dom/MessagePort.cpp	2022-02-02 23:25:43 UTC (rev 289000)
@@ -149,7 +149,7 @@
         return { };
     ASSERT(scriptExecutionContext());
 
-    TransferredMessagePortArray transferredPorts;
+    Vector<TransferredMessagePort> transferredPorts;
     // Make sure we aren't connected to any of the passed-in ports.
     if (!ports.isEmpty()) {
         for (auto& port : ports) {
@@ -373,10 +373,10 @@
     return nullptr;
 }
 
-ExceptionOr<TransferredMessagePortArray> MessagePort::disentanglePorts(Vector<RefPtr<MessagePort>>&& ports)
+ExceptionOr<Vector<TransferredMessagePort>> MessagePort::disentanglePorts(Vector<RefPtr<MessagePort>>&& ports)
 {
     if (ports.isEmpty())
-        return TransferredMessagePortArray { };
+        return Vector<TransferredMessagePort> { };
 
     // Walk the incoming array - if there are any duplicate ports, or null ports or cloned ports, throw an error (per section 8.3.3 of the HTML5 spec).
     HashSet<MessagePort*> portSet;
@@ -386,15 +386,12 @@
     }
 
     // Passed-in ports passed validity checks, so we can disentangle them.
-    TransferredMessagePortArray portArray;
-    portArray.reserveInitialCapacity(ports.size());
-    for (auto& port : ports)
-        portArray.uncheckedAppend(port->disentangle());
-
-    return portArray;
+    return WTF::map(ports, [](auto& port) {
+        return port->disentangle();
+    });
 }
 
-Vector<RefPtr<MessagePort>> MessagePort::entanglePorts(ScriptExecutionContext& context, TransferredMessagePortArray&& transferredPorts)
+Vector<RefPtr<MessagePort>> MessagePort::entanglePorts(ScriptExecutionContext& context, Vector<TransferredMessagePort>&& transferredPorts)
 {
     LOG(MessagePorts, "Entangling %zu transferred ports to ScriptExecutionContext %s (%p)", transferredPorts.size(), context.url().string().utf8().data(), &context);
 
@@ -401,11 +398,9 @@
     if (transferredPorts.isEmpty())
         return { };
 
-    Vector<RefPtr<MessagePort>> ports;
-    ports.reserveInitialCapacity(transferredPorts.size());
-    for (auto& transferredPort : transferredPorts)
-        ports.uncheckedAppend(MessagePort::entangle(context, WTFMove(transferredPort)));
-    return ports;
+    return WTF::map(transferredPorts, [&](auto& port) -> RefPtr<MessagePort> {
+        return MessagePort::entangle(context, WTFMove(port));
+    });
 }
 
 Ref<MessagePort> MessagePort::entangle(ScriptExecutionContext& context, TransferredMessagePort&& transferredPort)

Modified: trunk/Source/WebCore/dom/MessagePort.h (288999 => 289000)


--- trunk/Source/WebCore/dom/MessagePort.h	2022-02-02 23:04:09 UTC (rev 288999)
+++ trunk/Source/WebCore/dom/MessagePort.h	2022-02-02 23:25:43 UTC (rev 289000)
@@ -60,8 +60,8 @@
     void entangle();
 
     // Returns nullptr if the passed-in vector is empty.
-    static ExceptionOr<TransferredMessagePortArray> disentanglePorts(Vector<RefPtr<MessagePort>>&&);
-    static Vector<RefPtr<MessagePort>> entanglePorts(ScriptExecutionContext&, TransferredMessagePortArray&&);
+    static ExceptionOr<Vector<TransferredMessagePort>> disentanglePorts(Vector<RefPtr<MessagePort>>&&);
+    static Vector<RefPtr<MessagePort>> entanglePorts(ScriptExecutionContext&, Vector<TransferredMessagePort>&&);
 
     WEBCORE_EXPORT static bool isExistingMessagePortLocallyReachable(const MessagePortIdentifier&);
     WEBCORE_EXPORT static void notifyMessageAvailable(const MessagePortIdentifier&);

Deleted: trunk/Source/WebCore/dom/messageports/MessageWithMessagePorts.cpp (288999 => 289000)


--- trunk/Source/WebCore/dom/messageports/MessageWithMessagePorts.cpp	2022-02-02 23:04:09 UTC (rev 288999)
+++ trunk/Source/WebCore/dom/messageports/MessageWithMessagePorts.cpp	2022-02-02 23:25:43 UTC (rev 289000)
@@ -1,31 +0,0 @@
-/*
- * 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 "MessageWithMessagePorts.h"
-
-namespace WebCore {
-
-} // namespace WebCore

Modified: trunk/Source/WebCore/dom/messageports/MessageWithMessagePorts.h (288999 => 289000)


--- trunk/Source/WebCore/dom/messageports/MessageWithMessagePorts.h	2022-02-02 23:04:09 UTC (rev 288999)
+++ trunk/Source/WebCore/dom/messageports/MessageWithMessagePorts.h	2022-02-02 23:25:43 UTC (rev 289000)
@@ -25,20 +25,15 @@
 
 #pragma once
 
-#include "MessagePortIdentifier.h"
 #include "SerializedScriptValue.h"
+#include "TransferredMessagePort.h"
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
 
-// 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.
-using TransferredMessagePort = std::pair<WebCore::MessagePortIdentifier, WebCore::MessagePortIdentifier>;
-using TransferredMessagePortArray = Vector<TransferredMessagePort>;
-
 struct MessageWithMessagePorts {
     RefPtr<SerializedScriptValue> message;
-    TransferredMessagePortArray transferredPorts;
+    Vector<TransferredMessagePort> transferredPorts;
 
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static std::optional<MessageWithMessagePorts> decode(Decoder&);

Copied: trunk/Source/WebCore/dom/messageports/TransferredMessagePort.h (from rev 288999, trunk/Source/WebCore/dom/messageports/MessageWithMessagePorts.cpp) (0 => 289000)


--- trunk/Source/WebCore/dom/messageports/TransferredMessagePort.h	                        (rev 0)
+++ trunk/Source/WebCore/dom/messageports/TransferredMessagePort.h	2022-02-02 23:25:43 UTC (rev 289000)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2018-2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "MessagePortIdentifier.h"
+
+namespace WebCore {
+
+// 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.
+using TransferredMessagePort = std::pair<MessagePortIdentifier, MessagePortIdentifier>;
+
+} // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to