mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 09:52:31 +00:00
Everywhere: Implement persistence of localStorage using sqlite
This change follows the pattern of our cookies persistence implementation: the "browser" process is responsible for interacting with the sqlite database, and WebContent communicates all storage operations via IPC. The new database table uses (storage_endpoint, storage_key, bottle_key) as the primary key. This design follows concepts from the https://storage.spec.whatwg.org/ and is intended to support reuse of the persistence layer for other APIs (e.g., CacheStorage, IndexedDB). For now, `storage_endpoint` is always "localStorage", `storage_key` is the website's origin, and `bottle_key` is the name of the localStorage key.
This commit is contained in:
parent
f53559cb55
commit
84b9224121
Notes:
github-actions[bot]
2025-06-12 15:05:54 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 84b9224121
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5052
Reviewed-by: https://github.com/shannonbooth ✅
Reviewed-by: https://github.com/trflynn89
24 changed files with 694 additions and 118 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <LibGC/Heap.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/StorageAPI/StorageShed.h>
|
||||
|
||||
namespace Web::StorageAPI {
|
||||
|
@ -19,29 +20,22 @@ void StorageShed::visit_edges(GC::Cell::Visitor& visitor)
|
|||
}
|
||||
|
||||
// https://storage.spec.whatwg.org/#obtain-a-storage-shelf
|
||||
GC::Ptr<StorageShelf> StorageShed::obtain_a_storage_shelf(HTML::EnvironmentSettingsObject const& environment, StorageType type)
|
||||
GC::Ptr<StorageShelf> StorageShed::obtain_a_storage_shelf(HTML::EnvironmentSettingsObject& environment, StorageType type)
|
||||
{
|
||||
// 1. Let key be the result of running obtain a storage key with environment.
|
||||
auto key = obtain_a_storage_key(environment);
|
||||
|
||||
auto& page = as<HTML::Window>(environment.global_object()).page();
|
||||
|
||||
// 2. If key is failure, then return failure.
|
||||
if (!key.has_value())
|
||||
return {};
|
||||
|
||||
// 3. If shed[key] does not exist, then set shed[key] to the result of running create a storage shelf with type.
|
||||
// 4. Return shed[key].
|
||||
return m_data.ensure(key.value(), [type, &heap = this->heap()] {
|
||||
return StorageShelf::create(heap, type);
|
||||
return m_data.ensure(key.value(), [&page, key, type, &heap = this->heap()] {
|
||||
return StorageShelf::create(heap, page, *key, type);
|
||||
});
|
||||
}
|
||||
|
||||
// https://storage.spec.whatwg.org/#user-agent-storage-shed
|
||||
GC::Ref<StorageShed> user_agent_storage_shed(GC::Heap& heap)
|
||||
{
|
||||
// A user agent holds a storage shed, which is a storage shed. A user agent’s storage shed holds all local storage data.
|
||||
// FIXME: Storing this statically in memory is not the correct place or way of doing this!
|
||||
static GC::Root<StorageShed> storage_shed = GC::make_root(StorageShed::create(heap));
|
||||
return *storage_shed;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue