mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 04:39:06 +00:00
LibWebView: Add simple ID tracking to WebViews
For Firefox DevTools, we will need to track WebViews by a numerical ID. Here, we just increment a static 64-bit counter. We can switch to using IDAllocator if we ever have an issue with this. This patch adds such an ID to the views and a couple of APIs to access WebViews after creation.
This commit is contained in:
parent
82206d2abb
commit
3904765c4f
Notes:
github-actions[bot]
2025-02-19 13:47:36 +00:00
Author: https://github.com/trflynn89
Commit: 3904765c4f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3589
Reviewed-by: https://github.com/ADKaster
2 changed files with 33 additions and 1 deletions
|
@ -24,8 +24,29 @@
|
||||||
|
|
||||||
namespace WebView {
|
namespace WebView {
|
||||||
|
|
||||||
ViewImplementation::ViewImplementation()
|
static HashMap<u64, ViewImplementation*> s_all_views;
|
||||||
|
static u64 s_view_count = 1; // This has to start at 1 for Firefox DevTools.
|
||||||
|
|
||||||
|
void ViewImplementation::for_each_view(Function<IterationDecision(ViewImplementation&)> callback)
|
||||||
{
|
{
|
||||||
|
for (auto& view : s_all_views) {
|
||||||
|
if (callback(*view.value) == IterationDecision::Break)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<ViewImplementation&> ViewImplementation::find_view_by_id(u64 id)
|
||||||
|
{
|
||||||
|
if (auto view = s_all_views.get(id); view.has_value())
|
||||||
|
return *view.value();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewImplementation::ViewImplementation()
|
||||||
|
: m_view_id(s_view_count++)
|
||||||
|
{
|
||||||
|
s_all_views.set(m_view_id, this);
|
||||||
|
|
||||||
m_repeated_crash_timer = Core::Timer::create_single_shot(1000, [this] {
|
m_repeated_crash_timer = Core::Timer::create_single_shot(1000, [this] {
|
||||||
// Reset the "crashing a lot" counter after 1 second in case we just
|
// Reset the "crashing a lot" counter after 1 second in case we just
|
||||||
// happen to be visiting crashy websites a lot.
|
// happen to be visiting crashy websites a lot.
|
||||||
|
@ -44,6 +65,8 @@ ViewImplementation::ViewImplementation()
|
||||||
|
|
||||||
ViewImplementation::~ViewImplementation()
|
ViewImplementation::~ViewImplementation()
|
||||||
{
|
{
|
||||||
|
s_all_views.remove(m_view_id);
|
||||||
|
|
||||||
if (m_client_state.client)
|
if (m_client_state.client)
|
||||||
m_client_state.client->unregister_view(m_client_state.page_index);
|
m_client_state.client->unregister_view(m_client_state.page_index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,11 @@ public:
|
||||||
String fonts_json;
|
String fonts_json;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void for_each_view(Function<IterationDecision(ViewImplementation&)>);
|
||||||
|
static Optional<ViewImplementation&> find_view_by_id(u64);
|
||||||
|
|
||||||
|
u64 view_id() const { return m_view_id; }
|
||||||
|
|
||||||
void set_url(Badge<WebContentClient>, URL::URL url) { m_url = move(url); }
|
void set_url(Badge<WebContentClient>, URL::URL url) { m_url = move(url); }
|
||||||
URL::URL const& url() const { return m_url; }
|
URL::URL const& url() const { return m_url; }
|
||||||
|
|
||||||
|
@ -304,6 +309,10 @@ protected:
|
||||||
size_t m_number_of_elements_playing_audio { 0 };
|
size_t m_number_of_elements_playing_audio { 0 };
|
||||||
|
|
||||||
Web::HTML::MuteState m_mute_state { Web::HTML::MuteState::Unmuted };
|
Web::HTML::MuteState m_mute_state { Web::HTML::MuteState::Unmuted };
|
||||||
|
|
||||||
|
// FIXME: Reconcile this ID with `page_id`. The latter is only unique per WebContent connection, whereas the view ID
|
||||||
|
// is required to be globally unique for Firefox DevTools.
|
||||||
|
u64 m_view_id { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue