Title: [242908] trunk/Source
Revision
242908
Author
timo...@apple.com
Date
2019-03-13 14:18:34 -0700 (Wed, 13 Mar 2019)

Log Message

Consolidate ArgumentCodersMac and ArgumentCodersCocoa.
https://bugs.webkit.org/show_bug.cgi?id=195636
rdar://problem/45055697

Reviewed by Ryosuke Niwa.

Source/WebCore:

* editing/DictionaryPopupInfo.h:
(WebCore::DictionaryPopupInfo::encodingRequiresPlatformData const): Added.
* editing/FontAttributes.h:
(WebCore::FontAttributes::encodingRequiresPlatformData const): Added.

Source/WebKit:

Merge the two similar encoders and decoders. This avoids issues where
one encoder could be used and the other decoder, which caused a crash.
It also stops handling NSAttributedString specifically and just uses
the NSSecureCoding path to handle more complex attributes.

Some WebCore encoders code needed to move to platform files, since
ArgumentCodersCocoa.h requires an ObjectiveC++ implementation to work.

* Shared/Cocoa/ArgumentCodersCocoa.h:
(IPC::encode):
(IPC::decode):
(IPC::ArgumentCoder<RetainPtr<T>>::encode):
(IPC::ArgumentCoder<RetainPtr<T>>::decode):
* Shared/Cocoa/ArgumentCodersCocoa.mm:
(IPC::typeFromObject):
(IPC::isSerializableFont):
(IPC::isSerializableValue):
(IPC::encodeObject):
(IPC::decodeObject):
* Shared/Cocoa/LoadParametersCocoa.mm:
* Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
(IPC::ArgumentCoder<WebCore::DictionaryPopupInfo>::encodePlatformData):
(IPC::ArgumentCoder<WebCore::DictionaryPopupInfo>::decodePlatformData):
(IPC::ArgumentCoder<WebCore::FontAttributes>::encodePlatformData):
(IPC::ArgumentCoder<WebCore::FontAttributes>::decodePlatformData):
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<DictionaryPopupInfo>::encode):
(IPC::ArgumentCoder<DictionaryPopupInfo>::decode):
(IPC::ArgumentCoder<FontAttributes>::encode):
(IPC::ArgumentCoder<FontAttributes>::decode):
* Shared/WebCoreArgumentCoders.h:
* Shared/mac/ArgumentCodersMac.h: Removed.
* Shared/mac/ArgumentCodersMac.mm: Removed.
* Shared/mac/AttributedString.mm:
(WebKit::AttributedString::encode const):
* Shared/mac/ObjCObjectGraph.mm:
* SourcesCocoa.txt:
* WebKit.xcodeproj/project.pbxproj:

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (242907 => 242908)


--- trunk/Source/WebCore/ChangeLog	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebCore/ChangeLog	2019-03-13 21:18:34 UTC (rev 242908)
@@ -1,3 +1,16 @@
+2019-03-13  Timothy Hatcher  <timo...@apple.com>
+
+        Consolidate ArgumentCodersMac and ArgumentCodersCocoa.
+        https://bugs.webkit.org/show_bug.cgi?id=195636
+        rdar://problem/45055697
+
+        Reviewed by Ryosuke Niwa.
+
+        * editing/DictionaryPopupInfo.h:
+        (WebCore::DictionaryPopupInfo::encodingRequiresPlatformData const): Added.
+        * editing/FontAttributes.h:
+        (WebCore::FontAttributes::encodingRequiresPlatformData const): Added.
+
 2019-03-13  Chris Dumez  <cdu...@apple.com>
 
         Unreviewed build fix after r242901.

Modified: trunk/Source/WebCore/editing/DictionaryPopupInfo.h (242907 => 242908)


--- trunk/Source/WebCore/editing/DictionaryPopupInfo.h	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebCore/editing/DictionaryPopupInfo.h	2019-03-13 21:18:34 UTC (rev 242908)
@@ -40,6 +40,10 @@
 #if PLATFORM(COCOA)
     RetainPtr<NSDictionary> options;
     RetainPtr<NSAttributedString> attributedString;
+
+    bool encodingRequiresPlatformData() const { return true; }
+#else
+    bool encodingRequiresPlatformData() const { return false; }
 #endif
 };
 

Modified: trunk/Source/WebCore/editing/FontAttributes.h (242907 => 242908)


--- trunk/Source/WebCore/editing/FontAttributes.h	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebCore/editing/FontAttributes.h	2019-03-13 21:18:34 UTC (rev 242908)
@@ -79,7 +79,11 @@
     enum class HorizontalAlignment : uint8_t { Left, Center, Right, Justify, Natural };
 
 #if PLATFORM(COCOA)
+    bool encodingRequiresPlatformData() const { return true; }
+
     WEBCORE_EXPORT RetainPtr<NSDictionary> createDictionary() const;
+#else
+    bool encodingRequiresPlatformData() const { return false; }
 #endif
 
 #if PLATFORM(MAC)

Modified: trunk/Source/WebKit/ChangeLog (242907 => 242908)


--- trunk/Source/WebKit/ChangeLog	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/ChangeLog	2019-03-13 21:18:34 UTC (rev 242908)
@@ -1,3 +1,50 @@
+2019-03-13  Timothy Hatcher  <timo...@apple.com>
+
+        Consolidate ArgumentCodersMac and ArgumentCodersCocoa.
+        https://bugs.webkit.org/show_bug.cgi?id=195636
+        rdar://problem/45055697
+
+        Reviewed by Ryosuke Niwa.
+
+        Merge the two similar encoders and decoders. This avoids issues where
+        one encoder could be used and the other decoder, which caused a crash.
+        It also stops handling NSAttributedString specifically and just uses
+        the NSSecureCoding path to handle more complex attributes.
+
+        Some WebCore encoders code needed to move to platform files, since
+        ArgumentCodersCocoa.h requires an ObjectiveC++ implementation to work.
+
+        * Shared/Cocoa/ArgumentCodersCocoa.h:
+        (IPC::encode):
+        (IPC::decode):
+        (IPC::ArgumentCoder<RetainPtr<T>>::encode):
+        (IPC::ArgumentCoder<RetainPtr<T>>::decode):
+        * Shared/Cocoa/ArgumentCodersCocoa.mm:
+        (IPC::typeFromObject):
+        (IPC::isSerializableFont):
+        (IPC::isSerializableValue):
+        (IPC::encodeObject):
+        (IPC::decodeObject):
+        * Shared/Cocoa/LoadParametersCocoa.mm:
+        * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
+        (IPC::ArgumentCoder<WebCore::DictionaryPopupInfo>::encodePlatformData):
+        (IPC::ArgumentCoder<WebCore::DictionaryPopupInfo>::decodePlatformData):
+        (IPC::ArgumentCoder<WebCore::FontAttributes>::encodePlatformData):
+        (IPC::ArgumentCoder<WebCore::FontAttributes>::decodePlatformData):
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<DictionaryPopupInfo>::encode):
+        (IPC::ArgumentCoder<DictionaryPopupInfo>::decode):
+        (IPC::ArgumentCoder<FontAttributes>::encode):
+        (IPC::ArgumentCoder<FontAttributes>::decode):
+        * Shared/WebCoreArgumentCoders.h:
+        * Shared/mac/ArgumentCodersMac.h: Removed.
+        * Shared/mac/ArgumentCodersMac.mm: Removed.
+        * Shared/mac/AttributedString.mm:
+        (WebKit::AttributedString::encode const):
+        * Shared/mac/ObjCObjectGraph.mm:
+        * SourcesCocoa.txt:
+        * WebKit.xcodeproj/project.pbxproj:
+
 2019-03-13  Chris Dumez  <cdu...@apple.com>
 
         Use a ServiceWorker process per registrable domain

Modified: trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.h (242907 => 242908)


--- trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.h	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.h	2019-03-13 21:18:34 UTC (rev 242908)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2018, 2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -31,17 +31,14 @@
 
 namespace IPC {
 
-void encodeObject(Encoder&, id <NSSecureCoding>);
-Optional<RetainPtr<id <NSSecureCoding>>> decodeObject(Decoder&, NSArray<Class> *allowedClasses);
+void encodeObject(Encoder&, id);
+Optional<RetainPtr<id>> decodeObject(Decoder&, NSArray<Class> *allowedClasses);
 
-template<typename T> Optional<RetainPtr<T>> decode(Decoder&, Class allowedClass);
-template<typename T> Optional<RetainPtr<T>> decode(Decoder&, NSArray<Class> *allowedClasses = @[ [T class] ]);
+template<typename T> using IsObjCObject = std::enable_if_t<std::is_convertible<T *, id>::value, T *>;
 
-template<typename T>
-Optional<RetainPtr<T>> decode(Decoder& decoder, Class allowedClass)
-{
-    return decode<T>(decoder, @[ allowedClass ]);
-}
+template<typename T, typename = IsObjCObject<T>> void encode(Encoder&, T *);
+template<typename T, typename = IsObjCObject<T>> bool decode(Decoder&, RetainPtr<T>&, NSArray<Class> *allowedClasses = @[ [T class] ]);
+template<typename T, typename = IsObjCObject<T>> Optional<RetainPtr<T>> decode(Decoder&, NSArray<Class> *allowedClasses = @[ [T class] ]);
 
 #ifndef NDEBUG
 
@@ -56,25 +53,35 @@
 
 #endif
 
-template<typename T>
+template<typename T, typename>
+void encode(Encoder& encoder, T *object)
+{
+    encodeObject(encoder, object);
+}
+
+template<typename T, typename>
+bool decode(Decoder& decoder, RetainPtr<T>& result, NSArray<Class> *allowedClasses)
+{
+    auto object = decodeObject(decoder, allowedClasses);
+    if (!object)
+        return false;
+    result = *object;
+    ASSERT(!*object || isObjectClassAllowed((*object).get(), allowedClasses));
+    return true;
+}
+
+template<typename T, typename>
 Optional<RetainPtr<T>> decode(Decoder& decoder, NSArray<Class> *allowedClasses)
 {
     auto result = decodeObject(decoder, allowedClasses);
     if (!result)
         return WTF::nullopt;
-
-    if (!*result)
-        return { nullptr };
-
-    id object = result->leakRef();
-    ASSERT(isObjectClassAllowed(object, allowedClasses));
-    return { adoptNS(static_cast<T *>(object)) };
+    ASSERT(!*result || isObjectClassAllowed((*result).get(), allowedClasses));
+    return { *result };
 }
 
-template<typename T> using ConformsToSecureCoding = std::is_convertible<T *, id <NSSecureCoding>>;
-
 template<typename T> struct ArgumentCoder<T *> {
-    template<typename U = T, std::enable_if_t<ConformsToSecureCoding<U>::value>* = nullptr>
+    template<typename U = T, typename = IsObjCObject<U>>
     static void encode(Encoder& encoder, U *object)
     {
         encodeObject(encoder, object);
@@ -82,13 +89,13 @@
 };
 
 template<typename T> struct ArgumentCoder<RetainPtr<T>> {
-    template <typename U = T, std::enable_if_t<ConformsToSecureCoding<U>::value>* = nullptr>
+    template<typename U = T, typename = IsObjCObject<U>>
     static void encode(Encoder& encoder, const RetainPtr<U>& object)
     {
         ArgumentCoder<U *>::encode(encoder, object.get());
     }
 
-    template <typename U = T, std::enable_if_t<ConformsToSecureCoding<U>::value>* = nullptr>
+    template<typename U = T, typename = IsObjCObject<U>>
     static Optional<RetainPtr<U>> decode(Decoder& decoder)
     {
         return IPC::decode<U>(decoder);

Modified: trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm (242907 => 242908)


--- trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm	2019-03-13 21:18:34 UTC (rev 242908)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2018, 2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,21 +29,294 @@
 #if PLATFORM(COCOA)
 
 #import "ArgumentCodersCF.h"
+#import <CoreText/CTFont.h>
+#import <CoreText/CTFontDescriptor.h>
 #import <pal/spi/cocoa/NSKeyedArchiverSPI.h>
+#import <wtf/HashSet.h>
 
+#if USE(APPKIT)
+#import <WebCore/ColorMac.h>
+#endif
+
+#if USE(APPKIT)
+#define PlatformFont NSFont
+#define PlatformFontDescriptor NSFontDescriptor
+#else
+#define PlatformFont UIFont
+#define PlatformFontDescriptor UIFontDescriptor
+#endif
+
 namespace IPC {
+using namespace WebCore;
 
-void encodeObject(Encoder& encoder, id <NSSecureCoding> object)
+#pragma mark - Types
+
+enum class NSType {
+    Array,
+#if USE(APPKIT)
+    Color,
+#endif
+    Data,
+    Date,
+    Dictionary,
+    Font,
+    Number,
+    SecureCoding,
+    String,
+    URL,
+    Unknown,
+};
+
+#pragma mark - Helpers
+
+static NSType typeFromObject(id object)
 {
+    ASSERT(object);
+
+    // Specific classes handled.
+    if ([object isKindOfClass:[NSArray class]])
+        return NSType::Array;
+#if USE(APPKIT)
+    if ([object isKindOfClass:[NSColor class]])
+        return NSType::Color;
+#endif
+    if ([object isKindOfClass:[NSData class]])
+        return NSType::Data;
+    if ([object isKindOfClass:[NSDate class]])
+        return NSType::Date;
+    if ([object isKindOfClass:[NSDictionary class]])
+        return NSType::Dictionary;
+    if ([object isKindOfClass:[PlatformFont class]])
+        return NSType::Font;
+    if ([object isKindOfClass:[NSNumber class]])
+        return NSType::Number;
+    if ([object isKindOfClass:[NSString class]])
+        return NSType::String;
+    if ([object isKindOfClass:[NSURL class]])
+        return NSType::URL;
+
+    // Check NSSecureCoding after the specific cases since
+    // most of the classes above conform to NSSecureCoding,
+    // and we want our special case coders for them instead.
+    if ([object conformsToProtocol:@protocol(NSSecureCoding)])
+        return NSType::SecureCoding;
+
+    ASSERT_NOT_REACHED();
+    return NSType::Unknown;
+}
+
+static inline bool isSerializableFont(CTFontRef font)
+{
+    return adoptCF(CTFontCopyAttribute(font, kCTFontURLAttribute));
+}
+
+static inline bool isSerializableValue(id value)
+{
+    if ([value isKindOfClass:[PlatformFont class]])
+        return isSerializableFont((__bridge CTFontRef)value);
+    return typeFromObject(value) != NSType::Unknown;
+}
+
+#pragma mark - NSArray
+
+static void encodeArrayInternal(Encoder& encoder, NSArray *array)
+{
+    // Even though NSArray is toll free bridged with CFArrayRef, values may not be,
+    // so we should stay within this file's code.
+
+    if (!array.count) {
+        encoder << static_cast<uint64_t>(0);
+        return;
+    }
+
+    HashSet<NSUInteger> invalidIndicies;
+    for (NSUInteger i = 0; i < array.count; ++i) {
+        id value = array[i];
+
+        // Ignore values we don't support.
+        ASSERT(isSerializableValue(value));
+        if (!isSerializableValue(value))
+            invalidIndicies.add(i);
+    }
+
+    encoder << static_cast<uint64_t>(array.count - invalidIndicies.size());
+
+    for (NSUInteger i = 0; i < array.count; ++i) {
+        if (invalidIndicies.contains(i))
+            continue;
+        encodeObject(encoder, array[i]);
+    }
+}
+
+static Optional<RetainPtr<id>> decodeArrayInternal(Decoder& decoder)
+{
+    uint64_t size;
+    if (!decoder.decode(size))
+        return WTF::nullopt;
+
+    RetainPtr<NSMutableArray> array = adoptNS([[NSMutableArray alloc] initWithCapacity:size]);
+    for (uint64_t i = 0; i < size; ++i) {
+        auto value = decodeObject(decoder, nil);
+        if (!value)
+            return WTF::nullopt;
+        [array addObject:value.value().get()];
+    }
+
+    return { array };
+}
+
+#pragma mark - NSColor
+
+#if USE(APPKIT)
+static inline void encodeColorInternal(Encoder& encoder, NSColor *color)
+{
+    encoder << colorFromNSColor(color);
+}
+
+static inline Optional<RetainPtr<id>> decodeColorInternal(Decoder& decoder)
+{
+    Color color;
+    if (!decoder.decode(color))
+        return WTF::nullopt;
+    return { nsColor(color) };
+}
+#endif
+
+#pragma mark - NSData
+
+static inline void encodeDataInternal(Encoder& encoder, NSData *data)
+{
+    encode(encoder, (__bridge CFDataRef)data);
+}
+
+static inline Optional<RetainPtr<id>> decodeDataInternal(Decoder& decoder)
+{
+    RetainPtr<CFDataRef> data;
+    if (!decode(decoder, data))
+        return WTF::nullopt;
+    return { adoptNS((NSData *)data.leakRef()) };
+}
+
+#pragma mark - NSDate
+
+static inline void encodeDateInternal(Encoder& encoder, NSDate *date)
+{
+    encode(encoder, (__bridge CFDateRef)date);
+}
+
+static inline Optional<RetainPtr<id>> decodeDateInternal(Decoder& decoder)
+{
+    RetainPtr<CFDateRef> date;
+    if (!decode(decoder, date))
+        return WTF::nullopt;
+    return { adoptNS((NSDate *)date.leakRef()) };
+}
+
+#pragma mark - NSDictionary
+
+static void encodeDictionaryInternal(Encoder& encoder, NSDictionary *dictionary)
+{
+    // Even though NSDictionary is toll free bridged with CFDictionaryRef, keys/values may not be,
+    // so we should stay within this file's code.
+
+    if (!dictionary.count) {
+        encoder << static_cast<uint64_t>(0);
+        return;
+    }
+
+    HashSet<id> invalidKeys;
+    for (id key in dictionary) {
+        id value = dictionary[key];
+        ASSERT(value);
+
+        // Ignore values we don't support.
+        ASSERT(isSerializableValue(key));
+        ASSERT(isSerializableValue(value));
+        if (!isSerializableValue(key) || !isSerializableValue(value))
+            invalidKeys.add(key);
+    }
+
+    encoder << static_cast<uint64_t>(dictionary.count - invalidKeys.size());
+
+    for (id key in dictionary) {
+        if (invalidKeys.contains(key))
+            continue;
+        encodeObject(encoder, key);
+        encodeObject(encoder, dictionary[key]);
+    }
+}
+
+static Optional<RetainPtr<id>> decodeDictionaryInternal(Decoder& decoder)
+{
+    uint64_t size;
+    if (!decoder.decode(size))
+        return WTF::nullopt;
+
+    RetainPtr<NSMutableDictionary> dictionary = adoptNS([[NSMutableDictionary alloc] initWithCapacity:size]);
+    for (uint64_t i = 0; i < size; ++i) {
+        auto key = decodeObject(decoder, nil);
+        if (!key)
+            return WTF::nullopt;
+
+        auto value = decodeObject(decoder, nil);
+        if (!value)
+            return WTF::nullopt;
+
+        [dictionary setObject:value.value().get() forKey:key.value().get()];
+    }
+
+    return { dictionary };
+}
+
+#pragma mark - NSFont / UIFont
+
+static inline void encodeFontInternal(Encoder& encoder, PlatformFont *font)
+{
+    encode(encoder, font.fontDescriptor.fontAttributes);
+}
+
+static Optional<RetainPtr<id>> decodeFontInternal(Decoder& decoder)
+{
+    RetainPtr<NSDictionary> fontAttributes;
+    if (!decode(decoder, fontAttributes))
+        return WTF::nullopt;
+
+    PlatformFontDescriptor *fontDescriptor = [PlatformFontDescriptor fontDescriptorWithFontAttributes:fontAttributes.get()];
+    return { [PlatformFont fontWithDescriptor:fontDescriptor size:0] };
+}
+
+#pragma mark - NSNumber
+
+static inline void encodeNumberInternal(Encoder& encoder, NSNumber *number)
+{
+    encode(encoder, (__bridge CFNumberRef)number);
+}
+
+static inline Optional<RetainPtr<id>> decodeNumberInternal(Decoder& decoder)
+{
+    RetainPtr<CFNumberRef> number;
+    if (!decode(decoder, number))
+        return WTF::nullopt;
+    return { adoptNS((NSNumber *)number.leakRef()) };
+}
+
+#pragma mark - id <NSSecureCoding>
+
+static void encodeSecureCodingInternal(Encoder& encoder, id <NSObject, NSSecureCoding> object)
+{
     auto archiver = secureArchiver();
     [archiver encodeObject:object forKey:NSKeyedArchiveRootObjectKey];
     [archiver finishEncoding];
 
-    IPC::encode(encoder, (__bridge CFDataRef)[archiver encodedData]);
+    encode(encoder, (__bridge CFDataRef)[archiver encodedData]);
 }
 
-Optional<RetainPtr<id <NSSecureCoding>>> decodeObject(Decoder& decoder, NSArray<Class> *allowedClasses)
+static Optional<RetainPtr<id>> decodeSecureCodingInternal(Decoder& decoder, NSArray<Class> *allowedClasses)
 {
+    ASSERT(allowedClasses && allowedClasses.count);
+    if (!allowedClasses || !allowedClasses.count)
+        return WTF::nullopt;
+
     RetainPtr<CFDataRef> data;
     if (!decode(decoder, data))
         return WTF::nullopt;
@@ -61,6 +334,156 @@
     }
 }
 
+#pragma mark - NSString
+
+static inline void encodeStringInternal(Encoder& encoder, NSString *string)
+{
+    encode(encoder, (__bridge CFStringRef)string);
+}
+
+static inline Optional<RetainPtr<id>> decodeStringInternal(Decoder& decoder)
+{
+    RetainPtr<CFStringRef> string;
+    if (!decode(decoder, string))
+        return WTF::nullopt;
+    return { adoptNS((NSString *)string.leakRef()) };
+}
+
+#pragma mark - NSURL
+
+static inline void encodeURLInternal(Encoder& encoder, NSURL *URL)
+{
+    encode(encoder, (__bridge CFURLRef)URL);
+}
+
+static inline Optional<RetainPtr<id>> decodeURLInternal(Decoder& decoder)
+{
+    RetainPtr<CFURLRef> URL;
+    if (!decode(decoder, URL))
+        return WTF::nullopt;
+    return { adoptNS((NSURL *)URL.leakRef()) };
+}
+
+#pragma mark - Entry Point Encoder / Decoder
+
+void encodeObject(Encoder& encoder, id object)
+{
+    encoder << static_cast<bool>(!object);
+    if (!object)
+        return;
+
+    NSType type = typeFromObject(object);
+    encoder << type;
+
+    switch (type) {
+    case NSType::Array:
+        encodeArrayInternal(encoder, static_cast<NSArray *>(object));
+        return;
+#if USE(APPKIT)
+    case NSType::Color:
+        encodeColorInternal(encoder, static_cast<NSColor *>(object));
+        return;
+#endif
+    case NSType::Dictionary:
+        encodeDictionaryInternal(encoder, static_cast<NSDictionary *>(object));
+        return;
+    case NSType::Font:
+        encodeFontInternal(encoder, static_cast<PlatformFont *>(object));
+        return;
+    case NSType::Number:
+        encodeNumberInternal(encoder, static_cast<NSNumber *>(object));
+        return;
+    case NSType::SecureCoding:
+        encodeSecureCodingInternal(encoder, static_cast<id <NSObject, NSSecureCoding>>(object));
+        return;
+    case NSType::String:
+        encodeStringInternal(encoder, static_cast<NSString *>(object));
+        return;
+    case NSType::Date:
+        encodeDateInternal(encoder, static_cast<NSDate *>(object));
+        return;
+    case NSType::Data:
+        encodeDataInternal(encoder, static_cast<NSData *>(object));
+        return;
+    case NSType::URL:
+        encodeURLInternal(encoder, static_cast<NSURL *>(object));
+        return;
+    case NSType::Unknown:
+        break;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
+Optional<RetainPtr<id>> decodeObject(Decoder& decoder, NSArray<Class> *allowedClasses)
+{
+    bool isNull;
+    if (!decoder.decode(isNull))
+        return WTF::nullopt;
+    if (isNull)
+        return { nullptr };
+
+    NSType type;
+    if (!decoder.decodeEnum(type))
+        return WTF::nullopt;
+
+    switch (type) {
+    case NSType::Array:
+        return decodeArrayInternal(decoder);
+#if USE(APPKIT)
+    case NSType::Color:
+        return decodeColorInternal(decoder);
+#endif
+    case NSType::Dictionary:
+        return decodeDictionaryInternal(decoder);
+#if USE(APPKIT)
+    case NSType::Font:
+        return decodeFontInternal(decoder);
+#else
+    case NSType::Font:
+        return decodeFontInternal(decoder);
+#endif
+    case NSType::Number:
+        return decodeNumberInternal(decoder);
+    case NSType::SecureCoding:
+        return decodeSecureCodingInternal(decoder, allowedClasses);
+    case NSType::String:
+        return decodeStringInternal(decoder);
+    case NSType::Date:
+        return decodeDateInternal(decoder);
+    case NSType::Data:
+        return decodeDataInternal(decoder);
+    case NSType::URL:
+        return decodeURLInternal(decoder);
+    case NSType::Unknown:
+        break;
+    }
+
+    ASSERT_NOT_REACHED();
+    return WTF::nullopt;
+}
+
 } // namespace IPC
 
+namespace WTF {
+template<> struct EnumTraits<IPC::NSType> {
+    using values = EnumValues<
+        IPC::NSType,
+        IPC::NSType::Array,
+#if USE(APPKIT)
+        IPC::NSType::Color,
+#endif
+        IPC::NSType::Data,
+        IPC::NSType::Date,
+        IPC::NSType::Dictionary,
+        IPC::NSType::Font,
+        IPC::NSType::Number,
+        IPC::NSType::SecureCoding,
+        IPC::NSType::String,
+        IPC::NSType::URL,
+        IPC::NSType::Unknown
+    >;
+};
+} // namespace WTF
+
 #endif // PLATFORM(COCOA)

Modified: trunk/Source/WebKit/Shared/Cocoa/LoadParametersCocoa.mm (242907 => 242908)


--- trunk/Source/WebKit/Shared/Cocoa/LoadParametersCocoa.mm	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/Shared/Cocoa/LoadParametersCocoa.mm	2019-03-13 21:18:34 UTC (rev 242908)
@@ -28,7 +28,7 @@
 
 #if PLATFORM(COCOA)
 
-#include "ArgumentCodersMac.h"
+#include "ArgumentCodersCocoa.h"
 #include "WebCoreArgumentCoders.h"
 
 namespace WebKit {

Modified: trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm (242907 => 242908)


--- trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm	2019-03-13 21:18:34 UTC (rev 242908)
@@ -26,17 +26,24 @@
 #import "config.h"
 #import "WebCoreArgumentCoders.h"
 
+#import "ArgumentCodersCocoa.h"
+#import <WebCore/DictionaryPopupInfo.h>
+#import <WebCore/FontAttributes.h>
+
 #if ENABLE(APPLE_PAY)
 
-#import "ArgumentCodersCocoa.h"
 #import "DataReference.h"
 #import <WebCore/PaymentAuthorizationStatus.h>
 #import <pal/cocoa/PassKitSoftLink.h>
 #import <pal/spi/cocoa/NSKeyedArchiverSPI.h>
 
+#endif
+
 namespace IPC {
 using namespace WebCore;
 
+#if ENABLE(APPLE_PAY)
+
 void ArgumentCoder<WebCore::Payment>::encode(Encoder& encoder, const WebCore::Payment& payment)
 {
     encoder << payment.pkPayment();
@@ -408,5 +415,32 @@
     return {{ WTFMove(*newTotalAndLineItems) }};
 }
 
+#endif // ENABLE(APPLEPAY)
+
+void ArgumentCoder<WebCore::DictionaryPopupInfo>::encodePlatformData(Encoder& encoder, const WebCore::DictionaryPopupInfo& info)
+{
+    encoder << info.options << info.attributedString;
 }
-#endif
+
+bool ArgumentCoder<WebCore::DictionaryPopupInfo>::decodePlatformData(Decoder& decoder, WebCore::DictionaryPopupInfo& result)
+{
+    if (!IPC::decode(decoder, result.options))
+        return false;
+    if (!IPC::decode(decoder, result.attributedString))
+        return false;
+    return true;
+}
+
+void ArgumentCoder<WebCore::FontAttributes>::encodePlatformData(Encoder& encoder, const WebCore::FontAttributes& attributes)
+{
+    encoder << attributes.font;
+}
+
+Optional<FontAttributes> ArgumentCoder<WebCore::FontAttributes>::decodePlatformData(Decoder& decoder, WebCore::FontAttributes& attributes)
+{
+    if (!IPC::decode(decoder, attributes.font))
+        return WTF::nullopt;
+    return attributes;
+}
+
+} // namespace IPC

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (242907 => 242908)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2019-03-13 21:18:34 UTC (rev 242908)
@@ -90,7 +90,6 @@
 
 #if PLATFORM(COCOA)
 #include "ArgumentCodersCF.h"
-#include "ArgumentCodersMac.h"
 #endif
 
 #if PLATFORM(IOS_FAMILY)
@@ -2599,17 +2598,13 @@
     encoder << info.origin;
     encoder << info.textIndicator;
 
-#if PLATFORM(COCOA)
-    bool hadOptions = info.options;
-    encoder << hadOptions;
-    if (hadOptions)
-        IPC::encode(encoder, info.options.get());
+    if (info.encodingRequiresPlatformData()) {
+        encoder << true;
+        encodePlatformData(encoder, info);
+        return;
+    }
 
-    bool hadAttributedString = info.attributedString;
-    encoder << hadAttributedString;
-    if (hadAttributedString)
-        IPC::encode(encoder, info.attributedString.get());
-#endif
+    encoder << false;
 }
 
 bool ArgumentCoder<DictionaryPopupInfo>::decode(IPC::Decoder& decoder, DictionaryPopupInfo& result)
@@ -2623,25 +2618,11 @@
         return false;
     result.textIndicator = WTFMove(*textIndicator);
 
-#if PLATFORM(COCOA)
-    bool hadOptions;
-    if (!decoder.decode(hadOptions))
+    bool hasPlatformData;
+    if (!decoder.decode(hasPlatformData))
         return false;
-    if (hadOptions) {
-        if (!IPC::decode(decoder, result.options))
-            return false;
-    } else
-        result.options = nullptr;
-
-    bool hadAttributedString;
-    if (!decoder.decode(hadAttributedString))
-        return false;
-    if (hadAttributedString) {
-        if (!IPC::decode(decoder, result.attributedString))
-            return false;
-    } else
-        result.attributedString = nullptr;
-#endif
+    if (hasPlatformData)
+        return decodePlatformData(decoder, result);
     return true;
 }
 
@@ -3045,12 +3026,12 @@
     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
+
+    if (attributes.encodingRequiresPlatformData()) {
+        encoder << true;
+        encodePlatformData(encoder, attributes);
+        return;
+    }
 }
 
 Optional<FontAttributes> ArgumentCoder<FontAttributes>::decode(Decoder& decoder)
@@ -3081,15 +3062,12 @@
     if (!decoder.decodeEnum(attributes.subscriptOrSuperscript))
         return WTF::nullopt;
 
-#if PLATFORM(COCOA)
-    bool hasFont = false;
-    if (!decoder.decode(hasFont))
+    bool hasPlatformData;
+    if (!decoder.decode(hasPlatformData))
         return WTF::nullopt;
+    if (hasPlatformData)
+        return decodePlatformData(decoder, attributes);
 
-    if (hasFont && !IPC::decode(decoder, attributes.font))
-        return WTF::nullopt;
-#endif
-
     return attributes;
 }
 

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (242907 => 242908)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2019-03-13 21:18:34 UTC (rev 242908)
@@ -582,6 +582,8 @@
 template<> struct ArgumentCoder<WebCore::DictionaryPopupInfo> {
     static void encode(Encoder&, const WebCore::DictionaryPopupInfo&);
     static bool decode(Decoder&, WebCore::DictionaryPopupInfo&);
+    static void encodePlatformData(Encoder&, const WebCore::DictionaryPopupInfo&);
+    static bool decodePlatformData(Decoder&, WebCore::DictionaryPopupInfo&);
 };
 
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
@@ -744,6 +746,8 @@
 template<> struct ArgumentCoder<WebCore::FontAttributes> {
     static void encode(Encoder&, const WebCore::FontAttributes&);
     static Optional<WebCore::FontAttributes> decode(Decoder&);
+    static void encodePlatformData(Encoder&, const WebCore::FontAttributes&);
+    static Optional<WebCore::FontAttributes> decodePlatformData(Decoder&, WebCore::FontAttributes&);
 };
 
 #if ENABLE(ATTACHMENT_ELEMENT)

Modified: trunk/Source/WebKit/Shared/curl/WebCoreArgumentCodersCurl.cpp (242907 => 242908)


--- trunk/Source/WebKit/Shared/curl/WebCoreArgumentCodersCurl.cpp	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/Shared/curl/WebCoreArgumentCodersCurl.cpp	2019-03-13 21:18:34 UTC (rev 242908)
@@ -29,6 +29,8 @@
 #include "DataReference.h"
 #include <WebCore/CertificateInfo.h>
 #include <WebCore/CurlProxySettings.h>
+#include <WebCore/DictionaryPopupInfo.h>
+#include <WebCore/FontAttributes.h>
 #include <WebCore/ProtectionSpace.h>
 #include <WebCore/ResourceError.h>
 #include <WebCore/ResourceRequest.h>
@@ -210,4 +212,26 @@
     return CurlProxySettings { WTFMove(url), WTFMove(ignoreHosts) };
 }
 
+void ArgumentCoder<FontAttributes>::encodePlatformData(Encoder&, const FontAttributes&)
+{
+    ASSERT_NOT_REACHED();
 }
+
+Optional<FontAttributes> ArgumentCoder<FontAttributes>::decodePlatformData(Decoder&, FontAttributes&)
+{
+    ASSERT_NOT_REACHED();
+    return WTF::nullopt;
+}
+
+void ArgumentCoder<DictionaryPopupInfo>::encodePlatformData(Encoder&, const DictionaryPopupInfo&)
+{
+    ASSERT_NOT_REACHED();
+}
+
+bool ArgumentCoder<DictionaryPopupInfo>::decodePlatformData(Decoder&, DictionaryPopupInfo&)
+{
+    ASSERT_NOT_REACHED();
+    return false;
+}
+
+}

Deleted: trunk/Source/WebKit/Shared/mac/ArgumentCodersMac.h (242907 => 242908)


--- trunk/Source/WebKit/Shared/mac/ArgumentCodersMac.h	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/Shared/mac/ArgumentCodersMac.h	2019-03-13 21:18:34 UTC (rev 242908)
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2011 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 <objc/objc.h>
-#include <wtf/RetainPtr.h>
-
-OBJC_CLASS NSArray;
-OBJC_CLASS NSAttributedString;
-OBJC_CLASS NSColor;
-OBJC_CLASS NSData;
-OBJC_CLASS NSDate;
-OBJC_CLASS NSDictionary;
-OBJC_CLASS NSFont;
-OBJC_CLASS NSNumber;
-OBJC_CLASS NSString;
-OBJC_CLASS NSURL;
-OBJC_CLASS UIFont;
-
-namespace IPC {
-
-class Encoder;
-class Decoder;
-
-// id
-void encode(Encoder&, id);
-bool decode(Decoder&, RetainPtr<id>&);
-
-// NSAttributedString
-void encode(Encoder&, NSAttributedString *);
-bool decode(Decoder&, RetainPtr<NSAttributedString>&);
-
-#if USE(APPKIT)
-// NSColor
-void encode(Encoder&, NSColor *);
-bool decode(Decoder&, RetainPtr<NSColor>&);
-#endif
-
-// NSDictionary
-void encode(Encoder&, NSDictionary *);
-bool decode(Decoder&, RetainPtr<NSDictionary>&);
-
-// NSArray
-void encode(Encoder&, NSArray *);
-bool decode(Decoder&, RetainPtr<NSArray>&);
-
-#if USE(APPKIT)
-// NSFont
-void encode(Encoder&, NSFont *);
-bool decode(Decoder&, RetainPtr<NSFont>&);
-#endif
-
-#if PLATFORM(IOS_FAMILY)
-void encode(Encoder&, UIFont *);
-bool decode(Decoder&, RetainPtr<UIFont>&);
-#endif
-
-// NSNumber
-void encode(Encoder&, NSNumber *);
-bool decode(Decoder&, RetainPtr<NSNumber>&);
-
-// NSString
-void encode(Encoder&, NSString *);
-bool decode(Decoder&, RetainPtr<NSString>&);
-
-// NSDate
-void encode(Encoder&, NSDate *);
-bool decode(Decoder&, RetainPtr<NSDate>&);
-
-// NSData
-void encode(Encoder&, NSData *);
-bool decode(Decoder&, RetainPtr<NSData>&);
-
-// NSURL
-void encode(Encoder&, NSURL *);
-bool decode(Decoder&, RetainPtr<NSURL>&);
-
-} // namespace IPC

Deleted: trunk/Source/WebKit/Shared/mac/ArgumentCodersMac.mm (242907 => 242908)


--- trunk/Source/WebKit/Shared/mac/ArgumentCodersMac.mm	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/Shared/mac/ArgumentCodersMac.mm	2019-03-13 21:18:34 UTC (rev 242908)
@@ -1,582 +0,0 @@
-/*
- * Copyright (C) 2011 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.
- */
-
-#import "config.h"
-#import "ArgumentCodersMac.h"
-
-#import <CoreText/CoreText.h>
-#if PLATFORM(IOS_FAMILY)
-#import <UIKit/UIKit.h>
-#endif
-
-#import "ArgumentCodersCF.h"
-#import "Decoder.h"
-#import "Encoder.h"
-#import "WebCoreArgumentCoders.h"
-#import <WebCore/ColorMac.h>
-
-namespace IPC {
-
-enum class NSType {
-    AttributedString,
-#if USE(APPKIT)
-    Color,
-#endif
-    Dictionary,
-    Array,
-#if USE(APPKIT)
-    Font,
-#endif
-    Number,
-    String,
-    Date,
-    Data,
-    URL,
-    Unknown,
-};
-
-}
-
-namespace IPC {
-using namespace WebCore;
-
-static NSType typeFromObject(id object)
-{
-    ASSERT(object);
-
-    if ([object isKindOfClass:[NSAttributedString class]])
-        return NSType::AttributedString;
-#if USE(APPKIT)
-    if ([object isKindOfClass:[NSColor class]])
-        return NSType::Color;
-#endif
-    if ([object isKindOfClass:[NSDictionary class]])
-        return NSType::Dictionary;
-#if USE(APPKIT)
-    if ([object isKindOfClass:[NSFont class]])
-        return NSType::Font;
-#endif
-    if ([object isKindOfClass:[NSNumber class]])
-        return NSType::Number;
-    if ([object isKindOfClass:[NSString class]])
-        return NSType::String;
-    if ([object isKindOfClass:[NSArray class]])
-        return NSType::Array;
-    if ([object isKindOfClass:[NSDate class]])
-        return NSType::Date;
-    if ([object isKindOfClass:[NSData class]])
-        return NSType::Data;
-    if ([object isKindOfClass:[NSURL class]])
-        return NSType::URL;
-
-    ASSERT_NOT_REACHED();
-    return NSType::Unknown;
-}
-
-void encode(Encoder& encoder, id object)
-{
-    NSType type = typeFromObject(object);
-    encoder << type;
-
-    switch (type) {
-    case NSType::AttributedString:
-        encode(encoder, static_cast<NSAttributedString *>(object));
-        return;
-#if USE(APPKIT)
-    case NSType::Color:
-        encode(encoder, static_cast<NSColor *>(object));
-        return;
-#endif
-    case NSType::Dictionary:
-        encode(encoder, static_cast<NSDictionary *>(object));
-        return;
-#if USE(APPKIT)
-    case NSType::Font:
-        encode(encoder, static_cast<NSFont *>(object));
-        return;
-#endif
-    case NSType::Number:
-        encode(encoder, static_cast<NSNumber *>(object));
-        return;
-    case NSType::String:
-        encode(encoder, static_cast<NSString *>(object));
-        return;
-    case NSType::Array:
-        encode(encoder, static_cast<NSArray *>(object));
-        return;
-    case NSType::Date:
-        encode(encoder, static_cast<NSDate *>(object));
-        return;
-    case NSType::Data:
-        encode(encoder, static_cast<NSData *>(object));
-        return;
-    case NSType::URL:
-        encode(encoder, static_cast<NSURL *>(object));
-        return;
-    case NSType::Unknown:
-        break;
-    }
-
-    ASSERT_NOT_REACHED();
-}
-
-bool decode(Decoder& decoder, RetainPtr<id>& result)
-{
-    NSType type;
-    if (!decoder.decodeEnum(type))
-        return false;
-
-    switch (type) {
-    case NSType::AttributedString: {
-        RetainPtr<NSAttributedString> string;
-        if (!decode(decoder, string))
-            return false;
-        result = string;
-        return true;
-    }
-#if USE(APPKIT)
-    case NSType::Color: {
-        RetainPtr<NSColor> color;
-        if (!decode(decoder, color))
-            return false;
-        result = color;
-        return true;
-    }
-#endif
-    case NSType::Dictionary: {
-        RetainPtr<NSDictionary> dictionary;
-        if (!decode(decoder, dictionary))
-            return false;
-        result = dictionary;
-        return true;
-    }
-#if USE(APPKIT)
-    case NSType::Font: {
-        RetainPtr<NSFont> font;
-        if (!decode(decoder, font))
-            return false;
-        result = font;
-        return true;
-    }
-#endif
-    case NSType::Number: {
-        RetainPtr<NSNumber> number;
-        if (!decode(decoder, number))
-            return false;
-        result = number;
-        return true;
-    }
-    case NSType::String: {
-        RetainPtr<NSString> string;
-        if (!decode(decoder, string))
-            return false;
-        result = string;
-        return true;
-    }
-    case NSType::Array: {
-        RetainPtr<NSArray> array;
-        if (!decode(decoder, array))
-            return false;
-        result = array;
-        return true;
-    }
-    case NSType::Date: {
-        RetainPtr<NSDate> date;
-        if (!decode(decoder, date))
-            return false;
-        result = date;
-        return true;
-    }
-    case NSType::Data: {
-        RetainPtr<NSData> data;
-        if (!decode(decoder, data))
-            return false;
-        result = data;
-        return true;
-    }
-    case NSType::URL: {
-        RetainPtr<NSURL> URL;
-        if (!decode(decoder, URL))
-            return false;
-        result = URL;
-        return true;
-    }
-    case NSType::Unknown:
-        ASSERT_NOT_REACHED();
-        return false;
-    }
-
-    return false;
-}
-
-static inline bool isSerializableFont(CTFontRef font)
-{
-    return adoptCF(CTFontCopyAttribute(font, kCTFontURLAttribute));
-}
-
-static inline bool isSerializableValue(id value)
-{
-#if USE(APPKIT)
-    auto fontClass = [NSFont class];
-#else
-    auto fontClass = [UIFont class];
-#endif
-    return ![value isKindOfClass:fontClass] || isSerializableFont((__bridge CTFontRef)value);
-}
-
-static inline RetainPtr<NSDictionary> filterUnserializableValues(NSDictionary *dictionary)
-{
-    __block bool modificationNecessary = false;
-    [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
-        if (!isSerializableValue(object)) {
-            modificationNecessary = true;
-            *stop = YES;
-        }
-    }];
-    if (!modificationNecessary)
-        return dictionary;
-
-    auto result = adoptNS([[NSMutableDictionary alloc] init]);
-    [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
-        if (isSerializableValue(object))
-            [result setObject:object forKey:key];
-    }];
-    return result;
-}
-
-void encode(Encoder& encoder, NSAttributedString *string)
-{
-    // Even though NSAttributedString is toll free bridged with CFAttributedStringRef, attributes' values may be not, so we should stay within this file's code.
-
-    NSString *plainString = [string string];
-    NSUInteger length = [plainString length];
-    IPC::encode(encoder, plainString);
-
-    Vector<std::pair<NSRange, RetainPtr<NSDictionary>>> ranges;
-
-    NSUInteger position = 0;
-    while (position < length) {
-        // Collect ranges in a vector, becasue the total count should be encoded first.
-        NSRange effectiveRange;
-        RetainPtr<NSDictionary> attributesAtIndex = [string attributesAtIndex:position effectiveRange:&effectiveRange];
-        ASSERT(effectiveRange.location == position);
-        ASSERT(effectiveRange.length);
-        ASSERT(NSMaxRange(effectiveRange) <= length);
-
-        ranges.append(std::make_pair(effectiveRange, filterUnserializableValues(attributesAtIndex.get())));
-
-        position = NSMaxRange(effectiveRange);
-    }
-
-    encoder << static_cast<uint64_t>(ranges.size());
-
-    for (size_t i = 0; i < ranges.size(); ++i) {
-        encoder << static_cast<uint64_t>(ranges[i].first.location);
-        encoder << static_cast<uint64_t>(ranges[i].first.length);
-        IPC::encode(encoder, ranges[i].second.get());
-    }
-}
-
-bool decode(Decoder& decoder, RetainPtr<NSAttributedString>& result)
-{
-    RetainPtr<NSString> plainString;
-    if (!IPC::decode(decoder, plainString))
-        return false;
-
-    NSUInteger stringLength = [plainString length];
-
-    RetainPtr<NSMutableAttributedString> resultString = adoptNS([[NSMutableAttributedString alloc] initWithString:plainString.get()]);
-
-    uint64_t rangeCount;
-    if (!decoder.decode(rangeCount))
-        return false;
-
-    while (rangeCount--) {
-        uint64_t rangeLocation;
-        uint64_t rangeLength;
-        RetainPtr<NSDictionary> attributes;
-        if (!decoder.decode(rangeLocation))
-            return false;
-        if (!decoder.decode(rangeLength))
-            return false;
-
-        ASSERT(rangeLocation + rangeLength > rangeLocation);
-        ASSERT(rangeLocation + rangeLength <= stringLength);
-        if (rangeLocation + rangeLength <= rangeLocation || rangeLocation + rangeLength > stringLength)
-            return false;
-
-        if (!IPC::decode(decoder, attributes))
-            return false;
-        [resultString addAttributes:attributes.get() range:NSMakeRange(rangeLocation, rangeLength)];
-    }
-
-    result = adoptNS(resultString.leakRef());
-    return true;
-}
-
-#if USE(APPKIT)
-void encode(Encoder& encoder, NSColor *color)
-{
-    encoder << colorFromNSColor(color);
-}
-
-bool decode(Decoder& decoder, RetainPtr<NSColor>& result)
-{
-    Color color;
-    if (!decoder.decode(color))
-        return false;
-
-    result = nsColor(color);
-    return true;
-}
-#endif
-
-void encode(Encoder& encoder, NSDictionary *dictionary)
-{
-    // Even though NSDictionary is toll free bridged with CFDictionaryRef, values may be not, so we should stay within this file's code.
-
-    NSUInteger size = [dictionary count];
-    NSArray *keys = [dictionary allKeys];
-    NSArray *values = [dictionary allValues];
-
-    encoder << static_cast<uint64_t>(size);
-
-    for (NSUInteger i = 0; i < size; ++i) {
-        id key = [keys objectAtIndex:i];
-        id value = [values objectAtIndex:i];
-        ASSERT(key);
-        ASSERT(value);
-        ASSERT(isSerializableValue(value));
-
-        // Ignore values we don't recognize.
-        if (typeFromObject(value) == NSType::Unknown)
-            continue;
-
-        encode(encoder, key);
-        encode(encoder, value);
-    }
-}
-
-bool decode(Decoder& decoder, RetainPtr<NSDictionary>& result)
-{
-    uint64_t size;
-    if (!decoder.decode(size))
-        return false;
-
-    RetainPtr<NSMutableDictionary> dictionary = adoptNS([[NSMutableDictionary alloc] initWithCapacity:size]);
-    for (uint64_t i = 0; i < size; ++i) {
-        // Try to decode the key name.
-        RetainPtr<id> key;
-        if (!decode(decoder, key))
-            return false;
-
-        RetainPtr<id> value;
-        if (!decode(decoder, value))
-            return false;
-
-        [dictionary setObject:value.get() forKey:key.get()];
-    }
-
-    result = adoptNS(dictionary.leakRef());
-    return true;
-}
-
-#if USE(APPKIT)
-void encode(Encoder& encoder, NSFont *font)
-{
-    // NSFont could use CTFontRef code if we had it in ArgumentCodersCF.
-    encode(encoder, font.fontDescriptor.fontAttributes);
-}
-
-bool decode(Decoder& decoder, RetainPtr<NSFont>& result)
-{
-    RetainPtr<NSDictionary> fontAttributes;
-    if (!decode(decoder, fontAttributes))
-        return false;
-
-    NSFontDescriptor *fontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:fontAttributes.get()];
-    result = [NSFont fontWithDescriptor:fontDescriptor size:0];
-
-    return result;
-}
-#endif // USE(APPKIT)
-
-#if PLATFORM(IOS_FAMILY)
-
-void encode(Encoder& encoder, UIFont *font)
-{
-    encode(encoder, font.fontDescriptor.fontAttributes);
-}
-
-bool decode(Decoder& decoder, RetainPtr<UIFont>& result)
-{
-    RetainPtr<NSDictionary> fontAttributes;
-    if (!decode(decoder, fontAttributes))
-        return false;
-
-    UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:fontAttributes.get()];
-    result = [UIFont fontWithDescriptor:fontDescriptor size:0];
-
-    return result;
-}
-
-#endif // PLATFORM(IOS_FAMILY)
-
-void encode(Encoder& encoder, NSNumber *number)
-{
-    encode(encoder, (__bridge CFNumberRef)number);
-}
-
-bool decode(Decoder& decoder, RetainPtr<NSNumber>& result)
-{
-    RetainPtr<CFNumberRef> number;
-    if (!decode(decoder, number))
-        return false;
-
-    result = adoptNS((NSNumber *)number.leakRef());
-    return true;
-}
-
-void encode(Encoder& encoder, NSString *string)
-{
-    encode(encoder, (__bridge CFStringRef)string);
-}
-
-bool decode(Decoder& decoder, RetainPtr<NSString>& result)
-{
-    RetainPtr<CFStringRef> string;
-    if (!decode(decoder, string))
-        return false;
-
-    result = adoptNS((NSString *)string.leakRef());
-    return true;
-}
-
-void encode(Encoder& encoder, NSArray *array)
-{
-    NSUInteger size = [array count];
-    encoder << static_cast<uint64_t>(size);
-
-    for (NSUInteger i = 0; i < size; ++i) {
-        id value = [array objectAtIndex:i];
-
-        // Ignore values we don't recognize.
-        if (typeFromObject(value) == NSType::Unknown)
-            continue;
-
-        ASSERT(isSerializableValue(value));
-
-        encode(encoder, value);
-    }
-}
-
-bool decode(Decoder& decoder, RetainPtr<NSArray>& result)
-{
-    uint64_t size;
-    if (!decoder.decode(size))
-        return false;
-
-    RetainPtr<NSMutableArray> array = adoptNS([[NSMutableArray alloc] initWithCapacity:size]);
-    for (uint64_t i = 0; i < size; ++i) {
-        RetainPtr<id> value;
-        if (!decode(decoder, value))
-            return false;
-
-        [array addObject:value.get()];
-    }
-
-    result = adoptNS(array.leakRef());
-    return true;
-}
-
-void encode(Encoder& encoder, NSDate *date)
-{
-    encode(encoder, (__bridge CFDateRef)date);
-}
-
-bool decode(Decoder& decoder, RetainPtr<NSDate>& result)
-{
-    RetainPtr<CFDateRef> date;
-    if (!decode(decoder, date))
-        return false;
-
-    result = adoptNS((NSDate *)date.leakRef());
-    return true;
-}
-
-void encode(Encoder& encoder, NSData *data)
-{
-    encode(encoder, (__bridge CFDataRef)data);
-}
-
-bool decode(Decoder& decoder, RetainPtr<NSData>& result)
-{
-    RetainPtr<CFDataRef> data;
-    if (!decode(decoder, data))
-        return false;
-
-    result = adoptNS((NSData *)data.leakRef());
-    return true;
-}
-
-void encode(Encoder& encoder, NSURL *URL)
-{
-    encode(encoder, (__bridge CFURLRef)URL);
-}
-
-bool decode(Decoder& decoder, RetainPtr<NSURL>& result)
-{
-    RetainPtr<CFURLRef> URL;
-    if (!decode(decoder, URL))
-        return false;
-
-    result = adoptNS((NSURL *)URL.leakRef());
-    return true;
-}
-
-} // namespace IPC
-
-namespace WTF {
-template<> struct EnumTraits<IPC::NSType> {
-    using values = EnumValues<
-        IPC::NSType,
-        IPC::NSType::AttributedString,
-    #if USE(APPKIT)
-        IPC::NSType::Color,
-    #endif
-        IPC::NSType::Dictionary,
-        IPC::NSType::Array,
-    #if USE(APPKIT)
-        IPC::NSType::Font,
-    #endif
-        IPC::NSType::Number,
-        IPC::NSType::String,
-        IPC::NSType::Date,
-        IPC::NSType::Data,
-        IPC::NSType::URL,
-        IPC::NSType::Unknown
-    >;
-};
-}

