Changeset 242908 in webkit


Ignore:
Timestamp:
Mar 13, 2019 2:18:34 PM (5 years ago)
Author:
timothy@apple.com
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:
Location:
trunk/Source
Files:
2 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r242906 r242908  
     12019-03-13  Timothy Hatcher  <timothy@apple.com>
     2
     3        Consolidate ArgumentCodersMac and ArgumentCodersCocoa.
     4        https://bugs.webkit.org/show_bug.cgi?id=195636
     5        rdar://problem/45055697
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        * editing/DictionaryPopupInfo.h:
     10        (WebCore::DictionaryPopupInfo::encodingRequiresPlatformData const): Added.
     11        * editing/FontAttributes.h:
     12        (WebCore::FontAttributes::encodingRequiresPlatformData const): Added.
     13
    1142019-03-13  Chris Dumez  <cdumez@apple.com>
    215
  • trunk/Source/WebCore/editing/DictionaryPopupInfo.h

    r208646 r242908  
    4141    RetainPtr<NSDictionary> options;
    4242    RetainPtr<NSAttributedString> attributedString;
     43
     44    bool encodingRequiresPlatformData() const { return true; }
     45#else
     46    bool encodingRequiresPlatformData() const { return false; }
    4347#endif
    4448};
  • trunk/Source/WebCore/editing/FontAttributes.h

    r239427 r242908  
    8080
    8181#if PLATFORM(COCOA)
     82    bool encodingRequiresPlatformData() const { return true; }
     83
    8284    WEBCORE_EXPORT RetainPtr<NSDictionary> createDictionary() const;
     85#else
     86    bool encodingRequiresPlatformData() const { return false; }
    8387#endif
    8488
  • trunk/Source/WebKit/ChangeLog

    r242905 r242908  
     12019-03-13  Timothy Hatcher  <timothy@apple.com>
     2
     3        Consolidate ArgumentCodersMac and ArgumentCodersCocoa.
     4        https://bugs.webkit.org/show_bug.cgi?id=195636
     5        rdar://problem/45055697
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Merge the two similar encoders and decoders. This avoids issues where
     10        one encoder could be used and the other decoder, which caused a crash.
     11        It also stops handling NSAttributedString specifically and just uses
     12        the NSSecureCoding path to handle more complex attributes.
     13
     14        Some WebCore encoders code needed to move to platform files, since
     15        ArgumentCodersCocoa.h requires an ObjectiveC++ implementation to work.
     16
     17        * Shared/Cocoa/ArgumentCodersCocoa.h:
     18        (IPC::encode):
     19        (IPC::decode):
     20        (IPC::ArgumentCoder<RetainPtr<T>>::encode):
     21        (IPC::ArgumentCoder<RetainPtr<T>>::decode):
     22        * Shared/Cocoa/ArgumentCodersCocoa.mm:
     23        (IPC::typeFromObject):
     24        (IPC::isSerializableFont):
     25        (IPC::isSerializableValue):
     26        (IPC::encodeObject):
     27        (IPC::decodeObject):
     28        * Shared/Cocoa/LoadParametersCocoa.mm:
     29        * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
     30        (IPC::ArgumentCoder<WebCore::DictionaryPopupInfo>::encodePlatformData):
     31        (IPC::ArgumentCoder<WebCore::DictionaryPopupInfo>::decodePlatformData):
     32        (IPC::ArgumentCoder<WebCore::FontAttributes>::encodePlatformData):
     33        (IPC::ArgumentCoder<WebCore::FontAttributes>::decodePlatformData):
     34        * Shared/WebCoreArgumentCoders.cpp:
     35        (IPC::ArgumentCoder<DictionaryPopupInfo>::encode):
     36        (IPC::ArgumentCoder<DictionaryPopupInfo>::decode):
     37        (IPC::ArgumentCoder<FontAttributes>::encode):
     38        (IPC::ArgumentCoder<FontAttributes>::decode):
     39        * Shared/WebCoreArgumentCoders.h:
     40        * Shared/mac/ArgumentCodersMac.h: Removed.
     41        * Shared/mac/ArgumentCodersMac.mm: Removed.
     42        * Shared/mac/AttributedString.mm:
     43        (WebKit::AttributedString::encode const):
     44        * Shared/mac/ObjCObjectGraph.mm:
     45        * SourcesCocoa.txt:
     46        * WebKit.xcodeproj/project.pbxproj:
     47
    1482019-03-13  Chris Dumez  <cdumez@apple.com>
    249
  • trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.h

    r239427 r242908  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018, 2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3232namespace IPC {
    3333
    34 void encodeObject(Encoder&, id <NSSecureCoding>);
    35 Optional<RetainPtr<id <NSSecureCoding>>> decodeObject(Decoder&, NSArray<Class> *allowedClasses);
     34void encodeObject(Encoder&, id);
     35Optional<RetainPtr<id>> decodeObject(Decoder&, NSArray<Class> *allowedClasses);
    3636
    37 template<typename T> Optional<RetainPtr<T>> decode(Decoder&, Class allowedClass);
    38 template<typename T> Optional<RetainPtr<T>> decode(Decoder&, NSArray<Class> *allowedClasses = @[ [T class] ]);
     37template<typename T> using IsObjCObject = std::enable_if_t<std::is_convertible<T *, id>::value, T *>;
    3938
    40 template<typename T>
    41 Optional<RetainPtr<T>> decode(Decoder& decoder, Class allowedClass)
    42 {
    43     return decode<T>(decoder, @[ allowedClass ]);
    44 }
     39template<typename T, typename = IsObjCObject<T>> void encode(Encoder&, T *);
     40template<typename T, typename = IsObjCObject<T>> bool decode(Decoder&, RetainPtr<T>&, NSArray<Class> *allowedClasses = @[ [T class] ]);
     41template<typename T, typename = IsObjCObject<T>> Optional<RetainPtr<T>> decode(Decoder&, NSArray<Class> *allowedClasses = @[ [T class] ]);
    4542
    4643#ifndef NDEBUG
     
    5754#endif
    5855
    59 template<typename T>
     56template<typename T, typename>
     57void encode(Encoder& encoder, T *object)
     58{
     59    encodeObject(encoder, object);
     60}
     61
     62template<typename T, typename>
     63bool decode(Decoder& decoder, RetainPtr<T>& result, NSArray<Class> *allowedClasses)
     64{
     65    auto object = decodeObject(decoder, allowedClasses);
     66    if (!object)
     67        return false;
     68    result = *object;
     69    ASSERT(!*object || isObjectClassAllowed((*object).get(), allowedClasses));
     70    return true;
     71}
     72
     73template<typename T, typename>
    6074Optional<RetainPtr<T>> decode(Decoder& decoder, NSArray<Class> *allowedClasses)
    6175{
     
    6377    if (!result)
    6478        return WTF::nullopt;
    65 
    66     if (!*result)
    67         return { nullptr };
    68 
    69     id object = result->leakRef();
    70     ASSERT(isObjectClassAllowed(object, allowedClasses));
    71     return { adoptNS(static_cast<T *>(object)) };
     79    ASSERT(!*result || isObjectClassAllowed((*result).get(), allowedClasses));
     80    return { *result };
    7281}
    7382
    74 template<typename T> using ConformsToSecureCoding = std::is_convertible<T *, id <NSSecureCoding>>;
    75 
    7683template<typename T> struct ArgumentCoder<T *> {
    77     template<typename U = T, std::enable_if_t<ConformsToSecureCoding<U>::value>* = nullptr>
     84    template<typename U = T, typename = IsObjCObject<U>>
    7885    static void encode(Encoder& encoder, U *object)
    7986    {
     
    8390
    8491template<typename T> struct ArgumentCoder<RetainPtr<T>> {
    85     template <typename U = T, std::enable_if_t<ConformsToSecureCoding<U>::value>* = nullptr>
     92    template<typename U = T, typename = IsObjCObject<U>>
    8693    static void encode(Encoder& encoder, const RetainPtr<U>& object)
    8794    {
     
    8996    }
    9097
    91     template <typename U = T, std::enable_if_t<ConformsToSecureCoding<U>::value>* = nullptr>
     98    template<typename U = T, typename = IsObjCObject<U>>
    9299    static Optional<RetainPtr<U>> decode(Decoder& decoder)
    93100    {
  • trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm

    r239427 r242908  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018, 2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030
    3131#import "ArgumentCodersCF.h"
     32#import <CoreText/CTFont.h>
     33#import <CoreText/CTFontDescriptor.h>
    3234#import <pal/spi/cocoa/NSKeyedArchiverSPI.h>
     35#import <wtf/HashSet.h>
     36
     37#if USE(APPKIT)
     38#import <WebCore/ColorMac.h>
     39#endif
     40
     41#if USE(APPKIT)
     42#define PlatformFont NSFont
     43#define PlatformFontDescriptor NSFontDescriptor
     44#else
     45#define PlatformFont UIFont
     46#define PlatformFontDescriptor UIFontDescriptor
     47#endif
    3348
    3449namespace IPC {
    35 
    36 void encodeObject(Encoder& encoder, id <NSSecureCoding> object)
     50using namespace WebCore;
     51
     52#pragma mark - Types
     53
     54enum class NSType {
     55    Array,
     56#if USE(APPKIT)
     57    Color,
     58#endif
     59    Data,
     60    Date,
     61    Dictionary,
     62    Font,
     63    Number,
     64    SecureCoding,
     65    String,
     66    URL,
     67    Unknown,
     68};
     69
     70#pragma mark - Helpers
     71
     72static NSType typeFromObject(id object)
     73{
     74    ASSERT(object);
     75
     76    // Specific classes handled.
     77    if ([object isKindOfClass:[NSArray class]])
     78        return NSType::Array;
     79#if USE(APPKIT)
     80    if ([object isKindOfClass:[NSColor class]])
     81        return NSType::Color;
     82#endif
     83    if ([object isKindOfClass:[NSData class]])
     84        return NSType::Data;
     85    if ([object isKindOfClass:[NSDate class]])
     86        return NSType::Date;
     87    if ([object isKindOfClass:[NSDictionary class]])
     88        return NSType::Dictionary;
     89    if ([object isKindOfClass:[PlatformFont class]])
     90        return NSType::Font;
     91    if ([object isKindOfClass:[NSNumber class]])
     92        return NSType::Number;
     93    if ([object isKindOfClass:[NSString class]])
     94        return NSType::String;
     95    if ([object isKindOfClass:[NSURL class]])
     96        return NSType::URL;
     97
     98    // Check NSSecureCoding after the specific cases since
     99    // most of the classes above conform to NSSecureCoding,
     100    // and we want our special case coders for them instead.
     101    if ([object conformsToProtocol:@protocol(NSSecureCoding)])
     102        return NSType::SecureCoding;
     103
     104    ASSERT_NOT_REACHED();
     105    return NSType::Unknown;
     106}
     107
     108static inline bool isSerializableFont(CTFontRef font)
     109{
     110    return adoptCF(CTFontCopyAttribute(font, kCTFontURLAttribute));
     111}
     112
     113static inline bool isSerializableValue(id value)
     114{
     115    if ([value isKindOfClass:[PlatformFont class]])
     116        return isSerializableFont((__bridge CTFontRef)value);
     117    return typeFromObject(value) != NSType::Unknown;
     118}
     119
     120#pragma mark - NSArray
     121
     122static void encodeArrayInternal(Encoder& encoder, NSArray *array)
     123{
     124    // Even though NSArray is toll free bridged with CFArrayRef, values may not be,
     125    // so we should stay within this file's code.
     126
     127    if (!array.count) {
     128        encoder << static_cast<uint64_t>(0);
     129        return;
     130    }
     131
     132    HashSet<NSUInteger> invalidIndicies;
     133    for (NSUInteger i = 0; i < array.count; ++i) {
     134        id value = array[i];
     135
     136        // Ignore values we don't support.
     137        ASSERT(isSerializableValue(value));
     138        if (!isSerializableValue(value))
     139            invalidIndicies.add(i);
     140    }
     141
     142    encoder << static_cast<uint64_t>(array.count - invalidIndicies.size());
     143
     144    for (NSUInteger i = 0; i < array.count; ++i) {
     145        if (invalidIndicies.contains(i))
     146            continue;
     147        encodeObject(encoder, array[i]);
     148    }
     149}
     150
     151static Optional<RetainPtr<id>> decodeArrayInternal(Decoder& decoder)
     152{
     153    uint64_t size;
     154    if (!decoder.decode(size))
     155        return WTF::nullopt;
     156
     157    RetainPtr<NSMutableArray> array = adoptNS([[NSMutableArray alloc] initWithCapacity:size]);
     158    for (uint64_t i = 0; i < size; ++i) {
     159        auto value = decodeObject(decoder, nil);
     160        if (!value)
     161            return WTF::nullopt;
     162        [array addObject:value.value().get()];
     163    }
     164
     165    return { array };
     166}
     167
     168#pragma mark - NSColor
     169
     170#if USE(APPKIT)
     171static inline void encodeColorInternal(Encoder& encoder, NSColor *color)
     172{
     173    encoder << colorFromNSColor(color);
     174}
     175
     176static inline Optional<RetainPtr<id>> decodeColorInternal(Decoder& decoder)
     177{
     178    Color color;
     179    if (!decoder.decode(color))
     180        return WTF::nullopt;
     181    return { nsColor(color) };
     182}
     183#endif
     184
     185#pragma mark - NSData
     186
     187static inline void encodeDataInternal(Encoder& encoder, NSData *data)
     188{
     189    encode(encoder, (__bridge CFDataRef)data);
     190}
     191
     192static inline Optional<RetainPtr<id>> decodeDataInternal(Decoder& decoder)
     193{
     194    RetainPtr<CFDataRef> data;
     195    if (!decode(decoder, data))
     196        return WTF::nullopt;
     197    return { adoptNS((NSData *)data.leakRef()) };
     198}
     199
     200#pragma mark - NSDate
     201
     202static inline void encodeDateInternal(Encoder& encoder, NSDate *date)
     203{
     204    encode(encoder, (__bridge CFDateRef)date);
     205}
     206
     207static inline Optional<RetainPtr<id>> decodeDateInternal(Decoder& decoder)
     208{
     209    RetainPtr<CFDateRef> date;
     210    if (!decode(decoder, date))
     211        return WTF::nullopt;
     212    return { adoptNS((NSDate *)date.leakRef()) };
     213}
     214
     215#pragma mark - NSDictionary
     216
     217static void encodeDictionaryInternal(Encoder& encoder, NSDictionary *dictionary)
     218{
     219    // Even though NSDictionary is toll free bridged with CFDictionaryRef, keys/values may not be,
     220    // so we should stay within this file's code.
     221
     222    if (!dictionary.count) {
     223        encoder << static_cast<uint64_t>(0);
     224        return;
     225    }
     226
     227    HashSet<id> invalidKeys;
     228    for (id key in dictionary) {
     229        id value = dictionary[key];
     230        ASSERT(value);
     231
     232        // Ignore values we don't support.
     233        ASSERT(isSerializableValue(key));
     234        ASSERT(isSerializableValue(value));
     235        if (!isSerializableValue(key) || !isSerializableValue(value))
     236            invalidKeys.add(key);
     237    }
     238
     239    encoder << static_cast<uint64_t>(dictionary.count - invalidKeys.size());
     240
     241    for (id key in dictionary) {
     242        if (invalidKeys.contains(key))
     243            continue;
     244        encodeObject(encoder, key);
     245        encodeObject(encoder, dictionary[key]);
     246    }
     247}
     248
     249static Optional<RetainPtr<id>> decodeDictionaryInternal(Decoder& decoder)
     250{
     251    uint64_t size;
     252    if (!decoder.decode(size))
     253        return WTF::nullopt;
     254
     255    RetainPtr<NSMutableDictionary> dictionary = adoptNS([[NSMutableDictionary alloc] initWithCapacity:size]);
     256    for (uint64_t i = 0; i < size; ++i) {
     257        auto key = decodeObject(decoder, nil);
     258        if (!key)
     259            return WTF::nullopt;
     260
     261        auto value = decodeObject(decoder, nil);
     262        if (!value)
     263            return WTF::nullopt;
     264
     265        [dictionary setObject:value.value().get() forKey:key.value().get()];
     266    }
     267
     268    return { dictionary };
     269}
     270
     271#pragma mark - NSFont / UIFont
     272
     273static inline void encodeFontInternal(Encoder& encoder, PlatformFont *font)
     274{
     275    encode(encoder, font.fontDescriptor.fontAttributes);
     276}
     277
     278static Optional<RetainPtr<id>> decodeFontInternal(Decoder& decoder)
     279{
     280    RetainPtr<NSDictionary> fontAttributes;
     281    if (!decode(decoder, fontAttributes))
     282        return WTF::nullopt;
     283
     284    PlatformFontDescriptor *fontDescriptor = [PlatformFontDescriptor fontDescriptorWithFontAttributes:fontAttributes.get()];
     285    return { [PlatformFont fontWithDescriptor:fontDescriptor size:0] };
     286}
     287
     288#pragma mark - NSNumber
     289
     290static inline void encodeNumberInternal(Encoder& encoder, NSNumber *number)
     291{
     292    encode(encoder, (__bridge CFNumberRef)number);
     293}
     294
     295static inline Optional<RetainPtr<id>> decodeNumberInternal(Decoder& decoder)
     296{
     297    RetainPtr<CFNumberRef> number;
     298    if (!decode(decoder, number))
     299        return WTF::nullopt;
     300    return { adoptNS((NSNumber *)number.leakRef()) };
     301}
     302
     303#pragma mark - id <NSSecureCoding>
     304
     305static void encodeSecureCodingInternal(Encoder& encoder, id <NSObject, NSSecureCoding> object)
    37306{
    38307    auto archiver = secureArchiver();
     
    40309    [archiver finishEncoding];
    41310
    42     IPC::encode(encoder, (__bridge CFDataRef)[archiver encodedData]);
    43 }
    44 
    45 Optional<RetainPtr<id <NSSecureCoding>>> decodeObject(Decoder& decoder, NSArray<Class> *allowedClasses)
    46 {
     311    encode(encoder, (__bridge CFDataRef)[archiver encodedData]);
     312}
     313
     314static Optional<RetainPtr<id>> decodeSecureCodingInternal(Decoder& decoder, NSArray<Class> *allowedClasses)
     315{
     316    ASSERT(allowedClasses && allowedClasses.count);
     317    if (!allowedClasses || !allowedClasses.count)
     318        return WTF::nullopt;
     319
    47320    RetainPtr<CFDataRef> data;
    48321    if (!decode(decoder, data))
     
    62335}
    63336
     337#pragma mark - NSString
     338
     339static inline void encodeStringInternal(Encoder& encoder, NSString *string)
     340{
     341    encode(encoder, (__bridge CFStringRef)string);
     342}
     343
     344static inline Optional<RetainPtr<id>> decodeStringInternal(Decoder& decoder)
     345{
     346    RetainPtr<CFStringRef> string;
     347    if (!decode(decoder, string))
     348        return WTF::nullopt;
     349    return { adoptNS((NSString *)string.leakRef()) };
     350}
     351
     352#pragma mark - NSURL
     353
     354static inline void encodeURLInternal(Encoder& encoder, NSURL *URL)
     355{
     356    encode(encoder, (__bridge CFURLRef)URL);
     357}
     358
     359static inline Optional<RetainPtr<id>> decodeURLInternal(Decoder& decoder)
     360{
     361    RetainPtr<CFURLRef> URL;
     362    if (!decode(decoder, URL))
     363        return WTF::nullopt;
     364    return { adoptNS((NSURL *)URL.leakRef()) };
     365}
     366
     367#pragma mark - Entry Point Encoder / Decoder
     368
     369void encodeObject(Encoder& encoder, id object)
     370{
     371    encoder << static_cast<bool>(!object);
     372    if (!object)
     373        return;
     374
     375    NSType type = typeFromObject(object);
     376    encoder << type;
     377
     378    switch (type) {
     379    case NSType::Array:
     380        encodeArrayInternal(encoder, static_cast<NSArray *>(object));
     381        return;
     382#if USE(APPKIT)
     383    case NSType::Color:
     384        encodeColorInternal(encoder, static_cast<NSColor *>(object));
     385        return;
     386#endif
     387    case NSType::Dictionary:
     388        encodeDictionaryInternal(encoder, static_cast<NSDictionary *>(object));
     389        return;
     390    case NSType::Font:
     391        encodeFontInternal(encoder, static_cast<PlatformFont *>(object));
     392        return;
     393    case NSType::Number:
     394        encodeNumberInternal(encoder, static_cast<NSNumber *>(object));
     395        return;
     396    case NSType::SecureCoding:
     397        encodeSecureCodingInternal(encoder, static_cast<id <NSObject, NSSecureCoding>>(object));
     398        return;
     399    case NSType::String:
     400        encodeStringInternal(encoder, static_cast<NSString *>(object));
     401        return;
     402    case NSType::Date:
     403        encodeDateInternal(encoder, static_cast<NSDate *>(object));
     404        return;
     405    case NSType::Data:
     406        encodeDataInternal(encoder, static_cast<NSData *>(object));
     407        return;
     408    case NSType::URL:
     409        encodeURLInternal(encoder, static_cast<NSURL *>(object));
     410        return;
     411    case NSType::Unknown:
     412        break;
     413    }
     414
     415    ASSERT_NOT_REACHED();
     416}
     417
     418Optional<RetainPtr<id>> decodeObject(Decoder& decoder, NSArray<Class> *allowedClasses)
     419{
     420    bool isNull;
     421    if (!decoder.decode(isNull))
     422        return WTF::nullopt;
     423    if (isNull)
     424        return { nullptr };
     425
     426    NSType type;
     427    if (!decoder.decodeEnum(type))
     428        return WTF::nullopt;
     429
     430    switch (type) {
     431    case NSType::Array:
     432        return decodeArrayInternal(decoder);
     433#if USE(APPKIT)
     434    case NSType::Color:
     435        return decodeColorInternal(decoder);
     436#endif
     437    case NSType::Dictionary:
     438        return decodeDictionaryInternal(decoder);
     439#if USE(APPKIT)
     440    case NSType::Font:
     441        return decodeFontInternal(decoder);
     442#else
     443    case NSType::Font:
     444        return decodeFontInternal(decoder);
     445#endif
     446    case NSType::Number:
     447        return decodeNumberInternal(decoder);
     448    case NSType::SecureCoding:
     449        return decodeSecureCodingInternal(decoder, allowedClasses);
     450    case NSType::String:
     451        return decodeStringInternal(decoder);
     452    case NSType::Date:
     453        return decodeDateInternal(decoder);
     454    case NSType::Data:
     455        return decodeDataInternal(decoder);
     456    case NSType::URL:
     457        return decodeURLInternal(decoder);
     458    case NSType::Unknown:
     459        break;
     460    }
     461
     462    ASSERT_NOT_REACHED();
     463    return WTF::nullopt;
     464}
     465
    64466} // namespace IPC
    65467
     468namespace WTF {
     469template<> struct EnumTraits<IPC::NSType> {
     470    using values = EnumValues<
     471        IPC::NSType,
     472        IPC::NSType::Array,
     473#if USE(APPKIT)
     474        IPC::NSType::Color,
     475#endif
     476        IPC::NSType::Data,
     477        IPC::NSType::Date,
     478        IPC::NSType::Dictionary,
     479        IPC::NSType::Font,
     480        IPC::NSType::Number,
     481        IPC::NSType::SecureCoding,
     482        IPC::NSType::String,
     483        IPC::NSType::URL,
     484        IPC::NSType::Unknown
     485    >;
     486};
     487} // namespace WTF
     488
    66489#endif // PLATFORM(COCOA)
  • trunk/Source/WebKit/Shared/Cocoa/LoadParametersCocoa.mm

    r204668 r242908  
    2929#if PLATFORM(COCOA)
    3030
    31 #include "ArgumentCodersMac.h"
     31#include "ArgumentCodersCocoa.h"
    3232#include "WebCoreArgumentCoders.h"
    3333
  • trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm

    r239427 r242908  
    2727#import "WebCoreArgumentCoders.h"
    2828
     29#import "ArgumentCodersCocoa.h"
     30#import <WebCore/DictionaryPopupInfo.h>
     31#import <WebCore/FontAttributes.h>
     32
    2933#if ENABLE(APPLE_PAY)
    3034
    31 #import "ArgumentCodersCocoa.h"
    3235#import "DataReference.h"
    3336#import <WebCore/PaymentAuthorizationStatus.h>
     
    3538#import <pal/spi/cocoa/NSKeyedArchiverSPI.h>
    3639
     40#endif
     41
    3742namespace IPC {
    3843using namespace WebCore;
     44
     45#if ENABLE(APPLE_PAY)
    3946
    4047void ArgumentCoder<WebCore::Payment>::encode(Encoder& encoder, const WebCore::Payment& payment)
     
    409416}
    410417
    411 }
    412 #endif
     418#endif // ENABLE(APPLEPAY)
     419
     420void ArgumentCoder<WebCore::DictionaryPopupInfo>::encodePlatformData(Encoder& encoder, const WebCore::DictionaryPopupInfo& info)
     421{
     422    encoder << info.options << info.attributedString;
     423}
     424
     425bool ArgumentCoder<WebCore::DictionaryPopupInfo>::decodePlatformData(Decoder& decoder, WebCore::DictionaryPopupInfo& result)
     426{
     427    if (!IPC::decode(decoder, result.options))
     428        return false;
     429    if (!IPC::decode(decoder, result.attributedString))
     430        return false;
     431    return true;
     432}
     433
     434void ArgumentCoder<WebCore::FontAttributes>::encodePlatformData(Encoder& encoder, const WebCore::FontAttributes& attributes)
     435{
     436    encoder << attributes.font;
     437}
     438
     439Optional<FontAttributes> ArgumentCoder<WebCore::FontAttributes>::decodePlatformData(Decoder& decoder, WebCore::FontAttributes& attributes)
     440{
     441    if (!IPC::decode(decoder, attributes.font))
     442        return WTF::nullopt;
     443    return attributes;
     444}
     445
     446} // namespace IPC
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp

    r242155 r242908  
    9191#if PLATFORM(COCOA)
    9292#include "ArgumentCodersCF.h"
    93 #include "ArgumentCodersMac.h"
    9493#endif
    9594
     
    26002599    encoder << info.textIndicator;
    26012600
    2602 #if PLATFORM(COCOA)
    2603     bool hadOptions = info.options;
    2604     encoder << hadOptions;
    2605     if (hadOptions)
    2606         IPC::encode(encoder, info.options.get());
    2607 
    2608     bool hadAttributedString = info.attributedString;
    2609     encoder << hadAttributedString;
    2610     if (hadAttributedString)
    2611         IPC::encode(encoder, info.attributedString.get());
    2612 #endif
     2601    if (info.encodingRequiresPlatformData()) {
     2602        encoder << true;
     2603        encodePlatformData(encoder, info);
     2604        return;
     2605    }
     2606
     2607    encoder << false;
    26132608}
    26142609
     
    26242619    result.textIndicator = WTFMove(*textIndicator);
    26252620
    2626 #if PLATFORM(COCOA)
    2627     bool hadOptions;
    2628     if (!decoder.decode(hadOptions))
    2629         return false;
    2630     if (hadOptions) {
    2631         if (!IPC::decode(decoder, result.options))
    2632             return false;
    2633     } else
    2634         result.options = nullptr;
    2635 
    2636     bool hadAttributedString;
    2637     if (!decoder.decode(hadAttributedString))
    2638         return false;
    2639     if (hadAttributedString) {
    2640         if (!IPC::decode(decoder, result.attributedString))
    2641             return false;
    2642     } else
    2643         result.attributedString = nullptr;
    2644 #endif
     2621    bool hasPlatformData;
     2622    if (!decoder.decode(hasPlatformData))
     2623        return false;
     2624    if (hasPlatformData)
     2625        return decodePlatformData(decoder, result);
    26452626    return true;
    26462627}
     
    30463027    encoder.encodeEnum(attributes.horizontalAlignment);
    30473028    encoder.encodeEnum(attributes.subscriptOrSuperscript);
    3048 #if PLATFORM(COCOA)
    3049     bool hasFont = attributes.font;
    3050     encoder << hasFont;
    3051     if (hasFont)
    3052         IPC::encode(encoder, attributes.font.get());
    3053 #endif
     3029
     3030    if (attributes.encodingRequiresPlatformData()) {
     3031        encoder << true;
     3032        encodePlatformData(encoder, attributes);
     3033        return;
     3034    }
    30543035}
    30553036
     
    30823063        return WTF::nullopt;
    30833064
    3084 #if PLATFORM(COCOA)
    3085     bool hasFont = false;
    3086     if (!decoder.decode(hasFont))
    3087         return WTF::nullopt;
    3088 
    3089     if (hasFont && !IPC::decode(decoder, attributes.font))
    3090         return WTF::nullopt;
    3091 #endif
     3065    bool hasPlatformData;
     3066    if (!decoder.decode(hasPlatformData))
     3067        return WTF::nullopt;
     3068    if (hasPlatformData)
     3069        return decodePlatformData(decoder, attributes);
    30923070
    30933071    return attributes;
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h

    r240579 r242908  
    583583    static void encode(Encoder&, const WebCore::DictionaryPopupInfo&);
    584584    static bool decode(Decoder&, WebCore::DictionaryPopupInfo&);
     585    static void encodePlatformData(Encoder&, const WebCore::DictionaryPopupInfo&);
     586    static bool decodePlatformData(Decoder&, WebCore::DictionaryPopupInfo&);
    585587};
    586588
     
    745747    static void encode(Encoder&, const WebCore::FontAttributes&);
    746748    static Optional<WebCore::FontAttributes> decode(Decoder&);
     749    static void encodePlatformData(Encoder&, const WebCore::FontAttributes&);
     750    static Optional<WebCore::FontAttributes> decodePlatformData(Decoder&, WebCore::FontAttributes&);
    747751};
    748752
  • trunk/Source/WebKit/Shared/curl/WebCoreArgumentCodersCurl.cpp

    r239550 r242908  
    3030#include <WebCore/CertificateInfo.h>
    3131#include <WebCore/CurlProxySettings.h>
     32#include <WebCore/DictionaryPopupInfo.h>
     33#include <WebCore/FontAttributes.h>
    3234#include <WebCore/ProtectionSpace.h>
    3335#include <WebCore/ResourceError.h>
     
    211213}
    212214
    213 }
     215void ArgumentCoder<FontAttributes>::encodePlatformData(Encoder&, const FontAttributes&)
     216{
     217    ASSERT_NOT_REACHED();
     218}
     219
     220Optional<FontAttributes> ArgumentCoder<FontAttributes>::decodePlatformData(Decoder&, FontAttributes&)
     221{
     222    ASSERT_NOT_REACHED();
     223    return WTF::nullopt;
     224}
     225
     226void ArgumentCoder<DictionaryPopupInfo>::encodePlatformData(Encoder&, const DictionaryPopupInfo&)
     227{
     228    ASSERT_NOT_REACHED();
     229}
     230
     231bool ArgumentCoder<DictionaryPopupInfo>::decodePlatformData(Decoder&, DictionaryPopupInfo&)
     232{
     233    ASSERT_NOT_REACHED();
     234    return false;
     235}
     236
     237}
  • trunk/Source/WebKit/Shared/mac/AttributedString.mm

    r242285 r242908  
    2828
    2929#import "ArgumentCodersCocoa.h"
    30 #import "ArgumentCodersMac.h"
    31 #import <Foundation/Foundation.h>
     30#import "Decoder.h"
     31#import "Encoder.h"
    3232
    3333namespace IPC {
     
    3535void ArgumentCoder<WebKit::AttributedString>::encode(Encoder& encoder, const WebKit::AttributedString& attributedString)
    3636{
    37     encoder << static_cast<bool>(!attributedString.string);
    38     if (!attributedString.string)
    39         return;
    40     IPC::encode(encoder, attributedString.string.get());
     37    encoder << attributedString.string;
    4138}
    4239
    4340Optional<WebKit::AttributedString> ArgumentCoder<WebKit::AttributedString>::decode(Decoder& decoder)
    4441{
    45     bool isNull;
    46     if (!decoder.decode(isNull))
     42    RetainPtr<NSAttributedString> attributedString;
     43    if (!IPC::decode(decoder, attributedString))
    4744        return WTF::nullopt;
    48     if (isNull)
    49         return WebKit::AttributedString { };
    50 
    51     RetainPtr<NSAttributedString> attributedString;
    52     IPC::decode(decoder, attributedString);
    53     if (!attributedString)
    54         return WTF::nullopt;
    55 
    5645    return WebKit::AttributedString { attributedString.get() };
    5746}
  • trunk/Source/WebKit/Shared/mac/ObjCObjectGraph.mm

    r242339 r242908  
    2727#import "ObjCObjectGraph.h"
    2828
    29 #import "ArgumentCodersMac.h"
     29#import "ArgumentCodersCocoa.h"
    3030#import "Decoder.h"
    3131#import "Encoder.h"
  • trunk/Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp

    r237415 r242908  
    3131
    3232#include <WebCore/CertificateInfo.h>
     33#include <WebCore/DictionaryPopupInfo.h>
     34#include <WebCore/FontAttributes.h>
    3335#include <WebCore/ResourceError.h>
    3436#include <WebCore/ResourceRequest.h>
     
    228230}
    229231
    230 }
    231 
     232void ArgumentCoder<FontAttributes>::encodePlatformData(Encoder&, const FontAttributes&)
     233{
     234    ASSERT_NOT_REACHED();
     235}
     236
     237Optional<FontAttributes> ArgumentCoder<FontAttributes>::decodePlatformData(Decoder&, FontAttributes&)
     238{
     239    ASSERT_NOT_REACHED();
     240    return WTF::nullopt;
     241}
     242
     243void ArgumentCoder<DictionaryPopupInfo>::encodePlatformData(Encoder&, const DictionaryPopupInfo&)
     244{
     245    ASSERT_NOT_REACHED();
     246}
     247
     248bool ArgumentCoder<DictionaryPopupInfo>::decodePlatformData(Decoder&, DictionaryPopupInfo&)
     249{
     250    ASSERT_NOT_REACHED();
     251    return false;
     252}
     253
     254}
     255
  • trunk/Source/WebKit/SourcesCocoa.txt

    r242764 r242908  
    175175Shared/ios/WebTouchEventIOS.cpp
    176176
    177 Shared/mac/ArgumentCodersMac.mm
    178177Shared/mac/AttributedString.mm
    179178Shared/mac/AuxiliaryProcessMac.mm
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r242891 r242908  
    15991599                E170876C16D6CA6900F99226 /* BlobRegistryProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = E170876A16D6CA6900F99226 /* BlobRegistryProxy.h */; };
    16001600                E179088F169BAA6A006904C7 /* SecItemShim.h in Headers */ = {isa = PBXBuildFile; fileRef = E18E6948169B77C8009B6670 /* SecItemShim.h */; };
    1601                 E179FD9C134D38060015B883 /* ArgumentCodersMac.h in Headers */ = {isa = PBXBuildFile; fileRef = E179FD9B134D38060015B883 /* ArgumentCodersMac.h */; };
    16021601                E17AE2C316B9C63A001C42F1 /* com.apple.WebKit.NetworkProcess.sb in Resources */ = {isa = PBXBuildFile; fileRef = E17AE2C216B9C63A001C42F1 /* com.apple.WebKit.NetworkProcess.sb */; };
    16031602                E18E690C169B563F009B6670 /* SecItemShimProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = E18E690A169B563F009B6670 /* SecItemShimProxy.h */; };
     
    44724471                E170876A16D6CA6900F99226 /* BlobRegistryProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BlobRegistryProxy.h; path = WebProcess/FileAPI/BlobRegistryProxy.h; sourceTree = "<group>"; };
    44734472                E1798C7716E6818800240139 /* NetworkBlobRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkBlobRegistry.cpp; sourceTree = "<group>"; };
    4474                 E179FD9B134D38060015B883 /* ArgumentCodersMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArgumentCodersMac.h; sourceTree = "<group>"; };
    4475                 E179FD9E134D38250015B883 /* ArgumentCodersMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ArgumentCodersMac.mm; sourceTree = "<group>"; };
    44764473                E17AE2C116B9C139001C42F1 /* com.apple.WebKit.NetworkProcess.sb.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = com.apple.WebKit.NetworkProcess.sb.in; sourceTree = "<group>"; };
    44774474                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; };
     
    78617858                        isa = PBXGroup;
    78627859                        children = (
    7863                                 E179FD9B134D38060015B883 /* ArgumentCodersMac.h */,
    7864                                 E179FD9E134D38250015B883 /* ArgumentCodersMac.mm */,
    78657860                                E1A31731134CEA6C007C9A4F /* AttributedString.h */,
    78667861                                E1A31734134CEA80007C9A4F /* AttributedString.mm */,
     
    90619056                                1AAF0C4A12B16334008E49E2 /* ArgumentCodersCF.h in Headers */,
    90629057                                A175C44A21AA3171000037D0 /* ArgumentCodersCocoa.h in Headers */,
    9063                                 E179FD9C134D38060015B883 /* ArgumentCodersMac.h in Headers */,
    90649058                                CE1A0BD21A48E6C60054EF74 /* AssertionServicesSPI.h in Headers */,
    90659059                                515E7728183DD6F60007203F /* AsyncRequest.h in Headers */,
Note: See TracChangeset for help on using the changeset viewer.