Skip to content

Commit

Permalink
Use generated serialization for NSData
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=263378
rdar://117206485

Reviewed by Brady Eidson and Alex Christensen.

* Source/WebKit/DerivedSources-input.xcfilelist:
* Source/WebKit/DerivedSources.make:
* Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm:
(IPC::encodeDataInternal):
(IPC::decodeDataInternal):
* Source/WebKit/Shared/Cocoa/CoreIPCData.h: Added.
(WebKit::CoreIPCData::CoreIPCData):
(WebKit::CoreIPCData::createData const):
(WebKit::CoreIPCData::get const):
* Source/WebKit/Shared/Cocoa/CoreIPCData.serialization.in: Added.
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:

Canonical link: https://commits.webkit.org/269766@main
  • Loading branch information
sheeparegreat authored and beidson committed Oct 25, 2023
1 parent 3e61540 commit 0ee026d
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 5 deletions.
1 change: 1 addition & 0 deletions Source/WebKit/DerivedSources-input.xcfilelist
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ $(PROJECT_DIR)/Shared/AuxiliaryProcessCreationParameters.serialization.in
$(PROJECT_DIR)/Shared/BackgroundFetchState.serialization.in
$(PROJECT_DIR)/Shared/CallbackID.serialization.in
$(PROJECT_DIR)/Shared/Cocoa/CacheStoragePolicy.serialization.in
$(PROJECT_DIR)/Shared/Cocoa/CoreIPCData.serialization.in
$(PROJECT_DIR)/Shared/Cocoa/DataDetectionResult.serialization.in
$(PROJECT_DIR)/Shared/Cocoa/InsertTextOptions.serialization.in
$(PROJECT_DIR)/Shared/Cocoa/RevealItem.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 @@ -527,6 +527,7 @@ SERIALIZATION_DESCRIPTION_FILES = \
Shared/AlternativeTextClient.serialization.in \
Shared/AppPrivacyReportTestingData.serialization.in \
Shared/Cocoa/CacheStoragePolicy.serialization.in \
Shared/Cocoa/CoreIPCData.serialization.in \
Shared/Cocoa/DataDetectionResult.serialization.in \
Shared/Cocoa/InsertTextOptions.serialization.in \
Shared/Cocoa/RevealItem.serialization.in \
Expand Down
17 changes: 12 additions & 5 deletions Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
#if PLATFORM(COCOA)

#import "ArgumentCodersCF.h"
#import "CoreIPCData.h"
#import "CoreTextHelpers.h"
#import "DataReference.h"
#import "LegacyGlobalSettings.h"
#import "MessageNames.h"
#import "WebPreferencesKeys.h"
Expand Down Expand Up @@ -390,15 +392,20 @@ static inline void encodeColorInternal(Encoder& encoder, WebCore::CocoaColor *co

static inline void encodeDataInternal(Encoder& encoder, NSData *data)
{
encoder << bridge_cast(data);
IPC::DataReference dataRef(reinterpret_cast<uint8_t*>(const_cast<void*>([data bytes])), [data length]);
encoder << WebKit::CoreIPCData(dataRef);
}

static inline std::optional<RetainPtr<id>> decodeDataInternal(Decoder& decoder)
{
RetainPtr<CFDataRef> data;
if (!decoder.decode(data))
return std::nullopt;
return { bridge_cast(WTFMove(data)) };
std::optional<WebKit::CoreIPCData> data;

decoder >> data;
if (data) {
auto ret = data->createData();
return { bridge_cast(WTFMove(ret)) };
}
return { };
}

#pragma mark - NSDate
Expand Down
60 changes: 60 additions & 0 deletions Source/WebKit/Shared/Cocoa/CoreIPCData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if PLATFORM(COCOA)

#import "DataReference.h"

#import <CoreFoundation/CoreFoundation.h>
#import <wtf/RetainPtr.h>

namespace WebKit {

class CoreIPCData {
public:
CoreIPCData(const IPC::DataReference& data)
: m_reference(data)
{
}

RetainPtr<CFDataRef> createData() const
{
return adoptCF(CFDataCreate(0, m_reference.data(), m_reference.size()));
}

IPC::DataReference get() const
{
return m_reference;
}

private:
IPC::DataReference m_reference;
};

}

#endif // PLATFORM(COCOA)
29 changes: 29 additions & 0 deletions Source/WebKit/Shared/Cocoa/CoreIPCData.serialization.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (C) 2023 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#if PLATFORM(COCOA)

class WebKit::CoreIPCData {
IPC::DataReference get();
}

#endif // PLATFORM(COCOA)
6 changes: 6 additions & 0 deletions Source/WebKit/WebKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2281,6 +2281,7 @@
F4648E92296E81FA00744170 /* WebPrivacyHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = F4648E90296E81F500744170 /* WebPrivacyHelpers.h */; };
F4660BC225DEF08100E86598 /* PasteboardAccessIntent.h in Headers */ = {isa = PBXBuildFile; fileRef = F4660BC125DEF08100E86598 /* PasteboardAccessIntent.h */; };
F48570A32644BEC500C05F71 /* Timeout.h in Headers */ = {isa = PBXBuildFile; fileRef = F48570A22644BEC400C05F71 /* Timeout.h */; };
F48C81E42AE0BA8E00073850 /* CoreIPCData.h in Headers */ = {isa = PBXBuildFile; fileRef = F48C81E32AE0BA6E00073850 /* CoreIPCData.h */; };
F48D2A8521583A7E00C6752B /* AppKitSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = F48D2A8421583A0200C6752B /* AppKitSPI.h */; };
F496A4311F58A272004C1757 /* DragDropInteractionState.h in Headers */ = {isa = PBXBuildFile; fileRef = F496A42F1F58A272004C1757 /* DragDropInteractionState.h */; };
F4974E76265ECBBC00B49B8C /* WKRevealItemPresenter.h in Headers */ = {isa = PBXBuildFile; fileRef = F446EDEF265EB2B00031DA8F /* WKRevealItemPresenter.h */; };
Expand Down Expand Up @@ -7430,6 +7431,8 @@
F48BB8DE26F9635D001C1C40 /* RemoteDisplayListRecorderProxy.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteDisplayListRecorderProxy.cpp; sourceTree = "<group>"; };
F48BB8DF26F96392001C1C40 /* RemoteDisplayListRecorder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteDisplayListRecorder.h; sourceTree = "<group>"; };
F48BB8E026F96392001C1C40 /* RemoteDisplayListRecorder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteDisplayListRecorder.cpp; sourceTree = "<group>"; };
F48C81E32AE0BA6E00073850 /* CoreIPCData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreIPCData.h; sourceTree = "<group>"; };
F48C81E52AE0E1DF00073850 /* CoreIPCData.serialization.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = CoreIPCData.serialization.in; sourceTree = "<group>"; };
F48D2A8421583A0200C6752B /* AppKitSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppKitSPI.h; sourceTree = "<group>"; };
F496A42F1F58A272004C1757 /* DragDropInteractionState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DragDropInteractionState.h; path = ios/DragDropInteractionState.h; sourceTree = "<group>"; };
F496A4301F58A272004C1757 /* DragDropInteractionState.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = DragDropInteractionState.mm; path = ios/DragDropInteractionState.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -10561,6 +10564,8 @@
CE11AD4F1CBC47F800681EE5 /* CodeSigning.mm */,
37BEC4DF19491486008B4286 /* CompletionHandlerCallChecker.h */,
37BEC4DE19491486008B4286 /* CompletionHandlerCallChecker.mm */,
F48C81E32AE0BA6E00073850 /* CoreIPCData.h */,
F48C81E52AE0E1DF00073850 /* CoreIPCData.serialization.in */,
1C739E872347BD0F00C621EC /* CoreTextHelpers.h */,
1C739E852347BCF600C621EC /* CoreTextHelpers.mm */,
C55F916C1C595E440029E92D /* DataDetectionResult.h */,
Expand Down Expand Up @@ -14721,6 +14726,7 @@
CA05397923EE324400A553DC /* ContentAsStringIncludesChildFrames.h in Headers */,
5129EB1223D0DE7B00AF1CD7 /* ContentWorldShared.h in Headers */,
5106D7C418BDBE73000AB166 /* ContextMenuContextData.h in Headers */,
F48C81E42AE0BA8E00073850 /* CoreIPCData.h in Headers */,
A15799BC2584433200528236 /* CoreMediaWrapped.h in Headers */,
37C21CAE1E994C0C0029D5F9 /* CorePredictionSPI.h in Headers */,
1C62900D28EE2CD300C26B60 /* CoreSVGSPI.h in Headers */,
Expand Down

0 comments on commit 0ee026d

Please sign in to comment.