/src/serenity/Userland/Libraries/LibWeb/HTML/Storage.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
3 | | * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org> |
4 | | * |
5 | | * SPDX-License-Identifier: BSD-2-Clause |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <AK/HashMap.h> |
11 | | #include <LibWeb/Bindings/PlatformObject.h> |
12 | | #include <LibWeb/WebIDL/ExceptionOr.h> |
13 | | |
14 | | namespace Web::HTML { |
15 | | |
16 | | class Storage : public Bindings::PlatformObject { |
17 | | WEB_PLATFORM_OBJECT(Storage, Bindings::PlatformObject); |
18 | | JS_DECLARE_ALLOCATOR(Storage); |
19 | | |
20 | | public: |
21 | | [[nodiscard]] static JS::NonnullGCPtr<Storage> create(JS::Realm&); |
22 | | ~Storage(); |
23 | | |
24 | | size_t length() const; |
25 | | Optional<String> key(size_t index); |
26 | | Optional<String> get_item(StringView key) const; |
27 | | WebIDL::ExceptionOr<void> set_item(String const& key, String const& value); |
28 | | void remove_item(StringView key); |
29 | | void clear(); |
30 | | |
31 | 0 | auto const& map() const { return m_map; } |
32 | | |
33 | | void dump() const; |
34 | | |
35 | | private: |
36 | | explicit Storage(JS::Realm&); |
37 | | |
38 | | virtual void initialize(JS::Realm&) override; |
39 | | |
40 | | // ^PlatformObject |
41 | | virtual Optional<JS::Value> item_value(size_t index) const override; |
42 | | virtual JS::Value named_item_value(FlyString const&) const override; |
43 | | virtual WebIDL::ExceptionOr<DidDeletionFail> delete_value(String const&) override; |
44 | | virtual Vector<FlyString> supported_property_names() const override; |
45 | | virtual WebIDL::ExceptionOr<void> set_value_of_indexed_property(u32, JS::Value) override; |
46 | | virtual WebIDL::ExceptionOr<void> set_value_of_named_property(String const& key, JS::Value value) override; |
47 | | |
48 | | void reorder(); |
49 | | void broadcast(StringView key, StringView old_value, StringView new_value); |
50 | | |
51 | | OrderedHashMap<String, String> m_map; |
52 | | }; |
53 | | |
54 | | } |