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:
Aliaksandr Kalenik 2025-06-08 23:35:46 +02:00 committed by Alexander Kalenik
commit 84b9224121
Notes: github-actions[bot] 2025-06-12 15:05:54 +00:00
24 changed files with 694 additions and 118 deletions

View file

@ -1,12 +1,12 @@
/*
* Copyright (c) 2024-2025, Shannon Booth <shannon@serenityos.org>
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Array.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Types.h>
@ -14,14 +14,27 @@
namespace Web::StorageAPI {
enum class StorageEndpointType : u8 {
Caches = 0,
IndexedDB = 1,
LocalStorage = 2,
ServiceWorkerRegistrations = 3,
SessionStorage = 4,
Count = 5 // This should always be the last value in the enum.
};
// https://storage.spec.whatwg.org/#storage-endpoint
//
// A storage endpoint is a local or session storage API that uses the infrastructure defined by this
// standard, most notably storage bottles, to keep track of its storage needs.
struct StorageEndpoint {
static constexpr u64 LOCAL_STORAGE_QUOTA = 5 * MiB;
static constexpr u64 SESSION_STORAGE_QUOTA = 5 * MiB;
// https://storage.spec.whatwg.org/#storage-endpoint-identifier
// A storage endpoint has an identifier, which is a storage identifier.
String identifier;
StorageEndpointType identifier;
// https://storage.spec.whatwg.org/#storage-endpoint-types
// A storage endpoint also has types, which is a set of storage types.