Title: [283617] trunk/Source/WebKit
Revision
283617
Author
[email protected]
Date
2021-10-06 07:56:33 -0700 (Wed, 06 Oct 2021)

Log Message

[WebKit2] Refactor some IPC argument encoder logic to work with StreamConnectionEncoder
https://bugs.webkit.org/show_bug.cgi?id=230714
rdar://83477591

Reviewed by Tim Horton.

Make it possible to use `IPC::StreamConnectionEncoder` to encode display list items (and their members) in an
IPC stream. This patch comprises two main sets of changes in `ArgumentCoders`, and `WebCoreArgumentCoders`. See
below for more details.

* Platform/IPC/ArgumentCoders.cpp:
(IPC::ArgumentCoder<audit_token_t>::decode):
(IPC::ArgumentCoder<Monostate>::encode): Deleted.
(IPC::ArgumentCoder<Monostate>::decode): Deleted.
* Platform/IPC/ArgumentCoders.h:
(IPC::ArgumentCoder<Monostate>::encode):
(IPC::ArgumentCoder<Monostate>::decode):

Many of these `encode()` methods are currently non-templated, which means that Encoder and Decoder used here
refer solely to IPC::Encoder and IPC::Decoder (respectively) instead of other types of encoders (namely,
StreamConnectionEncoder). Make these use templated `encode` methods intead, so that they work with generic
encoders.

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<AffineTransform>::encode): Deleted.
(IPC::ArgumentCoder<AffineTransform>::decode): Deleted.
(IPC::ArgumentCoder<FloatPoint>::encode): Deleted.
(IPC::ArgumentCoder<FloatPoint>::decode): Deleted.
(IPC::ArgumentCoder<FloatPoint3D>::encode): Deleted.
(IPC::ArgumentCoder<FloatPoint3D>::decode): Deleted.
(IPC::ArgumentCoder<FloatRect>::encode): Deleted.
(IPC::ArgumentCoder<FloatRect>::decode): Deleted.
(IPC::ArgumentCoder<FloatBoxExtent>::encode): Deleted.
(IPC::ArgumentCoder<FloatBoxExtent>::decode): Deleted.
(IPC::ArgumentCoder<FloatSize>::encode): Deleted.
(IPC::ArgumentCoder<FloatSize>::decode): Deleted.
(IPC::ArgumentCoder<FloatRoundedRect>::encode): Deleted.
(IPC::ArgumentCoder<FloatRoundedRect>::decode): Deleted.
(IPC::ArgumentCoder<IntPoint>::encode): Deleted.
(IPC::ArgumentCoder<IntPoint>::decode): Deleted.
(IPC::ArgumentCoder<IntRect>::encode): Deleted.
(IPC::ArgumentCoder<IntRect>::decode): Deleted.
(IPC::ArgumentCoder<IntSize>::encode): Deleted.
(IPC::ArgumentCoder<IntSize>::decode): Deleted.
(IPC::ArgumentCoder<LayoutSize>::encode): Deleted.
(IPC::ArgumentCoder<LayoutSize>::decode): Deleted.
(IPC::ArgumentCoder<LayoutPoint>::encode): Deleted.
(IPC::ArgumentCoder<LayoutPoint>::decode): Deleted.

These WebCore argument coders are also currently incompatible with StreamConnectionEncoder, since they are non-
templated (and thus only work with IPC::Encoder). Since these are all encodable as POD types, we can just use
SimpleArgumentCoder for all of these. We also add new `DEFINE_SIMPLE_ARGUMENT_CODER_FOR_(HEADER|SOURCE)` macros
to make this code a bit easier to read, which adds SimpleArgumentCoder for the given type, for both standard
IPC::Encoder as well as IPC::StreamConnectionEncoder.

* Shared/WebCoreArgumentCoders.h:
* Shared/mac/WebCoreArgumentCodersMac.mm:
(IPC::ArgumentCoder<CGRect>::encode): Deleted.
(IPC::ArgumentCoder<CGRect>::decode): Deleted.
(IPC::ArgumentCoder<CGSize>::encode): Deleted.
(IPC::ArgumentCoder<CGSize>::decode): Deleted.
(IPC::ArgumentCoder<CGPoint>::encode): Deleted.
(IPC::ArgumentCoder<CGPoint>::decode): Deleted.
(IPC::ArgumentCoder<CGAffineTransform>::encode): Deleted.
(IPC::ArgumentCoder<CGAffineTransform>::decode): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (283616 => 283617)


