2024-09-14 20:02:27 -06:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Optional.h>
|
2024-10-07 20:17:58 -06:00
|
|
|
|
#include <AK/Traits.h>
|
2024-10-05 15:33:34 +13:00
|
|
|
|
#include <LibURL/Origin.h>
|
2024-09-14 20:02:27 -06:00
|
|
|
|
#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/.
|
2024-10-05 15:33:34 +13:00
|
|
|
|
URL::Origin origin;
|
2024-09-14 20:02:27 -06:00
|
|
|
|
|
2025-06-08 23:35:46 +02:00
|
|
|
|
String to_string() const
|
|
|
|
|
{
|
|
|
|
|
return origin.serialize();
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-14 20:02:27 -06:00
|
|
|
|
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 A’s origin is not same origin with B’s origin, then return false.
|
|
|
|
|
// 2. Return true.
|
|
|
|
|
return a.origin.is_same_origin(b.origin);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Optional<StorageKey> obtain_a_storage_key(HTML::Environment const&);
|
2025-01-19 18:15:06 +13:00
|
|
|
|
StorageKey obtain_a_storage_key_for_non_storage_purposes(URL::Origin const&);
|
2024-09-14 20:02:27 -06:00
|
|
|
|
StorageKey obtain_a_storage_key_for_non_storage_purposes(HTML::Environment const&);
|
|
|
|
|
|
|
|
|
|
}
|
2024-10-07 20:17:58 -06:00
|
|
|
|
|
|
|
|
|
namespace AK {
|
2025-05-13 07:06:33 -04:00
|
|
|
|
|
2024-10-07 20:17:58 -06:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-05-13 07:06:33 -04:00
|
|
|
|
|
2024-10-07 20:17:58 -06:00
|
|
|
|
}
|