mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-29 15:58:47 +00:00
LibWeb: Implement ModuleMap and expose it on EnvironmentSettingsObject
This patch adds the ModuleMap class used to keep track of the type and url of a module as well as the fetching state associated. Each environment settings object now also has a module map.
This commit is contained in:
parent
83554526f0
commit
992311c0ee
Notes:
sideshowbarker
2024-07-17 08:25:15 +09:00
Author: https://github.com/networkException
Commit: 992311c0ee
Pull-request: https://github.com/SerenityOS/serenity/pull/15275
Reviewed-by: https://github.com/davidot ✅
Reviewed-by: https://github.com/linusg
5 changed files with 143 additions and 1 deletions
50
Userland/Libraries/LibWeb/HTML/Scripting/ModuleMap.cpp
Normal file
50
Userland/Libraries/LibWeb/HTML/Scripting/ModuleMap.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2022, networkException <networkexception@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/HTML/Scripting/ModuleMap.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
bool ModuleMap::is_fetching(AK::URL const& url, String const& type) const
|
||||
{
|
||||
return is(url, type, EntryType::Fetching);
|
||||
}
|
||||
|
||||
bool ModuleMap::is_failed(AK::URL const& url, String const& type) const
|
||||
{
|
||||
return is(url, type, EntryType::Failed);
|
||||
}
|
||||
|
||||
bool ModuleMap::is(AK::URL const& url, String const& type, EntryType entry_type) const
|
||||
{
|
||||
auto value = m_values.get({ url, type });
|
||||
if (!value.has_value())
|
||||
return false;
|
||||
|
||||
return value->type == entry_type;
|
||||
}
|
||||
|
||||
Optional<ModuleMap::Entry> ModuleMap::get(AK::URL const& url, String const& type) const
|
||||
{
|
||||
return m_values.get({ url, type });
|
||||
}
|
||||
|
||||
AK::HashSetResult ModuleMap::set(AK::URL const& url, String const& type, Entry entry)
|
||||
{
|
||||
auto callbacks = m_callbacks.get({ url, type });
|
||||
if (callbacks.has_value())
|
||||
for (auto const& callback : *callbacks)
|
||||
callback(entry);
|
||||
|
||||
return m_values.set({ url, type }, entry);
|
||||
}
|
||||
|
||||
void ModuleMap::wait_for_change(AK::URL const& url, String const& type, Function<void(Entry)> callback)
|
||||
{
|
||||
m_callbacks.ensure({ url, type }).append(move(callback));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue