1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 00:27:43 +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:
Andreas Kling 2022-02-08 19:38:29 +01:00
parent a856cf8d4c
commit 47979996e8
10 changed files with 250 additions and 6 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -21,6 +21,7 @@
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/PageTransitionEvent.h>
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
#include <LibWeb/HTML/Storage.h>
#include <LibWeb/HighResolutionTime/Performance.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Page/Page.h>
@ -438,4 +439,15 @@ Selection::Selection* Window::get_selection()
return nullptr;
}
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-localstorage
RefPtr<HTML::Storage> Window::local_storage()
{
// FIXME: Implement according to spec.
static HashMap<Origin, NonnullRefPtr<HTML::Storage>> local_storage_per_origin;
return local_storage_per_origin.ensure(associated_document().origin(), [] {
return HTML::Storage::create();
});
}
}