Modified: trunk/Source/WebKit/Shared/mac/AttributedString.mm (242907 => 242908)


--- trunk/Source/WebKit/Shared/mac/AttributedString.mm	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/Shared/mac/AttributedString.mm	2019-03-13 21:18:34 UTC (rev 242908)
@@ -27,32 +27,21 @@
 #import "AttributedString.h"
 
 #import "ArgumentCodersCocoa.h"
-#import "ArgumentCodersMac.h"
-#import <Foundation/Foundation.h>
+#import "Decoder.h"
+#import "Encoder.h"
 
 namespace IPC {
 
 void ArgumentCoder<WebKit::AttributedString>::encode(Encoder& encoder, const WebKit::AttributedString& attributedString)
 {
-    encoder << static_cast<bool>(!attributedString.string);
-    if (!attributedString.string)
-        return;
-    IPC::encode(encoder, attributedString.string.get());
+    encoder << attributedString.string;
 }
 
 Optional<WebKit::AttributedString> ArgumentCoder<WebKit::AttributedString>::decode(Decoder& decoder)
 {
-    bool isNull;
-    if (!decoder.decode(isNull))
-        return WTF::nullopt;
-    if (isNull)
-        return WebKit::AttributedString { };
-
     RetainPtr<NSAttributedString> attributedString;
-    IPC::decode(decoder, attributedString);
-    if (!attributedString)
+    if (!IPC::decode(decoder, attributedString))
         return WTF::nullopt;
-
     return WebKit::AttributedString { attributedString.get() };
 }
 

Modified: trunk/Source/WebKit/Shared/mac/ObjCObjectGraph.mm (242907 => 242908)


--- trunk/Source/WebKit/Shared/mac/ObjCObjectGraph.mm	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/Shared/mac/ObjCObjectGraph.mm	2019-03-13 21:18:34 UTC (rev 242908)
@@ -26,7 +26,7 @@
 #import "config.h"
 #import "ObjCObjectGraph.h"
 
-#import "ArgumentCodersMac.h"
+#import "ArgumentCodersCocoa.h"
 #import "Decoder.h"
 #import "Encoder.h"
 #import "UserData.h"

Modified: trunk/Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp (242907 => 242908)


--- trunk/Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp	2019-03-13 21:18:34 UTC (rev 242908)
@@ -30,6 +30,8 @@
 #include "WebCoreArgumentCoders.h"
 
 #include <WebCore/CertificateInfo.h>
+#include <WebCore/DictionaryPopupInfo.h>
+#include <WebCore/FontAttributes.h>
 #include <WebCore/ResourceError.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/ResourceResponse.h>
@@ -227,5 +229,27 @@
     return false;
 }
 