--- trunk/Source/WebKit/ChangeLog	2021-10-06 14:41:52 UTC (rev 283616)
+++ trunk/Source/WebKit/ChangeLog	2021-10-06 14:56:33 UTC (rev 283617)
@@ -1,3 +1,71 @@
+2021-10-06  Wenson Hsieh  <[email protected]>
+
+        [WebKit2] Refactor some IPC argument encoder logic to work with StreamConnectionEncoder
+        https://bugs.webkit.org/show_bug.cgi?id=230714
+        rdar://83477591
+
+        Reviewed by Tim Horton.
+
+        Make it possible to use `IPC::StreamConnectionEncoder` to encode display list items (and their members) in an
+        IPC stream. This patch comprises two main sets of changes in `ArgumentCoders`, and `WebCoreArgumentCoders`. See
+        below for more details.
+
+        * Platform/IPC/ArgumentCoders.cpp:
+        (IPC::ArgumentCoder<audit_token_t>::decode):
+        (IPC::ArgumentCoder<Monostate>::encode): Deleted.
+        (IPC::ArgumentCoder<Monostate>::decode): Deleted.
+        * Platform/IPC/ArgumentCoders.h:
+        (IPC::ArgumentCoder<Monostate>::encode):
+        (IPC::ArgumentCoder<Monostate>::decode):
+
+        Many of these `encode()` methods are currently non-templated, which means that Encoder and Decoder used here
+        refer solely to IPC::Encoder and IPC::Decoder (respectively) instead of other types of encoders (namely,
+        StreamConnectionEncoder). Make these use templated `encode` methods intead, so that they work with generic
+        encoders.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<AffineTransform>::encode): Deleted.
+        (IPC::ArgumentCoder<AffineTransform>::decode): Deleted.
+        (IPC::ArgumentCoder<FloatPoint>::encode): Deleted.
+        (IPC::ArgumentCoder<FloatPoint>::decode): Deleted.
+        (IPC::ArgumentCoder<FloatPoint3D>::encode): Deleted.
+        (IPC::ArgumentCoder<FloatPoint3D>::decode): Deleted.
+        (IPC::ArgumentCoder<FloatRect>::encode): Deleted.
+        (IPC::ArgumentCoder<FloatRect>::decode): Deleted.
+        (IPC::ArgumentCoder<FloatBoxExtent>::encode): Deleted.
+        (IPC::ArgumentCoder<FloatBoxExtent>::decode): Deleted.
+        (IPC::ArgumentCoder<FloatSize>::encode): Deleted.
+        (IPC::ArgumentCoder<FloatSize>::decode): Deleted.
+        (IPC::ArgumentCoder<FloatRoundedRect>::encode): Deleted.
+        (IPC::ArgumentCoder<FloatRoundedRect>::decode): Deleted.
+        (IPC::ArgumentCoder<IntPoint>::encode): Deleted.
+        (IPC::ArgumentCoder<IntPoint>::decode): Deleted.
+        (IPC::ArgumentCoder<IntRect>::encode): Deleted.
+        (IPC::ArgumentCoder<IntRect>::decode): Deleted.
+        (IPC::ArgumentCoder<IntSize>::encode): Deleted.
+        (IPC::ArgumentCoder<IntSize>::decode): Deleted.
+        (IPC::ArgumentCoder<LayoutSize>::encode): Deleted.
+        (IPC::ArgumentCoder<LayoutSize>::decode): Deleted.
+        (IPC::ArgumentCoder<LayoutPoint>::encode): Deleted.
+        (IPC::ArgumentCoder<LayoutPoint>::decode): Deleted.
+
+        These WebCore argument coders are also currently incompatible with StreamConnectionEncoder, since they are non-
+        templated (and thus only work with IPC::Encoder). Since these are all encodable as POD types, we can just use
+        SimpleArgumentCoder for all of these. We also add new `DEFINE_SIMPLE_ARGUMENT_CODER_FOR_(HEADER|SOURCE)` macros
+        to make this code a bit easier to read, which adds SimpleArgumentCoder for the given type, for both standard
+        IPC::Encoder as well as IPC::StreamConnectionEncoder.
+
+        * Shared/WebCoreArgumentCoders.h:
+        * Shared/mac/WebCoreArgumentCodersMac.mm:
+        (IPC::ArgumentCoder<CGRect>::encode): Deleted.
+        (IPC::ArgumentCoder<CGRect>::decode): Deleted.
+        (IPC::ArgumentCoder<CGSize>::encode): Deleted.
+        (IPC::ArgumentCoder<CGSize>::decode): Deleted.
+        (IPC::ArgumentCoder<CGPoint>::encode): Deleted.
+        (IPC::ArgumentCoder<CGPoint>::decode): Deleted.
+        (IPC::ArgumentCoder<CGAffineTransform>::encode): Deleted.
+        (IPC::ArgumentCoder<CGAffineTransform>::decode): Deleted.
+
 2021-10-06  Youenn Fablet  <[email protected]>
 
         Implement https://w3c.github.io/push-api/#receiving-a-push-message

Modified: trunk/Source/WebKit/Platform/IPC/ArgumentCoders.cpp (283616 => 283617)


--- trunk/Source/WebKit/Platform/IPC/ArgumentCoders.cpp	2021-10-06 14:41:52 UTC (rev 283616)
+++ trunk/Source/WebKit/Platform/IPC/ArgumentCoders.cpp	2021-10-06 14:56:33 UTC (rev 283617)
@@ -30,6 +30,7 @@
 #include "PrivateClickMeasurementDecoder.h"
 #include "PrivateClickMeasurementEncoder.h"
 #include "StreamConnectionEncoder.h"
+#include <wtf/text/AtomString.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
 
@@ -218,6 +219,7 @@
 }
 
 #if HAVE(AUDIT_TOKEN)
+
 void ArgumentCoder<audit_token_t>::encode(Encoder& encoder, const audit_token_t& auditToken)
 {
     for (unsigned i = 0; i < WTF_ARRAY_LENGTH(auditToken.val); i++)
@@ -232,15 +234,7 @@
     }
     return true;
 }
-#endif
 
-void ArgumentCoder<Monostate>::encode(Encoder&, const Monostate&)
-{
-}
+#endif // HAVE(AUDIT_TOKEN)
 
