| Differences between
and this patch
- Source/WebKit/ChangeLog +103 lines
Lines 1-3 Source/WebKit/ChangeLog_sec1
1
2021-05-21  Sam Weinig  <weinig@apple.com>
2
3
        Make CGColorSpaceRef argument coding match other CF objects and use CGColorSpaceCreateWithPropertyList for fallback
4
        https://bugs.webkit.org/show_bug.cgi?id=226112
5
6
        Reviewed by Darin Adler.
7
8
        This is a precursor to some color space type unification. This change:
9
        
10
        - Modernizes CF arugment coders to use ArgumentCoder specialization. It also means
11
          we now support encoding CF types both as plain types and RetainPtr<> types, with
12
          decoding being kept only supporing RetainPtr<>s, as decoding into non-smart pointer
13
          is not very useful.
14
        - Move CGColorSpaceRef coding to ArgumentCodersCF and use CGColorSpaceCopyPropertyList
15
          and CGColorSpaceCreateWithPropertyList as the fallback coding (if there is no name),
16
          matching what other libraries on macOS and iOS do.
17
        - Switch ColorSpaceData to be a struct wrapping an Optional<RetainPtr<CGColorSpaceRef>>
18
          and use the new shared coding. This will be replaced entirely in subsequent changes
19
          so I didn't want to change this too much now.
20
21
        * NetworkProcess/NetworkProcessCreationParameters.cpp:
22
        (WebKit::NetworkProcessCreationParameters::encode const):
23
        (WebKit::NetworkProcessCreationParameters::decode):
24
        * NetworkProcess/NetworkSessionCreationParameters.cpp:
25
        (WebKit::NetworkSessionCreationParameters::encode const):
26
        (WebKit::NetworkSessionCreationParameters::decode):
27
        * Shared/Cocoa/ArgumentCodersCocoa.mm:
28
        (IPC::encodeDataInternal):
29
        (IPC::decodeDataInternal):
30
        (IPC::encodeDateInternal):
31
        (IPC::decodeDateInternal):
32
        (IPC::encodeNumberInternal):
33
        (IPC::decodeNumberInternal):
34
        (IPC::encodeSecureCodingInternal):
35
        (IPC::decodeSecureCodingInternal):
36
        (IPC::encodeStringInternal):
37
        (IPC::decodeStringInternal):
38
        (IPC::encodeURLInternal):
39
        (IPC::decodeURLInternal):
40
        * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
41
        (IPC::ArgumentCoder<Ref<Font>>::encodePlatformData):
42
        (IPC::ArgumentCoder<Ref<Font>>::decodePlatformData):
43
        * Shared/FontInfo.cpp:
44
        (WebKit::FontInfo::encode const):
45
        (WebKit::FontInfo::decode):
46
        * Shared/Plugins/PluginProcessCreationParameters.cpp:
47
        (WebKit::PluginProcessCreationParameters::encode const):
48
        (WebKit::PluginProcessCreationParameters::decode):
49
        * Shared/WebProcessCreationParameters.cpp:
50
        (WebKit::WebProcessCreationParameters::encode const):
51
        (WebKit::WebProcessCreationParameters::decode):
52
        * Shared/cf/ArgumentCodersCF.cpp:
53
        (IPC::typeFromCFTypeRef):
54
        (IPC::ArgumentCoder<CFTypeRef>::encode):
55
        (IPC::ArgumentCoder<RetainPtr<CFTypeRef>>::decode):
56
        (IPC::ArgumentCoder<CFArrayRef>::encode):
57
        (IPC::ArgumentCoder<RetainPtr<CFArrayRef>>::decode):
58
        (IPC::ArgumentCoder<CFBooleanRef>::encode):
59
        (IPC::ArgumentCoder<RetainPtr<CFBooleanRef>>::decode):
60
        (IPC::ArgumentCoder<CFDataRef>::encode):
61
        (IPC::ArgumentCoder<RetainPtr<CFDataRef>>::decode):
62
        (IPC::ArgumentCoder<CFDateRef>::encode):
63
        (IPC::ArgumentCoder<RetainPtr<CFDateRef>>::decode):
64
        (IPC::ArgumentCoder<CFDictionaryRef>::encode):
65
        (IPC::ArgumentCoder<RetainPtr<CFDictionaryRef>>::decode):
66
        (IPC::ArgumentCoder<CFNumberRef>::encode):
67
        (IPC::ArgumentCoder<RetainPtr<CFNumberRef>>::decode):
68
        (IPC::ArgumentCoder<CFStringRef>::encode):
69
        (IPC::ArgumentCoder<RetainPtr<CFStringRef>>::decode):
70
        (IPC::ArgumentCoder<CFURLRef>::encode):
71
        (IPC::ArgumentCoder<RetainPtr<CFURLRef>>::decode):
72
        (IPC::ArgumentCoder<CGColorSpaceRef>::encode):
73
        (IPC::ArgumentCoder<RetainPtr<CGColorSpaceRef>>::decode):
74
        (IPC::ArgumentCoder<SecCertificateRef>::encode):
75
        (IPC::ArgumentCoder<RetainPtr<SecCertificateRef>>::decode):
76
        (IPC::ArgumentCoder<SecKeychainItemRef>::encode):
77
        (IPC::ArgumentCoder<RetainPtr<SecKeychainItemRef>>::decode):
78
        (IPC::ArgumentCoder<SecAccessControlRef>::encode):
79
        (IPC::ArgumentCoder<RetainPtr<SecAccessControlRef>>::decode):
80
        (IPC::ArgumentCoder<SecTrustRef>::encode):
81
        (IPC::ArgumentCoder<RetainPtr<SecTrustRef>>::decode):
82
        (IPC::encode): Deleted.
83
        (IPC::decode): Deleted.
84
        * Shared/cf/ArgumentCodersCF.h:
85
        (IPC::CFRetainPtrArgumentCoder::encode):
86
        * Shared/mac/ColorSpaceData.mm:
87
        (WebKit::ColorSpaceData::encode const):
88
        (WebKit::ColorSpaceData::decode):
89
        (): Deleted.
90
        * Shared/mac/SecItemRequestData.cpp:
91
        (WebKit::SecItemRequestData::encode const):
92
        (WebKit::SecItemRequestData::decode):
93
        * Shared/mac/SecItemResponseData.cpp:
94
        (WebKit::SecItemResponseData::encode const):
95
        (WebKit::SecItemResponseData::decode):
96
        * Shared/mac/WebCoreArgumentCodersMac.mm:
97
        (IPC::ArgumentCoder<WebCore::CertificateInfo>::encode):
98
        (IPC::ArgumentCoder<WebCore::CertificateInfo>::decode):
99
        (IPC::encodeNSError):
100
        (IPC::decodeNSError):
101
        (IPC::ArgumentCoder<WebCore::ContentFilterUnblockHandler>::encode):
102
        (IPC::ArgumentCoder<WebCore::ContentFilterUnblockHandler>::decode):
103
1
2021-05-21  Brent Fulgham  <bfulgham@apple.com>
104
2021-05-21  Brent Fulgham  <bfulgham@apple.com>
2
105
3
        [Cocoa] Expand IOKit method filters to cover items encountered during testing
106
        [Cocoa] Expand IOKit method filters to cover items encountered during testing
- Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp -2 / +2 lines
Lines 57-63 void NetworkProcessCreationParameters::e Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp_sec1
57
    encoder << urlSchemesRegisteredForCustomProtocols;
57
    encoder << urlSchemesRegisteredForCustomProtocols;
58
#if PLATFORM(COCOA)
58
#if PLATFORM(COCOA)
59
    encoder << uiProcessBundleIdentifier;
59
    encoder << uiProcessBundleIdentifier;
60
    IPC::encode(encoder, networkATSContext.get());
60
    encoder << networkATSContext;
61
#endif
61
#endif
62
#if USE(SOUP)
62
#if USE(SOUP)
63
    encoder << cookieAcceptPolicy;
63
    encoder << cookieAcceptPolicy;
Lines 115-121 bool NetworkProcessCreationParameters::d Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp_sec2
115
#if PLATFORM(COCOA)
115
#if PLATFORM(COCOA)
116
    if (!decoder.decode(result.uiProcessBundleIdentifier))
116
    if (!decoder.decode(result.uiProcessBundleIdentifier))
117
        return false;
117
        return false;
118
    if (!IPC::decode(decoder, result.networkATSContext))
118
    if (!decoder.decode(result.networkATSContext))
119
        return false;
119
        return false;
120
#endif
120
#endif
121
121
- Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.cpp -2 / +2 lines
Lines 44-50 void NetworkSessionCreationParameters::e Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.cpp_sec1
44
    encoder << boundInterfaceIdentifier;
44
    encoder << boundInterfaceIdentifier;
45
    encoder << allowsCellularAccess;
45
    encoder << allowsCellularAccess;
46
#if PLATFORM(COCOA)
46
#if PLATFORM(COCOA)
47
    IPC::encode(encoder, proxyConfiguration.get());
47
    encoder << proxyConfiguration;
48
    encoder << sourceApplicationBundleIdentifier;
48
    encoder << sourceApplicationBundleIdentifier;
49
    encoder << sourceApplicationSecondaryIdentifier;
49
    encoder << sourceApplicationSecondaryIdentifier;
50
    encoder << attributedBundleIdentifier;
50
    encoder << attributedBundleIdentifier;
Lines 108-114 Optional<NetworkSessionCreationParameter Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.cpp_sec2
108
    
108
    
109
#if PLATFORM(COCOA)
109
#if PLATFORM(COCOA)
110
    RetainPtr<CFDictionaryRef> proxyConfiguration;
110
    RetainPtr<CFDictionaryRef> proxyConfiguration;
111
    if (!IPC::decode(decoder, proxyConfiguration))
111
    if (!decoder.decode(proxyConfiguration))
112
        return WTF::nullopt;
112
        return WTF::nullopt;
113
    
113
    
114
    Optional<String> sourceApplicationBundleIdentifier;
114
    Optional<String> sourceApplicationBundleIdentifier;
- Source/WebKit/Shared/FontInfo.cpp -2 / +2 lines
Lines 39-45 void FontInfo::encode(IPC::Encoder& enco Source/WebKit/Shared/FontInfo.cpp_sec1
39
#if PLATFORM(COCOA)
39
#if PLATFORM(COCOA)
40
    encoder << static_cast<bool>(fontAttributeDictionary);
40
    encoder << static_cast<bool>(fontAttributeDictionary);
41
    if (fontAttributeDictionary)
41
    if (fontAttributeDictionary)
42
        IPC::encode(encoder, fontAttributeDictionary.get());
42
        encoder << fontAttributeDictionary;
43
#else
43
#else
44
    UNUSED_PARAM(encoder);
44
    UNUSED_PARAM(encoder);
45
#endif
45
#endif
Lines 55-61 bool FontInfo::decode(IPC::Decoder& deco Source/WebKit/Shared/FontInfo.cpp_sec2
55
    if (!hasFontAttributeDictionary)
55
    if (!hasFontAttributeDictionary)
56
        return true;
56
        return true;
57
57
58
    if (!IPC::decode(decoder, fontInfo.fontAttributeDictionary))
58
    if (!decoder.decode(fontInfo.fontAttributeDictionary))
59
        return false;
59
        return false;
60
#else
60
#else
61
    UNUSED_PARAM(decoder);
61
    UNUSED_PARAM(decoder);
- Source/WebKit/Shared/WebProcessCreationParameters.cpp -2 / +2 lines
Lines 129-135 void WebProcessCreationParameters::encod Source/WebKit/Shared/WebProcessCreationParameters.cpp_sec1
129
#endif
129
#endif
130
130
131
#if PLATFORM(COCOA)
131
#if PLATFORM(COCOA)
132
    IPC::encode(encoder, networkATSContext.get());
132
    encoder << networkATSContext;
133
#endif
133
#endif
134
134
135
#if PLATFORM(WAYLAND)
135
#if PLATFORM(WAYLAND)
Lines 387-393 bool WebProcessCreationParameters::decod Source/WebKit/Shared/WebProcessCreationParameters.cpp_sec2
387
#endif
387
#endif
388
388
389
#if PLATFORM(COCOA)
389
#if PLATFORM(COCOA)
390
    if (!IPC::decode(decoder, parameters.networkATSContext))
390
    if (!decoder.decode(parameters.networkATSContext))
391
        return false;
391
        return false;
392
#endif
392
#endif
393
393
- Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm -12 / +12 lines
Lines 306-318 static inline Optional<RetainPtr<id>> de Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm_sec1
306
306
307
static inline void encodeDataInternal(Encoder& encoder, NSData *data)
307
static inline void encodeDataInternal(Encoder& encoder, NSData *data)
308
{
308
{
309
    encode(encoder, (__bridge CFDataRef)data);
309
    encoder << (__bridge CFDataRef)data;
310
}
310
}
311
311
312
static inline Optional<RetainPtr<id>> decodeDataInternal(Decoder& decoder)
312
static inline Optional<RetainPtr<id>> decodeDataInternal(Decoder& decoder)
313
{
313
{
314
    RetainPtr<CFDataRef> data;
314
    RetainPtr<CFDataRef> data;
315
    if (!decode(decoder, data))
315
    if (!decoder.decode(data))
316
        return WTF::nullopt;
316
        return WTF::nullopt;
317
    return { adoptNS((NSData *)data.leakRef()) };
317
    return { adoptNS((NSData *)data.leakRef()) };
318
}
318
}
Lines 321-333 static inline Optional<RetainPtr<id>> de Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm_sec2
321
321
322
static inline void encodeDateInternal(Encoder& encoder, NSDate *date)
322
static inline void encodeDateInternal(Encoder& encoder, NSDate *date)
323
{
323
{
324
    encode(encoder, (__bridge CFDateRef)date);
324
    encoder << (__bridge CFDateRef)date;
325
}
325
}
326
326
327
static inline Optional<RetainPtr<id>> decodeDateInternal(Decoder& decoder)
327
static inline Optional<RetainPtr<id>> decodeDateInternal(Decoder& decoder)
328
{
328
{
329
    RetainPtr<CFDateRef> date;
329
    RetainPtr<CFDateRef> date;
330
    if (!decode(decoder, date))
330
    if (!decoder.decode(date))
331
        return WTF::nullopt;
331
        return WTF::nullopt;
332
    return { adoptNS((NSDate *)date.leakRef()) };
332
    return { adoptNS((NSDate *)date.leakRef()) };
333
}
333
}
Lines 414-426 static Optional<RetainPtr<id>> decodeFon Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm_sec3
414
414
415
static inline void encodeNumberInternal(Encoder& encoder, NSNumber *number)
415
static inline void encodeNumberInternal(Encoder& encoder, NSNumber *number)
416
{
416
{
417
    encode(encoder, (__bridge CFNumberRef)number);
417
    encoder << (__bridge CFNumberRef)number;
418
}
418
}
419
419
420
static inline Optional<RetainPtr<id>> decodeNumberInternal(Decoder& decoder)
420
static inline Optional<RetainPtr<id>> decodeNumberInternal(Decoder& decoder)
421
{
421
{
422
    RetainPtr<CFNumberRef> number;
422
    RetainPtr<CFNumberRef> number;
423
    if (!decode(decoder, number))
423
    if (!decoder.decode(number))
424
        return WTF::nullopt;
424
        return WTF::nullopt;
425
    return { adoptNS((NSNumber *)number.leakRef()) };
425
    return { adoptNS((NSNumber *)number.leakRef()) };
426
}
426
}
Lines 438-444 static void encodeSecureCodingInternal(E Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm_sec4
438
    [archiver finishEncoding];
438
    [archiver finishEncoding];
439
    [archiver setDelegate:nil];
439
    [archiver setDelegate:nil];
440
440
441
    encode(encoder, (__bridge CFDataRef)[archiver encodedData]);
441
    encoder << (__bridge CFDataRef)[archiver encodedData];
442
}
442
}
443
443
444
static Optional<RetainPtr<id>> decodeSecureCodingInternal(Decoder& decoder, NSArray<Class> *allowedClasses)
444
static Optional<RetainPtr<id>> decodeSecureCodingInternal(Decoder& decoder, NSArray<Class> *allowedClasses)
Lines 448-454 static Optional<RetainPtr<id>> decodeSec Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm_sec5
448
        return WTF::nullopt;
448
        return WTF::nullopt;
449
449
450
    RetainPtr<CFDataRef> data;
450
    RetainPtr<CFDataRef> data;
451
    if (!decode(decoder, data))
451
    if (!decoder.decode(data))
452
        return WTF::nullopt;
452
        return WTF::nullopt;
453
453
454
    auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingFromData:(__bridge NSData *)data.get() error:nullptr]);
454
    auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingFromData:(__bridge NSData *)data.get() error:nullptr]);
Lines 477-489 static Optional<RetainPtr<id>> decodeSec Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm_sec6
477
477
478
static inline void encodeStringInternal(Encoder& encoder, NSString *string)
478
static inline void encodeStringInternal(Encoder& encoder, NSString *string)
479
{
479
{
480
    encode(encoder, (__bridge CFStringRef)string);
480
    encoder << (__bridge CFStringRef)string;
481
}
481
}
482
482
483
static inline Optional<RetainPtr<id>> decodeStringInternal(Decoder& decoder)
483
static inline Optional<RetainPtr<id>> decodeStringInternal(Decoder& decoder)
484
{
484
{
485
    RetainPtr<CFStringRef> string;
485
    RetainPtr<CFStringRef> string;
486
    if (!decode(decoder, string))
486
    if (!decoder.decode(string))
487
        return WTF::nullopt;
487
        return WTF::nullopt;
488
    return { adoptNS((NSString *)string.leakRef()) };
488
    return { adoptNS((NSString *)string.leakRef()) };
489
}
489
}
Lines 492-504 static inline Optional<RetainPtr<id>> de Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm_sec7
492
492
493
static inline void encodeURLInternal(Encoder& encoder, NSURL *URL)
493
static inline void encodeURLInternal(Encoder& encoder, NSURL *URL)
494
{
494
{
495
    encode(encoder, (__bridge CFURLRef)URL);
495
    encoder << (__bridge CFURLRef)URL;
496
}
496
}
497
497
498
static inline Optional<RetainPtr<id>> decodeURLInternal(Decoder& decoder)
498
static inline Optional<RetainPtr<id>> decodeURLInternal(Decoder& decoder)
499
{
499
{
500
    RetainPtr<CFURLRef> URL;
500
    RetainPtr<CFURLRef> URL;
501
    if (!decode(decoder, URL))
501
    if (!decoder.decode(URL))
502
        return WTF::nullopt;
502
        return WTF::nullopt;
503
    return { adoptNS((NSURL *)URL.leakRef()) };
503
    return { adoptNS((NSURL *)URL.leakRef()) };
504
}
504
}
- Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm -5 / +6 lines
Lines 431-437 void ArgumentCoder<Ref<Font>>::encodePla Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm_sec1
431
    auto ctFont = platformData.font();
431
    auto ctFont = platformData.font();
432
    auto fontDescriptor = adoptCF(CTFontCopyFontDescriptor(ctFont));
432
    auto fontDescriptor = adoptCF(CTFontCopyFontDescriptor(ctFont));
433
    auto attributes = adoptCF(CTFontDescriptorCopyAttributes(fontDescriptor.get()));
433
    auto attributes = adoptCF(CTFontDescriptorCopyAttributes(fontDescriptor.get()));
434
    IPC::encode(encoder, attributes.get());
434
    encoder << attributes;
435
435
436
    const auto& creationData = platformData.creationData();
436
    const auto& creationData = platformData.creationData();
437
    encoder << static_cast<bool>(creationData);
437
    encoder << static_cast<bool>(creationData);
Lines 499-506 Optional<FontPlatformData> ArgumentCoder Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm_sec2
499
    if (!syntheticOblique.hasValue())
499
    if (!syntheticOblique.hasValue())
500
        return WTF::nullopt;
500
        return WTF::nullopt;
501
501
502
    RetainPtr<CFDictionaryRef> attributes;
502
    Optional<RetainPtr<CFDictionaryRef>> attributes;
503
    if (!IPC::decode(decoder, attributes))
503
    decoder >> attributes;
504
    if (!attributes)
504
        return WTF::nullopt;
505
        return WTF::nullopt;
505
506
506
    Optional<bool> includesCreationData;
507
    Optional<bool> includesCreationData;
Lines 525-531 Optional<FontPlatformData> ArgumentCoder Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm_sec3
525
        auto baseFontDescriptor = fontCustomPlatformData->fontDescriptor.get();
526
        auto baseFontDescriptor = fontCustomPlatformData->fontDescriptor.get();
526
        if (!baseFontDescriptor)
527
        if (!baseFontDescriptor)
527
            return WTF::nullopt;
528
            return WTF::nullopt;
528
        auto fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(baseFontDescriptor, attributes.get()));
529
        auto fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(baseFontDescriptor, attributes->get()));
529
        auto ctFont = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), size.value(), nullptr));
530
        auto ctFont = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), size.value(), nullptr));
530
531
531
        auto creationData = FontPlatformData::CreationData { fontFaceData.value(), itemInCollection.value() };
532
        auto creationData = FontPlatformData::CreationData { fontFaceData.value(), itemInCollection.value() };
