StorageKey.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Optional.h>
  8. #include <AK/Traits.h>
  9. #include <LibURL/Origin.h>
  10. #include <LibWeb/Forward.h>
  11. namespace Web::StorageAPI {
  12. // https://storage.spec.whatwg.org/#storage-keys
  13. struct StorageKey {
  14. // A storage key is a tuple consisting of an origin (an origin). [HTML]
  15. // NOTE: This is expected to change; see Client-Side Storage Partitioning https://privacycg.github.io/storage-partitioning/.
  16. URL::Origin origin;
  17. friend bool operator==(StorageKey const& a, StorageKey const& b)
  18. {
  19. // To determine whether a storage key A equals storage key B, run these steps:
  20. // 1. If A’s origin is not same origin with B’s origin, then return false.
  21. // 2. Return true.
  22. return a.origin.is_same_origin(b.origin);
  23. }
  24. };
  25. Optional<StorageKey> obtain_a_storage_key(HTML::Environment const&);
  26. StorageKey obtain_a_storage_key_for_non_storage_purposes(HTML::Environment const&);
  27. }
  28. namespace AK {
  29. template<>
  30. struct Traits<Web::StorageAPI::StorageKey> : public DefaultTraits<Web::StorageAPI::StorageKey> {
  31. static unsigned hash(Web::StorageAPI::StorageKey const& key)
  32. {
  33. return Traits<URL::Origin>::hash(key.origin);
  34. }
  35. };
  36. }