-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate serializers for DDScannerResult and NSValue
https://bugs.webkit.org/show_bug.cgi?id=264915 rdar://118486039 Reviewed by Alex Christensen. This patch starts the process of breaking out specific secure coding types into their own wrappers. Starting with DDScannerResult, it optionally uses SPI on the object if it exists to grab a directly serializable NSDictionary, or it falls back to just wrapping the object itself like any secure coding type. That NSDictionary is known to contain NSValues that wrap an NSRange, so this patch also adds an NSValue wrapper. Currently, any NSValues that are serialized would go through the secure coding path. For this one wrapped type we're known to need (NSRange), we go through a directly serialized code path. Headed down this road, the goal is to identify all specific types we need to serialize, have a direct wrapper for each, and reduce our reliance on the secure coding code path to zero. * Source/WebKit/DerivedSources-input.xcfilelist: * Source/WebKit/DerivedSources.make: * Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.h: * Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm: (IPC::getClass<DDScannerResult>): (IPC::typeFromObject): * Source/WebKit/Shared/Cocoa/CoreIPCDDScannerResult.h: Copied from Source/WebKit/Shared/Cocoa/CoreIPCDictionary.h. (WebKit::CoreIPCDDScannerResult::CoreIPCDDScannerResult): * Source/WebKit/Shared/Cocoa/CoreIPCDDScannerResult.mm: Copied from Source/WebKit/Shared/Cocoa/CoreIPCSecureCoding.mm. (WebKit::shouldWrapDDScannerResult): (WebKit::CoreIPCDDScannerResult::CoreIPCDDScannerResult): (WebKit::CoreIPCDDScannerResult::toID const): * Source/WebKit/Shared/Cocoa/CoreIPCDDScannerResult.serialization.in: Added. * Source/WebKit/Shared/Cocoa/CoreIPCDictionary.h: * Source/WebKit/Shared/Cocoa/CoreIPCNSCFObject.h: * Source/WebKit/Shared/Cocoa/CoreIPCNSCFObject.mm: (WebKit::valueFromID): * Source/WebKit/Shared/Cocoa/CoreIPCNSValue.h: Copied from Source/WebKit/Shared/Cocoa/CoreIPCDictionary.h. (WebKit::CoreIPCNSValue::CoreIPCNSValue): * Source/WebKit/Shared/Cocoa/CoreIPCNSValue.mm: Copied from Source/WebKit/Shared/Cocoa/CoreIPCSecureCoding.mm. (WebKit::CoreIPCNSValue::CoreIPCNSValue): (WebKit::CoreIPCNSValue::toID const): (WebKit::CoreIPCNSValue::shouldWrapValue): * Source/WebKit/Shared/Cocoa/CoreIPCNSValue.serialization.in: Added. * Source/WebKit/Shared/Cocoa/CoreIPCSecureCoding.h: (WebKit::CoreIPCSecureCoding::CoreIPCSecureCoding): * Source/WebKit/Shared/Cocoa/CoreIPCSecureCoding.mm: (WebKit::CoreIPCSecureCoding::CoreIPCSecureCoding): * Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm: (IPC::getClass<DDScannerResult>): Deleted. * Source/WebKit/WebKit.xcodeproj/project.pbxproj: Since NSNumber is itself an NSValue, refactor these tests to explicitly emplace into the testing variant: * Tools/TestWebKitAPI/Tests/IPC/IPCSerialization.mm: (TEST): (fakeDataDetectorResultForTesting): Canonical link: https://commits.webkit.org/270840@main
- Loading branch information
Showing
19 changed files
with
524 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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 ENABLE(DATA_DETECTION) | ||
#if PLATFORM(COCOA) | ||
|
||
#include "ArgumentCodersCocoa.h" | ||
#include "CoreIPCDictionary.h" | ||
#include "CoreIPCSecureCoding.h" | ||
#include <wtf/RetainPtr.h> | ||
|
||
OBJC_CLASS DDScannerResult; | ||
|
||
namespace WebKit { | ||
|
||
class CoreIPCNSCFObject; | ||
|
||
class CoreIPCDDScannerResult { | ||
public: | ||
CoreIPCDDScannerResult(DDScannerResult *); | ||
CoreIPCDDScannerResult(const RetainPtr<DDScannerResult>& result) | ||
: CoreIPCDDScannerResult(result.get()) | ||
{ | ||
} | ||
|
||
RetainPtr<id> toID() const; | ||
|
||
private: | ||
friend struct IPC::ArgumentCoder<CoreIPCDDScannerResult, void>; | ||
|
||
using Value = std::variant<CoreIPCDictionary, CoreIPCSecureCoding>; | ||
|
||
static Value valueFromDDScannerResult(DDScannerResult *); | ||
|
||
CoreIPCDDScannerResult(Value&& value) | ||
: m_value(WTFMove(value)) | ||
{ | ||
} | ||
|
||
Value m_value; | ||
}; | ||
|
||
} // namespace WebKit | ||
|
||
#endif // PLATFORM(COCOA) | ||
#endif // ENABLE(DATA_DETECTION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#import "config.h" | ||
#import "CoreIPCDDScannerResult.h" | ||
|
||
#if ENABLE(DATA_DETECTION) | ||
#if PLATFORM(COCOA) | ||
|
||
#import "CoreIPCDictionary.h" | ||
#import "CoreIPCNSCFObject.h" | ||
#import <pal/cocoa/DataDetectorsCoreSoftLink.h> | ||
|
||
@interface DDScannerResult () | ||
- (NSDictionary *)_webKitPropertyListData; | ||
- (id)_initWithWebKitPropertyListData:(NSDictionary *)plist; | ||
@end | ||
|
||
namespace WebKit { | ||
|
||
static bool shouldWrapDDScannerResult() | ||
{ | ||
static std::once_flag onceFlag; | ||
static bool shouldWrap; | ||
std::call_once(onceFlag, [&] { | ||
shouldWrap = PAL::getDDScannerResultClass() | ||
&& [PAL::getDDScannerResultClass() instancesRespondToSelector:@selector(_webKitPropertyListData)] | ||
&& [PAL::getDDScannerResultClass() instancesRespondToSelector:@selector(_initWithWebKitPropertyListData:)]; | ||
}); | ||
|
||
return shouldWrap; | ||
} | ||
|
||
CoreIPCDDScannerResult::Value CoreIPCDDScannerResult::valueFromDDScannerResult(DDScannerResult *result) | ||
{ | ||
if (shouldWrapDDScannerResult()) | ||
return CoreIPCDictionary { [result _webKitPropertyListData] }; | ||
return CoreIPCSecureCoding { result }; | ||
} | ||
|
||
CoreIPCDDScannerResult::CoreIPCDDScannerResult(DDScannerResult *result) | ||
: m_value(valueFromDDScannerResult(result)) | ||
{ | ||
} | ||
|
||
RetainPtr<id> CoreIPCDDScannerResult::toID() const | ||
{ | ||
RetainPtr<id> result; | ||
|
||
WTF::switchOn(m_value, | ||
[&](const CoreIPCDictionary& dictionary) { | ||
ASSERT(shouldWrapDDScannerResult()); | ||
result = adoptNS([[PAL::getDDScannerResultClass() alloc] _initWithWebKitPropertyListData:dictionary.toID().get()]); | ||
}, [&](const CoreIPCSecureCoding& secureCoding) { | ||
result = secureCoding.toID(); | ||
} | ||
); | ||
|
||
return result; | ||
} | ||
|
||
} // namespace WebKit | ||
|
||
#endif // PLATFORM(COCOA) | ||
#endif // ENABLE(DATA_DETECTION) |
31 changes: 31 additions & 0 deletions
31
Source/WebKit/Shared/Cocoa/CoreIPCDDScannerResult.serialization.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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) && ENABLE(DATA_DETECTION) | ||
|
||
webkit_platform_headers: "CoreIPCDDScannerResult.h" | ||
|
||
[WebKitPlatform] class WebKit::CoreIPCDDScannerResult { | ||
WebKit::CoreIPCDDScannerResult::Value m_value | ||
} | ||
|
||
#endif // PLATFORM(COCOA) && ENABLE(DATA_DETECTION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.