Lines 545-551 Optional<FontPlatformData> ArgumentCoder Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm_sec4
545
    RetainPtr<CTFontDescriptorRef> fontDescriptor = findFontDescriptor(referenceURL.value(), postScriptName.value());
546
    RetainPtr<CTFontDescriptorRef> fontDescriptor = findFontDescriptor(referenceURL.value(), postScriptName.value());
546
    if (!fontDescriptor)
547
    if (!fontDescriptor)
547
        return WTF::nullopt;
548
        return WTF::nullopt;
548
    fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(fontDescriptor.get(), attributes.get()));
549
    fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(fontDescriptor.get(), attributes->get()));
549
    auto ctFont = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), size.value(), nullptr));
550
    auto ctFont = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), size.value(), nullptr));
550
551
551
    return FontPlatformData(ctFont.get(), size.value(), syntheticBold.value(), syntheticOblique.value(), orientation.value(), widthVariant.value(), textRenderingMode.value());
552
    return FontPlatformData(ctFont.get(), size.value(), syntheticBold.value(), syntheticOblique.value(), orientation.value(), widthVariant.value(), textRenderingMode.value());
- Source/WebKit/Shared/Plugins/PluginProcessCreationParameters.cpp -2 / +2 lines
Lines 46-52 void PluginProcessCreationParameters::en Source/WebKit/Shared/Plugins/PluginProcessCreationParameters.cpp_sec1
46
    encoder << terminationTimeout;
46
    encoder << terminationTimeout;
47
#if PLATFORM(COCOA)
47
#if PLATFORM(COCOA)
48
    encoder << acceleratedCompositingPort;
48
    encoder << acceleratedCompositingPort;
49
    IPC::encode(encoder, networkATSContext.get());
49
    encoder << networkATSContext;
50
#endif
50
#endif
51
}
51
}
52
52
Lines 61-67 bool PluginProcessCreationParameters::de Source/WebKit/Shared/Plugins/PluginProcessCreationParameters.cpp_sec2
61
#if PLATFORM(COCOA)
61
#if PLATFORM(COCOA)
62
    if (!decoder.decode(result.acceleratedCompositingPort))
62
    if (!decoder.decode(result.acceleratedCompositingPort))
63
        return false;
63
        return false;
64
    if (!IPC::decode(decoder, result.networkATSContext))
64
    if (!decoder.decode(result.networkATSContext))
65
        return false;
65
        return false;
