LibHTTP+Everywhere: Move the cookie implementation to LibHTTP

This will allow parsing cookies outside of LibWeb.

LibHTTP is basically becoming the home of HTTP WG specs.
This commit is contained in:
Timothy Flynn
2026-02-07 11:13:47 -05:00
committed by Andreas Kling
parent 0a334f50db
commit 8d97389038
Notes: github-actions[bot] 2026-02-10 11:23:01 +00:00
39 changed files with 212 additions and 203 deletions

View File

@@ -4,6 +4,8 @@ set(SOURCES
Cache/DiskCache.cpp
Cache/MemoryCache.cpp
Cache/Utilities.cpp
Cookie/Cookie.cpp
Cookie/ParsedCookie.cpp
Header.cpp
HeaderList.cpp
HTTP.cpp
@@ -12,4 +14,4 @@ set(SOURCES
)
ladybird_lib(LibHTTP http)
target_link_libraries(LibHTTP PRIVATE LibCompress LibCore LibCrypto LibDatabase LibFileSystem LibIPC LibRegex LibTextCodec LibTLS LibURL)
target_link_libraries(LibHTTP PRIVATE LibCompress LibCore LibCrypto LibDatabase LibFileSystem LibIPC LibRegex LibTextCodec LibTLS LibUnicode LibURL)

View File

@@ -7,11 +7,12 @@
#include <AK/IPv4Address.h>
#include <AK/IPv6Address.h>
#include <LibHTTP/Cookie/Cookie.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibURL/URL.h>
namespace Web::Cookie {
namespace HTTP::Cookie {
static String time_to_string(UnixDateTime const& time)
{
@@ -150,7 +151,7 @@ String default_path(URL::URL const& url)
}
// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-22#section-5.8.3
bool cookie_matches_url(Web::Cookie::Cookie const& cookie, URL::URL const& url, String const& retrieval_host_canonical, Optional<Web::Cookie::Source> source)
bool cookie_matches_url(Cookie const& cookie, URL::URL const& url, String const& retrieval_host_canonical, Optional<Source> source)
{
// * Either:
// - The cookie's host-only-flag is true and retrieval-host-canonical is identical to the cookie's domain.
@@ -159,14 +160,14 @@ bool cookie_matches_url(Web::Cookie::Cookie const& cookie, URL::URL const& url,
// - The cookie's host-only-flag is false and retrieval-host-canonical domain-matches (see Section 5.1.3)
// the cookie's domain.
// - The cookie's domain is not a public suffix, for user agents configured to reject "public suffixes".
bool is_not_host_only_and_domain_matches = (!cookie.host_only && Web::Cookie::domain_matches(retrieval_host_canonical, cookie.domain))
bool is_not_host_only_and_domain_matches = (!cookie.host_only && domain_matches(retrieval_host_canonical, cookie.domain))
&& !URL::is_public_suffix(cookie.domain);
if (!is_host_only_and_has_identical_domain && !is_not_host_only_and_domain_matches)
return false;
// * The retrieval's URI's path path-matches the cookie's path.
if (!Web::Cookie::path_matches(url.serialize_path(), cookie.path))
if (!path_matches(url.serialize_path(), cookie.path))
return false;
// * If the cookie's secure-only-flag is true, then the retrieval's URI must denote a "secure" connection (as
@@ -175,7 +176,7 @@ bool cookie_matches_url(Web::Cookie::Cookie const& cookie, URL::URL const& url,
return false;
// * If the cookie's http-only-flag is true, then exclude the cookie if the retrieval's type is "non-HTTP".
if (cookie.http_only && (source != Web::Cookie::Source::Http))
if (cookie.http_only && (source != Source::Http))
return false;
// FIXME: * If the cookie's same-site-flag is not "None" and the retrieval's same-site status is "cross-site", then
@@ -192,7 +193,7 @@ bool cookie_matches_url(Web::Cookie::Cookie const& cookie, URL::URL const& url,
}
template<>
ErrorOr<void> IPC::encode(Encoder& encoder, Web::Cookie::Cookie const& cookie)
ErrorOr<void> IPC::encode(Encoder& encoder, HTTP::Cookie::Cookie const& cookie)
{
TRY(encoder.encode(cookie.name));
TRY(encoder.encode(cookie.value));
@@ -211,7 +212,7 @@ ErrorOr<void> IPC::encode(Encoder& encoder, Web::Cookie::Cookie const& cookie)
}
template<>
ErrorOr<Web::Cookie::Cookie> IPC::decode(Decoder& decoder)
ErrorOr<HTTP::Cookie::Cookie> IPC::decode(Decoder& decoder)
{
auto name = TRY(decoder.decode<String>());
auto value = TRY(decoder.decode<String>());
@@ -224,13 +225,13 @@ ErrorOr<Web::Cookie::Cookie> IPC::decode(Decoder& decoder)
auto last_access_time = TRY(decoder.decode<UnixDateTime>());
auto persistent = TRY(decoder.decode<bool>());
auto secure = TRY(decoder.decode<bool>());
auto same_site = TRY(decoder.decode<Web::Cookie::SameSite>());
auto same_site = TRY(decoder.decode<HTTP::Cookie::SameSite>());
return Web::Cookie::Cookie { move(name), move(value), same_site, creation_time, last_access_time, expiry_time, move(domain), move(path), secure, http_only, host_only, persistent };
return HTTP::Cookie::Cookie { move(name), move(value), same_site, creation_time, last_access_time, expiry_time, move(domain), move(path), secure, http_only, host_only, persistent };
}
template<>
ErrorOr<void> IPC::encode(Encoder& encoder, Web::Cookie::VersionedCookie const& cookie)
ErrorOr<void> IPC::encode(Encoder& encoder, HTTP::Cookie::VersionedCookie const& cookie)
{
TRY(encoder.encode(cookie.cookie_version));
TRY(encoder.encode(cookie.cookie));
@@ -239,10 +240,10 @@ ErrorOr<void> IPC::encode(Encoder& encoder, Web::Cookie::VersionedCookie const&
}
template<>
ErrorOr<Web::Cookie::VersionedCookie> IPC::decode(Decoder& decoder)
ErrorOr<HTTP::Cookie::VersionedCookie> IPC::decode(Decoder& decoder)
{
auto cookie_version = TRY(decoder.decode<Optional<Core::SharedVersion>>());
auto cookie = TRY(decoder.decode<String>());
return Web::Cookie::VersionedCookie { cookie_version, move(cookie) };
return HTTP::Cookie::VersionedCookie { cookie_version, move(cookie) };
}

View File

@@ -6,14 +6,15 @@
#pragma once
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Time.h>
#include <LibCore/SharedVersion.h>
#include <LibHTTP/Forward.h>
#include <LibIPC/Forward.h>
#include <LibURL/URL.h>
#include <LibWeb/Export.h>
#include <LibURL/Forward.h>
namespace Web::Cookie {
namespace HTTP::Cookie {
enum class SameSite {
Default,
@@ -27,7 +28,7 @@ enum class Source {
Http,
};
struct WEB_API Cookie {
struct Cookie {
String creation_time_to_string() const;
String last_access_time_to_string() const;
String expiry_time_to_string() const;
@@ -51,30 +52,30 @@ struct VersionedCookie {
String cookie;
};
WEB_API StringView same_site_to_string(SameSite same_site_mode);
WEB_API SameSite same_site_from_string(StringView same_site_mode);
StringView same_site_to_string(SameSite same_site_mode);
SameSite same_site_from_string(StringView same_site_mode);
WEB_API Optional<String> canonicalize_domain(URL::URL const& url);
WEB_API bool domain_matches(StringView string, StringView domain_string);
WEB_API bool path_matches(StringView request_path, StringView cookie_path);
WEB_API String default_path(URL::URL const&);
Optional<String> canonicalize_domain(URL::URL const& url);
bool domain_matches(StringView string, StringView domain_string);
bool path_matches(StringView request_path, StringView cookie_path);
String default_path(URL::URL const&);
WEB_API bool cookie_matches_url(Cookie const&, URL::URL const&, String const& retrieval_host_canonical, Optional<Source> = {});
bool cookie_matches_url(Cookie const&, URL::URL const&, String const& retrieval_host_canonical, Optional<Source> = {});
}
namespace IPC {
template<>
WEB_API ErrorOr<void> encode(Encoder&, Web::Cookie::Cookie const&);
ErrorOr<void> encode(Encoder&, HTTP::Cookie::Cookie const&);
template<>
WEB_API ErrorOr<Web::Cookie::Cookie> decode(Decoder&);
ErrorOr<HTTP::Cookie::Cookie> decode(Decoder&);
template<>
WEB_API ErrorOr<void> encode(Encoder&, Web::Cookie::VersionedCookie const&);
ErrorOr<void> encode(Encoder&, HTTP::Cookie::VersionedCookie const&);
template<>
WEB_API ErrorOr<Web::Cookie::VersionedCookie> decode(Decoder&);
ErrorOr<HTTP::Cookie::VersionedCookie> decode(Decoder&);
}

View File

@@ -9,14 +9,13 @@
#include <AK/StdLibExtras.h>
#include <AK/Time.h>
#include <AK/Vector.h>
#include <LibHTTP/Cookie/ParsedCookie.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
#include <LibURL/URL.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/Infra/Strings.h>
#include <ctype.h>
namespace Web::Cookie {
namespace HTTP::Cookie {
static ErrorOr<void> parse_attributes(URL::URL const&, ParsedCookie& parsed_cookie, StringView unparsed_attributes);
static ErrorOr<void> process_attribute(URL::URL const&, ParsedCookie& parsed_cookie, StringView attribute_name, StringView attribute_value);
@@ -478,7 +477,7 @@ Optional<UnixDateTime> parse_date_time(StringView date_string)
}
template<>
ErrorOr<void> IPC::encode(Encoder& encoder, Web::Cookie::ParsedCookie const& cookie)
ErrorOr<void> IPC::encode(Encoder& encoder, HTTP::Cookie::ParsedCookie const& cookie)
{
TRY(encoder.encode(cookie.name));
TRY(encoder.encode(cookie.value));
@@ -494,7 +493,7 @@ ErrorOr<void> IPC::encode(Encoder& encoder, Web::Cookie::ParsedCookie const& coo
}
template<>
ErrorOr<Web::Cookie::ParsedCookie> IPC::decode(Decoder& decoder)
ErrorOr<HTTP::Cookie::ParsedCookie> IPC::decode(Decoder& decoder)
{
auto name = TRY(decoder.decode<String>());
auto value = TRY(decoder.decode<String>());
@@ -504,7 +503,7 @@ ErrorOr<Web::Cookie::ParsedCookie> IPC::decode(Decoder& decoder)
auto path = TRY(decoder.decode<Optional<String>>());
auto secure_attribute_present = TRY(decoder.decode<bool>());
auto http_only_attribute_present = TRY(decoder.decode<bool>());
auto same_site_attribute = TRY(decoder.decode<Web::Cookie::SameSite>());
auto same_site_attribute = TRY(decoder.decode<HTTP::Cookie::SameSite>());
return Web::Cookie::ParsedCookie { move(name), move(value), same_site_attribute, move(expiry_time_from_expires_attribute), move(expiry_time_from_max_age_attribute), move(domain), move(path), secure_attribute_present, http_only_attribute_present };
return HTTP::Cookie::ParsedCookie { move(name), move(value), same_site_attribute, move(expiry_time_from_expires_attribute), move(expiry_time_from_max_age_attribute), move(domain), move(path), secure_attribute_present, http_only_attribute_present };
}

View File

@@ -9,12 +9,12 @@
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Time.h>
#include <LibHTTP/Cookie/Cookie.h>
#include <LibHTTP/Forward.h>
#include <LibIPC/Forward.h>
#include <LibURL/Forward.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Export.h>
namespace Web::Cookie {
namespace HTTP::Cookie {
struct ParsedCookie {
String name;
@@ -29,7 +29,7 @@ struct ParsedCookie {
};
Optional<ParsedCookie> parse_cookie(URL::URL const&, StringView cookie_string);
WEB_API bool cookie_contains_invalid_control_character(StringView);
bool cookie_contains_invalid_control_character(StringView);
constexpr inline AK::Duration maximum_cookie_age = AK::Duration::from_seconds(400LL * 24 * 60 * 60);
@@ -38,9 +38,9 @@ constexpr inline AK::Duration maximum_cookie_age = AK::Duration::from_seconds(40
namespace IPC {
template<>
WEB_API ErrorOr<void> encode(Encoder&, Web::Cookie::ParsedCookie const&);
ErrorOr<void> encode(Encoder&, HTTP::Cookie::ParsedCookie const&);
template<>
WEB_API ErrorOr<Web::Cookie::ParsedCookie> decode(Decoder&);
ErrorOr<HTTP::Cookie::ParsedCookie> decode(Decoder&);
}

View File

@@ -22,3 +22,14 @@ class MemoryCache;
struct Header;
}
namespace HTTP::Cookie {
struct Cookie;
struct ParsedCookie;
struct VersionedCookie;
enum class SameSite;
enum class Source;
}

View File

@@ -82,8 +82,6 @@ set(SOURCES
ContentSecurityPolicy/SecurityPolicyViolationEvent.cpp
ContentSecurityPolicy/SerializedPolicy.cpp
ContentSecurityPolicy/Violation.cpp
Cookie/Cookie.cpp
Cookie/ParsedCookie.cpp
CookieStore/CookieChangeEvent.cpp
CookieStore/CookieStore.cpp
CredentialManagement/Credential.cpp

View File

@@ -4,11 +4,12 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibHTTP/Cookie/Cookie.h>
#include <LibHTTP/Cookie/ParsedCookie.h>
#include <LibJS/Runtime/Array.h>
#include <LibURL/Parser.h>
#include <LibWeb/Bindings/CookieStorePrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/CookieStore/CookieChangeEvent.h>
#include <LibWeb/CookieStore/CookieStore.h>
#include <LibWeb/HTML/Scripting/Environments.h>
@@ -43,7 +44,7 @@ void CookieStore::visit_edges(Cell::Visitor& visitor)
}
// https://cookiestore.spec.whatwg.org/#create-a-cookielistitem
static CookieListItem create_a_cookie_list_item(Cookie::Cookie const& cookie)
static CookieListItem create_a_cookie_list_item(HTTP::Cookie::Cookie const& cookie)
{
// 1. Let name be the result of running UTF-8 decode without BOM on cookies name.
// 2. Let value be the result of running UTF-8 decode without BOM on cookies value.
@@ -419,7 +420,7 @@ static bool set_a_cookie(PageClient& client, URL::URL const& url, String name, S
auto const& host = url.host();
// 11. Let attributes be a new list.
Cookie::ParsedCookie parsed_cookie {};
HTTP::Cookie::ParsedCookie parsed_cookie {};
parsed_cookie.name = move(name);
parsed_cookie.value = move(value);
@@ -461,7 +462,7 @@ static bool set_a_cookie(PageClient& client, URL::URL const& url, String name, S
// https://www.ietf.org/archive/id/draft-ietf-httpbis-rfc6265bis-15.html#section-5.6.1
// 3. Let cookie-age-limit be the maximum age of the cookie (which SHOULD be 400 days in the future or sooner, see
// Section 5.5).
auto cookie_age_limit = UnixDateTime::now() + Cookie::maximum_cookie_age;
auto cookie_age_limit = UnixDateTime::now() + HTTP::Cookie::maximum_cookie_age;
// 4. If the expiry-time is more than cookie-age-limit, the user agent MUST set the expiry time to cookie-age-limit
// in seconds.
@@ -499,17 +500,17 @@ static bool set_a_cookie(PageClient& client, URL::URL const& url, String name, S
// -> "none"
case Bindings::CookieSameSite::None:
// Append `SameSite`/`None` to attributes.
parsed_cookie.same_site_attribute = Cookie::SameSite::None;
parsed_cookie.same_site_attribute = HTTP::Cookie::SameSite::None;
break;
// -> "strict"
case Bindings::CookieSameSite::Strict:
// Append `SameSite`/`Strict` to attributes.
parsed_cookie.same_site_attribute = Cookie::SameSite::Strict;
parsed_cookie.same_site_attribute = HTTP::Cookie::SameSite::Strict;
break;
// -> "lax"
case Bindings::CookieSameSite::Lax:
// Append `SameSite`/`Lax` to attributes.
parsed_cookie.same_site_attribute = Cookie::SameSite::Lax;
parsed_cookie.same_site_attribute = HTTP::Cookie::SameSite::Lax;
break;
}
@@ -519,7 +520,7 @@ static bool set_a_cookie(PageClient& client, URL::URL const& url, String name, S
// 23. Perform the steps defined in Cookies § Storage Model for when the user agent "receives a cookie" with url as
// request-uri, encodedName as cookie-name, encodedValue as cookie-value, and attributes as cookie-attribute-list.
// For the purposes of the steps, the newly-created cookie was received from a "non-HTTP" API.
client.page_did_set_cookie(url, parsed_cookie, Cookie::Source::NonHttp);
client.page_did_set_cookie(url, parsed_cookie, HTTP::Cookie::Source::NonHttp);
// 24. Return success.
return true;
@@ -742,12 +743,12 @@ struct CookieChange {
Deleted,
};
Cookie::Cookie cookie;
HTTP::Cookie::Cookie cookie;
Type type;
};
// https://cookiestore.spec.whatwg.org/#observable-changes
static Vector<CookieChange> observable_changes(Vector<Cookie::Cookie> changes)
static Vector<CookieChange> observable_changes(Vector<HTTP::Cookie::Cookie> changes)
{
// The observable changes for url are the set of cookie changes to cookies in a cookie store which meet the
// requirements in step 1 of Cookies § Retrieval Algorithms steps to compute the "cookie-string from a given
@@ -808,7 +809,7 @@ static PreparedLists prepare_lists(Vector<CookieChange> const& changes)
}
// https://cookiestore.spec.whatwg.org/#process-cookie-changes
void CookieStore::process_cookie_changes(Vector<Cookie::Cookie> all_changes)
void CookieStore::process_cookie_changes(Vector<HTTP::Cookie::Cookie> all_changes)
{
auto& realm = this->realm();

View File

@@ -8,6 +8,7 @@
#include <AK/Optional.h>
#include <AK/String.h>
#include <LibHTTP/Forward.h>
#include <LibWeb/Bindings/CookieStorePrototype.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/Export.h>
@@ -67,7 +68,7 @@ public:
void set_onchange(WebIDL::CallbackType*);
WebIDL::CallbackType* onchange();
void process_cookie_changes(Vector<Cookie::Cookie>);
void process_cookie_changes(Vector<HTTP::Cookie::Cookie>);
private:
CookieStore(JS::Realm&, PageClient&);

View File

@@ -21,6 +21,7 @@
#include <AK/Utf8View.h>
#include <LibCore/Timer.h>
#include <LibGC/RootVector.h>
#include <LibHTTP/Cookie/ParsedCookie.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/NativeFunction.h>
@@ -58,7 +59,6 @@
#include <LibWeb/ContentSecurityPolicy/Directives/Directive.h>
#include <LibWeb/ContentSecurityPolicy/Policy.h>
#include <LibWeb/ContentSecurityPolicy/PolicyList.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/DOM/AdoptedStyleSheets.h>
#include <LibWeb/DOM/Attr.h>
#include <LibWeb/DOM/CDATASection.h>
@@ -3261,7 +3261,7 @@ void Document::completely_finish_loading()
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-cookie
WebIDL::ExceptionOr<String> Document::cookie(Cookie::Source source)
WebIDL::ExceptionOr<String> Document::cookie(HTTP::Cookie::Source source)
{
// On getting, if the document is a cookie-averse Document object, then the user agent must return the empty string.
if (is_cookie_averse())
@@ -3289,7 +3289,7 @@ WebIDL::ExceptionOr<String> Document::cookie(Cookie::Source source)
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-cookie
WebIDL::ExceptionOr<void> Document::set_cookie(StringView cookie_string, Cookie::Source source)
WebIDL::ExceptionOr<void> Document::set_cookie(StringView cookie_string, HTTP::Cookie::Source source)
{
// On setting, if the document is a cookie-averse Document object, then the user agent must do nothing.
if (is_cookie_averse())
@@ -3301,7 +3301,7 @@ WebIDL::ExceptionOr<void> Document::set_cookie(StringView cookie_string, Cookie:
// Otherwise, the user agent must act as it would when receiving a set-cookie-string for the document's URL via a
// "non-HTTP" API, consisting of the new value encoded as UTF-8.
if (auto cookie = Cookie::parse_cookie(url(), cookie_string); cookie.has_value())
if (auto cookie = HTTP::Cookie::parse_cookie(url(), cookie_string); cookie.has_value())
page().client().page_did_set_cookie(m_url, cookie.value(), source);
return {};
@@ -7248,13 +7248,13 @@ void Document::build_registered_properties_cache()
void Document::ensure_cookie_version_index(URL::URL const& new_url, URL::URL const& old_url)
{
auto new_domain = Cookie::canonicalize_domain(new_url);
auto new_domain = HTTP::Cookie::canonicalize_domain(new_url);
if (!new_domain.has_value()) {
m_cookie_version_index = {};
return;
}
if (m_cookie_version_index.has_value() && *new_domain == Cookie::canonicalize_domain(old_url))
if (m_cookie_version_index.has_value() && *new_domain == HTTP::Cookie::canonicalize_domain(old_url))
return;
page().client().page_did_request_document_cookie_version_index(unique_id(), *new_domain);

View File

@@ -18,6 +18,7 @@
#include <AK/WeakPtr.h>
#include <LibCore/Forward.h>
#include <LibCore/SharedVersion.h>
#include <LibHTTP/Cookie/Cookie.h>
#include <LibJS/Console.h>
#include <LibJS/Forward.h>
#include <LibURL/Origin.h>
@@ -29,7 +30,6 @@
#include <LibWeb/CSS/EnvironmentVariable.h>
#include <LibWeb/CSS/StyleScope.h>
#include <LibWeb/CSS/StyleSheetList.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/DOM/ParentNode.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/Export.h>
@@ -221,8 +221,8 @@ public:
GC::Ptr<Selection::Selection> get_selection() const;
WebIDL::ExceptionOr<String> cookie(Cookie::Source = Cookie::Source::NonHttp);
WebIDL::ExceptionOr<void> set_cookie(StringView, Cookie::Source = Cookie::Source::NonHttp);
WebIDL::ExceptionOr<String> cookie(HTTP::Cookie::Source = HTTP::Cookie::Source::NonHttp);
WebIDL::ExceptionOr<void> set_cookie(StringView, HTTP::Cookie::Source = HTTP::Cookie::Source::NonHttp);
bool is_cookie_averse() const;
void enable_cookies_on_file_domains(Badge<Internals::Internals>) { m_enable_cookies_on_file_domains = true; }

View File

@@ -14,6 +14,7 @@
#include <AK/ScopeGuard.h>
#include <LibHTTP/Cache/MemoryCache.h>
#include <LibHTTP/Cache/Utilities.h>
#include <LibHTTP/Cookie/Cookie.h>
#include <LibHTTP/Method.h>
#include <LibJS/Runtime/Completion.h>
#include <LibRequests/Request.h>
@@ -22,7 +23,6 @@
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/Bindings/PrincipalHostDefined.h>
#include <LibWeb/ContentSecurityPolicy/BlockingAlgorithms.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOMURL/DOMURL.h>
#include <LibWeb/Fetch/BodyInit.h>
@@ -1729,7 +1729,7 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
// with the user agents cookie store and httpRequests current URL.
auto cookies = ([&] {
auto& page = Bindings::principal_host_defined_page(HTML::principal_realm(realm));
return page.client().page_did_request_cookie(http_request->current_url(), Cookie::Source::Http).cookie;
return page.client().page_did_request_cookie(http_request->current_url(), HTTP::Cookie::Source::Http).cookie;
})();
// 2. If cookies is not the empty string, then append (`Cookie`, cookies) to httpRequests header list.

View File

@@ -168,15 +168,6 @@ struct SerializedDirective;
}
namespace Web::Cookie {
struct Cookie;
struct ParsedCookie;
enum class Source;
}
namespace Web::CookieStore {
class CookieChangeEvent;

View File

@@ -64,7 +64,7 @@ void WorkerAgentParent::initialize(JS::Realm& realm)
void WorkerAgentParent::setup_worker_ipc_callbacks(JS::Realm& realm)
{
// NOTE: As long as WorkerAgentParent is alive, realm and m_worker_ipc will be alive.
m_worker_ipc->on_request_cookie = [realm = GC::RawRef { realm }](URL::URL const& url, Cookie::Source source) {
m_worker_ipc->on_request_cookie = [realm = GC::RawRef { realm }](URL::URL const& url, HTTP::Cookie::Source source) {
auto& client = Bindings::principal_host_defined_page(realm).client();
return client.page_did_request_cookie(url, source);
};

View File

@@ -6,6 +6,7 @@
#pragma once
#include <LibURL/URL.h>
#include <LibWeb/Bindings/AgentType.h>
#include <LibWeb/Bindings/RequestPrototype.h>
#include <LibWeb/Bindings/WorkerPrototype.h>

View File

@@ -11,11 +11,11 @@
#include <LibCore/Resource.h>
#include <LibCore/System.h>
#include <LibGC/Function.h>
#include <LibHTTP/Cookie/Cookie.h>
#include <LibHTTP/Cookie/ParsedCookie.h>
#include <LibRequests/Request.h>
#include <LibRequests/RequestClient.h>
#include <LibURL/Parser.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/Fetch/Infrastructure/URL.h>
#include <LibWeb/Loader/ContentFilter.h>
@@ -110,11 +110,11 @@ static void store_response_cookies(Page& page, URL::URL const& url, StringView s
if (decoded_cookie.is_error())
return;
auto cookie = Cookie::parse_cookie(url, decoded_cookie.value());
auto cookie = HTTP::Cookie::parse_cookie(url, decoded_cookie.value());
if (!cookie.has_value())
return;
page.client().page_did_set_cookie(url, cookie.value(), Cookie::Source::Http);
page.client().page_did_set_cookie(url, cookie.value(), HTTP::Cookie::Source::Http);
}
static NonnullRefPtr<HTTP::HeaderList> response_headers_for_file(StringView path, Optional<time_t> const& modified_time)

View File

@@ -18,6 +18,8 @@
#include <LibGfx/Rect.h>
#include <LibGfx/ShareableBitmap.h>
#include <LibGfx/Size.h>
#include <LibHTTP/Cookie/Cookie.h>
#include <LibHTTP/Forward.h>
#include <LibHTTP/Header.h>
#include <LibIPC/Forward.h>
#include <LibRequests/NetworkError.h>
@@ -27,7 +29,6 @@
#include <LibWeb/CSS/PreferredColorScheme.h>
#include <LibWeb/CSS/PreferredContrast.h>
#include <LibWeb/CSS/PreferredMotion.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Export.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/ActivateTab.h>
@@ -382,12 +383,12 @@ public:
virtual void page_did_receive_document_cookie_version_buffer([[maybe_unused]] Core::AnonymousBuffer document_cookie_version_buffer) { }
virtual void page_did_request_document_cookie_version_index([[maybe_unused]] UniqueNodeID document_id, [[maybe_unused]] String const& domain) { }
virtual void page_did_receive_document_cookie_version_index([[maybe_unused]] UniqueNodeID document_id, [[maybe_unused]] Core::SharedVersionIndex document_index) { }
virtual Vector<Web::Cookie::Cookie> page_did_request_all_cookies_webdriver(URL::URL const&) { return {}; }
virtual Vector<Web::Cookie::Cookie> page_did_request_all_cookies_cookiestore(URL::URL const&) { return {}; }
virtual Optional<Web::Cookie::Cookie> page_did_request_named_cookie(URL::URL const&, String const&) { return {}; }
virtual Cookie::VersionedCookie page_did_request_cookie(URL::URL const&, Cookie::Source) { return {}; }
virtual void page_did_set_cookie(URL::URL const&, Cookie::ParsedCookie const&, Cookie::Source) { }
virtual void page_did_update_cookie(Web::Cookie::Cookie const&) { }
virtual Vector<HTTP::Cookie::Cookie> page_did_request_all_cookies_webdriver(URL::URL const&) { return {}; }
virtual Vector<HTTP::Cookie::Cookie> page_did_request_all_cookies_cookiestore(URL::URL const&) { return {}; }
virtual Optional<HTTP::Cookie::Cookie> page_did_request_named_cookie(URL::URL const&, String const&) { return {}; }
virtual HTTP::Cookie::VersionedCookie page_did_request_cookie(URL::URL const&, HTTP::Cookie::Source) { return {}; }
virtual void page_did_set_cookie(URL::URL const&, HTTP::Cookie::ParsedCookie const&, HTTP::Cookie::Source) { }
virtual void page_did_update_cookie(HTTP::Cookie::Cookie const&) { }
virtual void page_did_expire_cookies_with_time_offset(AK::Duration) { }
virtual Optional<String> page_did_request_storage_item([[maybe_unused]] Web::StorageAPI::StorageEndpointType storage_endpoint, [[maybe_unused]] String const& storage_key, [[maybe_unused]] String const& bottle_key) { return {}; }
virtual WebView::StorageSetResult page_did_set_storage_item([[maybe_unused]] Web::StorageAPI::StorageEndpointType storage_endpoint, [[maybe_unused]] String const& storage_key, [[maybe_unused]] String const& bottle_key, [[maybe_unused]] String const& value) { return WebView::StorageOperationError::QuotaExceededError; }

View File

@@ -204,7 +204,7 @@ ErrorOr<void> WebSocket::establish_web_socket_connection(URL::URL const& url_rec
auto cookies = ([&] {
auto& page = Bindings::principal_host_defined_page(HTML::principal_realm(realm()));
return page.client().page_did_request_cookie(url_record, Cookie::Source::Http).cookie;
return page.client().page_did_request_cookie(url_record, HTTP::Cookie::Source::Http).cookie;
})();
if (!cookies.is_empty()) {

View File

@@ -20,11 +20,11 @@ void WebWorkerClient::did_close_worker()
on_worker_close();
}
Messages::WebWorkerClient::DidRequestCookieResponse WebWorkerClient::did_request_cookie(URL::URL url, Cookie::Source source)
Messages::WebWorkerClient::DidRequestCookieResponse WebWorkerClient::did_request_cookie(URL::URL url, HTTP::Cookie::Source source)
{
if (on_request_cookie)
return on_request_cookie(url, source);
return Cookie::VersionedCookie {};
return HTTP::Cookie::VersionedCookie {};
}
Messages::WebWorkerClient::RequestWorkerAgentResponse WebWorkerClient::request_worker_agent(Web::Bindings::AgentType worker_type)

View File

@@ -6,8 +6,8 @@
#pragma once
#include <LibHTTP/Cookie/Cookie.h>
#include <LibIPC/ConnectionToServer.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Export.h>
#include <LibWeb/Worker/WebWorkerClientEndpoint.h>
#include <LibWeb/Worker/WebWorkerServerEndpoint.h>
@@ -23,11 +23,11 @@ public:
explicit WebWorkerClient(NonnullOwnPtr<IPC::Transport>);
virtual void did_close_worker() override;
virtual Messages::WebWorkerClient::DidRequestCookieResponse did_request_cookie(URL::URL, Cookie::Source) override;
virtual Messages::WebWorkerClient::DidRequestCookieResponse did_request_cookie(URL::URL, HTTP::Cookie::Source) override;
virtual Messages::WebWorkerClient::RequestWorkerAgentResponse request_worker_agent(Web::Bindings::AgentType worker_type) override;
Function<void()> on_worker_close;
Function<Cookie::VersionedCookie(URL::URL const&, Cookie::Source)> on_request_cookie;
Function<HTTP::Cookie::VersionedCookie(URL::URL const&, HTTP::Cookie::Source)> on_request_cookie;
Function<IPC::File(Web::Bindings::AgentType)> on_request_worker_agent;
IPC::File clone_transport();

View File

@@ -1,9 +1,9 @@
#include <LibHTTP/Cookie/Cookie.h>
#include <LibURL/URL.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Bindings/AgentType.h>
endpoint WebWorkerClient {
did_close_worker() =|
did_request_cookie(URL::URL url, Web::Cookie::Source source) => (Web::Cookie::VersionedCookie cookie)
did_request_cookie(URL::URL url, HTTP::Cookie::Source source) => (HTTP::Cookie::VersionedCookie cookie)
request_worker_agent(Web::Bindings::AgentType worker_type) => (IPC::File socket)
}

View File

@@ -12,8 +12,8 @@
#include <AK/Time.h>
#include <AK/Vector.h>
#include <LibDatabase/Database.h>
#include <LibHTTP/Cookie/ParsedCookie.h>
#include <LibURL/URL.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWebView/CookieJar.h>
#include <LibWebView/ViewImplementation.h>
@@ -44,7 +44,7 @@ ErrorOr<NonnullOwnPtr<CookieJar>> CookieJar::create(Database::Database& database
persistent BOOLEAN,
PRIMARY KEY(name, domain, path)
);)#",
to_underlying(Web::Cookie::SameSite::Lax)))));
to_underlying(HTTP::Cookie::SameSite::Lax)))));
database.execute_statement(create_table, {});
statements.insert_cookie = TRY(database.prepare_statement("INSERT OR REPLACE INTO Cookies VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"sv));
@@ -91,7 +91,7 @@ CookieJar::~CookieJar()
}
// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-22#section-5.8.3
String CookieJar::get_cookie(URL::URL const& url, Web::Cookie::Source source)
String CookieJar::get_cookie(URL::URL const& url, HTTP::Cookie::Source source)
{
m_transient_storage.purge_expired_cookies();
@@ -119,7 +119,7 @@ String CookieJar::get_cookie(URL::URL const& url, Web::Cookie::Source source)
}
// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-22#section-5.7
void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const& parsed_cookie, Web::Cookie::Source source)
void CookieJar::set_cookie(URL::URL const& url, HTTP::Cookie::ParsedCookie const& parsed_cookie, HTTP::Cookie::Source source)
{
// 1. A user agent MAY ignore a received cookie in its entirety. See Section 5.3.
@@ -129,9 +129,9 @@ void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const&
// 3. If the cookie-name or the cookie-value contains a %x00-08 / %x0A-1F / %x7F character (CTL characters excluding
// HTAB), abort this algorithm and ignore the cookie entirely.
if (Web::Cookie::cookie_contains_invalid_control_character(parsed_cookie.name))
if (HTTP::Cookie::cookie_contains_invalid_control_character(parsed_cookie.name))
return;
if (Web::Cookie::cookie_contains_invalid_control_character(parsed_cookie.value))
if (HTTP::Cookie::cookie_contains_invalid_control_character(parsed_cookie.value))
return;
// 4. If the sum of the lengths of cookie-name and cookie-value is more than 4096 octets, abort this algorithm and
@@ -141,7 +141,7 @@ void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const&
// 5. Create a new cookie with name cookie-name, value cookie-value. Set the creation-time and the last-access-time
// to the current date and time.
Web::Cookie::Cookie cookie { parsed_cookie.name, parsed_cookie.value };
HTTP::Cookie::Cookie cookie { parsed_cookie.name, parsed_cookie.value };
cookie.creation_time = UnixDateTime::now();
cookie.last_access_time = cookie.creation_time;
@@ -193,7 +193,7 @@ void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const&
if (!domain_attribute.is_ascii())
return;
auto request_host_canonical = Web::Cookie::canonicalize_domain(url);
auto request_host_canonical = HTTP::Cookie::canonicalize_domain(url);
if (!request_host_canonical.has_value())
return;
@@ -217,7 +217,7 @@ void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const&
// 10. If the domain-attribute is non-empty:
if (!domain_attribute.is_empty()) {
// 1. If request-host-canonical does not domain-match (see Section 5.1.3) the domain-attribute:
if (!Web::Cookie::domain_matches(*request_host_canonical, domain_attribute)) {
if (!HTTP::Cookie::domain_matches(*request_host_canonical, domain_attribute)) {
// 1. Abort this algorithm and ignore the cookie entirely.
return;
}
@@ -247,7 +247,7 @@ void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const&
if (parsed_cookie.path->byte_count() <= 1024)
cookie.path = parsed_cookie.path.value();
} else {
cookie.path = Web::Cookie::default_path(url);
cookie.path = HTTP::Cookie::default_path(url);
}
// 12. If the cookie-attribute-list contains an attribute with an attribute-name of "Secure", set the cookie's
@@ -265,7 +265,7 @@ void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const&
// 15. If the cookie was received from a "non-HTTP" API and the cookie's http-only-flag is true, abort this
// algorithm and ignore the cookie entirely.
if (source == Web::Cookie::Source::NonHttp && cookie.http_only)
if (source == HTTP::Cookie::Source::NonHttp && cookie.http_only)
return;
// 16. If the cookie's secure-only-flag is false, and the request-uri does not denote a "secure" connection, then
@@ -274,7 +274,7 @@ void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const&
if (!cookie.secure && url.scheme() != "https"sv) {
auto ignore_cookie = false;
m_transient_storage.for_each_cookie([&](Web::Cookie::Cookie const& old_cookie) {
m_transient_storage.for_each_cookie([&](HTTP::Cookie::Cookie const& old_cookie) {
// 1. Their name matches the name of the newly-created cookie.
if (old_cookie.name != cookie.name)
return IterationDecision::Continue;
@@ -284,11 +284,11 @@ void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const&
return IterationDecision::Continue;
// 3. Their domain domain-matches (see Section 5.1.3) the domain of the newly-created cookie, or vice-versa.
if (!Web::Cookie::domain_matches(old_cookie.domain, cookie.domain) && !Web::Cookie::domain_matches(cookie.domain, old_cookie.domain))
if (!HTTP::Cookie::domain_matches(old_cookie.domain, cookie.domain) && !HTTP::Cookie::domain_matches(cookie.domain, old_cookie.domain))
return IterationDecision::Continue;
// 4. The path of the newly-created cookie path-matches the path of the existing cookie.
if (!Web::Cookie::path_matches(cookie.path, old_cookie.path))
if (!HTTP::Cookie::path_matches(cookie.path, old_cookie.path))
return IterationDecision::Continue;
ignore_cookie = true;
@@ -306,7 +306,7 @@ void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const&
cookie.same_site = parsed_cookie.same_site_attribute;
// 18. If the cookie's same-site-flag is not "None":
if (cookie.same_site != Web::Cookie::SameSite::None) {
if (cookie.same_site != HTTP::Cookie::SameSite::None) {
// FIXME: 1. If the cookie was received from a "non-HTTP" API, and the API was called from a navigable's active document
// whose "site for cookies" is not same-site with the top-level origin, then abort this algorithm and ignore
// the newly created cookie entirely.
@@ -323,7 +323,7 @@ void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const&
// 19. If the cookie's "same-site-flag" is "None", abort this algorithm and ignore the cookie entirely unless the
// cookie's secure-only-flag is true.
if (cookie.same_site == Web::Cookie::SameSite::None && !cookie.secure)
if (cookie.same_site == HTTP::Cookie::SameSite::None && !cookie.secure)
return;
auto has_case_insensitive_prefix = [&](StringView value, StringView prefix) {
@@ -378,7 +378,7 @@ void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const&
// 2. If the newly-created cookie was received from a "non-HTTP" API and the old-cookie's http-only-flag is true,
// abort this algorithm and ignore the newly created cookie entirely.
if (source == Web::Cookie::Source::NonHttp && old_cookie->http_only)
if (source == HTTP::Cookie::Source::NonHttp && old_cookie->http_only)
return;
// 3. Update the creation-time of the newly-created cookie to match the creation-time of the old-cookie.
@@ -395,7 +395,7 @@ void CookieJar::set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const&
}
// This is based on store_cookie() below, however the whole ParsedCookie->Cookie conversion is skipped.
void CookieJar::update_cookie(Web::Cookie::Cookie cookie)
void CookieJar::update_cookie(HTTP::Cookie::Cookie cookie)
{
CookieStorageKey key { cookie.name, cookie.domain, cookie.path };
@@ -436,15 +436,15 @@ void CookieJar::dump_cookies()
builder.appendff("\t{}HttpOnly{} = {:s}\n", attribute_color, no_color, cookie.http_only);
builder.appendff("\t{}HostOnly{} = {:s}\n", attribute_color, no_color, cookie.host_only);
builder.appendff("\t{}Persistent{} = {:s}\n", attribute_color, no_color, cookie.persistent);
builder.appendff("\t{}SameSite{} = {:s}\n", attribute_color, no_color, Web::Cookie::same_site_to_string(cookie.same_site));
builder.appendff("\t{}SameSite{} = {:s}\n", attribute_color, no_color, HTTP::Cookie::same_site_to_string(cookie.same_site));
});
dbgln("{} cookies stored\n{}", m_transient_storage.size(), builder.string_view());
}
Vector<Web::Cookie::Cookie> CookieJar::get_all_cookies()
Vector<HTTP::Cookie::Cookie> CookieJar::get_all_cookies()
{
Vector<Web::Cookie::Cookie> cookies;
Vector<HTTP::Cookie::Cookie> cookies;
cookies.ensure_capacity(m_transient_storage.size());
m_transient_storage.for_each_cookie([&](auto const& cookie) {
@@ -455,19 +455,19 @@ Vector<Web::Cookie::Cookie> CookieJar::get_all_cookies()
}
// https://w3c.github.io/webdriver/#dfn-associated-cookies
Vector<Web::Cookie::Cookie> CookieJar::get_all_cookies_webdriver(URL::URL const& url)
Vector<HTTP::Cookie::Cookie> CookieJar::get_all_cookies_webdriver(URL::URL const& url)
{
return get_matching_cookies(url, Web::Cookie::Source::Http, MatchingCookiesSpecMode::WebDriver);
return get_matching_cookies(url, HTTP::Cookie::Source::Http, MatchingCookiesSpecMode::WebDriver);
}
Vector<Web::Cookie::Cookie> CookieJar::get_all_cookies_cookiestore(URL::URL const& url)
Vector<HTTP::Cookie::Cookie> CookieJar::get_all_cookies_cookiestore(URL::URL const& url)
{
return get_matching_cookies(url, Web::Cookie::Source::NonHttp, MatchingCookiesSpecMode::RFC6265);
return get_matching_cookies(url, HTTP::Cookie::Source::NonHttp, MatchingCookiesSpecMode::RFC6265);
}
Optional<Web::Cookie::Cookie> CookieJar::get_named_cookie(URL::URL const& url, StringView name)
Optional<HTTP::Cookie::Cookie> CookieJar::get_named_cookie(URL::URL const& url, StringView name)
{
auto cookie_list = get_matching_cookies(url, Web::Cookie::Source::Http, MatchingCookiesSpecMode::WebDriver);
auto cookie_list = get_matching_cookies(url, HTTP::Cookie::Source::Http, MatchingCookiesSpecMode::WebDriver);
for (auto const& cookie : cookie_list) {
if (cookie.name == name)
@@ -493,22 +493,22 @@ Requests::CacheSizes CookieJar::estimate_storage_size_accessed_since(UnixDateTim
}
// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-22#section-5.8.3
Vector<Web::Cookie::Cookie> CookieJar::get_matching_cookies(URL::URL const& url, Web::Cookie::Source source, MatchingCookiesSpecMode mode)
Vector<HTTP::Cookie::Cookie> CookieJar::get_matching_cookies(URL::URL const& url, HTTP::Cookie::Source source, MatchingCookiesSpecMode mode)
{
auto now = UnixDateTime::now();
// 1. Let retrieval-host-canonical be the canonicalized host of the retrieval's URI.
auto retrieval_host_canonical = Web::Cookie::canonicalize_domain(url);
auto retrieval_host_canonical = HTTP::Cookie::canonicalize_domain(url);
// 2. If the host of the retrieval's URI fails to be canonicalized then abort this algorithm.
if (!retrieval_host_canonical.has_value())
return {};
// 3. Let cookie-list be the set of cookies from the cookie store that meets all of the following requirements:
Vector<Web::Cookie::Cookie> cookie_list;
Vector<HTTP::Cookie::Cookie> cookie_list;
m_transient_storage.for_each_cookie([&](Web::Cookie::Cookie& cookie) {
if (!Web::Cookie::cookie_matches_url(cookie, url, *retrieval_host_canonical, source))
m_transient_storage.for_each_cookie([&](HTTP::Cookie::Cookie& cookie) {
if (!HTTP::Cookie::cookie_matches_url(cookie, url, *retrieval_host_canonical, source))
return;
// NOTE: The WebDriver spec expects only step 1 above to be executed to match cookies.
@@ -554,7 +554,7 @@ void CookieJar::TransientStorage::set_cookies(Cookies cookies)
purge_expired_cookies();
}
void CookieJar::TransientStorage::set_cookie(CookieStorageKey key, Web::Cookie::Cookie cookie)
void CookieJar::TransientStorage::set_cookie(CookieStorageKey key, HTTP::Cookie::Cookie cookie)
{
auto now = UnixDateTime::now();
@@ -577,7 +577,7 @@ void CookieJar::TransientStorage::set_cookie(CookieStorageKey key, Web::Cookie::
m_dirty_cookies.set(move(key), move(cookie));
}
Optional<Web::Cookie::Cookie const&> CookieJar::TransientStorage::get_cookie(CookieStorageKey const& key)
Optional<HTTP::Cookie::Cookie const&> CookieJar::TransientStorage::get_cookie(CookieStorageKey const& key)
{
return m_cookies.get(key);
}
@@ -630,18 +630,18 @@ Requests::CacheSizes CookieJar::TransientStorage::estimate_storage_size_accessed
void CookieJar::TransientStorage::send_cookie_changed_notifications(ReadonlySpan<CookieEntry> cookies, bool inform_web_view_about_changed_domains)
{
ViewImplementation::for_each_view([&](ViewImplementation& view) {
auto retrieval_host_canonical = Web::Cookie::canonicalize_domain(view.url());
auto retrieval_host_canonical = HTTP::Cookie::canonicalize_domain(view.url());
if (!retrieval_host_canonical.has_value())
return IterationDecision::Continue;
HashTable<String> changed_domains;
Vector<Web::Cookie::Cookie> matching_cookies;
Vector<HTTP::Cookie::Cookie> matching_cookies;
for (auto const& cookie : cookies) {
if (inform_web_view_about_changed_domains)
changed_domains.set(cookie.value.domain);
if (Web::Cookie::cookie_matches_url(cookie.value, view.url(), *retrieval_host_canonical))
if (HTTP::Cookie::cookie_matches_url(cookie.value, view.url(), *retrieval_host_canonical))
matching_cookies.append(cookie.value);
}
@@ -650,7 +650,7 @@ void CookieJar::TransientStorage::send_cookie_changed_notifications(ReadonlySpan
});
}
void CookieJar::PersistedStorage::insert_cookie(Web::Cookie::Cookie const& cookie)
void CookieJar::PersistedStorage::insert_cookie(HTTP::Cookie::Cookie const& cookie)
{
database.execute_statement(
statements.insert_cookie,
@@ -669,7 +669,7 @@ void CookieJar::PersistedStorage::insert_cookie(Web::Cookie::Cookie const& cooki
cookie.persistent);
}
static Web::Cookie::Cookie parse_cookie(Database::Database& database, Database::StatementID statement_id)
static HTTP::Cookie::Cookie parse_cookie(Database::Database& database, Database::StatementID statement_id)
{
int column = 0;
auto convert_text = [&](auto& field) { field = database.result_column<String>(statement_id, column++); };
@@ -677,11 +677,11 @@ static Web::Cookie::Cookie parse_cookie(Database::Database& database, Database::
auto convert_time = [&](auto& field) { field = database.result_column<UnixDateTime>(statement_id, column++); };
auto convert_same_site = [&](auto& field) {
auto same_site = database.result_column<UnderlyingType<Web::Cookie::SameSite>>(statement_id, column++);
field = static_cast<Web::Cookie::SameSite>(same_site);
auto same_site = database.result_column<UnderlyingType<HTTP::Cookie::SameSite>>(statement_id, column++);
field = static_cast<HTTP::Cookie::SameSite>(same_site);
};
Web::Cookie::Cookie cookie;
HTTP::Cookie::Cookie cookie;
convert_text(cookie.name);
convert_text(cookie.value);
convert_same_site(cookie.same_site);
@@ -700,7 +700,7 @@ static Web::Cookie::Cookie parse_cookie(Database::Database& database, Database::
CookieJar::TransientStorage::Cookies CookieJar::PersistedStorage::select_all_cookies()
{
HashMap<CookieStorageKey, Web::Cookie::Cookie> cookies;
HashMap<CookieStorageKey, HTTP::Cookie::Cookie> cookies;
database.execute_statement(
statements.select_all_cookies,

View File

@@ -14,9 +14,9 @@
#include <AK/Traits.h>
#include <LibCore/Timer.h>
#include <LibDatabase/Forward.h>
#include <LibHTTP/Cookie/Cookie.h>
#include <LibRequests/CacheSizes.h>
#include <LibURL/Forward.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Forward.h>
#include <LibWebView/Forward.h>
@@ -37,14 +37,14 @@ public:
~CookieJar();
String get_cookie(URL::URL const& url, Web::Cookie::Source source);
void set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const& parsed_cookie, Web::Cookie::Source source);
void update_cookie(Web::Cookie::Cookie);
String get_cookie(URL::URL const& url, HTTP::Cookie::Source source);
void set_cookie(URL::URL const& url, HTTP::Cookie::ParsedCookie const& parsed_cookie, HTTP::Cookie::Source source);
void update_cookie(HTTP::Cookie::Cookie);
void dump_cookies();
Vector<Web::Cookie::Cookie> get_all_cookies();
Vector<Web::Cookie::Cookie> get_all_cookies_webdriver(URL::URL const& url);
Vector<Web::Cookie::Cookie> get_all_cookies_cookiestore(URL::URL const& url);
Optional<Web::Cookie::Cookie> get_named_cookie(URL::URL const& url, StringView name);
Vector<HTTP::Cookie::Cookie> get_all_cookies();
Vector<HTTP::Cookie::Cookie> get_all_cookies_webdriver(URL::URL const& url);
Vector<HTTP::Cookie::Cookie> get_all_cookies_cookiestore(URL::URL const& url);
Optional<HTTP::Cookie::Cookie> get_named_cookie(URL::URL const& url, StringView name);
void expire_cookies_with_time_offset(AK::Duration);
void expire_cookies_accessed_since(UnixDateTime since);
Requests::CacheSizes estimate_storage_size_accessed_since(UnixDateTime since) const;
@@ -58,11 +58,11 @@ private:
class WEBVIEW_API TransientStorage {
public:
using Cookies = HashMap<CookieStorageKey, Web::Cookie::Cookie>;
using Cookies = HashMap<CookieStorageKey, HTTP::Cookie::Cookie>;
void set_cookies(Cookies);
void set_cookie(CookieStorageKey, Web::Cookie::Cookie);
Optional<Web::Cookie::Cookie const&> get_cookie(CookieStorageKey const&);
void set_cookie(CookieStorageKey, HTTP::Cookie::Cookie);
Optional<HTTP::Cookie::Cookie const&> get_cookie(CookieStorageKey const&);
size_t size() const { return m_cookies.size(); }
@@ -76,7 +76,7 @@ private:
template<typename Callback>
void for_each_cookie(Callback callback)
{
using ReturnType = InvokeResult<Callback, Web::Cookie::Cookie&>;
using ReturnType = InvokeResult<Callback, HTTP::Cookie::Cookie&>;
for (auto& it : m_cookies) {
if constexpr (IsSame<ReturnType, IterationDecision>) {
@@ -98,7 +98,7 @@ private:
};
struct WEBVIEW_API PersistedStorage {
void insert_cookie(Web::Cookie::Cookie const& cookie);
void insert_cookie(HTTP::Cookie::Cookie const& cookie);
TransientStorage::Cookies select_all_cookies();
Database::Database& database;
@@ -116,7 +116,7 @@ private:
WebDriver,
};
Vector<Web::Cookie::Cookie> get_matching_cookies(URL::URL const& url, Web::Cookie::Source source, MatchingCookiesSpecMode mode = MatchingCookiesSpecMode::RFC6265);
Vector<HTTP::Cookie::Cookie> get_matching_cookies(URL::URL const& url, HTTP::Cookie::Source source, MatchingCookiesSpecMode mode = MatchingCookiesSpecMode::RFC6265);
Optional<PersistedStorage> m_persisted_storage;
TransientStorage m_transient_storage;

View File

@@ -33,7 +33,7 @@ void FileDownloader::download_file(URL::URL const& url, LexicalPath destination)
// FIXME: What other request headers should be set? Perhaps we want to use exactly the same request headers used to
// originally fetch the image in WebContent.
auto request_headers = HTTP::HeaderList::create();
request_headers->set({ "Cookie"sv, TextCodec::isomorphic_encode(Application::cookie_jar().get_cookie(url, Web::Cookie::Source::Http)) });
request_headers->set({ "Cookie"sv, TextCodec::isomorphic_encode(Application::cookie_jar().get_cookie(url, HTTP::Cookie::Source::Http)) });
request_headers->set({ "User-Agent"sv, Web::default_user_agent });
auto request = Application::request_server_client().start_request("GET"sv, url, *request_headers);

View File

@@ -260,7 +260,7 @@ void ViewImplementation::set_preferred_motion(Web::CSS::PreferredMotion motion)
client().async_set_preferred_motion(page_id(), motion);
}
void ViewImplementation::notify_cookies_changed(HashTable<String> const& changed_domains, ReadonlySpan<Web::Cookie::Cookie> cookies)
void ViewImplementation::notify_cookies_changed(HashTable<String> const& changed_domains, ReadonlySpan<HTTP::Cookie::Cookie> cookies)
{
for (auto const& domain : changed_domains) {
if (auto document_index = m_document_cookie_version_indices.get(domain); document_index.has_value())
@@ -287,7 +287,7 @@ ErrorOr<Core::SharedVersionIndex> ViewImplementation::ensure_document_cookie_ver
Optional<Core::SharedVersion> ViewImplementation::document_cookie_version(URL::URL const& url) const
{
auto domain = Web::Cookie::canonicalize_domain(url);
auto domain = HTTP::Cookie::canonicalize_domain(url);
if (!domain.has_value())
return {};

View File

@@ -87,7 +87,7 @@ public:
void set_preferred_contrast(Web::CSS::PreferredContrast);
void set_preferred_motion(Web::CSS::PreferredMotion);
void notify_cookies_changed(HashTable<String> const& changed_domains, ReadonlySpan<Web::Cookie::Cookie>);
void notify_cookies_changed(HashTable<String> const& changed_domains, ReadonlySpan<HTTP::Cookie::Cookie>);
ErrorOr<Core::SharedVersionIndex> ensure_document_cookie_version_index(Badge<WebContentClient>, String const&);
Optional<Core::SharedVersion> document_cookie_version(URL::URL const&) const;

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibHTTP/Cookie/ParsedCookie.h>
#include <LibWebView/Application.h>
#include <LibWebView/CookieJar.h>
#include <LibWebView/HelperProcess.h>
@@ -560,12 +560,12 @@ Messages::WebContentClient::DidRequestNamedCookieResponse WebContentClient::did_
return Application::cookie_jar().get_named_cookie(url, name);
}
Messages::WebContentClient::DidRequestCookieResponse WebContentClient::did_request_cookie(u64 page_id, URL::URL url, Web::Cookie::Source source)
Messages::WebContentClient::DidRequestCookieResponse WebContentClient::did_request_cookie(u64 page_id, URL::URL url, HTTP::Cookie::Source source)
{
Web::Cookie::VersionedCookie cookie;
HTTP::Cookie::VersionedCookie cookie;
cookie.cookie = Application::cookie_jar().get_cookie(url, source);
if (source == Web::Cookie::Source::NonHttp) {
if (source == HTTP::Cookie::Source::NonHttp) {
if (auto view = view_for_page_id(page_id); view.has_value())
cookie.cookie_version = view->document_cookie_version(url);
}
@@ -573,12 +573,12 @@ Messages::WebContentClient::DidRequestCookieResponse WebContentClient::did_reque
return cookie;
}
void WebContentClient::did_set_cookie(URL::URL url, Web::Cookie::ParsedCookie cookie, Web::Cookie::Source source)
void WebContentClient::did_set_cookie(URL::URL url, HTTP::Cookie::ParsedCookie cookie, HTTP::Cookie::Source source)
{
Application::cookie_jar().set_cookie(url, cookie, source);
}
void WebContentClient::did_update_cookie(Web::Cookie::Cookie cookie)
void WebContentClient::did_update_cookie(HTTP::Cookie::Cookie cookie)
{
Application::cookie_jar().update_cookie(cookie);
}

View File

@@ -112,9 +112,9 @@ private:
virtual Messages::WebContentClient::DidRequestAllCookiesWebdriverResponse did_request_all_cookies_webdriver(URL::URL) override;
virtual Messages::WebContentClient::DidRequestAllCookiesCookiestoreResponse did_request_all_cookies_cookiestore(URL::URL) override;
virtual Messages::WebContentClient::DidRequestNamedCookieResponse did_request_named_cookie(URL::URL, String) override;
virtual Messages::WebContentClient::DidRequestCookieResponse did_request_cookie(u64 page_id, URL::URL, Web::Cookie::Source) override;
virtual void did_set_cookie(URL::URL, Web::Cookie::ParsedCookie, Web::Cookie::Source) override;
virtual void did_update_cookie(Web::Cookie::Cookie) override;
virtual Messages::WebContentClient::DidRequestCookieResponse did_request_cookie(u64 page_id, URL::URL, HTTP::Cookie::Source) override;
virtual void did_set_cookie(URL::URL, HTTP::Cookie::ParsedCookie, HTTP::Cookie::Source) override;
virtual void did_update_cookie(HTTP::Cookie::Cookie) override;
virtual void did_expire_cookies_with_time_offset(AK::Duration) override;
virtual Messages::WebContentClient::DidRequestStorageItemResponse did_request_storage_item(Web::StorageAPI::StorageEndpointType storage_endpoint, String storage_key, String bottle_key) override;
virtual Messages::WebContentClient::DidSetStorageItemResponse did_set_storage_item(Web::StorageAPI::StorageEndpointType storage_endpoint, String storage_key, String bottle_key, String value) override;

View File

@@ -76,7 +76,7 @@ static bool is_simple_type(ByteString const& type)
// Small types that it makes sense just to pass by value.
if (type.starts_with("ReadonlySpan<"sv) && type.ends_with(">"sv))
return true;
return type.is_one_of("AK::CaseSensitivity", "AK::Duration", "Gfx::Color", "ReadonlyBytes", "StringView", "Web::DevicePixels", "Gfx::IntPoint", "Gfx::FloatPoint", "Web::DevicePixelPoint", "Gfx::IntSize", "Gfx::FloatSize", "Web::DevicePixelSize", "Web::DevicePixelRect", "Core::File::OpenMode", "Web::Cookie::Source", "Web::EventResult", "Web::HTML::AllowMultipleFiles", "Web::HTML::AudioPlayState", "Web::HTML::HistoryHandlingBehavior", "Web::HTML::VisibilityState", "WebView::PageInfoType");
return type.is_one_of("AK::CaseSensitivity", "AK::Duration", "Gfx::Color", "ReadonlyBytes", "StringView", "Web::DevicePixels", "Gfx::IntPoint", "Gfx::FloatPoint", "Web::DevicePixelPoint", "Gfx::IntSize", "Gfx::FloatSize", "Web::DevicePixelSize", "Web::DevicePixelRect", "Core::File::OpenMode", "HTTP::Cookie::Source", "Web::EventResult", "Web::HTML::AllowMultipleFiles", "Web::HTML::AudioPlayState", "Web::HTML::HistoryHandlingBehavior", "Web::HTML::VisibilityState", "WebView::PageInfoType");
}
static bool is_primitive_or_simple_type(ByteString const& type)

View File

@@ -1369,7 +1369,7 @@ void ConnectionFromClient::set_document_cookie_version_index(u64 page_id, i64 do
page->page().client().page_did_receive_document_cookie_version_index(document_id, document_index);
}
void ConnectionFromClient::cookies_changed(u64 page_id, Vector<Web::Cookie::Cookie> cookies)
void ConnectionFromClient::cookies_changed(u64 page_id, Vector<HTTP::Cookie::Cookie> cookies)
{
if (auto page = this->page(page_id); page.has_value()) {
auto window = page->page().top_level_traversable()->active_window();

View File

@@ -165,7 +165,7 @@ private:
virtual void set_document_cookie_version_buffer(u64 page_id, Core::AnonymousBuffer document_cookie_version_buffer) override;
virtual void set_document_cookie_version_index(u64 page_id, i64 document_id, Core::SharedVersionIndex document_index) override;
virtual void cookies_changed(u64 page_id, Vector<Web::Cookie::Cookie>) override;
virtual void cookies_changed(u64 page_id, Vector<HTTP::Cookie::Cookie>) override;
NonnullOwnPtr<PageHost> m_page_host;

View File

@@ -12,11 +12,11 @@
#include <LibCore/Timer.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/ShareableBitmap.h>
#include <LibHTTP/Cookie/ParsedCookie.h>
#include <LibJS/Console.h>
#include <LibJS/Runtime/ConsoleObject.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/CSS/CSSImportRule.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/DOM/CharacterData.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
@@ -536,22 +536,22 @@ void PageClient::page_did_receive_document_cookie_version_index(Web::UniqueNodeI
document->set_cookie_version_index(document_index);
}
Vector<Web::Cookie::Cookie> PageClient::page_did_request_all_cookies_webdriver(URL::URL const& url)
Vector<HTTP::Cookie::Cookie> PageClient::page_did_request_all_cookies_webdriver(URL::URL const& url)
{
return client().did_request_all_cookies_webdriver(url);
}
Vector<Web::Cookie::Cookie> PageClient::page_did_request_all_cookies_cookiestore(URL::URL const& url)
Vector<HTTP::Cookie::Cookie> PageClient::page_did_request_all_cookies_cookiestore(URL::URL const& url)
{
return client().did_request_all_cookies_cookiestore(url);
}
Optional<Web::Cookie::Cookie> PageClient::page_did_request_named_cookie(URL::URL const& url, String const& name)
Optional<HTTP::Cookie::Cookie> PageClient::page_did_request_named_cookie(URL::URL const& url, String const& name)
{
return client().did_request_named_cookie(url, name);
}
Web::Cookie::VersionedCookie PageClient::page_did_request_cookie(URL::URL const& url, Web::Cookie::Source source)
HTTP::Cookie::VersionedCookie PageClient::page_did_request_cookie(URL::URL const& url, HTTP::Cookie::Source source)
{
auto response = client().send_sync_but_allow_failure<Messages::WebContentClient::DidRequestCookie>(m_id, url, source);
if (!response) {
@@ -561,7 +561,7 @@ Web::Cookie::VersionedCookie PageClient::page_did_request_cookie(URL::URL const&
return response->take_cookie();
}
void PageClient::page_did_set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source)
void PageClient::page_did_set_cookie(URL::URL const& url, HTTP::Cookie::ParsedCookie const& cookie, HTTP::Cookie::Source source)
{
auto response = client().send_sync_but_allow_failure<Messages::WebContentClient::DidSetCookie>(url, cookie, source);
if (!response) {
@@ -570,7 +570,7 @@ void PageClient::page_did_set_cookie(URL::URL const& url, Web::Cookie::ParsedCoo
}
}
void PageClient::page_did_update_cookie(Web::Cookie::Cookie const& cookie)
void PageClient::page_did_update_cookie(HTTP::Cookie::Cookie const& cookie)
{
client().async_did_update_cookie(cookie);

View File

@@ -156,12 +156,12 @@ private:
virtual void page_did_receive_document_cookie_version_buffer(Core::AnonymousBuffer document_cookie_version_buffer) override;
virtual void page_did_request_document_cookie_version_index(Web::UniqueNodeID document_id, String const& domain) override;
virtual void page_did_receive_document_cookie_version_index(Web::UniqueNodeID document_id, Core::SharedVersionIndex document_index) override;
virtual Vector<Web::Cookie::Cookie> page_did_request_all_cookies_webdriver(URL::URL const&) override;
virtual Vector<Web::Cookie::Cookie> page_did_request_all_cookies_cookiestore(URL::URL const&) override;
virtual Optional<Web::Cookie::Cookie> page_did_request_named_cookie(URL::URL const&, String const&) override;
virtual Web::Cookie::VersionedCookie page_did_request_cookie(URL::URL const&, Web::Cookie::Source) override;
virtual void page_did_set_cookie(URL::URL const&, Web::Cookie::ParsedCookie const&, Web::Cookie::Source) override;
virtual void page_did_update_cookie(Web::Cookie::Cookie const&) override;
virtual Vector<HTTP::Cookie::Cookie> page_did_request_all_cookies_webdriver(URL::URL const&) override;
virtual Vector<HTTP::Cookie::Cookie> page_did_request_all_cookies_cookiestore(URL::URL const&) override;
virtual Optional<HTTP::Cookie::Cookie> page_did_request_named_cookie(URL::URL const&, String const&) override;
virtual HTTP::Cookie::VersionedCookie page_did_request_cookie(URL::URL const&, HTTP::Cookie::Source) override;
virtual void page_did_set_cookie(URL::URL const&, HTTP::Cookie::ParsedCookie const&, HTTP::Cookie::Source) override;
virtual void page_did_update_cookie(HTTP::Cookie::Cookie const&) override;
virtual void page_did_expire_cookies_with_time_offset(AK::Duration) override;
virtual Optional<String> page_did_request_storage_item(Web::StorageAPI::StorageEndpointType storage_endpoint, String const& storage_key, String const& bottle_key) override;
virtual WebView::StorageSetResult page_did_set_storage_item(Web::StorageAPI::StorageEndpointType storage_endpoint, String const& storage_key, String const& bottle_key, String const& value) override;

View File

@@ -2,14 +2,14 @@
#include <LibGfx/Color.h>
#include <LibGfx/Cursor.h>
#include <LibGfx/ShareableBitmap.h>
#include <LibHTTP/Cookie/Cookie.h>
#include <LibHTTP/Cookie/ParsedCookie.h>
#include <LibHTTP/Header.h>
#include <LibRequests/NetworkError.h>
#include <LibRequests/RequestTimingInfo.h>
#include <LibURL/URL.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/Clipboard/SystemClipboard.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/CSS/StyleSheetIdentifier.h>
#include <LibWeb/HTML/ActivateTab.h>
@@ -77,12 +77,12 @@ endpoint WebContentClient
did_change_favicon(u64 page_id, Gfx::ShareableBitmap favicon) =|
did_request_document_cookie_version_index(u64 page_id, i64 document_id, String domain) =|
did_request_all_cookies_webdriver(URL::URL url) => (Vector<Web::Cookie::Cookie> cookies)
did_request_all_cookies_cookiestore(URL::URL url) => (Vector<Web::Cookie::Cookie> cookies)
did_request_named_cookie(URL::URL url, String name) => (Optional<Web::Cookie::Cookie> cookie)
did_request_cookie(u64 page_id, URL::URL url, Web::Cookie::Source source) => (Web::Cookie::VersionedCookie cookie)
did_set_cookie(URL::URL url, Web::Cookie::ParsedCookie cookie, Web::Cookie::Source source) => ()
did_update_cookie(Web::Cookie::Cookie cookie) =|
did_request_all_cookies_webdriver(URL::URL url) => (Vector<HTTP::Cookie::Cookie> cookies)
did_request_all_cookies_cookiestore(URL::URL url) => (Vector<HTTP::Cookie::Cookie> cookies)
did_request_named_cookie(URL::URL url, String name) => (Optional<HTTP::Cookie::Cookie> cookie)
did_request_cookie(u64 page_id, URL::URL url, HTTP::Cookie::Source source) => (HTTP::Cookie::VersionedCookie cookie)
did_set_cookie(URL::URL url, HTTP::Cookie::ParsedCookie cookie, HTTP::Cookie::Source source) => ()
did_update_cookie(HTTP::Cookie::Cookie cookie) =|
did_expire_cookies_with_time_offset(AK::Duration offset) =|
did_request_storage_item(Web::StorageAPI::StorageEndpointType storage_endpoint, String storage_key, String bottle_key) => (Optional<String> value)

View File

@@ -1,5 +1,6 @@
#include <LibCore/SharedVersion.h>
#include <LibGfx/Rect.h>
#include <LibHTTP/Cookie/Cookie.h>
#include <LibIPC/File.h>
#include <LibURL/URL.h>
#include <LibWeb/Clipboard/SystemClipboard.h>
@@ -137,5 +138,5 @@ endpoint WebContentServer
set_document_cookie_version_buffer(u64 page_id, Core::AnonymousBuffer document_cookie_version_buffer) =|
set_document_cookie_version_index(u64 page_id, i64 document_id, Core::SharedVersionIndex document_index) =|
cookies_changed(u64 page_id, Vector<Web::Cookie::Cookie> cookies) =|
cookies_changed(u64 page_id, Vector<HTTP::Cookie::Cookie> cookies) =|
}

View File

@@ -14,13 +14,13 @@
#include <AK/Time.h>
#include <AK/Vector.h>
#include <LibCore/File.h>
#include <LibHTTP/Cookie/Cookie.h>
#include <LibHTTP/Cookie/ParsedCookie.h>
#include <LibJS/Runtime/Value.h>
#include <LibURL/Parser.h>
#include <LibWeb/CSS/ComputedProperties.h>
#include <LibWeb/CSS/PropertyNameAndID.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/Crypto/Crypto.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentObserver.h>
@@ -80,7 +80,7 @@ namespace WebContent {
})
// https://w3c.github.io/webdriver/#dfn-serialized-cookie
static JsonValue serialize_cookie(Web::Cookie::Cookie const& cookie)
static JsonValue serialize_cookie(HTTP::Cookie::Cookie const& cookie)
{
JsonObject serialized_cookie;
serialized_cookie.set("name"sv, cookie.name);
@@ -91,7 +91,7 @@ static JsonValue serialize_cookie(Web::Cookie::Cookie const& cookie)
serialized_cookie.set("httpOnly"sv, cookie.http_only);
if (cookie.persistent)
serialized_cookie.set("expiry"sv, cookie.expiry_time.seconds_since_epoch()); // Must not be set if omitted when adding a cookie.
serialized_cookie.set("sameSite"sv, Web::Cookie::same_site_to_string(cookie.same_site));
serialized_cookie.set("sameSite"sv, HTTP::Cookie::same_site_to_string(cookie.same_site));
return serialized_cookie;
}
@@ -2243,7 +2243,7 @@ Web::WebDriver::Response WebDriverConnection::add_cookie_impl(JsonObject const&
// NOTE: This validation is either performed in subsequent steps.
// 7. Create a cookie in the cookie store associated with the active documents address using cookie name name, cookie value value, and an attribute-value list of the following cookie concepts listed in the table for cookie conversion from data:
Web::Cookie::ParsedCookie cookie {};
HTTP::Cookie::ParsedCookie cookie {};
cookie.name = TRY(Web::WebDriver::get_property(data, "name"sv));
cookie.value = TRY(Web::WebDriver::get_property(data, "value"sv));
@@ -2262,7 +2262,7 @@ Web::WebDriver::Response WebDriverConnection::add_cookie_impl(JsonObject const&
// FIXME: Spec issue: We must return InvalidCookieDomain for invalid domains, rather than InvalidArgument.
// https://github.com/w3c/webdriver/issues/1570
if (!Web::Cookie::domain_matches(*cookie.domain, document->domain()))
if (!HTTP::Cookie::domain_matches(*cookie.domain, document->domain()))
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidCookieDomain, "Cookie domain does not match document domain"sv);
}
@@ -2287,13 +2287,13 @@ Web::WebDriver::Response WebDriverConnection::add_cookie_impl(JsonObject const&
// The value if the entry exists, otherwise leave unset to indicate that no same site policy is defined.
if (data.has("sameSite"sv)) {
auto same_site = TRY(Web::WebDriver::get_property(data, "sameSite"sv));
cookie.same_site_attribute = Web::Cookie::same_site_from_string(same_site);
cookie.same_site_attribute = HTTP::Cookie::same_site_from_string(same_site);
if (cookie.same_site_attribute == Web::Cookie::SameSite::Default)
if (cookie.same_site_attribute == HTTP::Cookie::SameSite::Default)
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Invalid same-site attribute"sv);
}
current_browsing_context().page().client().page_did_set_cookie(document->url(), cookie, Web::Cookie::Source::Http);
current_browsing_context().page().client().page_did_set_cookie(document->url(), cookie, HTTP::Cookie::Source::Http);
// If there is an error during this step, return error with error code unable to set cookie.
// NOTE: This probably should only apply to the actual setting of the cookie in the Browser, which cannot fail in our case.

View File

@@ -13,7 +13,7 @@ target_include_directories(webworkerservice PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/
target_include_directories(webworkerservice PRIVATE ${LADYBIRD_SOURCE_DIR})
target_include_directories(webworkerservice PRIVATE ${LADYBIRD_SOURCE_DIR}/Services/)
target_link_libraries(webworkerservice PUBLIC LibCore LibFileSystem LibGfx LibIPC LibJS LibRequests LibWeb LibWebView LibUnicode LibImageDecoderClient LibMain LibURL LibGC)
target_link_libraries(webworkerservice PUBLIC LibCore LibFileSystem LibGfx LibHTTP LibIPC LibJS LibRequests LibWeb LibWebView LibUnicode LibImageDecoderClient LibMain LibURL LibGC)
target_link_libraries(webworkerservice PRIVATE OpenSSL::Crypto OpenSSL::SSL)
add_executable(WebWorker main.cpp)

View File

@@ -87,7 +87,7 @@ Web::CSS::PreferredMotion PageHost::preferred_motion() const
return Web::CSS::PreferredMotion::Auto;
}
Web::Cookie::VersionedCookie PageHost::page_did_request_cookie(URL::URL const& url, Web::Cookie::Source source)
HTTP::Cookie::VersionedCookie PageHost::page_did_request_cookie(URL::URL const& url, HTTP::Cookie::Source source)
{
return m_client.did_request_cookie(url, source);
}

View File

@@ -7,6 +7,7 @@
#pragma once
#include <LibGfx/Rect.h>
#include <LibHTTP/Forward.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/PixelUnits.h>
#include <WebWorker/Forward.h>
@@ -35,7 +36,7 @@ public:
virtual Web::CSS::PreferredContrast preferred_contrast() const override;
virtual Web::CSS::PreferredMotion preferred_motion() const override;
virtual size_t screen_count() const override { return 1; }
virtual Web::Cookie::VersionedCookie page_did_request_cookie(URL::URL const&, Web::Cookie::Source) override;
virtual HTTP::Cookie::VersionedCookie page_did_request_cookie(URL::URL const&, HTTP::Cookie::Source) override;
virtual void request_file(Web::FileRequest) override;
virtual IPC::File request_worker_agent(Web::Bindings::AgentType) override;
virtual Web::DisplayListPlayerType display_list_player_type() const override { VERIFY_NOT_REACHED(); }