Skip to content

Commit

Permalink
Generate serialization of CFTypeRef
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=269090
rdar://122666159

Reviewed by Brady Eidson.

* Source/WebKit/DerivedSources-input.xcfilelist:
* Source/WebKit/DerivedSources.make:
* Source/WebKit/Platform/IPC/ArgumentCoders.h:
* Source/WebKit/Scripts/webkit/messages.py:
(class_template_headers):
* Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.h:
* Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm:
(IPC::typeFromObject):
* Source/WebKit/Shared/Cocoa/CoreIPCArray.h:
(WebKit::CoreIPCArray::CoreIPCArray): Deleted.
* Source/WebKit/Shared/Cocoa/CoreIPCArray.mm:
(WebKit::CoreIPCArray::CoreIPCArray):
* Source/WebKit/Shared/Cocoa/CoreIPCCFType.h:
(WebKit::CoreIPCCFType::object const):
(WebKit::CoreIPCCFType::CoreIPCCFType): Deleted.
(WebKit::CoreIPCCFType::toID const): Deleted.
* Source/WebKit/Shared/Cocoa/CoreIPCCFType.mm: Added.
(WebKit::variantFromCFType):
(WebKit::CoreIPCCFType::CoreIPCCFType):
(WebKit::CoreIPCCFType::toID const):
(WebKit::CoreIPCCFType::toCFType const):
(IPC::typeFromCFTypeRef):
(IPC::ArgumentCoder<UniqueRef<WebKit::CFObjectValue>>::encode):
(IPC::ArgumentCoder<UniqueRef<WebKit::CFObjectValue>>::decode):
* Source/WebKit/Shared/Cocoa/CoreIPCCFType.serialization.in:
* Source/WebKit/Shared/Cocoa/CoreIPCColor.serialization.in:
* Source/WebKit/Shared/Cocoa/CoreIPCDictionary.h:
(WebKit::CoreIPCDictionary::CoreIPCDictionary): Deleted.
* Source/WebKit/Shared/Cocoa/CoreIPCDictionary.mm:
(WebKit::CoreIPCDictionary::CoreIPCDictionary):
* Source/WebKit/Shared/Cocoa/CoreIPCError.serialization.in:
* Source/WebKit/Shared/Cocoa/CoreIPCNSCFObject.h:
* Source/WebKit/Shared/Cocoa/CoreIPCNSCFObject.mm:
(WebKit::valueFromID):
* Source/WebKit/Shared/Cocoa/CoreIPCNSCFObject.serialization.in:
* Source/WebKit/Shared/Cocoa/CoreIPCNull.h: Copied from Source/WebKit/Shared/Cocoa/CoreIPCRetainPtr.h.
* Source/WebKit/Shared/Cocoa/CoreIPCNull.mm: Copied from Source/WebKit/Shared/Cocoa/CoreIPCRetainPtr.h.
(WebKit::CoreIPCNull::CoreIPCNull):
(WebKit::CoreIPCNull::toID const):
(WebKit::CoreIPCNull::toCFObject const):
* Source/WebKit/Shared/Cocoa/CoreIPCNull.serialization.in: Copied from Source/WebKit/Shared/Cocoa/CoreIPCCFType.serialization.in.
* Source/WebKit/Shared/Cocoa/CoreIPCRetainPtr.h:
* Source/WebKit/Shared/Cocoa/CoreIPCString.serialization.in:
* Source/WebKit/Shared/Cocoa/CoreIPCTypes.h:
* Source/WebKit/Shared/Cocoa/CoreIPCURL.serialization.in:
* Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
* Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm:
* Source/WebKit/Shared/WebCoreArgumentCoders.cpp:
* Source/WebKit/Shared/WebCoreArgumentCoders.h:
* Source/WebKit/Shared/cf/ArgumentCodersCF.cpp: Removed.
* Source/WebKit/Shared/cf/ArgumentCodersCF.h: Removed.
* Source/WebKit/Shared/cf/CFTypes.serialization.in:
* Source/WebKit/Shared/cf/CoreIPCCFArray.h:
* Source/WebKit/Shared/cf/CoreIPCCFArray.mm:
* Source/WebKit/Shared/ios/InteractionInformationRequest.cpp:
* Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/IPC/IPCSerialization.mm:
(cfHolder):
(TEST):

Canonical link: https://commits.webkit.org/274493@main
  • Loading branch information