+void ArgumentCoder<FontAttributes>::encodePlatformData(Encoder&, const FontAttributes&)
+{
+    ASSERT_NOT_REACHED();
 }
 
+Optional<FontAttributes> ArgumentCoder<FontAttributes>::decodePlatformData(Decoder&, FontAttributes&)
+{
+    ASSERT_NOT_REACHED();
+    return WTF::nullopt;
+}
+
+void ArgumentCoder<DictionaryPopupInfo>::encodePlatformData(Encoder&, const DictionaryPopupInfo&)
+{
+    ASSERT_NOT_REACHED();
+}
+
+bool ArgumentCoder<DictionaryPopupInfo>::decodePlatformData(Decoder&, DictionaryPopupInfo&)
+{
+    ASSERT_NOT_REACHED();
+    return false;
+}
+
+}
+

Modified: trunk/Source/WebKit/SourcesCocoa.txt (242907 => 242908)


--- trunk/Source/WebKit/SourcesCocoa.txt	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/SourcesCocoa.txt	2019-03-13 21:18:34 UTC (rev 242908)
@@ -174,7 +174,6 @@
 Shared/ios/WebPlatformTouchPointIOS.cpp
 Shared/ios/WebTouchEventIOS.cpp
 
-Shared/mac/ArgumentCodersMac.mm
 Shared/mac/AttributedString.mm
 Shared/mac/AuxiliaryProcessMac.mm
 Shared/mac/CodeSigning.mm

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (242907 => 242908)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2019-03-13 21:15:44 UTC (rev 242907)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2019-03-13 21:18:34 UTC (rev 242908)
@@ -1598,7 +1598,6 @@
 		E164A2F2191AF14E0010737D /* BlobDataFileReferenceWithSandboxExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = E164A2F0191AF14E0010737D /* BlobDataFileReferenceWithSandboxExtension.h */; };
 		E170876C16D6CA6900F99226 /* BlobRegistryProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = E170876A16D6CA6900F99226 /* BlobRegistryProxy.h */; };
 		E179088F169BAA6A006904C7 /* SecItemShim.h in Headers */ = {isa = PBXBuildFile; fileRef = E18E6948169B77C8009B6670 /* SecItemShim.h */; };
