/* * Copyright (c) 2021-2022, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include namespace Browser { class Database; class CookieJar { struct Statements { SQL::StatementID create_table { 0 }; SQL::StatementID insert_cookie { 0 }; SQL::StatementID update_cookie { 0 }; SQL::StatementID expire_cookie { 0 }; SQL::StatementID select_cookie { 0 }; SQL::StatementID select_all_cookies { 0 }; }; public: static ErrorOr create(Database& database); DeprecatedString get_cookie(const URL& url, Web::Cookie::Source source); void set_cookie(const URL& url, Web::Cookie::ParsedCookie const& parsed_cookie, Web::Cookie::Source source); void update_cookie(Web::Cookie::Cookie); void dump_cookies(); Vector get_all_cookies(); Vector get_all_cookies(URL const& url); Optional get_named_cookie(URL const& url, DeprecatedString const& name); private: CookieJar(Database& database, Statements statements); static Optional canonicalize_domain(const URL& url); static bool domain_matches(DeprecatedString const& string, DeprecatedString const& domain_string); static bool path_matches(DeprecatedString const& request_path, DeprecatedString const& cookie_path); static DeprecatedString default_path(const URL& url); enum class MatchingCookiesSpecMode { RFC6265, WebDriver, }; void store_cookie(Web::Cookie::ParsedCookie const& parsed_cookie, const URL& url, DeprecatedString canonicalized_domain, Web::Cookie::Source source); Vector get_matching_cookies(const URL& url, DeprecatedString const& canonicalized_domain, Web::Cookie::Source source, MatchingCookiesSpecMode mode = MatchingCookiesSpecMode::RFC6265); void insert_cookie_into_database(Web::Cookie::Cookie const& cookie); void update_cookie_in_database(Web::Cookie::Cookie const& cookie); using OnCookieFound = Function; using OnCookieNotFound = Function; void select_cookie_from_database(Web::Cookie::Cookie cookie, OnCookieFound on_result, OnCookieNotFound on_complete_without_results); using OnSelectAllCookiesResult = Function; void select_all_cookies_from_database(OnSelectAllCookiesResult on_result); void purge_expired_cookies(); Database& m_database; Statements m_statements; }; }