ladybird/Libraries/LibWeb/StorageAPI/StorageKey.h
Aliaksandr Kalenik 84b9224121 Everywhere: Implement persistence of localStorage using sqlite
This change follows the pattern of our cookies persistence
implementation: the "browser" process is responsible for interacting
with the sqlite database, and WebContent communicates all storage
operations via IPC.

The new database table uses (storage_endpoint, storage_key, bottle_key)
as the primary key. This design follows concepts from the
https://storage.spec.whatwg.org/ and is intended to support reuse of the
persistence layer for other APIs (e.g., CacheStorage, IndexedDB). For
now, `storage_endpoint` is always "localStorage", `storage_key` is the
website's origin, and `bottle_key` is the name of the localStorage key.
2025-06-12 17:04:35 +02:00

53 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Optional.h>
#include <AK/Traits.h>
#include <LibURL/Origin.h>
#include <LibWeb/Forward.h>
namespace Web::StorageAPI {
// https://storage.spec.whatwg.org/#storage-keys
struct StorageKey {
// A storage key is a tuple consisting of an origin (an origin). [HTML]
// NOTE: This is expected to change; see Client-Side Storage Partitioning https://privacycg.github.io/storage-partitioning/.
URL::Origin origin;
String to_string() const
{
return origin.serialize();
}
friend bool operator==(StorageKey const& a, StorageKey const& b)
{
// To determine whether a storage key A equals storage key B, run these steps:
// 1. If As origin is not same origin with Bs origin, then return false.
// 2. Return true.
return a.origin.is_same_origin(b.origin);
}
};
Optional<StorageKey> obtain_a_storage_key(HTML::Environment const&);
StorageKey obtain_a_storage_key_for_non_storage_purposes(URL::Origin const&);
StorageKey obtain_a_storage_key_for_non_storage_purposes(HTML::Environment const&);
}
namespace AK {
template<>
struct Traits<Web::StorageAPI::StorageKey> : public DefaultTraits<Web::StorageAPI::StorageKey> {
static unsigned hash(Web::StorageAPI::StorageKey const& key)
{
return Traits<URL::Origin>::hash(key.origin);
}
};
}