Storage.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/HashMap.h>
  8. #include <LibWeb/Bindings/PlatformObject.h>
  9. #include <LibWeb/DOM/ExceptionOr.h>
  10. namespace Web::HTML {
  11. class Storage : public Bindings::PlatformObject {
  12. WEB_PLATFORM_OBJECT(Storage, Bindings::PlatformObject);
  13. public:
  14. static JS::NonnullGCPtr<Storage> create(HTML::Window&);
  15. ~Storage();
  16. size_t length() const;
  17. String key(size_t index);
  18. String get_item(String const& key) const;
  19. DOM::ExceptionOr<void> set_item(String const& key, String const& value);
  20. void remove_item(String const& key);
  21. void clear();
  22. Vector<String> supported_property_names() const;
  23. auto const& map() const { return m_map; }
  24. void dump() const;
  25. private:
  26. explicit Storage(HTML::Window&);
  27. void reorder();
  28. void broadcast(String const& key, String const& old_value, String const& new_value);
  29. OrderedHashMap<String, String> m_map;
  30. };
  31. }
  32. WRAPPER_HACK(Storage, Web::HTML)