achristensen07 committed Feb 12, 2024
1 parent 00f4aff commit 61fe261
Show file tree
Hide file tree
Showing 37 changed files with 502 additions and 439 deletions.
1 change: 1 addition & 0 deletions Source/WebKit/DerivedSources-input.xcfilelist
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ $(PROJECT_DIR)/Shared/Cocoa/CoreIPCFont.serialization.in
$(PROJECT_DIR)/Shared/Cocoa/CoreIPCLocale.serialization.in
$(PROJECT_DIR)/Shared/Cocoa/CoreIPCNSCFObject.serialization.in
$(PROJECT_DIR)/Shared/Cocoa/CoreIPCNSValue.serialization.in
$(PROJECT_DIR)/Shared/Cocoa/CoreIPCNull.serialization.in
$(PROJECT_DIR)/Shared/Cocoa/CoreIPCPassKit.serialization.in
$(PROJECT_DIR)/Shared/Cocoa/CoreIPCPersonNameComponents.serialization.in
$(PROJECT_DIR)/Shared/Cocoa/CoreIPCPresentationIntent.serialization.in
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/DerivedSources.make
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ SERIALIZATION_DESCRIPTION_FILES = \
Shared/Cocoa/CoreIPCLocale.serialization.in \
Shared/Cocoa/CoreIPCNSCFObject.serialization.in \
Shared/Cocoa/CoreIPCNSValue.serialization.in \
Shared/Cocoa/CoreIPCNull.serialization.in \
Shared/Cocoa/CoreIPCPassKit.serialization.in \
Shared/Cocoa/CoreIPCPersonNameComponents.serialization.in \
Shared/Cocoa/CoreIPCPresentationIntent.serialization.in \
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/Platform/IPC/ArgumentCoders.h
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ template<> struct ArgumentCoder<StringView> {
};

template<> struct ArgumentCoder<std::nullptr_t> {
template<typename Encoder>
static void encode(Encoder&, const std::nullptr_t&) { }
static std::optional<std::nullptr_t> decode(Decoder&) { return nullptr; }
};
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/Scripts/webkit/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def class_template_headers(template_string):
'IPC::ArrayReferenceTuple': {'headers': ['"ArrayReferenceTuple.h"'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
'Ref': {'headers': ['<wtf/Ref.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
'RefPtr': {'headers': ['<wtf/RefCounted.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
'RetainPtr': {'headers': ['<wtf/RetainPtr.h>'], 'argument_coder_headers': ['"ArgumentCodersCF.h"']},
'RetainPtr': {'headers': ['<wtf/RetainPtr.h>'], 'argument_coder_headers': []},
'WebCore::ProcessQualified': {'headers': ['<WebCore/ProcessQualified.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
'std::unique_ptr': {'headers': ['<memory>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
#include "config.h"
#include "TestWithCVPixelBuffer.h"

#if USE(AVFOUNDATION)
#include "ArgumentCodersCF.h" // NOLINT
#endif
#include "Decoder.h" // NOLINT
#include "HandleMessage.h" // NOLINT
#include "TestWithCVPixelBufferMessages.h" // NOLINT
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ enum class NSType : uint8_t {
Font,
Locale,
Number,
Null,
PersonNameComponents,
PresentationIntent,
SecureCoding,
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#if PLATFORM(COCOA)

#import "ArgumentCodersCF.h"
#import "CoreIPCNSCFObject.h"
#import "CoreIPCTypes.h"
#import "CoreTextHelpers.h"
Expand Down Expand Up @@ -387,6 +386,8 @@ NSType typeFromObject(id object)
return NSType::Locale;
if ([object isKindOfClass:[NSNumber class]])
return NSType::Number;
if ([object isKindOfClass:[NSNull class]])
return NSType::Null;
if ([object isKindOfClass:[NSValue class]])
return NSType::NSValue;
if ([object isKindOfClass:[NSPersonNameComponents class]])
Expand Down
12 changes: 4 additions & 8 deletions Source/WebKit/Shared/Cocoa/CoreIPCArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,16 @@ class CoreIPCNSCFObject;
class CoreIPCArray {
public:
CoreIPCArray(NSArray *);
CoreIPCArray(const RetainPtr<NSArray>& array)
: CoreIPCArray(array.get())
{
}
CoreIPCArray(const RetainPtr<NSArray>&);
CoreIPCArray(CoreIPCArray&&);
~CoreIPCArray();

RetainPtr<id> toID() const;

private:
friend struct IPC::ArgumentCoder<CoreIPCArray, void>;

CoreIPCArray(Vector<CoreIPCNSCFObject>&& array)
: m_array(WTFMove(array))
{
}
CoreIPCArray(Vector<CoreIPCNSCFObject>&&);

Vector<CoreIPCNSCFObject> m_array;
};
Expand Down
10 changes: 10 additions & 0 deletions Source/WebKit/Shared/Cocoa/CoreIPCArray.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
}
}

CoreIPCArray::CoreIPCArray(const RetainPtr<NSArray>& array)
: CoreIPCArray(array.get()) { }

CoreIPCArray::CoreIPCArray(CoreIPCArray&&) = default;

CoreIPCArray::~CoreIPCArray() = default;

CoreIPCArray::CoreIPCArray(Vector<CoreIPCNSCFObject>&& array)
: m_array(WTFMove(array)) { }

RetainPtr<id> CoreIPCArray::toID() const
{
auto result = adoptNS([[NSMutableArray alloc] initWithCapacity:m_array.size()]);
Expand Down
85 changes: 69 additions & 16 deletions Source/WebKit/Shared/Cocoa/CoreIPCCFType.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,86 @@

#pragma once

#if PLATFORM(COCOA)

#include "CoreIPCRetainPtr.h"
#include <wtf/ArgumentCoder.h>
#include <wtf/UniqueRef.h>

namespace WebCore {
class Color;
}

namespace WebKit {

class CoreIPCCFArray;
class CoreIPCBoolean;
class CoreIPCCFCharacterSet;
class CoreIPCColor;
class CoreIPCData;
class CoreIPCDate;
class CoreIPCCFDictionary;
class CoreIPCNull;
class CoreIPCNumber;
class CoreIPCString;
class CoreIPCCFURL;
class CoreIPCCGColorSpace;
class CoreIPCSecCertificate;
class CoreIPCSecTrust;
#if HAVE(SEC_KEYCHAIN)
class CoreIPCSecKeychainItem;
#endif
#if HAVE(SEC_ACCESS_CONTROL)
class CoreIPCSecAccessControl;
#endif

using CFObjectValue = std::variant<
std::nullptr_t,
CoreIPCCFArray,
CoreIPCBoolean,
CoreIPCCFCharacterSet,
CoreIPCData,
CoreIPCDate,
CoreIPCCFDictionary,
CoreIPCNull,
CoreIPCNumber,
CoreIPCString,
CoreIPCCFURL,
CoreIPCSecCertificate,
CoreIPCSecTrust,
CoreIPCCGColorSpace,
WebCore::Color
#if HAVE(SEC_KEYCHAIN)
, CoreIPCSecKeychainItem
#endif
#if HAVE(SEC_ACCESS_CONTROL)
, CoreIPCSecAccessControl
#endif
>;

class CoreIPCCFType {
public:
CoreIPCCFType(CFTypeRef cfType)
: m_cfType(cfType)
{
}

CoreIPCCFType(RetainPtr<CFTypeRef>&& cfType)
: m_cfType(WTFMove(cfType))
{
}
CoreIPCCFType(CFTypeRef);
CoreIPCCFType(CoreIPCCFType&&);
CoreIPCCFType(UniqueRef<CFObjectValue>&&);
~CoreIPCCFType();

RetainPtr<id> toID() const { return (__bridge id)(m_cfType.get()); }
const UniqueRef<CFObjectValue>& object() const { return m_object; }
RetainPtr<id> toID() const;
RetainPtr<CFTypeRef> toCFType() const;

private:
friend struct IPC::ArgumentCoder<CoreIPCCFType, void>;

IPC::CoreIPCRetainPtr<CFTypeRef> m_cfType;
UniqueRef<CFObjectValue> m_object;
};

} // namespace WebKit

#endif // PLATFORM(COCOA)
namespace IPC {

// This ArgumentCoders specialization for UniqueRef<CFObjectValue> is to allow us to use
// makeUniqueRefWithoutFastMallocCheck<>, since we can't make the variant fast malloc'ed
template<> struct ArgumentCoder<UniqueRef<WebKit::CFObjectValue>> {
template<typename Encoder>
static void encode(Encoder&, const UniqueRef<WebKit::CFObjectValue>&);
static std::optional<UniqueRef<WebKit::CFObjectValue>> decode(Decoder&);
};

} // namespace IPC
Loading

0 comments on commit 61fe261

Please sign in to comment.