mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:07:36 +00:00
LibWeb: Add Storage interface and window.localStorage
This is a naive-but-somewhat-functional initial implementation of HTML Storage. Note that there is no persistence yet, everything is in-process only, and one local Storage object per origin.
This commit is contained in:
parent
a856cf8d4c
commit
47979996e8
10 changed files with 250 additions and 6 deletions
50
Userland/Libraries/LibWeb/HTML/Storage.h
Normal file
50
Userland/Libraries/LibWeb/HTML/Storage.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
class Storage
|
||||
: public RefCounted<Storage>
|
||||
, public Bindings::Wrappable {
|
||||
public:
|
||||
using WrapperType = Bindings::StorageWrapper;
|
||||
|
||||
static NonnullRefPtr<Storage> create();
|
||||
~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;
|
||||
|
||||
private:
|
||||
Storage();
|
||||
|
||||
void reorder();
|
||||
void broadcast(String const& key, String const& old_value, String const& new_value);
|
||||
|
||||
OrderedHashMap<String, String> m_map;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
StorageWrapper* wrap(JS::GlobalObject&, HTML::Storage&);
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue