Everywhere: Hoist the Libraries folder to the top-level

This commit is contained in:
Timothy Flynn 2024-11-09 12:25:08 -05:00 committed by Andreas Kling
commit 93712b24bf
Notes: github-actions[bot] 2024-11-10 11:51:52 +00:00
4547 changed files with 104 additions and 113 deletions

View file

@ -0,0 +1,22 @@
/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/StorageAPI/NavigatorStorage.h>
#include <LibWeb/StorageAPI/StorageManager.h>
namespace Web::StorageAPI {
// https://storage.spec.whatwg.org/#dom-navigatorstorage-storage
JS::NonnullGCPtr<StorageManager> NavigatorStorage::storage()
{
// The storage getter steps are to return thiss relevant settings objects StorageManager object.
return HTML::relevant_settings_object(this_navigator_storage_object()).storage_manager();
}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Forward.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h>
namespace Web::StorageAPI {
class NavigatorStorage {
public:
virtual ~NavigatorStorage() = default;
JS::NonnullGCPtr<StorageManager> storage();
protected:
virtual Bindings::PlatformObject const& this_navigator_storage_object() const = 0;
};
}

View file

@ -0,0 +1,7 @@
#import <StorageAPI/StorageManager.idl>
// https://storage.spec.whatwg.org/#navigatorstorage
[SecureContext]
interface mixin NavigatorStorage {
[SameObject] readonly attribute StorageManager storage;
};

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/DOMURL/DOMURL.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/StorageAPI/StorageKey.h>
namespace Web::StorageAPI {
// https://storage.spec.whatwg.org/#obtain-a-storage-key
Optional<StorageKey> obtain_a_storage_key(HTML::Environment const& environment)
{
// 1. Let key be the result of running obtain a storage key for non-storage purposes with environment.
auto key = obtain_a_storage_key_for_non_storage_purposes(environment);
// 2. If keys origin is an opaque origin, then return failure.
if (key.origin.is_opaque())
return {};
// FIXME: 3. If the user has disabled storage, then return failure.
// 4. Return key.
return key;
}
// https://storage.spec.whatwg.org/#obtain-a-storage-key-for-non-storage-purposes
StorageKey obtain_a_storage_key_for_non_storage_purposes(HTML::Environment const& environment)
{
// 1. Let origin be environments origin if environment is an environment settings object; otherwise environments creation URLs origin.
if (is<HTML::EnvironmentSettingsObject>(environment)) {
auto const& settings = static_cast<HTML::EnvironmentSettingsObject const&>(environment);
// FIXME: EnvironmentSettingsObject::origin() should be const :|
auto& mutable_settings = const_cast<HTML::EnvironmentSettingsObject&>(settings);
return { mutable_settings.origin() };
}
return { environment.creation_url.origin() };
}
}

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Optional.h>
#include <AK/Traits.h>
#include <LibURL/Origin.h>
#include <LibWeb/Forward.h>
namespace Web::StorageAPI {
// https://storage.spec.whatwg.org/#storage-keys
struct StorageKey {
// A storage key is a tuple consisting of an origin (an origin). [HTML]
// NOTE: This is expected to change; see Client-Side Storage Partitioning https://privacycg.github.io/storage-partitioning/.
URL::Origin origin;
friend bool operator==(StorageKey const& a, StorageKey const& b)
{
// To determine whether a storage key A equals storage key B, run these steps:
// 1. If As origin is not same origin with Bs origin, then return false.
// 2. Return true.
return a.origin.is_same_origin(b.origin);
}
};
Optional<StorageKey> obtain_a_storage_key(HTML::Environment const&);
StorageKey obtain_a_storage_key_for_non_storage_purposes(HTML::Environment const&);
}
namespace AK {
template<>
struct Traits<Web::StorageAPI::StorageKey> : public DefaultTraits<Web::StorageAPI::StorageKey> {
static unsigned hash(Web::StorageAPI::StorageKey const& key)
{
return Traits<URL::Origin>::hash(key.origin);
}
};
}

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/StorageManagerPrototype.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/StorageAPI/StorageManager.h>
namespace Web::StorageAPI {
JS_DEFINE_ALLOCATOR(StorageManager);
WebIDL::ExceptionOr<JS::NonnullGCPtr<StorageManager>> StorageManager::create(JS::Realm& realm)
{
return realm.heap().allocate<StorageManager>(realm, realm);
}
StorageManager::StorageManager(JS::Realm& realm)
: PlatformObject(realm)
{
}
void StorageManager::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(StorageManager);
}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::StorageAPI {
class StorageManager final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(StorageManager, Bindings::PlatformObject);
JS_DECLARE_ALLOCATOR(StorageManager);
public:
static WebIDL::ExceptionOr<JS::NonnullGCPtr<StorageManager>> create(JS::Realm&);
virtual ~StorageManager() override = default;
private:
StorageManager(JS::Realm&);
virtual void initialize(JS::Realm&) override;
};
}

View file

@ -0,0 +1,14 @@
// https://storage.spec.whatwg.org/#storagemanager
[SecureContext, Exposed=(Window,Worker)]
interface StorageManager {
[FIXME] Promise<boolean> persisted();
[FIXME, Exposed=Window] Promise<boolean> persist();
[FIXME] Promise<StorageEstimate> estimate();
};
// https://storage.spec.whatwg.org/#dictdef-storageestimate
dictionary StorageEstimate {
unsigned long long usage;
unsigned long long quota;
};