Move URL from WebCore to WTF
[WebKit-https.git] / Source / WebKit / Shared / WebCoreArgumentCoders.cpp
index 8860592..66ffe91 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "DataReference.h"
 #include "ShareableBitmap.h"
+#include "SharedBufferDataReference.h"
 #include <WebCore/AuthenticationChallenge.h>
 #include <WebCore/BlobPart.h>
 #include <WebCore/CacheQueryOptions.h>
@@ -45,6 +46,7 @@
 #include <WebCore/FileChooser.h>
 #include <WebCore/FilterOperation.h>
 #include <WebCore/FilterOperations.h>
+#include <WebCore/FontAttributes.h>
 #include <WebCore/GraphicsContext.h>
 #include <WebCore/GraphicsLayer.h>
 #include <WebCore/IDBGetResult.h>
@@ -68,6 +70,7 @@
 #include <WebCore/ScrollingCoordinator.h>
 #include <WebCore/SearchPopupMenu.h>
 #include <WebCore/SecurityOrigin.h>
+#include <WebCore/SerializedAttachmentData.h>
 #include <WebCore/ServiceWorkerClientData.h>
 #include <WebCore/ServiceWorkerClientIdentifier.h>
 #include <WebCore/ServiceWorkerData.h>
 #include <WebCore/TextIndicator.h>
 #include <WebCore/TimingFunction.h>
 #include <WebCore/TransformationMatrix.h>
-#include <WebCore/URL.h>
 #include <WebCore/UserStyleSheet.h>
 #include <WebCore/ViewportArguments.h>
 #include <WebCore/WindowFeatures.h>
 #include <pal/SessionID.h>
+#include <wtf/URL.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/StringHash.h>
 
 #include "ArgumentCodersMac.h"
 #endif
 
-#if PLATFORM(IOS)
+#if PLATFORM(IOS_FAMILY)
 #include <WebCore/FloatQuad.h>
 #include <WebCore/InspectorOverlay.h>
 #include <WebCore/SelectionRect.h>
 #include <WebCore/SharedBuffer.h>
-#endif // PLATFORM(IOS)
+#endif // PLATFORM(IOS_FAMILY)
 
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
 #include <WebCore/MediaPlaybackTargetContext.h>
@@ -504,25 +507,6 @@ bool ArgumentCoder<StepsTimingFunction>::decode(Decoder& decoder, StepsTimingFun
     return true;
 }
 
-void ArgumentCoder<FramesTimingFunction>::encode(Encoder& encoder, const FramesTimingFunction& timingFunction)
-{
-    encoder.encodeEnum(timingFunction.type());
-    
-    encoder << timingFunction.numberOfFrames();
-}
-
-bool ArgumentCoder<FramesTimingFunction>::decode(Decoder& decoder, FramesTimingFunction& timingFunction)
-{
-    // Type is decoded by the caller.
-    int numFrames;
-    if (!decoder.decode(numFrames))
-        return false;
-
-    timingFunction.setNumberOfFrames(numFrames);
-
-    return true;
-}
-
 void ArgumentCoder<SpringTimingFunction>::encode(Encoder& encoder, const SpringTimingFunction& timingFunction)
 {
     encoder.encodeEnum(timingFunction.type());
@@ -637,7 +621,7 @@ bool ArgumentCoder<FloatRoundedRect>::decode(Decoder& decoder, FloatRoundedRect&
     return SimpleArgumentCoder<FloatRoundedRect>::decode(decoder, roundedRect);
 }
 
-#if PLATFORM(IOS)
+#if PLATFORM(IOS_FAMILY)
 void ArgumentCoder<FloatQuad>::encode(Encoder& encoder, const FloatQuad& floatQuad)
 {
     SimpleArgumentCoder<FloatQuad>::encode(encoder, floatQuad);
@@ -668,7 +652,7 @@ std::optional<ViewportArguments> ArgumentCoder<ViewportArguments>::decode(Decode
         return std::nullopt;
     return WTFMove(viewportArguments);
 }
-#endif // PLATFORM(IOS)
+#endif // PLATFORM(IOS_FAMILY)
 
 
 void ArgumentCoder<IntPoint>::encode(Encoder& encoder, const IntPoint& intPoint)
@@ -1178,7 +1162,7 @@ static bool decodeOptionalImage(Decoder& decoder, RefPtr<Image>& image)
     return decodeImage(decoder, image);
 }
 
-#if !PLATFORM(IOS)
+#if !PLATFORM(IOS_FAMILY)
 void ArgumentCoder<Cursor>::encode(Encoder& encoder, const Cursor& cursor)
 {
     encoder.encodeEnum(cursor.type());
@@ -1334,7 +1318,7 @@ bool ArgumentCoder<ResourceError>::decode(Decoder& decoder, ResourceError& resou
     return true;
 }
 
-#if PLATFORM(IOS)
+#if PLATFORM(IOS_FAMILY)
 
 void ArgumentCoder<SelectionRect>::encode(Encoder& encoder, const SelectionRect& selectionRect)
 {
@@ -1730,7 +1714,7 @@ bool ArgumentCoder<PasteboardURL>::decode(Decoder& decoder, PasteboardURL& conte
     return true;
 }
 
-#if PLATFORM(IOS)
+#if PLATFORM(IOS_FAMILY)
 
 void ArgumentCoder<Highlight>::encode(Encoder& encoder, const Highlight& highlight)
 {
@@ -1842,7 +1826,7 @@ bool ArgumentCoder<PasteboardImage>::decode(Decoder& decoder, PasteboardImage& p
 
 #endif
 
-#if PLATFORM(WPE)
+#if USE(LIBWPE)
 void ArgumentCoder<PasteboardWebContent>::encode(Encoder& encoder, const PasteboardWebContent& content)
 {
     encoder << content.text;
@@ -1857,7 +1841,7 @@ bool ArgumentCoder<PasteboardWebContent>::decode(Decoder& decoder, PasteboardWeb
         return false;
     return true;
 }
-#endif // PLATFORM(WPE)
+#endif // USE(LIBWPE)
 
 void ArgumentCoder<DictationAlternative>::encode(Encoder& encoder, const DictationAlternative& dictationAlternative)
 {
@@ -2760,7 +2744,6 @@ void ArgumentCoder<MediaConstraints>::encode(Encoder& encoder, const WebCore::Me
 {
     encoder << constraint.mandatoryConstraints
         << constraint.advancedConstraints
-        << constraint.deviceIDHashSalt
         << constraint.isValid;
 }
 
@@ -2772,7 +2755,6 @@ bool ArgumentCoder<MediaConstraints>::decode(Decoder& decoder, WebCore::MediaCon
         return false;
     constraints.mandatoryConstraints = WTFMove(*mandatoryConstraints);
     return decoder.decode(constraints.advancedConstraints)
-        && decoder.decode(constraints.deviceIDHashSalt)
         && decoder.decode(constraints.isValid);
 }
 #endif
@@ -2979,4 +2961,83 @@ bool ArgumentCoder<Vector<RefPtr<SecurityOrigin>>>::decode(Decoder& decoder, Vec
     return true;
 }
 
+void ArgumentCoder<FontAttributes>::encode(Encoder& encoder, const FontAttributes& attributes)
+{
+    encoder << attributes.backgroundColor << attributes.foregroundColor << attributes.fontShadow << attributes.hasUnderline << attributes.hasStrikeThrough << attributes.textLists;
+    encoder.encodeEnum(attributes.horizontalAlignment);
+    encoder.encodeEnum(attributes.subscriptOrSuperscript);
+#if PLATFORM(COCOA)
+    bool hasFont = attributes.font;
+    encoder << hasFont;
+    if (hasFont)
+        IPC::encode(encoder, attributes.font.get());
+#endif
+}
+
+std::optional<FontAttributes> ArgumentCoder<FontAttributes>::decode(Decoder& decoder)
+{
+    FontAttributes attributes;
+
+    if (!decoder.decode(attributes.backgroundColor))
+        return std::nullopt;
+
+    if (!decoder.decode(attributes.foregroundColor))
+        return std::nullopt;
+
+    if (!decoder.decode(attributes.fontShadow))
+        return std::nullopt;
+
+    if (!decoder.decode(attributes.hasUnderline))
+        return std::nullopt;
+
+    if (!decoder.decode(attributes.hasStrikeThrough))
+        return std::nullopt;
+
+    if (!decoder.decode(attributes.textLists))
+        return std::nullopt;
+
+    if (!decoder.decodeEnum(attributes.horizontalAlignment))
+        return std::nullopt;
+
+    if (!decoder.decodeEnum(attributes.subscriptOrSuperscript))
+        return std::nullopt;
+
+#if PLATFORM(COCOA)
+    bool hasFont = false;
+    if (!decoder.decode(hasFont))
+        return std::nullopt;
+
+    if (hasFont && !IPC::decode(decoder, attributes.font))
+        return std::nullopt;
+#endif
+
+    return attributes;
+}
+
+#if ENABLE(ATTACHMENT_ELEMENT)
+
+void ArgumentCoder<SerializedAttachmentData>::encode(IPC::Encoder& encoder, const WebCore::SerializedAttachmentData& data)
+{
+    encoder << data.identifier << data.mimeType << IPC::SharedBufferDataReference { data.data.get() };
+}
+
+std::optional<SerializedAttachmentData> ArgumentCoder<WebCore::SerializedAttachmentData>::decode(IPC::Decoder& decoder)
+{
+    String identifier;
+    if (!decoder.decode(identifier))
+        return std::nullopt;
+
+    String mimeType;
+    if (!decoder.decode(mimeType))
+        return std::nullopt;
+
+    IPC::DataReference data;
+    if (!decoder.decode(data))
+        return std::nullopt;
+
+    return {{ WTFMove(identifier), WTFMove(mimeType), WebCore::SharedBuffer::create(data.data(), data.size()) }};
+}
+
+#endif // ENABLE(ATTACHMENT_ELEMENT)
+
 } // namespace IPC