66
#endif
66
#endif
67
67
- Source/WebKit/Shared/cf/ArgumentCodersCF.cpp -112 / +236 lines
Lines 32-37 Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec1
32
#include "DataReference.h"
32
#include "DataReference.h"
33
#include "Decoder.h"
33
#include "Decoder.h"
34
#include "Encoder.h"
34
#include "Encoder.h"
35
#include "StreamConnectionEncoder.h"
36
#include <CoreGraphics/CoreGraphics.h>
35
#include <wtf/EnumTraits.h>
37
#include <wtf/EnumTraits.h>
36
#include <wtf/HashSet.h>
38
#include <wtf/HashSet.h>
37
#include <wtf/ProcessPrivilege.h>
39
#include <wtf/ProcessPrivilege.h>
Lines 72-77 enum class CFType : uint8_t { Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec2
72
#if HAVE(SEC_TRUST_SERIALIZATION)
74
#if HAVE(SEC_TRUST_SERIALIZATION)
73
    SecTrust,
75
    SecTrust,
74
#endif
76
#endif
77
    CGColorSpace,
75
    Nullptr,
78
    Nullptr,
76
    Unknown,
79
    Unknown,
77
};
80
};
Lines 102-107 static CFType typeFromCFTypeRef(CFTypeRe Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec3
102
        return CFType::CFString;
105
        return CFType::CFString;
103
    if (typeID == CFURLGetTypeID())
106
    if (typeID == CFURLGetTypeID())
104
        return CFType::CFURL;
107
        return CFType::CFURL;
108
    if (typeID == CGColorSpaceGetTypeID())
109
        return CFType::CGColorSpace;
105
    if (typeID == SecCertificateGetTypeID())
110
    if (typeID == SecCertificateGetTypeID())
106
        return CFType::SecCertificate;
111
        return CFType::SecCertificate;
107
#if HAVE(SEC_KEYCHAIN)
112
#if HAVE(SEC_KEYCHAIN)
Lines 121-174 static CFType typeFromCFTypeRef(CFTypeRe Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec4
121
    return CFType::Unknown;
126
    return CFType::Unknown;
122
}
127
}
123
128
124
void encode(Encoder& encoder, CFTypeRef typeRef)
129
130
template<typename Encoder>
131
void ArgumentCoder<CFTypeRef>::encode(Encoder& encoder, CFTypeRef typeRef)
125
{
132
{
126
    CFType type = typeFromCFTypeRef(typeRef);
133
    auto type = typeFromCFTypeRef(typeRef);
127
    encoder << type;
134
    encoder << type;
128
135
129
    switch (type) {
136
    switch (type) {
130
    case CFType::CFArray:
137
    case CFType::CFArray:
131
        encode(encoder, static_cast<CFArrayRef>(typeRef));
138
        encoder << static_cast<CFArrayRef>(typeRef);
132
        return;
139
        return;
133
    case CFType::CFBoolean:
140
    case CFType::CFBoolean:
134
        encode(encoder, static_cast<CFBooleanRef>(typeRef));
141
        encoder << static_cast<CFBooleanRef>(typeRef);
135
        return;
142
        return;
136
    case CFType::CFData:
143
    case CFType::CFData:
137
        encode(encoder, static_cast<CFDataRef>(typeRef));
144
        encoder << static_cast<CFDataRef>(typeRef);
138
        return;
145
        return;
139
    case CFType::CFDate:
146
    case CFType::CFDate:
140
        encode(encoder, static_cast<CFDateRef>(typeRef));
147
        encoder << static_cast<CFDateRef>(typeRef);
141
        return;
148
        return;
142
    case CFType::CFDictionary:
149
    case CFType::CFDictionary:
143
        encode(encoder, static_cast<CFDictionaryRef>(typeRef));
150
        encoder << static_cast<CFDictionaryRef>(typeRef);
144
        return;
151
        return;
145
    case CFType::CFNull:
152
    case CFType::CFNull:
146
        return;
153
        return;
147
    case CFType::CFNumber:
154
    case CFType::CFNumber:
148
        encode(encoder, static_cast<CFNumberRef>(typeRef));
155
        encoder << static_cast<CFNumberRef>(typeRef);
149
        return;
156
        return;
150
    case CFType::CFString:
157
    case CFType::CFString:
151
        encode(encoder, static_cast<CFStringRef>(typeRef));
158
        encoder << static_cast<CFStringRef>(typeRef);
152
        return;
159
        return;
153
    case CFType::CFURL:
160
    case CFType::CFURL:
154
        encode(encoder, static_cast<CFURLRef>(typeRef));
161
        encoder << static_cast<CFURLRef>(typeRef);
162
        return;
163
    case CFType::CGColorSpace:
164
        encoder << static_cast<CGColorSpaceRef>(const_cast<void*>(typeRef));
155
        return;
165
        return;
156
    case CFType::SecCertificate:
166
    case CFType::SecCertificate:
157
        encode(encoder, static_cast<SecCertificateRef>(const_cast<void*>(typeRef)));
167
        encoder << static_cast<SecCertificateRef>(const_cast<void*>(typeRef));
158
        return;
168
        return;
159
#if HAVE(SEC_KEYCHAIN)
169
#if HAVE(SEC_KEYCHAIN)
160
    case CFType::SecKeychainItem:
170
    case CFType::SecKeychainItem:
161
        encode(encoder, static_cast<SecKeychainItemRef>(const_cast<void*>(typeRef)));
171
        encoder << static_cast<SecKeychainItemRef>(const_cast<void*>(typeRef));
162
        return;
172
        return;
163
#endif
173
#endif
164
#if HAVE(SEC_ACCESS_CONTROL)
174
#if HAVE(SEC_ACCESS_CONTROL)
165
    case CFType::SecAccessControl:
175
    case CFType::SecAccessControl:
166
        encode(encoder, static_cast<SecAccessControlRef>(const_cast<void*>(typeRef)));
176
        encoder << static_cast<SecAccessControlRef>(const_cast<void*>(typeRef));
167
        return;
177
        return;
168
#endif
178
#endif
169
#if HAVE(SEC_TRUST_SERIALIZATION)
179
#if HAVE(SEC_TRUST_SERIALIZATION)
170
    case CFType::SecTrust:
180
    case CFType::SecTrust:
171
        encode(encoder, static_cast<SecTrustRef>(const_cast<void*>(typeRef)));
181
        encoder << static_cast<SecTrustRef>(const_cast<void*>(typeRef));
172
        return;
182
        return;
173
#endif
183
#endif
174
    case CFType::Nullptr:
184
    case CFType::Nullptr:
Lines 180-225 void encode(Encoder& encoder, CFTypeRef Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec5
180
    ASSERT_NOT_REACHED();
190
    ASSERT_NOT_REACHED();
181
}
191
}
182
192
183
bool decode(Decoder& decoder, RetainPtr<CFTypeRef>& result)
193
template void ArgumentCoder<CFTypeRef>::encode<Encoder>(Encoder&, CFTypeRef);
194
template void ArgumentCoder<CFTypeRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, CFTypeRef);
195
196
bool ArgumentCoder<RetainPtr<CFTypeRef>>::decode(Decoder& decoder, RetainPtr<CFTypeRef>& result)
184
{
197
{
185
    CFType type;
198
    Optional<CFType> type;
186
    if (!decoder.decode(type))
199
    decoder >> type;
200
    if (!type)
187
        return false;
201
        return false;
188
202
189
    switch (type) {
203
    switch (*type) {
190
    case CFType::CFArray: {
204
    case CFType::CFArray: {
191
        RetainPtr<CFArrayRef> array;
205
        RetainPtr<CFArrayRef> array;
192
        if (!decode(decoder, array))
206
        if (!decoder.decode(array))
193
            return false;
207
            return false;
194
        result = adoptCF(array.leakRef());
208
        result = WTFMove(array);
195
        return true;
209
        return true;
196
    }
210
    }
197
    case CFType::CFBoolean: {
211
    case CFType::CFBoolean: {
198
        RetainPtr<CFBooleanRef> boolean;
212
        RetainPtr<CFBooleanRef> boolean;
199
        if (!decode(decoder, boolean))
213
        if (!decoder.decode(boolean))
200
            return false;
214
            return false;
201
        result = adoptCF(boolean.leakRef());
215
        result = WTFMove(boolean);
202
        return true;
216
        return true;
203
    }
217
    }
204
    case CFType::CFData: {
218
    case CFType::CFData: {
205
        RetainPtr<CFDataRef> data;
219
        RetainPtr<CFDataRef> data;
206
        if (!decode(decoder, data))
220
        if (!decoder.decode(data))
207
            return false;
221
            return false;
208
        result = adoptCF(data.leakRef());
222
        result = WTFMove(data);
209
        return true;
223
        return true;
210
    }
224
    }
211
    case CFType::CFDate: {
225
    case CFType::CFDate: {
212
        RetainPtr<CFDateRef> date;
226
        RetainPtr<CFDateRef> date;
213
        if (!decode(decoder, date))
227
        if (!decoder.decode(date))
214
            return false;
228
            return false;
215
        result = adoptCF(date.leakRef());
229
        result = WTFMove(date);
216
        return true;
230
        return true;
217
    }
231
    }
218
    case CFType::CFDictionary: {
232
    case CFType::CFDictionary: {
219
        RetainPtr<CFDictionaryRef> dictionary;
233
        RetainPtr<CFDictionaryRef> dictionary;
220
        if (!decode(decoder, dictionary))
234
        if (!decoder.decode(dictionary))
221
            return false;
235
            return false;
222
        result = adoptCF(dictionary.leakRef());
236
        result = WTFMove(dictionary);
223
        return true;
237
        return true;
224
    }
238
    }
225
    case CFType::CFNull:
239
    case CFType::CFNull:
Lines 227-282 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec6
227
        return true;
241
        return true;
228
    case CFType::CFNumber: {
242
    case CFType::CFNumber: {
229
        RetainPtr<CFNumberRef> number;
243
        RetainPtr<CFNumberRef> number;
230
        if (!decode(decoder, number))
244
        if (!decoder.decode(number))
231
            return false;
245
            return false;
232
        result = adoptCF(number.leakRef());
246
        result = WTFMove(number);
233
        return true;
247
        return true;
234
    }
248
    }
235
    case CFType::CFString: {
249
    case CFType::CFString: {
236
        RetainPtr<CFStringRef> string;
250
        RetainPtr<CFStringRef> string;
237
        if (!decode(decoder, string))
251
        if (!decoder.decode(string))
238
            return false;
252
            return false;
239
        result = adoptCF(string.leakRef());
253
        result = WTFMove(string);
240
        return true;
254
        return true;
241
    }
255
    }
242
    case CFType::CFURL: {
256
    case CFType::CFURL: {
243
        RetainPtr<CFURLRef> url;
257
        RetainPtr<CFURLRef> url;
244
        if (!decode(decoder, url))
258
        if (!decoder.decode(url))
259
            return false;
260
        result = WTFMove(url);
261
        return true;
262
    }
263
    case CFType::CGColorSpace: {
264
        RetainPtr<CGColorSpaceRef> colorSpace;
265
        if (!decoder.decode(colorSpace))
245
            return false;
266
            return false;
246
        result = adoptCF(url.leakRef());
267
        result = WTFMove(colorSpace);
247
        return true;
268
        return true;
248
    }
269
    }
249
    case CFType::SecCertificate: {
270
    case CFType::SecCertificate: {
250
        RetainPtr<SecCertificateRef> certificate;
271
        RetainPtr<SecCertificateRef> certificate;
251
        if (!decode(decoder, certificate))
272
        if (!decoder.decode(certificate))
252
            return false;
273
            return false;
253
        result = adoptCF(certificate.leakRef());
274
        result = WTFMove(certificate);
254
        return true;
275
        return true;
255
    }
276
    }
256
#if HAVE(SEC_KEYCHAIN)
277
#if HAVE(SEC_KEYCHAIN)
257
    case CFType::SecKeychainItem: {
278
    case CFType::SecKeychainItem: {
258
        RetainPtr<SecKeychainItemRef> keychainItem;
279
        RetainPtr<SecKeychainItemRef> keychainItem;
259
        if (!decode(decoder, keychainItem))
280
        if (!decoder.decode(keychainItem))
260
            return false;
281
            return false;
261
        result = adoptCF(keychainItem.leakRef());
282
        result = WTFMove(keychainItem);
262
        return true;
283
        return true;
263
    }
284
    }
264
#endif
285
#endif
265
#if HAVE(SEC_ACCESS_CONTROL)
286
#if HAVE(SEC_ACCESS_CONTROL)
266
    case CFType::SecAccessControl: {
287
    case CFType::SecAccessControl: {
267
        RetainPtr<SecAccessControlRef> accessControl;
288
        RetainPtr<SecAccessControlRef> accessControl;
268
        if (!decode(decoder, accessControl))
289
        if (!decoder.decode(accessControl))
269
            return false;
290
            return false;
270
        result = adoptCF(accessControl.leakRef());
291
        result = WTFMove(accessControl);
271
        return true;
292
        return true;
272
    }
293
    }
273
#endif
294
#endif
274
#if HAVE(SEC_TRUST_SERIALIZATION)
295
#if HAVE(SEC_TRUST_SERIALIZATION)
275
    case CFType::SecTrust: {
296
    case CFType::SecTrust: {
276
        RetainPtr<SecTrustRef> trust;
297
        RetainPtr<SecTrustRef> trust;
277
        if (!decode(decoder, trust))
298
        if (!decoder.decode(trust))
278
            return false;
299
            return false;
279
        result = adoptCF(trust.leakRef());
300
        result = WTFMove(trust);
280
        return true;
301
        return true;
281
    }
302
    }
282
#endif
303
#endif
Lines 291-297 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec7
291
    return false;
312
    return false;
292
}
313
}
293
314
294
void encode(Encoder& encoder, CFArrayRef array)
315
template<typename Encoder>
316
void ArgumentCoder<CFArrayRef>::encode(Encoder& encoder, CFArrayRef array)
295
{
317
{
296
    if (!array) {
318
    if (!array) {
297
        encoder << true;
319
        encoder << true;
Lines 318-328 void encode(Encoder& encoder, CFArrayRef Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec8
318
    for (CFIndex i = 0; i < size; ++i) {
340
    for (CFIndex i = 0; i < size; ++i) {
319
        if (invalidIndicies.contains(i))
341
        if (invalidIndicies.contains(i))
320
            continue;
342
            continue;
321
        encode(encoder, values[i]);
343
        encoder << values[i];
322
    }
344
    }
323
}
345
}
324
346
325
bool decode(Decoder& decoder, RetainPtr<CFArrayRef>& result)
347
template void ArgumentCoder<CFArrayRef>::encode<Encoder>(Encoder&, CFArrayRef);
348
template void ArgumentCoder<CFArrayRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, CFArrayRef);
349
350
bool ArgumentCoder<RetainPtr<CFArrayRef>>::decode(Decoder& decoder, RetainPtr<CFArrayRef>& result)
326
{
351
{
327
    bool isNull = false;
352
    bool isNull = false;
328
    if (!decoder.decode(isNull))
353
    if (!decoder.decode(isNull))
Lines 341-347 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec9
341
366
342
    for (size_t i = 0; i < size; ++i) {
367
    for (size_t i = 0; i < size; ++i) {
343
        RetainPtr<CFTypeRef> element;
368
        RetainPtr<CFTypeRef> element;
344
        if (!decode(decoder, element))
369
        if (!decoder.decode(element))
345
            return false;
370
            return false;
346
371
347
        if (!element)
372
        if (!element)
Lines 354-365 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec10
354
    return true;
379
    return true;
355
}
380
}
356
381
357
void encode(Encoder& encoder, CFBooleanRef boolean)
382
template<typename Encoder>
383
void ArgumentCoder<CFBooleanRef>::encode(Encoder& encoder, CFBooleanRef boolean)
358
{
384
{
359
    encoder << static_cast<bool>(CFBooleanGetValue(boolean));
385
    encoder << static_cast<bool>(CFBooleanGetValue(boolean));
360
}
386
}
361
387
362
bool decode(Decoder& decoder, RetainPtr<CFBooleanRef>& result)
388
template void ArgumentCoder<CFBooleanRef>::encode<Encoder>(Encoder&, CFBooleanRef);
389
template void ArgumentCoder<CFBooleanRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, CFBooleanRef);
390
391
bool ArgumentCoder<RetainPtr<CFBooleanRef>>::decode(Decoder& decoder, RetainPtr<CFBooleanRef>& result)
363
{
392
{
364
    bool boolean;
393
    bool boolean;
365
    if (!decoder.decode(boolean))
394
    if (!decoder.decode(boolean))
Lines 369-383 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec11
369
    return true;
398
    return true;
370
}
399
}
371
400
372
void encode(Encoder& encoder, CFDataRef data)
401
template<typename Encoder>
402
void ArgumentCoder<CFDataRef>::encode(Encoder& encoder, CFDataRef data)
373
{
403
{
374
    CFIndex length = CFDataGetLength(data);
404
    encoder << IPC::DataReference(CFDataGetBytePtr(data), CFDataGetLength(data));
375
    const UInt8* bytePtr = CFDataGetBytePtr(data);
376
377
    encoder << IPC::DataReference(bytePtr, length);
378
}
405
}
379
406
380
bool decode(Decoder& decoder, RetainPtr<CFDataRef>& result)
407
template void ArgumentCoder<CFDataRef>::encode<Encoder>(Encoder&, CFDataRef);
408
template void ArgumentCoder<CFDataRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, CFDataRef);
409
410
bool ArgumentCoder<RetainPtr<CFDataRef>>::decode(Decoder& decoder, RetainPtr<CFDataRef>& result)
381
{
411
{
382
    IPC::DataReference dataReference;
412
    IPC::DataReference dataReference;
383
    if (!decoder.decode(dataReference))
413
    if (!decoder.decode(dataReference))
Lines 387-398 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec12
387
    return true;
417
    return true;
388
}
418
}
389
419
390
void encode(Encoder& encoder, CFDateRef date)
420
template<typename Encoder>
421
void ArgumentCoder<CFDateRef>::encode(Encoder& encoder, CFDateRef date)
391
{
422
{
392
    encoder << static_cast<double>(CFDateGetAbsoluteTime(date));
423
    encoder << static_cast<double>(CFDateGetAbsoluteTime(date));
393
}
424
}
394
425
395
bool decode(Decoder& decoder, RetainPtr<CFDateRef>& result)
426
template void ArgumentCoder<CFDateRef>::encode<Encoder>(Encoder&, CFDateRef);
427
template void ArgumentCoder<CFDateRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, CFDateRef);
428
429
bool ArgumentCoder<RetainPtr<CFDateRef>>::decode(Decoder& decoder, RetainPtr<CFDateRef>& result)
396
{
430
{
397
    double absoluteTime;
431
    double absoluteTime;
398
    if (!decoder.decode(absoluteTime))
432
    if (!decoder.decode(absoluteTime))
Lines 402-408 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec13
402
    return true;
436
    return true;
403
}
437
}
404
438
405
void encode(Encoder& encoder, CFDictionaryRef dictionary)
439
template<typename Encoder>
440
void ArgumentCoder<CFDictionaryRef>::encode(Encoder& encoder, CFDictionaryRef dictionary)
406
{
441
{
407
    if (!dictionary) {
442
    if (!dictionary) {
408
        encoder << true;
443
        encoder << true;
Lines 435-446 void encode(Encoder& encoder, CFDictiona Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec14
435
        if (invalidKeys.contains(keys[i]))
470
        if (invalidKeys.contains(keys[i]))
436
            continue;
471
            continue;
437
472
438
        encode(encoder, keys[i]);
473
        encoder << keys[i] << values[i];
439
        encode(encoder, values[i]);
440
    }
474
    }
441
}
475
}
442
476
443
bool decode(Decoder& decoder, RetainPtr<CFDictionaryRef>& result)
477
template void ArgumentCoder<CFDictionaryRef>::encode<Encoder>(Encoder&, CFDictionaryRef);
478
template void ArgumentCoder<CFDictionaryRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, CFDictionaryRef);
479
480
bool ArgumentCoder<RetainPtr<CFDictionaryRef>>::decode(Decoder& decoder, RetainPtr<CFDictionaryRef>& result)
444
{
481
{
445
    bool isNull = false;
482
    bool isNull = false;
446
    if (!decoder.decode(isNull))
483
    if (!decoder.decode(isNull))
Lines 458-478 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec15
458
    RetainPtr<CFMutableDictionaryRef> dictionary = adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
495
    RetainPtr<CFMutableDictionaryRef> dictionary = adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
459
    for (uint64_t i = 0; i < size; ++i) {
496
    for (uint64_t i = 0; i < size; ++i) {
460
        RetainPtr<CFTypeRef> key;
497
        RetainPtr<CFTypeRef> key;
461
        if (!decode(decoder, key) || !key)
498
        if (!decoder.decode(key) || !key)
462
            return false;
499
            return false;
463
500
464
        RetainPtr<CFTypeRef> value;
501
        RetainPtr<CFTypeRef> value;
465
        if (!decode(decoder, value) || !value)
502
        if (!decoder.decode(value) || !value)
466
            return false;
503
            return false;
467
504
468
        CFDictionarySetValue(dictionary.get(), key.get(), value.get());
505
        CFDictionarySetValue(dictionary.get(), key.get(), value.get());
469
    }
506
    }
470
507
471
    result = adoptCF(dictionary.leakRef());
508
    result = WTFMove(dictionary);
472
    return true;
509
    return true;
473
}
510
}
474
511
475
void encode(Encoder& encoder, CFNumberRef number)
512
template<typename Encoder>
513
void ArgumentCoder<CFNumberRef>::encode(Encoder& encoder, CFNumberRef number)
476
{
514
{
477
    CFNumberType numberType = CFNumberGetType(number);
515
    CFNumberType numberType = CFNumberGetType(number);
478
516
Lines 480-489 void encode(Encoder& encoder, CFNumberRe Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec16
480
    bool result = CFNumberGetValue(number, numberType, buffer.data());
518
    bool result = CFNumberGetValue(number, numberType, buffer.data());
481
    ASSERT_UNUSED(result, result);
519
    ASSERT_UNUSED(result, result);
482
520
483
    encoder << static_cast<uint8_t>(numberType);
521
    encoder << static_cast<uint8_t>(numberType) << IPC::DataReference(buffer);
484
    encoder << IPC::DataReference(buffer);
485
}
522
}
486
523
524
template void ArgumentCoder<CFNumberRef>::encode<Encoder>(Encoder&, CFNumberRef);
525
template void ArgumentCoder<CFNumberRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, CFNumberRef);
526
487
static size_t sizeForNumberType(CFNumberType numberType)
527
static size_t sizeForNumberType(CFNumberType numberType)
488
{
528
{
489
    switch (numberType) {
529
    switch (numberType) {
Lines 524-530 static size_t sizeForNumberType(CFNumber Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec17
524
    return 0;
564
    return 0;
525
}
565
}
526
566
527
bool decode(Decoder& decoder, RetainPtr<CFNumberRef>& result)
567
bool ArgumentCoder<RetainPtr<CFNumberRef>>::decode(Decoder& decoder, RetainPtr<CFNumberRef>& result)
528
{
568
{
529
    Optional<uint8_t> numberTypeFromIPC;
569
    Optional<uint8_t> numberTypeFromIPC;
530
    decoder >> numberTypeFromIPC;
570
    decoder >> numberTypeFromIPC;
Lines 546-552 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec18
546
    return true;
586
    return true;
547
}
587
}
548
588
549
void encode(Encoder& encoder, CFStringRef string)
589
template<typename Encoder>
590
void ArgumentCoder<CFStringRef>::encode(Encoder& encoder, CFStringRef string)
550
{
591
{
551
    CFIndex length = CFStringGetLength(string);
592
    CFIndex length = CFStringGetLength(string);
552
    CFStringEncoding encoding = CFStringGetFastestEncoding(string);
593
    CFStringEncoding encoding = CFStringGetFastestEncoding(string);
Lines 561-571 void encode(Encoder& encoder, CFStringRe Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec19
561
    numConvertedBytes = CFStringGetBytes(string, range, encoding, 0, false, buffer.data(), buffer.size(), &bufferLength);
602
    numConvertedBytes = CFStringGetBytes(string, range, encoding, 0, false, buffer.data(), buffer.size(), &bufferLength);
562
    ASSERT(numConvertedBytes == length);
603
    ASSERT(numConvertedBytes == length);
563
604
564
    encoder << static_cast<uint32_t>(encoding);
605
    encoder << static_cast<uint32_t>(encoding) << IPC::DataReference(buffer);
565
    encoder << IPC::DataReference(buffer);
566
}
606
}
567
607
568
bool decode(Decoder& decoder, RetainPtr<CFStringRef>& result)
608
template void ArgumentCoder<CFStringRef>::encode<Encoder>(Encoder&, CFStringRef);
609
template void ArgumentCoder<CFStringRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, CFStringRef);
610
611
bool ArgumentCoder<RetainPtr<CFStringRef>>::decode(Decoder& decoder, RetainPtr<CFStringRef>& result)
569
{
612
{
570
    Optional<uint32_t> encodingFromIPC;
613
    Optional<uint32_t> encodingFromIPC;
571
    decoder >> encodingFromIPC;
614
    decoder >> encodingFromIPC;
Lines 588-614 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec20
588
    return true;
631
    return true;
589
}
632
}
590
633
591
void encode(Encoder& encoder, CFURLRef url)
634
template<typename Encoder>
635
void ArgumentCoder<CFURLRef>::encode(Encoder& encoder, CFURLRef url)
592
{
636
{
593
    CFURLRef baseURL = CFURLGetBaseURL(url);
637
    CFURLRef baseURL = CFURLGetBaseURL(url);
594
    encoder << static_cast<bool>(baseURL);
638
    encoder << static_cast<bool>(baseURL);
595
    if (baseURL)
639
    if (baseURL)
596
        encode(encoder, baseURL);
640
        encoder << baseURL;
597
641
598
    WTF::URLCharBuffer urlBytes;
642
    WTF::URLCharBuffer urlBytes;
599
    WTF::getURLBytes(url, urlBytes);
643
    WTF::getURLBytes(url, urlBytes);
600
    IPC::DataReference dataReference(reinterpret_cast<const uint8_t*>(urlBytes.data()), urlBytes.size());
644
    encoder << IPC::DataReference(reinterpret_cast<const uint8_t*>(urlBytes.data()), urlBytes.size());
601
    encoder << dataReference;
602
}
645
}
603
646
604
bool decode(Decoder& decoder, RetainPtr<CFURLRef>& result)
647
template void ArgumentCoder<CFURLRef>::encode<Encoder>(Encoder&, CFURLRef);
648
template void ArgumentCoder<CFURLRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, CFURLRef);
649
650
bool ArgumentCoder<RetainPtr<CFURLRef>>::decode(Decoder& decoder, RetainPtr<CFURLRef>& result)
605
{
651
{
606
    RetainPtr<CFURLRef> baseURL;
652
    RetainPtr<CFURLRef> baseURL;
607
    bool hasBaseURL;
653
    bool hasBaseURL;
608
    if (!decoder.decode(hasBaseURL))
654
    if (!decoder.decode(hasBaseURL))
609
        return false;
655
        return false;
610
    if (hasBaseURL) {
656
    if (hasBaseURL) {
611
        if (!decode(decoder, baseURL))
657
        if (!decoder.decode(baseURL))
612
            return false;
658
            return false;
613
    }
659
    }
614
660
Lines 631-646 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec21
631
    return result;
677
    return result;
632
}
678
}
633
679
634
void encode(Encoder& encoder, SecCertificateRef certificate)
680
enum class CGColorSpaceEncodingScheme { Name, PropertyList };
681
682
template<typename Encoder>
683
void ArgumentCoder<CGColorSpaceRef>::encode(Encoder& encoder, CGColorSpaceRef colorSpace)
684
{
685
    if (auto name = CGColorSpaceGetName(colorSpace)) {
686
        encoder << CGColorSpaceEncodingScheme::Name << name;
687
        return;
688
    }
689
690
    encoder << CGColorSpaceEncodingScheme::PropertyList << adoptCF(CGColorSpaceCopyPropertyList(colorSpace))
691
}
692
693
template void ArgumentCoder<CGColorSpaceRef>::encode<Encoder>(Encoder&, CGColorSpaceRef);
694
template void ArgumentCoder<CGColorSpaceRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, CGColorSpaceRef);
695
696
bool ArgumentCoder<RetainPtr<CGColorSpaceRef>>::decode(Decoder& decoder, RetainPtr<CGColorSpaceRef>& result)
697
{
698
    CGColorSpaceEncodingScheme encodingScheme;
699
    if (!decoder.decode(encodingScheme))
700
        return false;
701
702
    switch (encodingScheme) {
703
    case CGColorSpaceEncodingScheme::Name: {
704
        RetainPtr<CFStringRef> name;
705
        if (!decoder.decode(name))
706
            return false;
707
708
        auto colorSpace = adoptCF(CGColorSpaceCreateWithName(name.get()));
709
        if (!colorSpace)
710
            return false;
711
712
        result = WTFMove(colorSpace);
713
        return true;
714
    }
715
    case CGColorSpaceEncodingScheme::PropertyList: {
716
        RetainPtr<CFTypeRef> propertyList;
717
        if (!decoder.decode(propertyList))
718
            return false;
719
720
        auto colorSpace = adoptCF(CGColorSpaceCreateWithPropertyList(propertyList.get()));
721
        if (!colorSpace)
722
            return false;
723
724
        result = WTFMove(colorSpace);
725
        return true;
726
    }
727
    }
728
729
    ASSERT_NOT_REACHED();
730
    return false;
731
}
732
733
734
template<typename Encoder>
735
void ArgumentCoder<SecCertificateRef>::encode(Encoder& encoder, SecCertificateRef certificate)
635
{
736
{
636
    RetainPtr<CFDataRef> data = adoptCF(SecCertificateCopyData(certificate));
737
    auto data = adoptCF(SecCertificateCopyData(certificate));
637
    encode(encoder, data.get());
738
    encoder << data;
638
}
739
}
639
740
640
bool decode(Decoder& decoder, RetainPtr<SecCertificateRef>& result)
741
template void ArgumentCoder<SecCertificateRef>::encode<Encoder>(Encoder&, SecCertificateRef);
742
template void ArgumentCoder<SecCertificateRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, SecCertificateRef);
743
744
bool ArgumentCoder<RetainPtr<SecCertificateRef>>::decode(Decoder& decoder, RetainPtr<SecCertificateRef>& result)
641
{
745
{
642
    RetainPtr<CFDataRef> data;
746
    RetainPtr<CFDataRef> data;
643
    if (!decode(decoder, data))
747
    if (!decoder.decode(data))
644
        return false;
748
        return false;
645
749
646
    result = adoptCF(SecCertificateCreateWithData(0, data.get()));
750
    result = adoptCF(SecCertificateCreateWithData(0, data.get()));
Lines 648-670 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec22
648
}
752
}
649
753
650
#if HAVE(SEC_KEYCHAIN)
754
#if HAVE(SEC_KEYCHAIN)
651
void encode(Encoder& encoder, SecKeychainItemRef keychainItem)
755
template<typename Encoder>
756
void ArgumentCoder<SecKeychainItemRef>::encode(Encoder& encoder, SecKeychainItemRef keychainItem)
652
{
757
{
653
    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
758
    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
654
759
655
    CFDataRef data;
760
    CFDataRef data;
656
    if (SecKeychainItemCreatePersistentReference(keychainItem, &data) == errSecSuccess) {
761
    if (SecKeychainItemCreatePersistentReference(keychainItem, &data) == errSecSuccess) {
657
        encode(encoder, data);
762
        encoder << data;
658
        CFRelease(data);
763
        CFRelease(data);
659
    }
764
    }
660
}
765
}
661
766
662
bool decode(Decoder& decoder, RetainPtr<SecKeychainItemRef>& result)
767
template void ArgumentCoder<SecKeychainItemRef>::encode<Encoder>(Encoder&, SecKeychainItemRef);
768
template void ArgumentCoder<SecKeychainItemRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, SecKeychainItemRef);
769
770
bool ArgumentCoder<RetainPtr<SecKeychainItemRef>>::decode(Decoder& decoder, RetainPtr<SecKeychainItemRef>& result)
663
{
771
{
664
    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
772
    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
665
773
666
    RetainPtr<CFDataRef> data;
774
    RetainPtr<CFDataRef> data;
667
    if (!IPC::decode(decoder, data))
775
    if (!decoder.decode(data))
668
        return false;
776
        return false;
669
777
670
    CFDataRef dref = data.get();
778
    CFDataRef dref = data.get();
Lines 682-698 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec23
682
#endif
790
#endif
683
791
684
#if HAVE(SEC_ACCESS_CONTROL)
792
#if HAVE(SEC_ACCESS_CONTROL)
685
void encode(Encoder& encoder, SecAccessControlRef accessControl)
793
template<typename Encoder>
794
void ArgumentCoder<SecAccessControlRef>::encode(Encoder& encoder, SecAccessControlRef accessControl)
686
{
795
{
687
    RetainPtr<CFDataRef> data = adoptCF(SecAccessControlCopyData(accessControl));
796
    auto data = adoptCF(SecAccessControlCopyData(accessControl));
688
    if (data)
797
    if (data)
689
        encode(encoder, data.get());
798
        encoder << data;
690
}
799
}
691
800
692
bool decode(Decoder& decoder, RetainPtr<SecAccessControlRef>& result)
801
template void ArgumentCoder<SecAccessControlRef>::encode<Encoder>(Encoder&, SecAccessControlRef);
802
template void ArgumentCoder<SecAccessControlRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, SecAccessControlRef);
803
804
bool ArgumentCoder<RetainPtr<SecAccessControlRef>>::decode(Decoder& decoder, RetainPtr<SecAccessControlRef>& result)
693
{
805
{
694
    RetainPtr<CFDataRef> data;
806
    RetainPtr<CFDataRef> data;
695
    if (!decode(decoder, data))
807
    if (!decoder.decode(data))
696
        return false;
808
        return false;
697
809
698
    result = adoptCF(SecAccessControlCreateFromData(kCFAllocatorDefault, data.get(), nullptr));
810
    result = adoptCF(SecAccessControlCreateFromData(kCFAllocatorDefault, data.get(), nullptr));
Lines 704-710 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec24
704
#endif
816
#endif
705
817
706
#if HAVE(SEC_TRUST_SERIALIZATION)
818
#if HAVE(SEC_TRUST_SERIALIZATION)
707
void encode(Encoder& encoder, SecTrustRef trust)
819
template<typename Encoder>
820
void ArgumentCoder<SecTrustRef>::encode(Encoder& encoder, SecTrustRef trust)
708
{
821
{
709
    auto data = adoptCF(SecTrustSerialize(trust, nullptr));
822
    auto data = adoptCF(SecTrustSerialize(trust, nullptr));
710
    if (!data) {
823
    if (!data) {
Lines 712-722 void encode(Encoder& encoder, SecTrustRe Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec25
712
        return;
825
        return;
713
    }
826
    }
714
827
715
    encoder << true;
828
    encoder << true << data;
716
    IPC::encode(encoder, data.get());
717
}
829
}
718
830
719
bool decode(Decoder& decoder, RetainPtr<SecTrustRef>& result)
831
template void ArgumentCoder<SecTrustRef>::encode<Encoder>(Encoder&, SecTrustRef);
832
template void ArgumentCoder<SecTrustRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, SecTrustRef);
833
834
bool ArgumentCoder<RetainPtr<SecTrustRef>>::decode(Decoder& decoder, RetainPtr<SecTrustRef>& result)
720
{
835
{
721
    bool hasTrust;
836
    bool hasTrust;
722
    if (!decoder.decode(hasTrust))
837
    if (!decoder.decode(hasTrust))
Lines 726-732 bool decode(Decoder& decoder, RetainPtr< Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec26
726
        return true;
841
        return true;
727
842
728
    RetainPtr<CFDataRef> trustData;
843
    RetainPtr<CFDataRef> trustData;
729
    if (!IPC::decode(decoder, trustData))
844
    if (!decoder.decode(trustData))
730
        return false;
845
        return false;
731
846
732
    auto trust = adoptCF(SecTrustDeserialize(trustData.get(), nullptr));
847
    auto trust = adoptCF(SecTrustDeserialize(trustData.get(), nullptr));
Lines 744-771 namespace WTF { Source/WebKit/Shared/cf/ArgumentCodersCF.cpp_sec27
744
859
745
template<> struct EnumTraits<IPC::CFType> {
860
template<> struct EnumTraits<IPC::CFType> {
746
    using values = EnumValues<
861
    using values = EnumValues<
747
    IPC::CFType,
862
        IPC::CFType,
748
    IPC::CFType::CFArray,
863
        IPC::CFType::CFArray,
749
    IPC::CFType::CFBoolean,
864
        IPC::CFType::CFBoolean,
750
    IPC::CFType::CFData,
865
        IPC::CFType::CFData,
751
    IPC::CFType::CFDate,
866
        IPC::CFType::CFDate,
752
    IPC::CFType::CFDictionary,
867
        IPC::CFType::CFDictionary,
753
    IPC::CFType::CFNull,
868
        IPC::CFType::CFNull,
754
    IPC::CFType::CFNumber,
869
        IPC::CFType::CFNumber,
755
    IPC::CFType::CFString,
870
        IPC::CFType::CFString,
756
    IPC::CFType::CFURL,
871
        IPC::CFType::CFURL,
757
    IPC::CFType::SecCertificate,
872
        IPC::CFType::SecCertificate,
758
#if HAVE(SEC_KEYCHAIN)
873
#if HAVE(SEC_KEYCHAIN)
759
    IPC::CFType::SecKeychainItem,
874
        IPC::CFType::SecKeychainItem,
760
#endif
875
#endif
761
#if HAVE(SEC_ACCESS_CONTROL)
876
#if HAVE(SEC_ACCESS_CONTROL)
762
    IPC::CFType::SecAccessControl,
877
        IPC::CFType::SecAccessControl,
763
#endif
878
#endif
764
#if HAVE(SEC_TRUST_SERIALIZATION)
879
#if HAVE(SEC_TRUST_SERIALIZATION)
765
    IPC::CFType::SecTrust,
880
        IPC::CFType::SecTrust,
766
#endif
881
#endif
767
    IPC::CFType::Nullptr,
882
        IPC::CFType::CGColorSpace,
768
    IPC::CFType::Unknown
883
        IPC::CFType::Nullptr,
884
        IPC::CFType::Unknown
885
    >;
886
};
887
888
template<> struct EnumTraits<IPC::CGColorSpaceEncodingScheme> {
889
    using values = EnumValues<
890
        IPC::CGColorSpaceEncodingScheme,
891
        IPC::CGColorSpaceEncodingScheme::Name,
892
        IPC::CGColorSpaceEncodingScheme::PropertyList
769
    >;
893
    >;
770
};
894
};
771
895
- Source/WebKit/Shared/cf/ArgumentCodersCF.h -32 / +117 lines
Lines 23-31 Source/WebKit/Shared/cf/ArgumentCodersCF.h_sec1
23
 * THE POSSIBILITY OF SUCH DAMAGE.
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
24
 */
25
25
26
#ifndef ArgumentCodersCF_h
26
#pragma once
27
#define ArgumentCodersCF_h
28
27
28
#include "ArgumentCoder.h"
29
#include <Security/SecCertificate.h>
29
#include <Security/SecCertificate.h>
30
#include <Security/SecTrust.h>
30
#include <Security/SecTrust.h>
31
#include <wtf/RetainPtr.h>
31
#include <wtf/RetainPtr.h>
Lines 34-104 Source/WebKit/Shared/cf/ArgumentCodersCF.h_sec2
34
#include <Security/SecKeychainItem.h>
34
#include <Security/SecKeychainItem.h>
35
#endif
35
#endif
36
36
37
typedef struct CGColorSpace* CGColorSpaceRef;
38
37
namespace IPC {
39
namespace IPC {
38
40
39
class Encoder;
41
class Encoder;
40
class Decoder;
42
class Decoder;
41
43
44
// NOTE: These coders are structured such that they expose encoder functions for both CFType and RetainPtr<CFType>
45
// but only a decoder only for RetainPtr<CFType>.
46
47
template<typename T>
48
struct CFRetainPtrArgumentCoder {
49
    template<typename Encoder> static void encode(Encoder& encoder, const RetainPtr<T>& retainPtr)
50
    {
51
        ArgumentCoder<T>::encode(encoder, retainPtr.get());
52
    }
53
};
54
55
// CFTypeRef
56
template<> struct ArgumentCoder<CFTypeRef> {
57
    template<typename Encoder> static void encode(Encoder&, CFTypeRef);
58
};
59
60
template<> struct ArgumentCoder<RetainPtr<CFTypeRef>> : CFRetainPtrArgumentCoder<CFTypeRef> {
61
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFTypeRef>&);
62
};
63
42
// CFArrayRef
64
// CFArrayRef
43
void encode(Encoder&, CFArrayRef);
65
template<> struct ArgumentCoder<CFArrayRef> {
44
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFArrayRef>& result);
66
    template<typename Encoder> static void encode(Encoder&, CFArrayRef);
67
};
68
69
template<> struct ArgumentCoder<RetainPtr<CFArrayRef>> : CFRetainPtrArgumentCoder<CFArrayRef> {
70
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFArrayRef>&);
71
};
45
72
46
// CFBooleanRef
73
// CFBooleanRef
47
void encode(Encoder&, CFBooleanRef);
74
template<> struct ArgumentCoder<CFBooleanRef> {
48
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFBooleanRef>& result);
75
    template<typename Encoder> static void encode(Encoder&, CFBooleanRef);
76
};
77
78
template<> struct ArgumentCoder<RetainPtr<CFBooleanRef>> : CFRetainPtrArgumentCoder<CFBooleanRef> {
79
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFBooleanRef>&);
80
};
49
81
50
// CFDataRef
82
// CFDataRef
51
void encode(Encoder&, CFDataRef);
83
template<> struct ArgumentCoder<CFDataRef> {
52
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFDataRef>& result);
84
    template<typename Encoder> static void encode(Encoder&, CFDataRef);
85
};
86
87
template<> struct ArgumentCoder<RetainPtr<CFDataRef>> : CFRetainPtrArgumentCoder<CFDataRef> {
88
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFDataRef>&);
89
};
53
90
54
// CFDateRef
91
// CFDateRef
55
void encode(Encoder&, CFDateRef);
92
template<> struct ArgumentCoder<CFDateRef> {
56
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFDateRef>& result);
93
    template<typename Encoder> static void encode(Encoder&, CFDateRef);
94
};
95
96
template<> struct ArgumentCoder<RetainPtr<CFDateRef>> : CFRetainPtrArgumentCoder<CFDateRef> {
97
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFDateRef>&);
98
};
57
99
58
// CFDictionaryRef
100
// CFDictionaryRef
59
void encode(Encoder&, CFDictionaryRef);
101
template<> struct ArgumentCoder<CFDictionaryRef> {
60
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFDictionaryRef>& result);
102
    template<typename Encoder> static void encode(Encoder&, CFDictionaryRef);
103
};
104
105
template<> struct ArgumentCoder<RetainPtr<CFDictionaryRef>> : CFRetainPtrArgumentCoder<CFDictionaryRef> {
106
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFDictionaryRef>&);
107
};
61
108
62
// CFNumberRef
109
// CFNumberRef
63
void encode(Encoder&, CFNumberRef);
110
template<> struct ArgumentCoder<CFNumberRef> {
64
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFNumberRef>& result);
111
    template<typename Encoder> static void encode(Encoder&, CFNumberRef);
112
};
113
114
template<> struct ArgumentCoder<RetainPtr<CFNumberRef>> : CFRetainPtrArgumentCoder<CFNumberRef> {
115
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFNumberRef>&);
116
};
65
117
66
// CFStringRef
118
// CFStringRef
67
void encode(Encoder&, CFStringRef);
119
template<> struct ArgumentCoder<CFStringRef> {
68
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFStringRef>& result);
120
    template<typename Encoder> static void encode(Encoder&, CFStringRef);
69
121
};
70
// CFTypeRef
122
71
void encode(Encoder&, CFTypeRef);
123
template<> struct ArgumentCoder<RetainPtr<CFStringRef>> : CFRetainPtrArgumentCoder<CFStringRef> {
72
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFTypeRef>& result);
124
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFStringRef>&);
125
};
73
126
74
// CFURLRef
127
// CFURLRef
75
void encode(Encoder&, CFURLRef);
128
template<> struct ArgumentCoder<CFURLRef> {
76
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFURLRef>& result);
129
    template<typename Encoder> static void encode(Encoder&, CFURLRef);
130
};
131
132
template<> struct ArgumentCoder<RetainPtr<CFURLRef>> : CFRetainPtrArgumentCoder<CFURLRef> {
133
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CFURLRef>&);
134
};
135
136
// CGColorSpaceRef
137
template<> struct ArgumentCoder<CGColorSpaceRef> {
138
    template<typename Encoder> static void encode(Encoder&, CGColorSpaceRef);
139
};
140
141
template<> struct ArgumentCoder<RetainPtr<CGColorSpaceRef>> : CFRetainPtrArgumentCoder<CGColorSpaceRef> {
142
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<CGColorSpaceRef>&);
143
};
77
144
78
// SecCertificateRef
145
// SecCertificateRef
79
void encode(Encoder&, SecCertificateRef);
146
template<> struct ArgumentCoder<SecCertificateRef> {
80
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<SecCertificateRef>& result);
147
    template<typename Encoder> static void encode(Encoder&, SecCertificateRef);
