LibWeb: Implement NavigatorStorage mixin interface

Co-authored-by: Tim Flynn <trflynn89@serenityos.org>
This commit is contained in:
Jamie Mansfield 2024-08-13 20:56:19 +01:00 committed by Tim Flynn
commit e3b3041a0c
Notes: github-actions[bot] 2024-08-16 15:23:10 +00:00
12 changed files with 93 additions and 3 deletions

View file

@ -1,5 +1,8 @@
source_set("StorageAPI") {
configs += [ "//Userland/Libraries/LibWeb:configs" ]
deps = [ "//Userland/Libraries/LibWeb:all_generated" ]
sources = [ "StorageManager.cpp" ]
sources = [
"NavigatorStorage.cpp",
"StorageManager.cpp",
]
}

View file

@ -609,6 +609,7 @@ set(SOURCES
ResizeObserver/ResizeObserverSize.cpp
SecureContexts/AbstractOperations.cpp
SRI/SRI.cpp
StorageAPI/NavigatorStorage.cpp
StorageAPI/StorageManager.cpp
Streams/AbstractOperations.cpp
Streams/ByteLengthQueuingStrategy.cpp

View file

@ -663,6 +663,7 @@ struct UnderlyingSource;
}
namespace Web::StorageAPI {
class NavigatorStorage;
class StorageManager;
}

View file

@ -15,6 +15,7 @@
#include <LibWeb/HTML/NavigatorOnLine.h>
#include <LibWeb/HTML/PluginArray.h>
#include <LibWeb/HTML/UserActivation.h>
#include <LibWeb/StorageAPI/NavigatorStorage.h>
namespace Web::HTML {
@ -23,7 +24,8 @@ class Navigator : public Bindings::PlatformObject
, public NavigatorConcurrentHardwareMixin
, public NavigatorIDMixin
, public NavigatorLanguageMixin
, public NavigatorOnLineMixin {
, public NavigatorOnLineMixin
, public StorageAPI::NavigatorStorage {
WEB_PLATFORM_OBJECT(Navigator, Bindings::PlatformObject);
JS_DECLARE_ALLOCATOR(Navigator);
@ -64,6 +66,9 @@ private:
virtual void initialize(JS::Realm&) override;
// ^StorageAPI::NavigatorStorage
virtual Bindings::PlatformObject const& this_navigator_storage_object() const override { return *this; }
JS::GCPtr<PluginArray> m_plugin_array;
JS::GCPtr<MimeTypeArray> m_mime_type_array;

View file

@ -7,6 +7,7 @@
#import <HTML/NavigatorConcurrentHardware.idl>
#import <HTML/PluginArray.idl>
#import <HTML/UserActivation.idl>
#import <StorageAPI/NavigatorStorage.idl>
// https://html.spec.whatwg.org/multipage/system-state.html#navigator
[Exposed=Window]
@ -62,3 +63,4 @@ Navigator includes NavigatorCookies;
Navigator includes NavigatorPlugins;
Navigator includes NavigatorConcurrentHardware;
Navigator includes NavigatorAutomationInformation;
Navigator includes NavigatorStorage;

View file

@ -17,6 +17,7 @@
#include <LibWeb/HTML/WorkerGlobalScope.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/SecureContexts/AbstractOperations.h>
#include <LibWeb/StorageAPI/StorageManager.h>
namespace Web::HTML {
@ -56,6 +57,7 @@ void EnvironmentSettingsObject::visit_edges(Cell::Visitor& visitor)
visitor.ignore(m_outstanding_rejected_promises_weak_set);
m_realm_execution_context->visit_edges(visitor);
visitor.visit(m_fetch_group);
visitor.visit(m_storage_manager);
}
JS::ExecutionContext& EnvironmentSettingsObject::realm_execution_context()
@ -517,4 +519,11 @@ SerializedEnvironmentSettingsObject EnvironmentSettingsObject::serialize()
return object;
}
JS::NonnullGCPtr<StorageAPI::StorageManager> EnvironmentSettingsObject::storage_manager()
{
if (!m_storage_manager)
m_storage_manager = realm().heap().allocate<StorageAPI::StorageManager>(realm(), realm());
return *m_storage_manager;
}
}

View file

@ -122,6 +122,8 @@ public:
SerializedEnvironmentSettingsObject serialize();
JS::NonnullGCPtr<StorageAPI::StorageManager> storage_manager();
protected:
explicit EnvironmentSettingsObject(NonnullOwnPtr<JS::ExecutionContext>);
@ -143,6 +145,10 @@ private:
// https://fetch.spec.whatwg.org/#concept-fetch-record
// A fetch group holds an ordered list of fetch records
Vector<JS::NonnullGCPtr<Fetch::Infrastructure::FetchRecord>> m_fetch_group;
// https://storage.spec.whatwg.org/#api
// Each environment settings object has an associated StorageManager object.
JS::GCPtr<StorageAPI::StorageManager> m_storage_manager;
};
EnvironmentSettingsObject& incumbent_settings_object();

View file

@ -11,6 +11,7 @@
#include <LibWeb/HTML/NavigatorID.h>
#include <LibWeb/HTML/NavigatorLanguage.h>
#include <LibWeb/HTML/NavigatorOnLine.h>
#include <LibWeb/StorageAPI/NavigatorStorage.h>
namespace Web::HTML {
@ -18,7 +19,8 @@ class WorkerNavigator : public Bindings::PlatformObject
, public NavigatorConcurrentHardwareMixin
, public NavigatorIDMixin
, public NavigatorLanguageMixin
, public NavigatorOnLineMixin {
, public NavigatorOnLineMixin
, public StorageAPI::NavigatorStorage {
WEB_PLATFORM_OBJECT(WorkerNavigator, Bindings::PlatformObject);
JS_DECLARE_ALLOCATOR(WorkerNavigator);
@ -31,6 +33,9 @@ private:
explicit WorkerNavigator(WorkerGlobalScope&);
virtual void initialize(JS::Realm&) override;
// ^StorageAPI::NavigatorStorage
virtual Bindings::PlatformObject const& this_navigator_storage_object() const override { return *this; }
};
}

View file

@ -2,6 +2,7 @@
#import <HTML/NavigatorLanguage.idl>
#import <HTML/NavigatorOnLine.idl>
#import <HTML/NavigatorConcurrentHardware.idl>
#import <StorageAPI/NavigatorStorage.idl>
// https://html.spec.whatwg.org/multipage/workers.html#workernavigator
[Exposed=Worker]
@ -11,3 +12,4 @@ WorkerNavigator includes NavigatorID;
WorkerNavigator includes NavigatorLanguage;
WorkerNavigator includes NavigatorOnLine;
WorkerNavigator includes NavigatorConcurrentHardware;
WorkerNavigator includes NavigatorStorage;

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;
};