mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-08 12:12:53 +00:00
Instead of storing all storage objects in static memory, we now follow the the spec by lazily creating a unique Storage object on each document object. Each Storage object now holds a 'proxy' to the underlying backing storage. For now, this proxy is simply a reference to the backing object. In the future, it will need to be some type of interface object that stores on a SQLite database or similar. Session storage is now correctly stored / tracked as part of the TraversableNavigable object. Local storage is still stored in a static map, but eventually this should be factored into something that is stored at the user agent level.
52 lines
1.8 KiB
C++
52 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2024-2025, Shannon Booth <shannon@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <AK/String.h>
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/StorageAPI/StorageType.h>
|
|
|
|
namespace Web::StorageAPI {
|
|
|
|
// https://storage.spec.whatwg.org/#storage-bottle
|
|
struct StorageBottle : public RefCounted<StorageBottle> {
|
|
static NonnullRefPtr<StorageBottle> create(Optional<u64> quota) { return adopt_ref(*new StorageBottle(quota)); }
|
|
|
|
// A storage bottle has a map, which is initially an empty map
|
|
OrderedHashMap<String, String> map;
|
|
|
|
// A storage bottle also has a proxy map reference set, which is initially an empty set
|
|
NonnullRefPtr<StorageBottle> proxy() { return *this; }
|
|
|
|
// A storage bottle also has a quota, which is null or a number representing a conservative estimate of
|
|
// the total amount of bytes it can hold. Null indicates the lack of a limit.
|
|
Optional<u64> quota;
|
|
|
|
private:
|
|
explicit StorageBottle(Optional<u64> quota_)
|
|
: quota(quota_)
|
|
{
|
|
}
|
|
};
|
|
|
|
using BottleMap = OrderedHashMap<String, NonnullRefPtr<StorageBottle>>;
|
|
|
|
// https://storage.spec.whatwg.org/#storage-bucket
|
|
// A storage bucket is a place for storage endpoints to store data.
|
|
struct StorageBucket {
|
|
explicit StorageBucket(StorageType);
|
|
|
|
// A storage bucket has a bottle map of storage identifiers to storage bottles.
|
|
BottleMap bottle_map;
|
|
};
|
|
|
|
RefPtr<StorageBottle> obtain_a_session_storage_bottle_map(HTML::EnvironmentSettingsObject&, StringView storage_identifier);
|
|
RefPtr<StorageBottle> obtain_a_local_storage_bottle_map(HTML::EnvironmentSettingsObject&, StringView storage_identifier);
|
|
RefPtr<StorageBottle> obtain_a_storage_bottle_map(StorageType, HTML::EnvironmentSettingsObject&, StringView storage_identifier);
|
|
|
|
}
|