148
};
149
150
template<> struct ArgumentCoder<RetainPtr<SecCertificateRef>> : CFRetainPtrArgumentCoder<SecCertificateRef> {
151
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<SecCertificateRef>&);
152
};
81
153
82
#if HAVE(SEC_KEYCHAIN)
154
#if HAVE(SEC_KEYCHAIN)
83
// SecKeychainItemRef
155
// SecKeychainItemRef
84
void encode(Encoder&, SecKeychainItemRef);
156
template<> struct ArgumentCoder<SecKeychainItemRef> {
85
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<SecKeychainItemRef>& result);
157
    template<typename Encoder> static void encode(Encoder&, SecKeychainItemRef);
158
};
159
160
template<> struct ArgumentCoder<RetainPtr<SecKeychainItemRef>> : CFRetainPtrArgumentCoder<SecKeychainItemRef> {
161
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<SecKeychainItemRef>&);
162
};
86
#endif
163
#endif
87
164
88
#if HAVE(SEC_ACCESS_CONTROL)
165
#if HAVE(SEC_ACCESS_CONTROL)
89
// SecAccessControlRef
166
// SecAccessControlRef
90
void encode(Encoder&, SecAccessControlRef);
167
template<> struct ArgumentCoder<SecAccessControlRef> {
91
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<SecAccessControlRef>& result);
168
    template<typename Encoder> static void encode(Encoder&, SecAccessControlRef);
