LibWeb+LibWebView+WebContent: Add a new IPC for modifying history state

Let's not re-invoke the "page did start loading" IPC when the history
state is pushed/replaced. It's a bit misleading (the change does not
actually load the new URL), but also the chromes may do more work than
we want when we change the URL.

Instead, add a new IPC for the history object to invoke.
This commit is contained in:
Timothy Flynn 2024-03-28 22:12:23 -04:00 committed by Tim Flynn
parent 1767f405dc
commit 8b1ad5c496
Notes: sideshowbarker 2024-07-16 23:57:20 +09:00
9 changed files with 31 additions and 3 deletions

View file

@ -70,7 +70,7 @@ static bool is_primitive_type(ByteString const& type)
static bool is_simple_type(ByteString const& type)
{
// Small types that it makes sense just to pass by value.
return type.is_one_of("Gfx::Color", "Web::DevicePixels", "Gfx::IntPoint", "Gfx::FloatPoint", "Web::DevicePixelPoint", "Gfx::IntSize", "Gfx::FloatSize", "Web::DevicePixelSize", "Core::File::OpenMode", "Web::Cookie::Source", "Web::HTML::AllowMultipleFiles", "Web::HTML::AudioPlayState");
return type.is_one_of("Gfx::Color", "Web::DevicePixels", "Gfx::IntPoint", "Gfx::FloatPoint", "Web::DevicePixelPoint", "Gfx::IntSize", "Gfx::FloatSize", "Web::DevicePixelSize", "Core::File::OpenMode", "Web::Cookie::Source", "Web::HTML::AllowMultipleFiles", "Web::HTML::AudioPlayState", "Web::HTML::HistoryHandlingBehavior");
}
static bool is_primitive_or_simple_type(ByteString const& type)

View file

@ -209,7 +209,7 @@ WebIDL::ExceptionOr<void> History::shared_history_push_replace_state(JS::Value d
auto navigable = document->navigable();
if (navigable->is_top_level_traversable()) {
navigable->active_browsing_context()->page().client().page_did_start_loading(new_url, false);
navigable->active_browsing_context()->page().client().page_did_update_url(new_url, history_handling);
}
// 10. Run the URL and history update steps given document and newURL, with serializedData set to

View file

@ -33,6 +33,7 @@
#include <LibWeb/HTML/AudioPlayState.h>
#include <LibWeb/HTML/ColorPickerUpdateState.h>
#include <LibWeb/HTML/FileFilter.h>
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
#include <LibWeb/HTML/SelectItem.h>
#include <LibWeb/HTML/TokenizedFeatures.h>
#include <LibWeb/HTML/WebViewHints.h>
@ -249,6 +250,7 @@ public:
virtual void page_did_create_new_document(Web::DOM::Document&) { }
virtual void page_did_destroy_document(Web::DOM::Document&) { }
virtual void page_did_finish_loading(URL::URL const&) { }
virtual void page_did_update_url(URL::URL const&, Web::HTML::HistoryHandlingBehavior) { }
virtual void page_did_request_cursor_change(Gfx::StandardCursor) { }
virtual void page_did_request_context_menu(CSSPixelPoint) { }
virtual void page_did_request_link_context_menu(CSSPixelPoint, URL::URL const&, [[maybe_unused]] ByteString const& target, [[maybe_unused]] unsigned modifiers) { }

View file

@ -138,6 +138,7 @@ public:
Function<void(ByteString const&)> on_title_change;
Function<void(URL::URL const&, bool)> on_load_start;
Function<void(URL::URL const&)> on_load_finish;
Function<void(URL::URL const&, Web::HTML::HistoryHandlingBehavior)> on_url_updated;
Function<void(ByteString const& path, i32)> on_request_file;
Function<void()> on_navigate_back;
Function<void()> on_navigate_forward;

View file

@ -76,6 +76,21 @@ void WebContentClient::did_finish_loading(u64 page_id, URL::URL const& url)
view.on_load_finish(url);
}
void WebContentClient::did_update_url(u64 page_id, URL::URL const& url, Web::HTML::HistoryHandlingBehavior history_behavior)
{
auto maybe_view = m_views.get(page_id);
if (!maybe_view.has_value()) {
dbgln("Received finish loading for unknown page ID {}", page_id);
return;
}
auto& view = *maybe_view.value();
view.set_url({}, url);
if (view.on_url_updated)
view.on_url_updated(url, history_behavior);
}
void WebContentClient::did_finish_text_test(u64 page_id)
{
auto maybe_view = m_views.get(page_id);

View file

@ -10,6 +10,7 @@
#include <LibIPC/ConnectionToServer.h>
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWeb/HTML/FileFilter.h>
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
#include <LibWeb/HTML/SelectItem.h>
#include <LibWeb/HTML/WebViewHints.h>
#include <WebContent/WebContentClientEndpoint.h>
@ -37,6 +38,7 @@ private:
virtual void did_paint(u64 page_id, Gfx::IntRect const&, i32) override;
virtual void did_finish_loading(u64 page_id, URL::URL const&) override;
virtual void did_update_url(u64 page_id, URL::URL const& url, Web::HTML::HistoryHandlingBehavior history_behavior) override;
virtual void did_request_navigate_back(u64 page_id) override;
virtual void did_request_navigate_forward(u64 page_id) override;
virtual void did_request_refresh(u64 page_id) override;

View file

@ -361,6 +361,11 @@ void PageClient::page_did_finish_loading(URL::URL const& url)
client().async_did_finish_loading(m_id, url);
}
void PageClient::page_did_update_url(URL::URL const& url, Web::HTML::HistoryHandlingBehavior history_behavior)
{
client().async_did_update_url(m_id, url, history_behavior);
}
void PageClient::page_did_finish_text_test()
{
client().async_did_finish_text_test(m_id);

View file

@ -118,6 +118,7 @@ private:
virtual void page_did_create_new_document(Web::DOM::Document&) override;
virtual void page_did_destroy_document(Web::DOM::Document&) override;
virtual void page_did_finish_loading(URL::URL const&) override;
virtual void page_did_update_url(URL::URL const&, Web::HTML::HistoryHandlingBehavior) override;
virtual void page_did_request_alert(String const&) override;
virtual void page_did_request_confirm(String const&) override;
virtual void page_did_request_prompt(String const&, String const&) override;

View file

@ -1,13 +1,14 @@
#include <LibURL/URL.h>
#include <LibCore/AnonymousBuffer.h>
#include <LibGfx/Color.h>
#include <LibGfx/ShareableBitmap.h>
#include <LibURL/URL.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWeb/HTML/AudioPlayState.h>
#include <LibWeb/HTML/FileFilter.h>
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
#include <LibWeb/HTML/SelectedFile.h>
#include <LibWeb/HTML/SelectItem.h>
#include <LibWeb/HTML/WebViewHints.h>
@ -19,6 +20,7 @@ endpoint WebContentClient
{
did_start_loading(u64 page_id, URL::URL url, bool is_redirect) =|
did_finish_loading(u64 page_id, URL::URL url) =|
did_update_url(u64 page_id, URL::URL url, Web::HTML::HistoryHandlingBehavior history_behavior) =|
did_request_navigate_back(u64 page_id) =|
did_request_navigate_forward(u64 page_id) =|
did_request_refresh(u64 page_id) =|