CookieJar.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /*
  2. * Copyright (c) 2021-2024, Tim Flynn <trflynn89@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
  5. * Copyright (c) 2023, Jelle Raaijmakers <jelle@gmta.nl>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #include <AK/IPv4Address.h>
  10. #include <AK/StringBuilder.h>
  11. #include <AK/Time.h>
  12. #include <AK/Vector.h>
  13. #include <LibURL/URL.h>
  14. #include <LibWeb/Cookie/ParsedCookie.h>
  15. #include <LibWebView/CookieJar.h>
  16. #include <LibWebView/URL.h>
  17. namespace WebView {
  18. static constexpr auto DATABASE_SYNCHRONIZATION_TIMER = Duration::from_seconds(30);
  19. ErrorOr<NonnullOwnPtr<CookieJar>> CookieJar::create(Database& database)
  20. {
  21. Statements statements {};
  22. auto create_table = TRY(database.prepare_statement(MUST(String::formatted(R"#(
  23. CREATE TABLE IF NOT EXISTS Cookies (
  24. name TEXT,
  25. value TEXT,
  26. same_site INTEGER CHECK (same_site >= 0 AND same_site <= {}),
  27. creation_time INTEGER,
  28. last_access_time INTEGER,
  29. expiry_time INTEGER,
  30. domain TEXT,
  31. path TEXT,
  32. secure BOOLEAN,
  33. http_only BOOLEAN,
  34. host_only BOOLEAN,
  35. persistent BOOLEAN,
  36. PRIMARY KEY(name, domain, path)
  37. );)#",
  38. to_underlying(Web::Cookie::SameSite::Lax)))));
  39. database.execute_statement(create_table, {});
  40. statements.insert_cookie = TRY(database.prepare_statement("INSERT OR REPLACE INTO Cookies VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"sv));
  41. statements.expire_cookie = TRY(database.prepare_statement("DELETE FROM Cookies WHERE (expiry_time < ?);"sv));
  42. statements.select_all_cookies = TRY(database.prepare_statement("SELECT * FROM Cookies;"sv));
  43. return adopt_own(*new CookieJar { PersistedStorage { database, statements } });
  44. }
  45. NonnullOwnPtr<CookieJar> CookieJar::create()
  46. {
  47. return adopt_own(*new CookieJar { OptionalNone {} });
  48. }
  49. CookieJar::CookieJar(Optional<PersistedStorage> persisted_storage)
  50. : m_persisted_storage(move(persisted_storage))
  51. {
  52. if (!m_persisted_storage.has_value())
  53. return;
  54. // FIXME: Make cookie retrieval lazy so we don't need to retrieve all cookies up front.
  55. auto cookies = m_persisted_storage->select_all_cookies();
  56. m_transient_storage.set_cookies(move(cookies));
  57. m_persisted_storage->synchronization_timer = Core::Timer::create_repeating(
  58. static_cast<int>(DATABASE_SYNCHRONIZATION_TIMER.to_milliseconds()),
  59. [this]() {
  60. auto now = m_transient_storage.purge_expired_cookies();
  61. m_persisted_storage->database.execute_statement(m_persisted_storage->statements.expire_cookie, {}, now);
  62. for (auto const& it : m_transient_storage.take_dirty_cookies())
  63. m_persisted_storage->insert_cookie(it.value);
  64. });
  65. m_persisted_storage->synchronization_timer->start();
  66. }
  67. CookieJar::~CookieJar()
  68. {
  69. if (!m_persisted_storage.has_value())
  70. return;
  71. m_persisted_storage->synchronization_timer->stop();
  72. m_persisted_storage->synchronization_timer->on_timeout();
  73. }
  74. String CookieJar::get_cookie(const URL::URL& url, Web::Cookie::Source source)
  75. {
  76. m_transient_storage.purge_expired_cookies();
  77. auto domain = canonicalize_domain(url);
  78. if (!domain.has_value())
  79. return {};
  80. auto cookie_list = get_matching_cookies(url, domain.value(), source);
  81. StringBuilder builder;
  82. for (auto const& cookie : cookie_list) {
  83. // If there is an unprocessed cookie in the cookie-list, output the characters %x3B and %x20 ("; ")
  84. if (!builder.is_empty())
  85. builder.append("; "sv);
  86. // Output the cookie's name, the %x3D ("=") character, and the cookie's value.
  87. builder.appendff("{}={}", cookie.name, cookie.value);
  88. }
  89. return MUST(builder.to_string());
  90. }
  91. void CookieJar::set_cookie(const URL::URL& url, Web::Cookie::ParsedCookie const& parsed_cookie, Web::Cookie::Source source)
  92. {
  93. auto domain = canonicalize_domain(url);
  94. if (!domain.has_value())
  95. return;
  96. store_cookie(parsed_cookie, url, domain.release_value(), source);
  97. }
  98. // This is based on https://www.rfc-editor.org/rfc/rfc6265#section-5.3 as store_cookie() below
  99. // however the whole ParsedCookie->Cookie conversion is skipped.
  100. void CookieJar::update_cookie(Web::Cookie::Cookie cookie)
  101. {
  102. CookieStorageKey key { cookie.name, cookie.domain, cookie.path };
  103. // 11. If the cookie store contains a cookie with the same name, domain, and path as the newly created cookie:
  104. if (auto old_cookie = m_transient_storage.get_cookie(key); old_cookie.has_value()) {
  105. // Update the creation-time of the newly created cookie to match the creation-time of the old-cookie.
  106. cookie.creation_time = old_cookie->creation_time;
  107. // Remove the old-cookie from the cookie store.
  108. // NOTE: Rather than deleting then re-inserting this cookie, we update it in-place.
  109. }
  110. // 12. Insert the newly created cookie into the cookie store.
  111. m_transient_storage.set_cookie(move(key), move(cookie));
  112. m_transient_storage.purge_expired_cookies();
  113. }
  114. void CookieJar::dump_cookies()
  115. {
  116. StringBuilder builder;
  117. m_transient_storage.for_each_cookie([&](auto const& cookie) {
  118. static constexpr auto key_color = "\033[34;1m"sv;
  119. static constexpr auto attribute_color = "\033[33m"sv;
  120. static constexpr auto no_color = "\033[0m"sv;
  121. builder.appendff("{}{}{} - ", key_color, cookie.name, no_color);
  122. builder.appendff("{}{}{} - ", key_color, cookie.domain, no_color);
  123. builder.appendff("{}{}{}\n", key_color, cookie.path, no_color);
  124. builder.appendff("\t{}Value{} = {}\n", attribute_color, no_color, cookie.value);
  125. builder.appendff("\t{}CreationTime{} = {}\n", attribute_color, no_color, cookie.creation_time_to_string());
  126. builder.appendff("\t{}LastAccessTime{} = {}\n", attribute_color, no_color, cookie.last_access_time_to_string());
  127. builder.appendff("\t{}ExpiryTime{} = {}\n", attribute_color, no_color, cookie.expiry_time_to_string());
  128. builder.appendff("\t{}Secure{} = {:s}\n", attribute_color, no_color, cookie.secure);
  129. builder.appendff("\t{}HttpOnly{} = {:s}\n", attribute_color, no_color, cookie.http_only);
  130. builder.appendff("\t{}HostOnly{} = {:s}\n", attribute_color, no_color, cookie.host_only);
  131. builder.appendff("\t{}Persistent{} = {:s}\n", attribute_color, no_color, cookie.persistent);
  132. builder.appendff("\t{}SameSite{} = {:s}\n", attribute_color, no_color, Web::Cookie::same_site_to_string(cookie.same_site));
  133. });
  134. dbgln("{} cookies stored\n{}", m_transient_storage.size(), builder.string_view());
  135. }
  136. Vector<Web::Cookie::Cookie> CookieJar::get_all_cookies()
  137. {
  138. Vector<Web::Cookie::Cookie> cookies;
  139. cookies.ensure_capacity(m_transient_storage.size());
  140. m_transient_storage.for_each_cookie([&](auto const& cookie) {
  141. cookies.unchecked_append(cookie);
  142. });
  143. return cookies;
  144. }
  145. // https://w3c.github.io/webdriver/#dfn-associated-cookies
  146. Vector<Web::Cookie::Cookie> CookieJar::get_all_cookies(URL::URL const& url)
  147. {
  148. auto domain = canonicalize_domain(url);
  149. if (!domain.has_value())
  150. return {};
  151. return get_matching_cookies(url, domain.value(), Web::Cookie::Source::Http, MatchingCookiesSpecMode::WebDriver);
  152. }
  153. Optional<Web::Cookie::Cookie> CookieJar::get_named_cookie(URL::URL const& url, StringView name)
  154. {
  155. auto domain = canonicalize_domain(url);
  156. if (!domain.has_value())
  157. return {};
  158. auto cookie_list = get_matching_cookies(url, domain.value(), Web::Cookie::Source::Http, MatchingCookiesSpecMode::WebDriver);
  159. for (auto const& cookie : cookie_list) {
  160. if (cookie.name == name)
  161. return cookie;
  162. }
  163. return {};
  164. }
  165. Optional<String> CookieJar::canonicalize_domain(const URL::URL& url)
  166. {
  167. // https://tools.ietf.org/html/rfc6265#section-5.1.2
  168. if (!url.is_valid())
  169. return {};
  170. // FIXME: Implement RFC 5890 to "Convert each label that is not a Non-Reserved LDH (NR-LDH) label to an A-label".
  171. if (url.host().has<Empty>())
  172. return {};
  173. return MUST(MUST(url.serialized_host()).to_lowercase());
  174. }
  175. bool CookieJar::domain_matches(StringView string, StringView domain_string)
  176. {
  177. // https://tools.ietf.org/html/rfc6265#section-5.1.3
  178. // A string domain-matches a given domain string if at least one of the following conditions hold:
  179. // The domain string and the string are identical.
  180. if (string == domain_string)
  181. return true;
  182. // All of the following conditions hold:
  183. // - The domain string is a suffix of the string.
  184. // - The last character of the string that is not included in the domain string is a %x2E (".") character.
  185. // - The string is a host name (i.e., not an IP address).
  186. if (!string.ends_with(domain_string))
  187. return false;
  188. if (string[string.length() - domain_string.length() - 1] != '.')
  189. return false;
  190. if (AK::IPv4Address::from_string(string).has_value())
  191. return false;
  192. return true;
  193. }
  194. bool CookieJar::path_matches(StringView request_path, StringView cookie_path)
  195. {
  196. // https://tools.ietf.org/html/rfc6265#section-5.1.4
  197. // A request-path path-matches a given cookie-path if at least one of the following conditions holds:
  198. // The cookie-path and the request-path are identical.
  199. if (request_path == cookie_path)
  200. return true;
  201. if (request_path.starts_with(cookie_path)) {
  202. // The cookie-path is a prefix of the request-path, and the last character of the cookie-path is %x2F ("/").
  203. if (cookie_path.ends_with('/'))
  204. return true;
  205. // The cookie-path is a prefix of the request-path, and the first character of the request-path that is not included in the cookie-path is a %x2F ("/") character.
  206. if (request_path[cookie_path.length()] == '/')
  207. return true;
  208. }
  209. return false;
  210. }
  211. String CookieJar::default_path(const URL::URL& url)
  212. {
  213. // https://tools.ietf.org/html/rfc6265#section-5.1.4
  214. // 1. Let uri-path be the path portion of the request-uri if such a portion exists (and empty otherwise).
  215. auto uri_path = url.serialize_path();
  216. // 2. If the uri-path is empty or if the first character of the uri-path is not a %x2F ("/") character, output %x2F ("/") and skip the remaining steps.
  217. if (uri_path.is_empty() || (uri_path[0] != '/'))
  218. return "/"_string;
  219. StringView uri_path_view = uri_path;
  220. size_t last_separator = uri_path_view.find_last('/').value();
  221. // 3. If the uri-path contains no more than one %x2F ("/") character, output %x2F ("/") and skip the remaining step.
  222. if (last_separator == 0)
  223. return "/"_string;
  224. // 4. Output the characters of the uri-path from the first character up to, but not including, the right-most %x2F ("/").
  225. return MUST(String::from_utf8(uri_path.substring_view(0, last_separator)));
  226. }
  227. void CookieJar::store_cookie(Web::Cookie::ParsedCookie const& parsed_cookie, const URL::URL& url, String canonicalized_domain, Web::Cookie::Source source)
  228. {
  229. // https://tools.ietf.org/html/rfc6265#section-5.3
  230. // 2. 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.
  231. Web::Cookie::Cookie cookie { parsed_cookie.name, parsed_cookie.value, parsed_cookie.same_site_attribute };
  232. cookie.creation_time = UnixDateTime::now();
  233. cookie.last_access_time = cookie.creation_time;
  234. if (parsed_cookie.expiry_time_from_max_age_attribute.has_value()) {
  235. // 3. If the cookie-attribute-list contains an attribute with an attribute-name of "Max-Age": Set the cookie's persistent-flag to true.
  236. // Set the cookie's expiry-time to attribute-value of the last attribute in the cookie-attribute-list with an attribute-name of "Max-Age".
  237. cookie.persistent = true;
  238. cookie.expiry_time = parsed_cookie.expiry_time_from_max_age_attribute.value();
  239. } else if (parsed_cookie.expiry_time_from_expires_attribute.has_value()) {
  240. // If the cookie-attribute-list contains an attribute with an attribute-name of "Expires": Set the cookie's persistent-flag to true.
  241. // Set the cookie's expiry-time to attribute-value of the last attribute in the cookie-attribute-list with an attribute-name of "Expires".
  242. cookie.persistent = true;
  243. cookie.expiry_time = parsed_cookie.expiry_time_from_expires_attribute.value();
  244. } else {
  245. // Set the cookie's persistent-flag to false. Set the cookie's expiry-time to the latest representable date.
  246. cookie.persistent = false;
  247. cookie.expiry_time = UnixDateTime::from_unix_time_parts(3000, 1, 1, 0, 0, 0, 0);
  248. }
  249. // 4. If the cookie-attribute-list contains an attribute with an attribute-name of "Domain":
  250. if (parsed_cookie.domain.has_value()) {
  251. // Let the domain-attribute be the attribute-value of the last attribute in the cookie-attribute-list with an attribute-name of "Domain".
  252. cookie.domain = parsed_cookie.domain.value();
  253. }
  254. // 5. If the user agent is configured to reject "public suffixes" and the domain-attribute is a public suffix:
  255. if (is_public_suffix(cookie.domain)) {
  256. // If the domain-attribute is identical to the canonicalized request-host:
  257. if (cookie.domain == canonicalized_domain) {
  258. // Let the domain-attribute be the empty string.
  259. cookie.domain = String {};
  260. }
  261. // Otherwise:
  262. else {
  263. // Ignore the cookie entirely and abort these steps.
  264. return;
  265. }
  266. }
  267. // 6. If the domain-attribute is non-empty:
  268. if (!cookie.domain.is_empty()) {
  269. // If the canonicalized request-host does not domain-match the domain-attribute: Ignore the cookie entirely and abort these steps.
  270. if (!domain_matches(canonicalized_domain, cookie.domain))
  271. return;
  272. // Set the cookie's host-only-flag to false. Set the cookie's domain to the domain-attribute.
  273. cookie.host_only = false;
  274. } else {
  275. // Set the cookie's host-only-flag to true. Set the cookie's domain to the canonicalized request-host.
  276. cookie.host_only = true;
  277. cookie.domain = move(canonicalized_domain);
  278. }
  279. // 7. If the cookie-attribute-list contains an attribute with an attribute-name of "Path":
  280. if (parsed_cookie.path.has_value()) {
  281. // Set the cookie's path to attribute-value of the last attribute in the cookie-attribute-list with an attribute-name of "Path".
  282. cookie.path = parsed_cookie.path.value();
  283. } else {
  284. cookie.path = default_path(url);
  285. }
  286. // 8. If the cookie-attribute-list contains an attribute with an attribute-name of "Secure", set the cookie's secure-only-flag to true.
  287. cookie.secure = parsed_cookie.secure_attribute_present;
  288. // 9. If the cookie-attribute-list contains an attribute with an attribute-name of "HttpOnly", set the cookie's http-only-flag to false.
  289. cookie.http_only = parsed_cookie.http_only_attribute_present;
  290. // 10. If the cookie was received from a "non-HTTP" API and the cookie's http-only-flag is set, abort these steps and ignore the cookie entirely.
  291. if (source != Web::Cookie::Source::Http && cookie.http_only)
  292. return;
  293. CookieStorageKey key { cookie.name, cookie.domain, cookie.path };
  294. // 11. If the cookie store contains a cookie with the same name, domain, and path as the newly created cookie:
  295. if (auto const& old_cookie = m_transient_storage.get_cookie(key); old_cookie.has_value()) {
  296. // If the newly created cookie was received from a "non-HTTP" API and the old-cookie's http-only-flag is set, abort these
  297. // steps and ignore the newly created cookie entirely.
  298. if (source != Web::Cookie::Source::Http && old_cookie->http_only)
  299. return;
  300. // Update the creation-time of the newly created cookie to match the creation-time of the old-cookie.
  301. cookie.creation_time = old_cookie->creation_time;
  302. // Remove the old-cookie from the cookie store.
  303. // NOTE: Rather than deleting then re-inserting this cookie, we update it in-place.
  304. }
  305. // 12. Insert the newly created cookie into the cookie store.
  306. m_transient_storage.set_cookie(move(key), move(cookie));
  307. m_transient_storage.purge_expired_cookies();
  308. }
  309. Vector<Web::Cookie::Cookie> CookieJar::get_matching_cookies(const URL::URL& url, StringView canonicalized_domain, Web::Cookie::Source source, MatchingCookiesSpecMode mode)
  310. {
  311. // https://tools.ietf.org/html/rfc6265#section-5.4
  312. auto now = UnixDateTime::now();
  313. // 1. Let cookie-list be the set of cookies from the cookie store that meets all of the following requirements:
  314. Vector<Web::Cookie::Cookie> cookie_list;
  315. m_transient_storage.for_each_cookie([&](auto& cookie) {
  316. // Either: The cookie's host-only-flag is true and the canonicalized request-host is identical to the cookie's domain.
  317. // Or: The cookie's host-only-flag is false and the canonicalized request-host domain-matches the cookie's domain.
  318. bool is_host_only_and_has_identical_domain = cookie.host_only && (canonicalized_domain == cookie.domain);
  319. bool is_not_host_only_and_domain_matches = !cookie.host_only && domain_matches(canonicalized_domain, cookie.domain);
  320. if (!is_host_only_and_has_identical_domain && !is_not_host_only_and_domain_matches)
  321. return;
  322. // The request-uri's path path-matches the cookie's path.
  323. if (!path_matches(url.serialize_path(), cookie.path))
  324. return;
  325. // If the cookie's secure-only-flag is true, then the request-uri's scheme must denote a "secure" protocol.
  326. if (cookie.secure && (url.scheme() != "https"))
  327. return;
  328. // If the cookie's http-only-flag is true, then exclude the cookie if the cookie-string is being generated for a "non-HTTP" API.
  329. if (cookie.http_only && (source != Web::Cookie::Source::Http))
  330. return;
  331. // NOTE: The WebDriver spec expects only step 1 above to be executed to match cookies.
  332. if (mode == MatchingCookiesSpecMode::WebDriver) {
  333. cookie_list.append(cookie);
  334. return;
  335. }
  336. // 3. Update the last-access-time of each cookie in the cookie-list to the current date and time.
  337. // NOTE: We do this first so that both our internal storage and cookie-list are updated.
  338. cookie.last_access_time = now;
  339. // 2. The user agent SHOULD sort the cookie-list in the following order:
  340. // - Cookies with longer paths are listed before cookies with shorter paths.
  341. // - Among cookies that have equal-length path fields, cookies with earlier creation-times are listed before cookies with later creation-times.
  342. auto cookie_path_length = cookie.path.bytes().size();
  343. auto cookie_creation_time = cookie.creation_time;
  344. cookie_list.insert_before_matching(cookie, [cookie_path_length, cookie_creation_time](auto const& entry) {
  345. if (cookie_path_length > entry.path.bytes().size()) {
  346. return true;
  347. }
  348. if (cookie_path_length == entry.path.bytes().size()) {
  349. if (cookie_creation_time < entry.creation_time)
  350. return true;
  351. }
  352. return false;
  353. });
  354. });
  355. if (mode != MatchingCookiesSpecMode::WebDriver)
  356. m_transient_storage.purge_expired_cookies();
  357. return cookie_list;
  358. }
  359. void CookieJar::TransientStorage::set_cookies(Cookies cookies)
  360. {
  361. m_cookies = move(cookies);
  362. purge_expired_cookies();
  363. }
  364. void CookieJar::TransientStorage::set_cookie(CookieStorageKey key, Web::Cookie::Cookie cookie)
  365. {
  366. m_cookies.set(key, cookie);
  367. m_dirty_cookies.set(move(key), move(cookie));
  368. }
  369. Optional<Web::Cookie::Cookie> CookieJar::TransientStorage::get_cookie(CookieStorageKey const& key)
  370. {
  371. return m_cookies.get(key);
  372. }
  373. UnixDateTime CookieJar::TransientStorage::purge_expired_cookies()
  374. {
  375. auto now = UnixDateTime::now();
  376. auto is_expired = [&](auto const&, auto const& cookie) { return cookie.expiry_time < now; };
  377. m_cookies.remove_all_matching(is_expired);
  378. m_dirty_cookies.remove_all_matching(is_expired);
  379. return now;
  380. }
  381. void CookieJar::PersistedStorage::insert_cookie(Web::Cookie::Cookie const& cookie)
  382. {
  383. database.execute_statement(
  384. statements.insert_cookie,
  385. {},
  386. cookie.name,
  387. cookie.value,
  388. to_underlying(cookie.same_site),
  389. cookie.creation_time,
  390. cookie.last_access_time,
  391. cookie.expiry_time,
  392. cookie.domain,
  393. cookie.path,
  394. cookie.secure,
  395. cookie.http_only,
  396. cookie.host_only,
  397. cookie.persistent);
  398. }
  399. static Web::Cookie::Cookie parse_cookie(Database& database, Database::StatementID statement_id)
  400. {
  401. int column = 0;
  402. auto convert_text = [&](auto& field) { field = database.result_column<String>(statement_id, column++); };
  403. auto convert_bool = [&](auto& field) { field = database.result_column<bool>(statement_id, column++); };
  404. auto convert_time = [&](auto& field) { field = database.result_column<UnixDateTime>(statement_id, column++); };
  405. auto convert_same_site = [&](auto& field) {
  406. auto same_site = database.result_column<UnderlyingType<Web::Cookie::SameSite>>(statement_id, column++);
  407. field = static_cast<Web::Cookie::SameSite>(same_site);
  408. };
  409. Web::Cookie::Cookie cookie;
  410. convert_text(cookie.name);
  411. convert_text(cookie.value);
  412. convert_same_site(cookie.same_site);
  413. convert_time(cookie.creation_time);
  414. convert_time(cookie.last_access_time);
  415. convert_time(cookie.expiry_time);
  416. convert_text(cookie.domain);
  417. convert_text(cookie.path);
  418. convert_bool(cookie.secure);
  419. convert_bool(cookie.http_only);
  420. convert_bool(cookie.host_only);
  421. convert_bool(cookie.persistent);
  422. return cookie;
  423. }
  424. CookieJar::TransientStorage::Cookies CookieJar::PersistedStorage::select_all_cookies()
  425. {
  426. HashMap<CookieStorageKey, Web::Cookie::Cookie> cookies;
  427. database.execute_statement(
  428. statements.select_all_cookies,
  429. [&](auto statement_id) {
  430. auto cookie = parse_cookie(database, statement_id);
  431. CookieStorageKey key { cookie.name, cookie.domain, cookie.path };
  432. cookies.set(move(key), move(cookie));
  433. });
  434. return cookies;
  435. }
  436. }