169
};
170
171
template<> struct ArgumentCoder<RetainPtr<SecAccessControlRef>> : CFRetainPtrArgumentCoder<SecAccessControlRef> {
172
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<SecAccessControlRef>&);
173
};
92
#endif
174
#endif
93
175
94
#if HAVE(SEC_TRUST_SERIALIZATION)
176
#if HAVE(SEC_TRUST_SERIALIZATION)
95
// SecTrustRef
177
// SecTrustRef
96
void encode(Encoder&, SecTrustRef);
178
template<> struct ArgumentCoder<SecTrustRef> {
97
WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<SecTrustRef>&);
179
    template<typename Encoder> static void encode(Encoder&, SecTrustRef);
180
};
181
182
template<> struct ArgumentCoder<RetainPtr<SecTrustRef>> : CFRetainPtrArgumentCoder<SecTrustRef> {
183
    static WARN_UNUSED_RETURN bool decode(Decoder&, RetainPtr<SecTrustRef>&);
184
};
98
#endif
185
#endif
99
186
100
CFTypeRef tokenNullptrTypeRef();
187
CFTypeRef tokenNullptrTypeRef();
101
188
102
} // namespace IPC
189
} // namespace IPC
103
104
#endif // ArgumentCodersCF_h
- Source/WebKit/Shared/mac/ColorSpaceData.mm -61 / +12 lines
Lines 33-109 Source/WebKit/Shared/mac/ColorSpaceData.mm_sec1
33
33
34
namespace WebKit {
34
namespace WebKit {
35
35
36
enum EncodedDataType {
37
    Null,
38
    Name,
39
    Data,
40
};
41
42
void ColorSpaceData::encode(IPC::Encoder& encoder) const
36
void ColorSpaceData::encode(IPC::Encoder& encoder) const
43
{
37
{
44
    if (cgColorSpace) {
38
    encoder << static_cast<bool>(cgColorSpace);
45
        // Try to encode the name.
39
    if (cgColorSpace)
46
        if (RetainPtr<CFStringRef> name = adoptCF(CGColorSpaceCopyName(cgColorSpace.get()))) {
40
        encoder << cgColorSpace;
47
            encoder << Name;
48
            IPC::encode(encoder, name.get());
49
            return;
50
        }
51
52
        // Failing that, just encode the ICC data.
53
        if (RetainPtr<CFDataRef> profileData = adoptCF(CGColorSpaceCopyICCData(cgColorSpace.get()))) {
54
            encoder << Data;
55
            IPC::encode(encoder, profileData.get());
56
            return;
57
        }
58
    }
59
60
    // The color space was null or failed to be encoded.
61
    encoder << Null;
62
}
41
}
63
42
64
bool ColorSpaceData::decode(IPC::Decoder& decoder, ColorSpaceData& colorSpaceData)
43
bool ColorSpaceData::decode(IPC::Decoder& decoder, ColorSpaceData& colorSpaceData)
65
{
44
{
66
    EncodedDataType dataType;
45
    bool hasCGColorSpace;
67
    if (!decoder.decode(dataType))
46
    if (!decoder.decode(hasCGColorSpace))
68
        return false;
47
        return false;
69
48
70
    switch (dataType) {
49
    if (!hasCGColorSpace)
71
    case Null:
72
        colorSpaceData.cgColorSpace = nullptr;
73
        return true;
74
    case Name: {
75
        RetainPtr<CFStringRef> name;
76
        if (!IPC::decode(decoder, name))
77
            return false;
78
79
        colorSpaceData.cgColorSpace = adoptCF(CGColorSpaceCreateWithName(name.get()));
80
        return true;
81
    }
82
    case Data: {
83
        RetainPtr<CFDataRef> data;
84
        if (!IPC::decode(decoder, data))
85
            return false;
86
87
        colorSpaceData.cgColorSpace = adoptCF(CGColorSpaceCreateWithICCData(data.get()));
88
        return true;
50
        return true;
89
    }
90
    }
91
51
92
    ASSERT_NOT_REACHED();
52
    RetainPtr<CGColorSpaceRef> colorSpace;
93
    return false;
53
    if (!decoder.decode(colorSpace))
54
        return false;
55
    
56
    colorSpaceData.cgColorSpace = WTFMove(colorSpace);
57
    return true;
94
}
58
}
95
59
96
} // namespace WebKit
60
} // namespace WebKit
97
98
namespace WTF {
99
100
template<> struct EnumTraits<WebKit::EncodedDataType> {
101
    using values = EnumValues<
102
        WebKit::EncodedDataType,
103
        WebKit::EncodedDataType::Null,
104
        WebKit::EncodedDataType::Name,
105
        WebKit::EncodedDataType::Data
106
    >;
107
};
108
109
} // namespace WTF
- Source/WebKit/Shared/mac/SecItemRequestData.cpp -4 / +4 lines
Lines 50-60 void SecItemRequestData::encode(IPC::Enc Source/WebKit/Shared/mac/SecItemRequestData.cpp_sec1
50
50
51
    encoder << static_cast<bool>(m_queryDictionary);
51
    encoder << static_cast<bool>(m_queryDictionary);
52
    if (m_queryDictionary)
52
    if (m_queryDictionary)
53
        IPC::encode(encoder, m_queryDictionary.get());
53
        encoder << m_queryDictionary;
54
54
55
    encoder << static_cast<bool>(m_attributesToMatch);
55
    encoder << static_cast<bool>(m_attributesToMatch);
56
    if (m_attributesToMatch)
56
    if (m_attributesToMatch)
57
        IPC::encode(encoder, m_attributesToMatch.get());
57
        encoder << m_attributesToMatch;
58
}
58
}
59
59
60
bool SecItemRequestData::decode(IPC::Decoder& decoder, SecItemRequestData& secItemRequestData)
60
bool SecItemRequestData::decode(IPC::Decoder& decoder, SecItemRequestData& secItemRequestData)
Lines 66-79 bool SecItemRequestData::decode(IPC::Dec Source/WebKit/Shared/mac/SecItemRequestData.cpp_sec2
66
    if (!decoder.decode(expectQuery))
66
    if (!decoder.decode(expectQuery))
67
        return false;
67
        return false;
68
68
69
    if (expectQuery && !IPC::decode(decoder, secItemRequestData.m_queryDictionary))
69
    if (expectQuery && !decoder.decode(secItemRequestData.m_queryDictionary))
70
        return false;
70
        return false;
71
    
71
    
72
    bool expectAttributes;
72
    bool expectAttributes;
73
    if (!decoder.decode(expectAttributes))
73
    if (!decoder.decode(expectAttributes))
74
        return false;
74
        return false;
75
    
75
    
76
    if (expectAttributes && !IPC::decode(decoder, secItemRequestData.m_attributesToMatch))
76
    if (expectAttributes && !decoder.decode(secItemRequestData.m_attributesToMatch))
77
        return false;
77
        return false;
78
    
78
    
79
    return true;
79
    return true;
- Source/WebKit/Shared/mac/SecItemResponseData.cpp -2 / +2 lines
Lines 42-48 void SecItemResponseData::encode(IPC::En Source/WebKit/Shared/mac/SecItemResponseData.cpp_sec1
42
    encoder << static_cast<int64_t>(m_resultCode);
42
    encoder << static_cast<int64_t>(m_resultCode);
43
    encoder << static_cast<bool>(m_resultObject);
43
    encoder << static_cast<bool>(m_resultObject);
44
    if (m_resultObject)
44
    if (m_resultObject)
45
        IPC::encode(encoder, m_resultObject.get());
45
        encoder << m_resultObject;
46
}
46
}
47
47
48
Optional<SecItemResponseData> SecItemResponseData::decode(IPC::Decoder& decoder)
48
Optional<SecItemResponseData> SecItemResponseData::decode(IPC::Decoder& decoder)
Lines 56-62 Optional<SecItemResponseData> SecItemRes Source/WebKit/Shared/mac/SecItemResponseData.cpp_sec2
56
        return WTF::nullopt;