-		E179FD9C134D38060015B883 /* ArgumentCodersMac.h in Headers */ = {isa = PBXBuildFile; fileRef = E179FD9B134D38060015B883 /* ArgumentCodersMac.h */; };
 		E17AE2C316B9C63A001C42F1 /* com.apple.WebKit.NetworkProcess.sb in Resources */ = {isa = PBXBuildFile; fileRef = E17AE2C216B9C63A001C42F1 /* com.apple.WebKit.NetworkProcess.sb */; };
 		E18E690C169B563F009B6670 /* SecItemShimProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = E18E690A169B563F009B6670 /* SecItemShimProxy.h */; };
 		E18E6917169B667B009B6670 /* SecItemShimProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18E6913169B667B009B6670 /* SecItemShimProxyMessageReceiver.cpp */; };
@@ -4471,8 +4470,6 @@
 		E170876916D6CA6900F99226 /* BlobRegistryProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BlobRegistryProxy.cpp; path = WebProcess/FileAPI/BlobRegistryProxy.cpp; sourceTree = "<group>"; };
 		E170876A16D6CA6900F99226 /* BlobRegistryProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BlobRegistryProxy.h; path = WebProcess/FileAPI/BlobRegistryProxy.h; sourceTree = "<group>"; };
 		E1798C7716E6818800240139 /* NetworkBlobRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkBlobRegistry.cpp; sourceTree = "<group>"; };
-		E179FD9B134D38060015B883 /* ArgumentCodersMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArgumentCodersMac.h; sourceTree = "<group>"; };
-		E179FD9E134D38250015B883 /* ArgumentCodersMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ArgumentCodersMac.mm; sourceTree = "<group>"; };
 		E17AE2C116B9C139001C42F1 /* com.apple.WebKit.NetworkProcess.sb.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = com.apple.WebKit.NetworkProcess.sb.in; sourceTree = "<group>"; };
 		E17AE2C216B9C63A001C42F1 /* com.apple.WebKit.NetworkProcess.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = com.apple.WebKit.NetworkProcess.sb; path = DerivedSources/WebKit2/com.apple.WebKit.NetworkProcess.sb; sourceTree = BUILT_PRODUCTS_DIR; };
 		E18C92F312DB9E7100CF2AEB /* PrintInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrintInfo.cpp; sourceTree = "<group>"; };
@@ -7860,8 +7857,6 @@
 		BC111B5A112F628200337BAB /* mac */ = {
 			isa = PBXGroup;
 			children = (
-				E179FD9B134D38060015B883 /* ArgumentCodersMac.h */,
-				E179FD9E134D38250015B883 /* ArgumentCodersMac.mm */,
 				E1A31731134CEA6C007C9A4F /* AttributedString.h */,
 				E1A31734134CEA80007C9A4F /* AttributedString.mm */,
 				9F54F88E16488E87007DF81A /* AuxiliaryProcessMac.mm */,
@@ -9060,7 +9055,6 @@
 				1AEFD2F711D1807B008219D3 /* ArgumentCoders.h in Headers */,
 				1AAF0C4A12B16334008E49E2 /* ArgumentCodersCF.h in Headers */,
 				A175C44A21AA3171000037D0 /* ArgumentCodersCocoa.h in Headers */,
-				E179FD9C134D38060015B883 /* ArgumentCodersMac.h in Headers */,
 				CE1A0BD21A48E6C60054EF74 /* AssertionServicesSPI.h in Headers */,
 				515E7728183DD6F60007203F /* AsyncRequest.h in Headers */,
 				BCEE966D112FAF57006BCC24 /* Attachment.h in Headers */,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to