diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-08 21:44:42 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-08 23:36:19 +0100 |
commit | eda9fb13cc96f9b2885f96c4b525907f5acd7582 (patch) | |
tree | eefbe5c14d5bb23dfead715d728e0ca083522813 /Libraries | |
parent | 52dbdf42455b27b05935f9c0f024e462718237c2 (diff) | |
download | serenity-eda9fb13cc96f9b2885f96c4b525907f5acd7582.zip |
LibWeb+WebContent: Add on_load_finish hook to web views
This isn't entirely symmetrical with on_load_start as it will also fire
on reloads and back/forward navigations. However, it's good enough for
some basic use cases, and we can do more sophisticated notifications
later on when we need them.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibWeb/InProcessWebView.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibWeb/InProcessWebView.h | 1 | ||||
-rw-r--r-- | Libraries/LibWeb/Loader/FrameLoader.cpp | 3 | ||||
-rw-r--r-- | Libraries/LibWeb/OutOfProcessWebView.cpp | 7 | ||||
-rw-r--r-- | Libraries/LibWeb/OutOfProcessWebView.h | 1 | ||||
-rw-r--r-- | Libraries/LibWeb/Page/Page.h | 1 | ||||
-rw-r--r-- | Libraries/LibWeb/WebContentClient.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibWeb/WebContentClient.h | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/WebViewHooks.h | 1 |
9 files changed, 23 insertions, 5 deletions
diff --git a/Libraries/LibWeb/InProcessWebView.cpp b/Libraries/LibWeb/InProcessWebView.cpp index 40f33b32e3..8701583145 100644 --- a/Libraries/LibWeb/InProcessWebView.cpp +++ b/Libraries/LibWeb/InProcessWebView.cpp @@ -150,6 +150,12 @@ void InProcessWebView::page_did_start_loading(const URL& url) on_load_start(url); } +void InProcessWebView::page_did_finish_loading(const URL& url) +{ + if (on_load_finish) + on_load_finish(url); +} + void InProcessWebView::page_did_change_selection() { update(); diff --git a/Libraries/LibWeb/InProcessWebView.h b/Libraries/LibWeb/InProcessWebView.h index 7194836b9d..084c3a01c4 100644 --- a/Libraries/LibWeb/InProcessWebView.h +++ b/Libraries/LibWeb/InProcessWebView.h @@ -88,6 +88,7 @@ private: virtual void page_did_change_title(const String&) override; virtual void page_did_set_document_in_main_frame(DOM::Document*) override; virtual void page_did_start_loading(const URL&) override; + virtual void page_did_finish_loading(const URL&) override; virtual void page_did_change_selection() override; virtual void page_did_request_cursor_change(Gfx::StandardCursor) override; virtual void page_did_request_context_menu(const Gfx::IntPoint&) override; diff --git a/Libraries/LibWeb/Loader/FrameLoader.cpp b/Libraries/LibWeb/Loader/FrameLoader.cpp index c5c417e7cc..9df29cf52e 100644 --- a/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -274,6 +274,9 @@ void FrameLoader::resource_did_load() ASSERT(is<HTML::HTMLIFrameElement>(*host_element)); downcast<HTML::HTMLIFrameElement>(*host_element).content_frame_did_load({}); } + + if (auto* page = frame().page()) + page->client().page_did_finish_loading(url); } void FrameLoader::resource_did_fail() diff --git a/Libraries/LibWeb/OutOfProcessWebView.cpp b/Libraries/LibWeb/OutOfProcessWebView.cpp index 736f523233..64206d301b 100644 --- a/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -209,6 +209,13 @@ void OutOfProcessWebView::notify_server_did_start_loading(Badge<WebContentClient on_load_start(url); } + +void OutOfProcessWebView::notify_server_did_finish_loading(Badge<WebContentClient>, const URL& url) +{ + if (on_load_finish) + on_load_finish(url); +} + void OutOfProcessWebView::notify_server_did_request_context_menu(Badge<WebContentClient>, const Gfx::IntPoint& content_position) { if (on_context_menu_request) diff --git a/Libraries/LibWeb/OutOfProcessWebView.h b/Libraries/LibWeb/OutOfProcessWebView.h index f610a40bdf..5779d6f6da 100644 --- a/Libraries/LibWeb/OutOfProcessWebView.h +++ b/Libraries/LibWeb/OutOfProcessWebView.h @@ -60,6 +60,7 @@ public: void notify_server_did_click_link(Badge<WebContentClient>, const URL&, const String& target, unsigned modifiers); void notify_server_did_middle_click_link(Badge<WebContentClient>, const URL&, const String& target, unsigned modifiers); void notify_server_did_start_loading(Badge<WebContentClient>, const URL&); + void notify_server_did_finish_loading(Badge<WebContentClient>, const URL&); void notify_server_did_request_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&); void notify_server_did_request_link_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers); void notify_server_did_request_alert(Badge<WebContentClient>, const String& message); diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h index 8fa1719d2e..5d7325d283 100644 --- a/Libraries/LibWeb/Page/Page.h +++ b/Libraries/LibWeb/Page/Page.h @@ -85,6 +85,7 @@ public: virtual void page_did_set_document_in_main_frame(DOM::Document*) { } virtual void page_did_change_title(const String&) { } virtual void page_did_start_loading(const URL&) { } + virtual void page_did_finish_loading(const URL&) { } virtual void page_did_change_selection() { } virtual void page_did_request_cursor_change(Gfx::StandardCursor) { } virtual void page_did_request_context_menu(const Gfx::IntPoint&) { } diff --git a/Libraries/LibWeb/WebContentClient.cpp b/Libraries/LibWeb/WebContentClient.cpp index 5a679ab068..0c09cb92af 100644 --- a/Libraries/LibWeb/WebContentClient.cpp +++ b/Libraries/LibWeb/WebContentClient.cpp @@ -52,11 +52,9 @@ void WebContentClient::handle(const Messages::WebContentClient::DidPaint& messag m_view.notify_server_did_paint({}, message.shbuf_id()); } -void WebContentClient::handle([[maybe_unused]] const Messages::WebContentClient::DidFinishLoad& message) +void WebContentClient::handle([[maybe_unused]] const Messages::WebContentClient::DidFinishLoading& message) { -#ifdef DEBUG_SPAM - dbg() << "handle: WebContentClient::DidFinishLoad! url=" << message.url(); -#endif + m_view.notify_server_did_finish_loading({}, message.url()); } void WebContentClient::handle(const Messages::WebContentClient::DidInvalidateContentRect& message) diff --git a/Libraries/LibWeb/WebContentClient.h b/Libraries/LibWeb/WebContentClient.h index c712b193b7..2078882578 100644 --- a/Libraries/LibWeb/WebContentClient.h +++ b/Libraries/LibWeb/WebContentClient.h @@ -47,7 +47,7 @@ private: WebContentClient(OutOfProcessWebView&); virtual void handle(const Messages::WebContentClient::DidPaint&) override; - virtual void handle(const Messages::WebContentClient::DidFinishLoad&) override; + virtual void handle(const Messages::WebContentClient::DidFinishLoading&) override; virtual void handle(const Messages::WebContentClient::DidInvalidateContentRect&) override; virtual void handle(const Messages::WebContentClient::DidChangeSelection&) override; virtual void handle(const Messages::WebContentClient::DidLayout&) override; diff --git a/Libraries/LibWeb/WebViewHooks.h b/Libraries/LibWeb/WebViewHooks.h index d93655bcea..198526e019 100644 --- a/Libraries/LibWeb/WebViewHooks.h +++ b/Libraries/LibWeb/WebViewHooks.h @@ -42,6 +42,7 @@ public: Function<void(const URL&)> on_link_hover; Function<void(const String&)> on_title_change; Function<void(const URL&)> on_load_start; + Function<void(const URL&)> on_load_finish; Function<void(const Gfx::Bitmap&)> on_favicon_change; Function<void(const URL&)> on_url_drop; Function<void(DOM::Document*)> on_set_document; |