summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/Storage.h
blob: c6dbee2bffae4a93850fe5f3bb52d6258dc8b486 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/HashMap.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/DOM/ExceptionOr.h>

namespace Web::HTML {

class Storage : public Bindings::PlatformObject {
    WEB_PLATFORM_OBJECT(Storage, Bindings::PlatformObject);

public:
    static JS::NonnullGCPtr<Storage> create(HTML::Window&);
    ~Storage();

    size_t length() const;
    String key(size_t index);
    String get_item(String const& key) const;
    DOM::ExceptionOr<void> set_item(String const& key, String const& value);
    void remove_item(String const& key);
    void clear();

    Vector<String> supported_property_names() const;

    auto const& map() const { return m_map; }

    void dump() const;

private:
    explicit Storage(HTML::Window&);

    void reorder();
    void broadcast(String const& key, String const& old_value, String const& new_value);

    OrderedHashMap<String, String> m_map;
};

}

WRAPPER_HACK(Storage, Web::HTML)