From 8b1ad5c49616935df249ce979e8a733429de338d Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 28 Mar 2024 22:12:23 -0400 Subject: [PATCH] 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. --- .../Tools/CodeGenerators/IPCCompiler/main.cpp | 2 +- Userland/Libraries/LibWeb/HTML/History.cpp | 2 +- Userland/Libraries/LibWeb/Page/Page.h | 2 ++ .../Libraries/LibWebView/ViewImplementation.h | 1 + .../Libraries/LibWebView/WebContentClient.cpp | 15 +++++++++++++++ Userland/Libraries/LibWebView/WebContentClient.h | 2 ++ Userland/Services/WebContent/PageClient.cpp | 5 +++++ Userland/Services/WebContent/PageClient.h | 1 + Userland/Services/WebContent/WebContentClient.ipc | 4 +++- 9 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp index 8f18d637cba..e876e032bbc 100644 --- a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp @@ -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) diff --git a/Userland/Libraries/LibWeb/HTML/History.cpp b/Userland/Libraries/LibWeb/HTML/History.cpp index 4fd3ecdc086..17703479ca2 100644 --- a/Userland/Libraries/LibWeb/HTML/History.cpp +++ b/Userland/Libraries/LibWeb/HTML/History.cpp @@ -209,7 +209,7 @@ WebIDL::ExceptionOr 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 diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index 97c708ba355..9b199900f16 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -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) { } diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index b70eb702173..a53a84fb10a 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -138,6 +138,7 @@ public: Function on_title_change; Function on_load_start; Function on_load_finish; + Function on_url_updated; Function on_request_file; Function on_navigate_back; Function on_navigate_forward; diff --git a/Userland/Libraries/LibWebView/WebContentClient.cpp b/Userland/Libraries/LibWebView/WebContentClient.cpp index 705a71d557b..be01e882f7c 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.cpp +++ b/Userland/Libraries/LibWebView/WebContentClient.cpp @@ -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); diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h index 3a625d16f06..9ab5c01eabf 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.h +++ b/Userland/Libraries/LibWebView/WebContentClient.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -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; diff --git a/Userland/Services/WebContent/PageClient.cpp b/Userland/Services/WebContent/PageClient.cpp index cf74e290a77..7d29a87edad 100644 --- a/Userland/Services/WebContent/PageClient.cpp +++ b/Userland/Services/WebContent/PageClient.cpp @@ -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); diff --git a/Userland/Services/WebContent/PageClient.h b/Userland/Services/WebContent/PageClient.h index 56abba7acf4..180b00bfaf8 100644 --- a/Userland/Services/WebContent/PageClient.h +++ b/Userland/Services/WebContent/PageClient.h @@ -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; diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc index dcd224f90a2..c6c691a40fa 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -1,13 +1,14 @@ -#include #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -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) =|