56
        return WTF::nullopt;
57
57
58
    RetainPtr<CFTypeRef> result;
58
    RetainPtr<CFTypeRef> result;
59
    if (expectResultObject && !IPC::decode(decoder, result))
59
    if (expectResultObject && !decoder.decode(result))
60
        return WTF::nullopt;
60
        return WTF::nullopt;
61
61
62
    return {{ static_cast<OSStatus>(resultCode), WTFMove(result) }};
62
    return {{ static_cast<OSStatus>(resultCode), WTFMove(result) }};
- Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm -8 / +8 lines
Lines 51-61 void ArgumentCoder<WebCore::CertificateI Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm_sec1
51
    switch (certificateInfo.type()) {
51
    switch (certificateInfo.type()) {
52
#if HAVE(SEC_TRUST_SERIALIZATION)
52
#if HAVE(SEC_TRUST_SERIALIZATION)
53
    case WebCore::CertificateInfo::Type::Trust:
53
    case WebCore::CertificateInfo::Type::Trust:
54
        IPC::encode(encoder, certificateInfo.trust());
54
        encoder << certificateInfo.trust();
55
        break;
55
        break;
56
#endif
56
#endif
57
    case WebCore::CertificateInfo::Type::CertificateChain:
57
    case WebCore::CertificateInfo::Type::CertificateChain:
58
        IPC::encode(encoder, certificateInfo.certificateChain());
58
        encoder << certificateInfo.certificateChain();
59
        break;
59
        break;
60
    case WebCore::CertificateInfo::Type::None:
60
    case WebCore::CertificateInfo::Type::None:
61
        // Do nothing.
61
        // Do nothing.
Lines 73-79 bool ArgumentCoder<WebCore::CertificateI Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm_sec2
73
#if HAVE(SEC_TRUST_SERIALIZATION)
73
#if HAVE(SEC_TRUST_SERIALIZATION)
74
    case WebCore::CertificateInfo::Type::Trust: {
74
    case WebCore::CertificateInfo::Type::Trust: {
75
        RetainPtr<SecTrustRef> trust;
75
        RetainPtr<SecTrustRef> trust;
76
        if (!IPC::decode(decoder, trust) || !trust)
76
        if (!decoder.decode(trust) || !trust)
77
            return false;
77
            return false;
78
78
79
        certificateInfo = WebCore::CertificateInfo(WTFMove(trust));
79
        certificateInfo = WebCore::CertificateInfo(WTFMove(trust));
Lines 82-88 bool ArgumentCoder<WebCore::CertificateI Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm_sec3
82
#endif
82
#endif
83
    case WebCore::CertificateInfo::Type::CertificateChain: {
83
    case WebCore::CertificateInfo::Type::CertificateChain: {
84
        RetainPtr<CFArrayRef> certificateChain;
84
        RetainPtr<CFArrayRef> certificateChain;
85
        if (!IPC::decode(decoder, certificateChain) || !certificateChain)
85
        if (!decoder.decode(certificateChain) || !certificateChain)
86
            return false;
86
            return false;
87
87
88
        certificateInfo = WebCore::CertificateInfo(WTFMove(certificateChain));
88
        certificateInfo = WebCore::CertificateInfo(WTFMove(certificateChain));
Lines 166-172 static void encodeNSError(Encoder& encod Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm_sec4
166
        CFDictionarySetValue(filteredUserInfo.get(), (__bridge CFStringRef)NSURLErrorFailingURLPeerTrustErrorKey, peerTrust);
166
        CFDictionarySetValue(filteredUserInfo.get(), (__bridge CFStringRef)NSURLErrorFailingURLPeerTrustErrorKey, peerTrust);
167
#endif
167
#endif
168
168
169
    IPC::encode(encoder, filteredUserInfo.get());
169
    encoder << static_cast<CFDictionaryRef>(filteredUserInfo.get());
170
170
171
    if (id underlyingError = [userInfo objectForKey:NSUnderlyingErrorKey]) {
171
    if (id underlyingError = [userInfo objectForKey:NSUnderlyingErrorKey]) {
172
        ASSERT([underlyingError isKindOfClass:[NSError class]]);
172
        ASSERT([underlyingError isKindOfClass:[NSError class]]);
Lines 192-198 static RetainPtr<NSError> decodeNSError( Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm_sec5
192
        return nil;
192
        return nil;
193
193
194
    RetainPtr<CFDictionaryRef> userInfo;
194
    RetainPtr<CFDictionaryRef> userInfo;
195
    if (!IPC::decode(decoder, userInfo) || !userInfo)
195
    if (!decoder.decode(userInfo) || !userInfo)
196
        return nil;
196
        return nil;
197
197
198
    bool hasUnderlyingError = false;
198
    bool hasUnderlyingError = false;
Lines 377-389 void ArgumentCoder<WebCore::ContentFilte Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm_sec6
377
{
377
{
378
    auto archiver = adoptNS([[NSKeyedArchiver alloc] initRequiringSecureCoding:YES]);
378
    auto archiver = adoptNS([[NSKeyedArchiver alloc] initRequiringSecureCoding:YES]);
379
    contentFilterUnblockHandler.encode(archiver.get());
379
    contentFilterUnblockHandler.encode(archiver.get());
380
    IPC::encode(encoder, (__bridge CFDataRef)archiver.get().encodedData);
380
    encoder << (__bridge CFDataRef)archiver.get().encodedData;
381
}
381
}
382
382
383
bool ArgumentCoder<WebCore::ContentFilterUnblockHandler>::decode(Decoder& decoder, WebCore::ContentFilterUnblockHandler& contentFilterUnblockHandler)
383
bool ArgumentCoder<WebCore::ContentFilterUnblockHandler>::decode(Decoder& decoder, WebCore::ContentFilterUnblockHandler& contentFilterUnblockHandler)
384
{
384
{
385
    RetainPtr<CFDataRef> data;
385
    RetainPtr<CFDataRef> data;
386
    if (!IPC::decode(decoder, data) || !data)
386
    if (!decoder.decode(data) || !data)
387
        return false;
387
        return false;
388
388
389
    auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingFromData:(__bridge NSData *)data.get() error:nullptr]);
389
    auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingFromData:(__bridge NSData *)data.get() error:nullptr]);

Return to Bug 226112