From 2c808958b9b6c23b7450b364edbb2e859f6d85a9 Mon Sep 17 00:00:00 2001 From: Tobias Christiansen Date: Sat, 15 Oct 2022 13:54:54 +0200 Subject: [PATCH] LibWeb: Make Cookie::Cookie transportable over IPC --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + Userland/Libraries/LibWeb/Cookie/Cookie.cpp | 42 +++++++++++++++++++++ Userland/Libraries/LibWeb/Cookie/Cookie.h | 8 ++++ 3 files changed, 51 insertions(+) create mode 100644 Userland/Libraries/LibWeb/Cookie/Cookie.cpp diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 060c4ce06aa..182683e3b52 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -66,6 +66,7 @@ set(SOURCES CSS/Supports.cpp CSS/SyntaxHighlighter/SyntaxHighlighter.cpp CSS/Time.cpp + Cookie/Cookie.cpp Cookie/ParsedCookie.cpp DOM/AbortController.cpp DOM/AbortSignal.cpp diff --git a/Userland/Libraries/LibWeb/Cookie/Cookie.cpp b/Userland/Libraries/LibWeb/Cookie/Cookie.cpp new file mode 100644 index 00000000000..f4de92571cd --- /dev/null +++ b/Userland/Libraries/LibWeb/Cookie/Cookie.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022, Tobias Christiansen + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "Cookie.h" +#include +#include + +bool IPC::encode(Encoder& encoder, Web::Cookie::Cookie const& cookie) +{ + encoder << cookie.name; + encoder << cookie.value; + encoder << cookie.domain; + encoder << cookie.path; + encoder << cookie.creation_time; + encoder << cookie.expiry_time; + encoder << cookie.host_only; + encoder << cookie.http_only; + encoder << cookie.last_access_time; + encoder << cookie.persistent; + encoder << cookie.secure; + + return true; +} + +ErrorOr IPC::decode(Decoder& decoder, Web::Cookie::Cookie& cookie) +{ + TRY(decoder.decode(cookie.name)); + TRY(decoder.decode(cookie.value)); + TRY(decoder.decode(cookie.domain)); + TRY(decoder.decode(cookie.path)); + TRY(decoder.decode(cookie.creation_time)); + TRY(decoder.decode(cookie.expiry_time)); + TRY(decoder.decode(cookie.host_only)); + TRY(decoder.decode(cookie.http_only)); + TRY(decoder.decode(cookie.last_access_time)); + TRY(decoder.decode(cookie.persistent)); + TRY(decoder.decode(cookie.secure)); + return {}; +} diff --git a/Userland/Libraries/LibWeb/Cookie/Cookie.h b/Userland/Libraries/LibWeb/Cookie/Cookie.h index f1a41bb610d..758feab3c0a 100644 --- a/Userland/Libraries/LibWeb/Cookie/Cookie.h +++ b/Userland/Libraries/LibWeb/Cookie/Cookie.h @@ -8,6 +8,7 @@ #include #include +#include namespace Web::Cookie { @@ -31,3 +32,10 @@ struct Cookie { }; } + +namespace IPC { + +bool encode(Encoder&, Web::Cookie::Cookie const&); +ErrorOr decode(Decoder&, Web::Cookie::Cookie&); + +}