Skip to content

Commit

Permalink
Port IPC::FormDataReference to the new IPC serialization format
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264895

Reviewed by Alex Christensen.

* Source/WebKit/CMakeLists.txt:
* Source/WebKit/DerivedSources-input.xcfilelist:
* Source/WebKit/DerivedSources.make:
* Source/WebKit/Platform/IPC/FormDataReference.h:
(IPC::FormDataReference::data const):
(IPC::FormDataReference::takeData):
(IPC::FormDataReference::FormDataReference):
(IPC::FormDataReference::sandboxExtensionHandles const):
(IPC::FormDataReference::encode const): Deleted.
(IPC::FormDataReference::decode): Deleted.
* Source/WebKit/Platform/IPC/FormDataReference.serialization.in: Added.
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:

Canonical link: https://commits.webkit.org/270801@main
  • Loading branch information
cdumez committed Nov 16, 2023
1 parent a6c52f8 commit 63f2089
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 42 deletions.
1 change: 1 addition & 0 deletions Source/WebKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ set(WebKit_SERIALIZATION_IN_FILES

NetworkProcess/storage/FileSystemStorageError.serialization.in

Platform/IPC/FormDataReference.serialization.in
Platform/IPC/StreamServerConnection.serialization.in

Platform/SharedMemory.serialization.in
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/DerivedSources-input.xcfilelist
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ $(PROJECT_DIR)/NetworkProcess/webrtc/NetworkRTCMonitor.messages.in
$(PROJECT_DIR)/NetworkProcess/webrtc/NetworkRTCProvider.messages.in
$(PROJECT_DIR)/NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy.messages.in
$(PROJECT_DIR)/NetworkProcess/webtransport/NetworkTransportSession.messages.in
$(PROJECT_DIR)/Platform/IPC/FormDataReference.serialization.in
$(PROJECT_DIR)/Platform/IPC/StreamServerConnection.serialization.in
$(PROJECT_DIR)/Platform/SharedMemory.serialization.in
$(PROJECT_DIR)/PluginProcess/PluginControllerProxy.messages.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 @@ -498,6 +498,7 @@ SERIALIZATION_DESCRIPTION_FILES = \
NetworkProcess/Classifier/StorageAccessStatus.serialization.in \
NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerInterface.serialization.in \
NetworkProcess/storage/FileSystemStorageError.serialization.in \
Platform/IPC/FormDataReference.serialization.in \
Platform/IPC/StreamServerConnection.serialization.in \
Platform/SharedMemory.serialization.in \
Shared/AuxiliaryProcessCreationParameters.serialization.in \
Expand Down
67 changes: 25 additions & 42 deletions Source/WebKit/Platform/IPC/FormDataReference.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,53 +40,36 @@ class FormDataReference {
{
}

RefPtr<WebCore::FormData> takeData() { return WTFMove(m_data); }

void encode(Encoder& encoder) const
{
encoder << !!m_data;
if (!m_data)
return;

encoder << *m_data;

Vector<WebKit::SandboxExtension::Handle> sandboxExtensionHandles;
for (auto& element : m_data->elements()) {
if (auto* fileData = std::get_if<WebCore::FormDataElement::EncodedFileData>(&element.data)) {
const String& path = fileData->filename;
if (auto handle = WebKit::SandboxExtension::createHandle(path, WebKit::SandboxExtension::Type::ReadOnly))
sandboxExtensionHandles.append(WTFMove(*handle));
}
}
encoder << WTFMove(sandboxExtensionHandles);
}

static std::optional<FormDataReference> decode(Decoder& decoder)
{
std::optional<bool> hasFormData;
decoder >> hasFormData;
if (!hasFormData)
return std::nullopt;
if (!hasFormData.value())
return FormDataReference { };
FormDataReference(RefPtr<WebCore::FormData>&&, Vector<WebKit::SandboxExtension::Handle>&&);

std::optional<Ref<WebCore::FormData>> formData;
decoder >> formData;
if (!formData)
return std::nullopt;

std::optional<Vector<WebKit::SandboxExtension::Handle>> sandboxExtensionHandles;
decoder >> sandboxExtensionHandles;
if (!sandboxExtensionHandles)
return std::nullopt;

WebKit::SandboxExtension::consumePermanently(*sandboxExtensionHandles);
RefPtr<WebCore::FormData> data() const { return m_data.get(); }
RefPtr<WebCore::FormData> takeData() { return WTFMove(m_data); }

return FormDataReference { WTFMove(*formData) };
}
Vector<WebKit::SandboxExtension::Handle> sandboxExtensionHandles() const;

private:
RefPtr<WebCore::FormData> m_data;
};

inline FormDataReference::FormDataReference(RefPtr<WebCore::FormData>&& data, Vector<WebKit::SandboxExtension::Handle>&& sandboxExtensionHandles)
: m_data(WTFMove(data))
{
WebKit::SandboxExtension::consumePermanently(WTFMove(sandboxExtensionHandles));
}

inline Vector<WebKit::SandboxExtension::Handle> FormDataReference::sandboxExtensionHandles() const
{
if (!m_data)
return { };

return WTF::compactMap(m_data->elements(), [](auto& element) -> std::optional<WebKit::SandboxExtension::Handle> {
if (auto* fileData = std::get_if<WebCore::FormDataElement::EncodedFileData>(&element.data)) {
const String& path = fileData->filename;
if (auto handle = WebKit::SandboxExtension::createHandle(path, WebKit::SandboxExtension::Type::ReadOnly))
return { WTFMove(*handle) };
}
return std::nullopt;
});
}

} // namespace IPC
28 changes: 28 additions & 0 deletions Source/WebKit/Platform/IPC/FormDataReference.serialization.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.

header: "FormDataReference.h"

[CustomHeader] class IPC::FormDataReference {
RefPtr<WebCore::FormData> data();
Vector<WebKit::SandboxExtension::Handle> sandboxExtensionHandles();
};
2 changes: 2 additions & 0 deletions Source/WebKit/WebKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4941,6 +4941,7 @@
463FD4811EB94EAD00A2982C /* ProcessTerminationReason.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProcessTerminationReason.h; sourceTree = "<group>"; };
46411E3D2AFDA94400CC00E4 /* WebCompiledContentRuleListData.serialization.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebCompiledContentRuleListData.serialization.in; sourceTree = "<group>"; };
4651ECE622178A850067EB95 /* WebProcessCacheCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessCacheCocoa.mm; sourceTree = "<group>"; };
465237FA2B055C41005B3097 /* FormDataReference.serialization.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FormDataReference.serialization.in; sourceTree = "<group>"; };
465250E51ECF52CD002025CB /* WebKit2InitializeCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebKit2InitializeCocoa.mm; sourceTree = "<group>"; };
4656F7BA27ACAA8000CB3D7C /* WebSharedWorkerServerToContextConnection.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebSharedWorkerServerToContextConnection.messages.in; sourceTree = "<group>"; };
4656F7BB27ACAA8100CB3D7C /* WebSharedWorker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebSharedWorker.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -8886,6 +8887,7 @@
BC032D9F10F437D10058C15A /* Encoder.cpp */,
BC032DA010F437D10058C15A /* Encoder.h */,
4151E5C31FBB90A900E47E2D /* FormDataReference.h */,
465237FA2B055C41005B3097 /* FormDataReference.serialization.in */,
C0CE72AC1247E78D00BC0EC4 /* HandleMessage.h */,
A73E66BC2AB107BB005FC327 /* IPCEvent.h */,
A31F60A225CC7DB800AF14F4 /* IPCSemaphore.h */,
Expand Down

0 comments on commit 63f2089

Please sign in to comment.