-WARN_UNUSED_RETURN std::optional<Monostate> ArgumentCoder<Monostate>::decode(Decoder&)
-{
-    return Monostate { };
-}
-
 } // namespace IPC

Modified: trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h (283616 => 283617)


--- trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h	2021-10-06 14:41:52 UTC (rev 283616)
+++ trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h	2021-10-06 14:56:33 UTC (rev 283617)
@@ -108,6 +108,7 @@
 };
 
 template<typename T> struct ArgumentCoder<OptionSet<T>> {
+    template<typename Encoder>
     static void encode(Encoder& encoder, const OptionSet<T>& optionSet)
     {
         ASSERT(WTF::isValidOptionSet(optionSet));
@@ -114,6 +115,7 @@
         encoder << optionSet.toRaw();
     }
 
+    template<typename Decoder>
     static WARN_UNUSED_RETURN bool decode(Decoder& decoder, OptionSet<T>& optionSet)
     {
         typename OptionSet<T>::StorageType value;
@@ -125,6 +127,7 @@
         return true;
     }
 
+    template<typename Decoder>
     static std::optional<OptionSet<T>> decode(Decoder& decoder)
     {
         std::optional<typename OptionSet<T>::StorageType> value;
@@ -188,6 +191,7 @@
 };
 
 template<typename T> struct ArgumentCoder<Box<T>> {
+    template<typename Encoder>
     static void encode(Encoder& encoder, const Box<T>& box)
     {
         if (!box) {
@@ -199,6 +203,7 @@
         encoder << *box.get();
     }
 
+    template<typename Decoder>
     static WARN_UNUSED_RETURN bool decode(Decoder& decoder, Box<T>& box)
     {
         bool isEngaged;
@@ -218,6 +223,7 @@
         return true;
     }
 
+    template<typename Decoder>
     static std::optional<Box<T>> decode(Decoder& decoder)
     {
         std::optional<bool> isEngaged;
@@ -236,11 +242,13 @@
 };
 
 template<typename T, typename U> struct ArgumentCoder<std::pair<T, U>> {
+    template<typename Encoder>
     static void encode(Encoder& encoder, const std::pair<T, U>& pair)
     {
         encoder << pair.first << pair.second;
     }
 
+    template<typename Decoder>
     static WARN_UNUSED_RETURN bool decode(Decoder& decoder, std::pair<T, U>& pair)
     {
         T first;
@@ -256,6 +264,7 @@
         return true;
     }
 
+    template<typename Decoder>
     static std::optional<std::pair<T, U>> decode(Decoder& decoder)
     {
         std::optional<T> first;
@@ -366,11 +375,13 @@
 };
 
 template<typename KeyType, typename ValueType> struct ArgumentCoder<WTF::KeyValuePair<KeyType, ValueType>> {
+    template<typename Encoder>
     static void encode(Encoder& encoder, const WTF::KeyValuePair<KeyType, ValueType>& pair)
     {
         encoder << pair.key << pair.value;
     }
 
+    template<typename Decoder>
     static WARN_UNUSED_RETURN bool decode(Decoder& decoder, WTF::KeyValuePair<KeyType, ValueType>& pair)
     {
         KeyType key;
@@ -398,6 +409,7 @@
             encoder << vector[i];
     }
 
+    template<typename Decoder>
     static WARN_UNUSED_RETURN bool decode(Decoder& decoder, Vector<T, inlineCapacity, OverflowHandler, minCapacity>& vector)
     {
         std::optional<Vector<T, inlineCapacity, OverflowHandler, minCapacity>> optional;
@@ -437,6 +449,7 @@
         encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(vector.data()), vector.size() * sizeof(T), alignof(T));
     }
     
+    template<typename Decoder>
     static WARN_UNUSED_RETURN bool decode(Decoder& decoder, Vector<T, inlineCapacity, OverflowHandler, minCapacity>& vector)
     {
         uint64_t decodedSize;
@@ -451,7 +464,7 @@
         // Since we know the total size of the elements, we can allocate the vector in
         // one fell swoop. Before allocating we must however make sure that the decoder buffer
         // is big enough.
-        if (!decoder.bufferIsLargeEnoughToContain<T>(size))
+        if (!decoder.template bufferIsLargeEnoughToContain<T>(size))
             return false;
 
         Vector<T, inlineCapacity, OverflowHandler, minCapacity> temp;
@@ -498,6 +511,7 @@
 template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg, typename HashTableTraits> struct ArgumentCoder<HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg, HashTableTraits>> {
     typedef HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg, HashTableTraits> HashMapType;
 
+    template<typename Encoder>
     static void encode(Encoder& encoder, const HashMapType& hashMap)
     {
         encoder << static_cast<uint32_t>(hashMap.size());
@@ -505,6 +519,7 @@
             encoder << *it;
     }
 
+    template<typename Decoder>
     static std::optional<HashMapType> decode(Decoder& decoder)
     {
         uint32_t hashMapSize;
@@ -535,6 +550,7 @@
         return hashMap;
     }
 
+    template<typename Decoder>
     static WARN_UNUSED_RETURN bool decode(Decoder& decoder, HashMapType& hashMap)
     {
         std::optional<HashMapType> tempHashMap;
@@ -549,6 +565,7 @@
 template<typename KeyArg, typename HashArg, typename KeyTraitsArg, typename HashTableTraits> struct ArgumentCoder<HashSet<KeyArg, HashArg, KeyTraitsArg, HashTableTraits>> {
     typedef HashSet<KeyArg, HashArg, KeyTraitsArg, HashTableTraits> HashSetType;
 
+    template<typename Encoder>
     static void encode(Encoder& encoder, const HashSetType& hashSet)
     {
         encoder << static_cast<uint64_t>(hashSet.size());
@@ -556,6 +573,7 @@
             encoder << *it;
     }
 
+    template<typename Decoder>
     static WARN_UNUSED_RETURN bool decode(Decoder& decoder, HashSetType& hashSet)
     {
         std::optional<HashSetType> tempHashSet;
@@ -567,6 +585,7 @@
         return true;
     }
 
+    template<typename Decoder>
     static std::optional<HashSetType> decode(Decoder& decoder)
     {
         uint64_t hashSetSize;
@@ -596,6 +615,7 @@
 template<typename KeyArg, typename HashArg, typename KeyTraitsArg> struct ArgumentCoder<HashCountedSet<KeyArg, HashArg, KeyTraitsArg>> {
     typedef HashCountedSet<KeyArg, HashArg, KeyTraitsArg> HashCountedSetType;
     
+    template<typename Encoder>
     static void encode(Encoder& encoder, const HashCountedSetType& hashCountedSet)
     {
         encoder << static_cast<uint64_t>(hashCountedSet.size());
@@ -606,6 +626,7 @@
         }
     }
     
+    template<typename Decoder>
     static WARN_UNUSED_RETURN bool decode(Decoder& decoder, HashCountedSetType& hashCountedSet)
     {
         uint64_t hashCountedSetSize;
@@ -637,6 +658,7 @@
 };
 
 template<typename ValueType, typename ErrorType> struct ArgumentCoder<Expected<ValueType, ErrorType>> {
+    template<typename Encoder>
     static void encode(Encoder& encoder, const Expected<ValueType, ErrorType>& expected)
     {
         if (!expected.has_value()) {
@@ -648,6 +670,7 @@
         encoder << expected.value();
     }
 
+    template<typename Decoder>
     static std::optional<Expected<ValueType, ErrorType>> decode(Decoder& decoder)
     {
         std::optional<bool> hasValue;
@@ -704,6 +727,7 @@
 
 template<size_t index, typename... Types>
 struct VariantCoder {
+    template<typename Encoder>
     static void encode(Encoder& encoder, const WTF::Variant<Types...>& variant, unsigned i)
     {
         if (i == index) {
@@ -713,6 +737,7 @@
         VariantCoder<index - 1, Types...>::encode(encoder, variant, i);
     }
     
+    template<typename Decoder>
     static std::optional<WTF::Variant<Types...>> decode(Decoder& decoder, unsigned i)
     {
         if (i == index) {
@@ -728,6 +753,7 @@
 
 template<typename... Types>
 struct VariantCoder<0, Types...> {
+    template<typename Encoder>
     static void encode(Encoder& encoder, const WTF::Variant<Types...>& variant, unsigned i)
     {
         ASSERT_UNUSED(i, !i);
@@ -734,6 +760,7 @@
         encoder << WTF::get<0>(variant);
     }
     
+    template<typename Decoder>
     static std::optional<WTF::Variant<Types...>> decode(Decoder& decoder, unsigned i)
     {
         ASSERT_UNUSED(i, !i);
@@ -746,6 +773,7 @@
 };
 
 template<typename... Types> struct ArgumentCoder<WTF::Variant<Types...>> {
+    template<typename Encoder>
     static void encode(Encoder& encoder, const WTF::Variant<Types...>& variant)
     {
         unsigned i = variant.index();
@@ -753,6 +781,7 @@
         VariantCoder<sizeof...(Types) - 1, Types...>::encode(encoder, variant, i);
     }
     
+    template<typename Decoder>
     static std::optional<WTF::Variant<Types...>> decode(Decoder& decoder)
     {
         std::optional<unsigned> i;
@@ -804,8 +833,14 @@
 #endif
 
 template<> struct ArgumentCoder<Monostate> {
-    static void encode(Encoder&, const Monostate&);
-    static std::optional<Monostate> decode(Decoder&);
+    template<typename Encoder>
+    static void encode(Encoder&, const Monostate&) { }
+
+    template<typename Decoder>
+    static std::optional<Monostate> decode(Decoder&)
+    {
+        return Monostate { };
+    }
 };
 
 } // namespace IPC

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (283616 => 283617)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2021-10-06 14:41:52 UTC (rev 283616)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2021-10-06 14:56:33 UTC (rev 283617)
@@ -125,6 +125,42 @@
 using namespace WebCore;
 using namespace WebKit;
 
+#define DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(Type) \
+    template<typename Encoder> \
+    void ArgumentCoder<Type>::encode(Encoder& encoder, const Type& value) { SimpleArgumentCoder<Type>::encode(encoder, value); } \
+    bool ArgumentCoder<Type>::decode(Decoder& decoder, Type& value) { return SimpleArgumentCoder<Type>::decode(decoder, value); } \
+    std::optional<Type> ArgumentCoder<Type>::decode(Decoder& decoder) \
+    { \
+        Type value; \
+        if (!decode(decoder, value)) \
+            return std::nullopt; \
+        return value; \
+    } \
+    template void ArgumentCoder<Type>::encode<Encoder>(Encoder&, const Type&); \
+    template void ArgumentCoder<Type>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, const Type&);
+
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(AffineTransform)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(FloatBoxExtent)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(FloatPoint)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(FloatPoint3D)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(FloatRect)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(FloatRoundedRect)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(FloatSize)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(IntPoint)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(IntRect)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(IntSize)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(LayoutPoint)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(LayoutSize)
+
+#if USE(CG)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(CGRect)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(CGSize)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(CGPoint)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE(CGAffineTransform)
+#endif
+
+#undef DEFINE_SIMPLE_ARGUMENT_CODER_FOR_SOURCE
+
 static void encodeSharedBuffer(Encoder& encoder, const SharedBuffer* buffer)
 {
     bool isNull = !buffer;
@@ -231,16 +267,6 @@
     return true;
 }
 
-void ArgumentCoder<AffineTransform>::encode(Encoder& encoder, const AffineTransform& affineTransform)
-{
-    SimpleArgumentCoder<AffineTransform>::encode(encoder, affineTransform);
-}
-
-bool ArgumentCoder<AffineTransform>::decode(Decoder& decoder, AffineTransform& affineTransform)
-{
-    return SimpleArgumentCoder<AffineTransform>::decode(decoder, affineTransform);
-}
-
 void ArgumentCoder<CacheQueryOptions>::encode(Encoder& encoder, const CacheQueryOptions& options)
 {
     encoder << options.ignoreSearch;
@@ -425,6 +451,7 @@
     return true;
 }
 
+template<typename Encoder>
 void ArgumentCoder<TransformationMatrix>::encode(Encoder& encoder, const TransformationMatrix& transformationMatrix)
 {
     encoder << transformationMatrix.m11();
@@ -506,6 +533,9 @@
     return true;
 }
 
+template void ArgumentCoder<TransformationMatrix>::encode<Encoder>(Encoder&, const TransformationMatrix&);
+template void ArgumentCoder<TransformationMatrix>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, const TransformationMatrix&);
+
 void ArgumentCoder<LinearTimingFunction>::encode(Encoder& encoder, const LinearTimingFunction& timingFunction)
 {
     encoder << timingFunction.type();
@@ -617,65 +647,6 @@
     return true;
 }
 
-void ArgumentCoder<FloatPoint>::encode(Encoder& encoder, const FloatPoint& floatPoint)
-{
-    SimpleArgumentCoder<FloatPoint>::encode(encoder, floatPoint);
-}
-
-bool ArgumentCoder<FloatPoint>::decode(Decoder& decoder, FloatPoint& floatPoint)
-{
-    return SimpleArgumentCoder<FloatPoint>::decode(decoder, floatPoint);
-}
-
-std::optional<FloatPoint> ArgumentCoder<FloatPoint>::decode(Decoder& decoder)
-{
-    FloatPoint floatPoint;
-    if (!SimpleArgumentCoder<FloatPoint>::decode(decoder, floatPoint))
-        return std::nullopt;
-    return floatPoint;
-}
-
-void ArgumentCoder<FloatPoint3D>::encode(Encoder& encoder, const FloatPoint3D& floatPoint)
-{
-    SimpleArgumentCoder<FloatPoint3D>::encode(encoder, floatPoint);
-}
-
-bool ArgumentCoder<FloatPoint3D>::decode(Decoder& decoder, FloatPoint3D& floatPoint)
-{
-    return SimpleArgumentCoder<FloatPoint3D>::decode(decoder, floatPoint);
-}
-
-
-void ArgumentCoder<FloatRect>::encode(Encoder& encoder, const FloatRect& floatRect)
-{
-    SimpleArgumentCoder<FloatRect>::encode(encoder, floatRect);
-}
-
-bool ArgumentCoder<FloatRect>::decode(Decoder& decoder, FloatRect& floatRect)
-{
-    return SimpleArgumentCoder<FloatRect>::decode(decoder, floatRect);
-}
-
-std::optional<FloatRect> ArgumentCoder<FloatRect>::decode(Decoder& decoder)
-{
-    FloatRect floatRect;
-    if (!SimpleArgumentCoder<FloatRect>::decode(decoder, floatRect))
-        return std::nullopt;
-    return floatRect;
-}
-
-
-void ArgumentCoder<FloatBoxExtent>::encode(Encoder& encoder, const FloatBoxExtent& floatBoxExtent)
-{
-    SimpleArgumentCoder<FloatBoxExtent>::encode(encoder, floatBoxExtent);
-}
-    
-bool ArgumentCoder<FloatBoxExtent>::decode(Decoder& decoder, FloatBoxExtent& floatBoxExtent)
-{
-    return SimpleArgumentCoder<FloatBoxExtent>::decode(decoder, floatBoxExtent);
-}
-
-
 void ArgumentCoder<RectEdges<bool>>::encode(Encoder& encoder, const RectEdges<bool>& boxEdges)
 {
     SimpleArgumentCoder<RectEdges<bool>>::encode(encoder, boxEdges);
@@ -686,28 +657,6 @@
     return SimpleArgumentCoder<RectEdges<bool>>::decode(decoder, boxEdges);
 }
 
-
-void ArgumentCoder<FloatSize>::encode(Encoder& encoder, const FloatSize& floatSize)
-{
-    SimpleArgumentCoder<FloatSize>::encode(encoder, floatSize);
-}
-
-bool ArgumentCoder<FloatSize>::decode(Decoder& decoder, FloatSize& floatSize)
-{
-    return SimpleArgumentCoder<FloatSize>::decode(decoder, floatSize);
-}
-
-
-void ArgumentCoder<FloatRoundedRect>::encode(Encoder& encoder, const FloatRoundedRect& roundedRect)
-{
-    SimpleArgumentCoder<FloatRoundedRect>::encode(encoder, roundedRect);
-}
-
-bool ArgumentCoder<FloatRoundedRect>::decode(Decoder& decoder, FloatRoundedRect& roundedRect)
-{
-    return SimpleArgumentCoder<FloatRoundedRect>::decode(decoder, roundedRect);
-}
-
 #if ENABLE(META_VIEWPORT)
 void ArgumentCoder<ViewportArguments>::encode(Encoder& encoder, const ViewportArguments& viewportArguments)
 {
@@ -739,87 +688,6 @@
     return SimpleArgumentCoder<ViewportAttributes>::decode(decoder, viewportAttributes);
 }
 
-void ArgumentCoder<IntPoint>::encode(Encoder& encoder, const IntPoint& intPoint)
-{
-    SimpleArgumentCoder<IntPoint>::encode(encoder, intPoint);
-}
-
-bool ArgumentCoder<IntPoint>::decode(Decoder& decoder, IntPoint& intPoint)
-{
-    return SimpleArgumentCoder<IntPoint>::decode(decoder, intPoint);
-}
-
-std::optional<WebCore::IntPoint> ArgumentCoder<IntPoint>::decode(Decoder& decoder)
-{
-    IntPoint intPoint;
-    if (!SimpleArgumentCoder<IntPoint>::decode(decoder, intPoint))
-        return std::nullopt;
-    return intPoint;
-}
-
-void ArgumentCoder<IntRect>::encode(Encoder& encoder, const IntRect& intRect)
-{
-    SimpleArgumentCoder<IntRect>::encode(encoder, intRect);
-}
-
-bool ArgumentCoder<IntRect>::decode(Decoder& decoder, IntRect& intRect)
-{
-    return SimpleArgumentCoder<IntRect>::decode(decoder, intRect);
-}
-
-std::optional<IntRect> ArgumentCoder<IntRect>::decode(Decoder& decoder)
-{
-    IntRect rect;
-    if (!decode(decoder, rect))
-        return std::nullopt;
-    return rect;
-}
-
-template<typename Encoder>
-void ArgumentCoder<IntSize>::encode(Encoder& encoder, const IntSize& intSize)
-{
-    SimpleArgumentCoder<IntSize>::encode(encoder, intSize);
-}
-
-template
-void ArgumentCoder<IntSize>::encode<Encoder>(Encoder&, const IntSize&);
-template
-void ArgumentCoder<IntSize>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, const IntSize&);
-
-bool ArgumentCoder<IntSize>::decode(Decoder& decoder, IntSize& intSize)
-{
-    return SimpleArgumentCoder<IntSize>::decode(decoder, intSize);
-}
-
-std::optional<IntSize> ArgumentCoder<IntSize>::decode(Decoder& decoder)
-{
-    IntSize intSize;
-    if (!SimpleArgumentCoder<IntSize>::decode(decoder, intSize))
-        return std::nullopt;
-    return intSize;
-}
-
-void ArgumentCoder<LayoutSize>::encode(Encoder& encoder, const LayoutSize& layoutSize)
-{
-    SimpleArgumentCoder<LayoutSize>::encode(encoder, layoutSize);
-}
-
-bool ArgumentCoder<LayoutSize>::decode(Decoder& decoder, LayoutSize& layoutSize)
-{
-    return SimpleArgumentCoder<LayoutSize>::decode(decoder, layoutSize);
-}
-
-
-void ArgumentCoder<LayoutPoint>::encode(Encoder& encoder, const LayoutPoint& layoutPoint)
-{
-    SimpleArgumentCoder<LayoutPoint>::encode(encoder, layoutPoint);
-}
-
-bool ArgumentCoder<LayoutPoint>::decode(Decoder& decoder, LayoutPoint& layoutPoint)
-{
-    return SimpleArgumentCoder<LayoutPoint>::decode(decoder, layoutPoint);
-}
-
 void ArgumentCoder<RecentSearch>::encode(Encoder& encoder, const RecentSearch& recentSearch)
 {
     encoder << recentSearch.string << recentSearch.time;

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (283616 => 283617)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2021-10-06 14:41:52 UTC (rev 283616)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2021-10-06 14:56:33 UTC (rev 283617)
@@ -26,12 +26,24 @@
 #pragma once
 
 #include "ArgumentCoders.h"
+#include <WebCore/AffineTransform.h>
 #include <WebCore/AutoplayEvent.h>
 #include <WebCore/ColorSpace.h>
 #include <WebCore/DiagnosticLoggingClient.h>
+#include <WebCore/FloatPoint.h>
+#include <WebCore/FloatPoint3D.h>
+#include <WebCore/FloatRect.h>
+#include <WebCore/FloatRoundedRect.h>
+#include <WebCore/FloatSize.h>
 #include <WebCore/FrameLoaderTypes.h>
 #include <WebCore/IndexedDB.h>
 #include <WebCore/InputMode.h>
+#include <WebCore/IntPoint.h>
+#include <WebCore/IntRect.h>
+#include <WebCore/IntSize.h>
+#include <WebCore/LayoutPoint.h>
+#include <WebCore/LayoutSize.h>
+#include <WebCore/LengthBox.h>
 #include <WebCore/MediaSelectionOption.h>
 #include <WebCore/NativeImage.h>
 #include <WebCore/NetworkLoadMetrics.h>
@@ -96,7 +108,6 @@
 namespace WebCore {
 
 class AbsolutePositionConstraints;
-class AffineTransform;
 class AuthenticationChallenge;
 class BlobPart;
 class CertificateInfo;
@@ -109,21 +120,11 @@
 class File;
 class FilterOperation;
 class FilterOperations;
-class FloatPoint;
-class FloatPoint3D;
-class FloatRect;
-class FloatRoundedRect;
-class FloatSize;
 class FixedPositionViewportConstraints;
 class Font;
 class FontPlatformData;
 class HTTPHeaderMap;
-class IntPoint;
-class IntRect;
-class IntSize;
 class KeyframeValueList;
-class LayoutSize;
-class LayoutPoint;
 class LinearTimingFunction;
 class Notification;
 class PasteboardCustomData;
@@ -174,9 +175,7 @@
 struct VelocityData;
 struct ViewportAttributes;
 struct WindowFeatures;
-    
-template<typename> class RectEdges;
-using FloatBoxExtent = RectEdges<float>;
+
 using IDBKeyPath = Variant<String, Vector<String>>;
 
 #if PLATFORM(COCOA)
@@ -227,11 +226,35 @@
 
 namespace IPC {
 
-template<> struct ArgumentCoder<WebCore::AffineTransform> {
-    static void encode(Encoder&, const WebCore::AffineTransform&);
-    static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::AffineTransform&);
-};
+#define DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(Type) \
+    template<> struct ArgumentCoder<Type> { \
+        template<typename Encoder> static void encode(Encoder&, const Type&); \
+        static WARN_UNUSED_RETURN bool decode(Decoder&, Type&); \
+        static std::optional<Type> decode(Decoder&); \
+    };
 
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(WebCore::AffineTransform)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(WebCore::FloatBoxExtent)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(WebCore::FloatPoint)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(WebCore::FloatPoint3D)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(WebCore::FloatRect)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(WebCore::FloatRoundedRect)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(WebCore::FloatSize)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(WebCore::IntPoint)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(WebCore::IntRect)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(WebCore::IntSize)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(WebCore::LayoutPoint)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(WebCore::LayoutSize)
+
+#if USE(CG)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(CGRect)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(CGSize)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(CGPoint)
+DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER(CGAffineTransform)
+#endif
+
+#undef DEFINE_SIMPLE_ARGUMENT_CODER_FOR_HEADER
+
 template<> struct ArgumentCoder<WebCore::AttributedString> {
     static void encode(Encoder&, const WebCore::AttributedString&);
     static std::optional<WebCore::AttributedString> decode(Decoder&);
@@ -268,6 +291,7 @@
 };
 
 template<> struct ArgumentCoder<WebCore::TransformationMatrix> {
+    template<typename Encoder>
     static void encode(Encoder&, const WebCore::TransformationMatrix&);
     static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::TransformationMatrix&);
 };
@@ -299,43 +323,11 @@
     static std::optional<WebCore::CertificateInfo> decode(Decoder&);
 };
 
-template<> struct ArgumentCoder<WebCore::FloatPoint> {
-    static void encode(Encoder&, const WebCore::FloatPoint&);
-    static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::FloatPoint&);
-    static std::optional<WebCore::FloatPoint> decode(Decoder&);
-};
-
-template<> struct ArgumentCoder<WebCore::FloatPoint3D> {
-    static void encode(Encoder&, const WebCore::FloatPoint3D&);
-    static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::FloatPoint3D&);
-};
-
-template<> struct ArgumentCoder<WebCore::FloatRect> {
-    static void encode(Encoder&, const WebCore::FloatRect&);
-    static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::FloatRect&);
-    static std::optional<WebCore::FloatRect> decode(Decoder&);
-};
-    
-template<> struct ArgumentCoder<WebCore::FloatBoxExtent> {
-    static void encode(Encoder&, const WebCore::FloatBoxExtent&);
-    static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::FloatBoxExtent&);
-};
-
 template<> struct ArgumentCoder<WebCore::RectEdges<bool>> {
     static void encode(Encoder&, const WebCore::RectEdges<bool>&);
     static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::RectEdges<bool>&);
 };
 
-template<> struct ArgumentCoder<WebCore::FloatSize> {
-    static void encode(Encoder&, const WebCore::FloatSize&);
-    static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::FloatSize&);
-};
-
-template<> struct ArgumentCoder<WebCore::FloatRoundedRect> {
-    static void encode(Encoder&, const WebCore::FloatRoundedRect&);
-    static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::FloatRoundedRect&);
-};
-
 #if ENABLE(META_VIEWPORT)
 template<> struct ArgumentCoder<WebCore::ViewportArguments> {
     static void encode(Encoder&, const WebCore::ViewportArguments&);
@@ -350,35 +342,6 @@
     static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::ViewportAttributes&);
 };
 
-template<> struct ArgumentCoder<WebCore::IntPoint> {
-    static void encode(Encoder&, const WebCore::IntPoint&);
-    static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::IntPoint&);
-    static std::optional<WebCore::IntPoint> decode(Decoder&);
-};
-
-template<> struct ArgumentCoder<WebCore::IntRect> {
-    static void encode(Encoder&, const WebCore::IntRect&);
-    static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::IntRect&);
-    static std::optional<WebCore::IntRect> decode(Decoder&);
-};
-
-template<> struct ArgumentCoder<WebCore::IntSize> {
-    template<typename Encoder>
-    static void encode(Encoder&, const WebCore::IntSize&);
-    static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::IntSize&);
-    static std::optional<WebCore::IntSize> decode(Decoder&);
-};
-
-template<> struct ArgumentCoder<WebCore::LayoutSize> {
-    static void encode(Encoder&, const WebCore::LayoutSize&);
-    static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::LayoutSize&);
-};
-
-template<> struct ArgumentCoder<WebCore::LayoutPoint> {
-    static void encode(Encoder&, const WebCore::LayoutPoint&);
-    static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::LayoutPoint&);
-};
-
 template<> struct ArgumentCoder<WebCore::Length> {
     static void encode(Encoder&, const WebCore::Length&);
     static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::Length&);
@@ -457,6 +420,7 @@
 #endif
 
 #if PLATFORM(COCOA)
+
 template<> struct ArgumentCoder<WTF::MachSendRight> {
     static void encode(Encoder&, const WTF::MachSendRight&);
     static void encode(Encoder&, WTF::MachSendRight&&);
@@ -468,27 +432,8 @@
     static std::optional<WebCore::KeypressCommand> decode(Decoder&);
 };
 
-template<> struct ArgumentCoder<CGPoint> {
-    static void encode(Encoder&, CGPoint);
-    static std::optional<CGPoint> decode(Decoder&);
-};
+#endif // PLATFORM(COCOA)
 
-template<> struct ArgumentCoder<CGSize> {
-    static void encode(Encoder&, CGSize);
-    static std::optional<CGSize> decode(Decoder&);
-};
-
-template<> struct ArgumentCoder<CGRect> {
-    static void encode(Encoder&, CGRect);
-    static std::optional<CGRect> decode(Decoder&);
-};
-
-template<> struct ArgumentCoder<CGAffineTransform> {
-    static void encode(Encoder&, CGAffineTransform);
-    static std::optional<CGAffineTransform> decode(Decoder&);
-};
-#endif
-
 #if PLATFORM(IOS_FAMILY)
 template<> struct ArgumentCoder<WebCore::SelectionGeometry> {
     static void encode(Encoder&, const WebCore::SelectionGeometry&);

Modified: trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm (283616 => 283617)


--- trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm	2021-10-06 14:41:52 UTC (rev 283616)
+++ trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm	2021-10-06 14:56:33 UTC (rev 283617)
@@ -321,79 +321,6 @@
     return WTFMove(command);
 }
 
-void ArgumentCoder<CGRect>::encode(Encoder& encoder, CGRect rect)
-{
-    encoder << rect.origin << rect.size;
-}
-
-std::optional<CGRect> ArgumentCoder<CGRect>::decode(Decoder& decoder)
-{
-    std::optional<CGPoint> origin;
-    decoder >> origin;
-    if (!origin)
-        return { };
-
-    std::optional<CGSize> size;
-    decoder >> size;
-    if (!size)
-        return { };
-
-    return CGRect { *origin, *size };
-}
-
-void ArgumentCoder<CGSize>::encode(Encoder& encoder, CGSize size)
-{
-    encoder << size.width << size.height;
-}
-
-std::optional<CGSize> ArgumentCoder<CGSize>::decode(Decoder& decoder)
-{
-    CGSize size;
-    if (!decoder.decode(size.width))
-        return { };
-    if (!decoder.decode(size.height))
-        return { };
-    return size;
-}
-
-void ArgumentCoder<CGPoint>::encode(Encoder& encoder, CGPoint point)
-{
-    encoder << point.x << point.y;
-}
-
-std::optional<CGPoint> ArgumentCoder<CGPoint>::decode(Decoder& decoder)
-{
-    CGPoint point;
-    if (!decoder.decode(point.x))
-        return { };
-    if (!decoder.decode(point.y))
-        return { };
-    return point;
-}
-
-void ArgumentCoder<CGAffineTransform>::encode(Encoder& encoder, CGAffineTransform transform)
-{
-    encoder << transform.a << transform.b << transform.c << transform.d << transform.tx << transform.ty;
-}
-
-std::optional<CGAffineTransform> ArgumentCoder<CGAffineTransform>::decode(Decoder& decoder)
-{
-    CGAffineTransform transform;
-    if (!decoder.decode(transform.a))
-        return { };
-    if (!decoder.decode(transform.b))
-        return { };
-    if (!decoder.decode(transform.c))
-        return { };
-    if (!decoder.decode(transform.d))
-        return { };
-    if (!decoder.decode(transform.tx))
-        return { };
-    if (!decoder.decode(transform.ty))
-        return { };
-    return transform;
-}
-
 #if ENABLE(CONTENT_FILTERING)
 
 void ArgumentCoder<WebCore::ContentFilterUnblockHandler>::encode(Encoder& encoder, const WebCore::ContentFilterUnblockHandler& contentFilterUnblockHandler)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to