From 75943503761acd5b83523544202a6f5d9c7aa68d Mon Sep 17 00:00:00 2001 From: Ben Abraham Date: Sun, 20 Feb 2022 17:03:39 -0500 Subject: [PATCH] Browser: Show currently loading host and remaining resource count --- Userland/Applications/Browser/Tab.cpp | 41 ++++++++++++++++++- Userland/Applications/Browser/Tab.h | 5 +++ Userland/Libraries/LibWeb/DOM/Document.cpp | 17 ++++++++ Userland/Libraries/LibWeb/DOM/Document.h | 8 +--- .../Libraries/LibWeb/OutOfProcessWebView.cpp | 6 +++ .../Libraries/LibWeb/OutOfProcessWebView.h | 1 + Userland/Libraries/LibWeb/Page/Page.h | 1 + .../Libraries/LibWeb/WebContentClient.cpp | 5 +++ Userland/Libraries/LibWeb/WebContentClient.h | 1 + Userland/Libraries/LibWeb/WebViewHooks.h | 1 + Userland/Services/WebContent/PageHost.cpp | 5 +++ Userland/Services/WebContent/PageHost.h | 1 + .../Services/WebContent/WebContentClient.ipc | 1 + 13 files changed, 85 insertions(+), 8 deletions(-) diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 1799010089..771cd83925 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -80,6 +80,29 @@ void Tab::view_source(const URL& url, const String& source) window->show(); } +void Tab::update_status(Optional text_override, i32 count_waiting) +{ + if (text_override.has_value()) { + m_statusbar->set_text(*text_override); + return; + } + + if (m_loaded) { + m_statusbar->set_text(""); + return; + } + + VERIFY(m_navigating_url.has_value()); + + if (count_waiting == 0) { + // ex: "Loading google.com" + m_statusbar->set_text(String::formatted("Loading {}", m_navigating_url->host())); + } else { + // ex: "google.com is waiting on 5 resources" + m_statusbar->set_text(String::formatted("{} is waiting on {} resource{}", m_navigating_url->host(), count_waiting, count_waiting == 1 ? ""sv : "s"sv)); + } +} + Tab::Tab(BrowserWindow& window) { load_from_gml(tab_gml); @@ -165,6 +188,11 @@ Tab::Tab(BrowserWindow& window) this); hooks().on_load_start = [this](auto& url) { + m_navigating_url = url; + m_loaded = false; + + update_status(); + m_location_box->set_icon(nullptr); m_location_box->set_text(url.to_string()); @@ -184,6 +212,11 @@ Tab::Tab(BrowserWindow& window) }; hooks().on_load_finish = [this](auto&) { + m_navigating_url = {}; + m_loaded = true; + + update_status(); + if (m_dom_inspector_widget) m_web_content_view->inspect_dom_tree(); }; @@ -196,6 +229,10 @@ Tab::Tab(BrowserWindow& window) } }; + hooks().on_resource_status_change = [this](auto count_waiting) { + update_status({}, count_waiting); + }; + m_link_context_menu = GUI::Menu::construct(); auto link_default_action = GUI::Action::create("&Open", [this](auto&) { hooks().on_link_click(m_link_context_menu_url, "", 0); @@ -317,9 +354,9 @@ Tab::Tab(BrowserWindow& window) hooks().on_link_hover = [this](auto& url) { if (url.is_valid()) - m_statusbar->set_text(url.to_string()); + update_status(url.to_string()); else - m_statusbar->set_text(""); + update_status(); }; hooks().on_url_drop = [this](auto& url) { diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h index 928ccf3340..265266a730 100644 --- a/Userland/Applications/Browser/Tab.h +++ b/Userland/Applications/Browser/Tab.h @@ -8,6 +8,7 @@ #pragma once #include "History.h" +#include #include #include #include @@ -91,6 +92,7 @@ private: void update_bookmark_button(const String& url); void start_download(const URL& url); void view_source(const URL& url, const String& source); + void update_status(Optional text_override = {}, i32 count_waiting = 0); History m_history; @@ -119,6 +121,9 @@ private: String m_title; RefPtr m_icon; + Optional m_navigating_url; + + bool m_loaded { false }; bool m_is_history_navigation { false }; }; diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index e06f1c04f8..1a5900e831 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1496,4 +1496,21 @@ void Document::unregister_node_iterator(Badge, NodeIterator& node_ VERIFY(was_removed); } +void Document::increment_number_of_things_delaying_the_load_event(Badge) +{ + ++m_number_of_things_delaying_the_load_event; + + if (auto* page = this->page()) + page->client().page_did_update_resource_count(m_number_of_things_delaying_the_load_event); +} + +void Document::decrement_number_of_things_delaying_the_load_event(Badge) +{ + VERIFY(m_number_of_things_delaying_the_load_event); + --m_number_of_things_delaying_the_load_event; + + if (auto* page = this->page()) + page->client().page_did_update_resource_count(m_number_of_things_delaying_the_load_event); +} + } diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 24d5e19b96..ec080dde64 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -294,12 +294,8 @@ public: Bindings::LocationObject* location(); size_t number_of_things_delaying_the_load_event() { return m_number_of_things_delaying_the_load_event; } - void increment_number_of_things_delaying_the_load_event(Badge) { ++m_number_of_things_delaying_the_load_event; } - void decrement_number_of_things_delaying_the_load_event(Badge) - { - VERIFY(m_number_of_things_delaying_the_load_event); - --m_number_of_things_delaying_the_load_event; - } + void increment_number_of_things_delaying_the_load_event(Badge); + void decrement_number_of_things_delaying_the_load_event(Badge); bool page_showing() const { return m_page_showing; } void set_page_showing(bool value) { m_page_showing = value; } diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index 88c56d4180..a88fcd747d 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -391,6 +391,12 @@ void OutOfProcessWebView::notify_server_did_set_cookie(Badge, on_set_cookie(url, cookie, source); } +void OutOfProcessWebView::notify_server_did_update_resource_count(i32 count_waiting) +{ + if (on_resource_status_change) + on_resource_status_change(count_waiting); +} + void OutOfProcessWebView::did_scroll() { client().async_set_viewport_rect(visible_content_rect()); diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.h b/Userland/Libraries/LibWeb/OutOfProcessWebView.h index 8a4a430ad6..2f168d1c18 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.h @@ -88,6 +88,7 @@ public: void notify_server_did_change_favicon(const Gfx::Bitmap& favicon); String notify_server_did_request_cookie(Badge, const AK::URL& url, Cookie::Source source); void notify_server_did_set_cookie(Badge, const AK::URL& url, const Cookie::ParsedCookie& cookie, Cookie::Source source); + void notify_server_did_update_resource_count(i32 count_waiting); private: OutOfProcessWebView(); diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index f0c3bcb259..8c3cfd19d2 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -103,6 +103,7 @@ public: virtual String page_did_request_prompt(const String&, const String&) { return {}; } virtual String page_did_request_cookie(const AK::URL&, Cookie::Source) { return {}; } virtual void page_did_set_cookie(const AK::URL&, const Cookie::ParsedCookie&, Cookie::Source) { } + virtual void page_did_update_resource_count(i32) { } protected: virtual ~PageClient() = default; diff --git a/Userland/Libraries/LibWeb/WebContentClient.cpp b/Userland/Libraries/LibWeb/WebContentClient.cpp index 1787e94c09..531cf0cda3 100644 --- a/Userland/Libraries/LibWeb/WebContentClient.cpp +++ b/Userland/Libraries/LibWeb/WebContentClient.cpp @@ -195,4 +195,9 @@ void WebContentClient::did_set_cookie(AK::URL const& url, Web::Cookie::ParsedCoo m_view.notify_server_did_set_cookie({}, url, cookie, static_cast(source)); } +void WebContentClient::did_update_resource_count(i32 count_waiting) +{ + m_view.notify_server_did_update_resource_count(count_waiting); +} + } diff --git a/Userland/Libraries/LibWeb/WebContentClient.h b/Userland/Libraries/LibWeb/WebContentClient.h index 8c7ac2ed89..5beef79b29 100644 --- a/Userland/Libraries/LibWeb/WebContentClient.h +++ b/Userland/Libraries/LibWeb/WebContentClient.h @@ -60,6 +60,7 @@ private: virtual Messages::WebContentClient::DidRequestPromptResponse did_request_prompt(String const&, String const&) override; virtual Messages::WebContentClient::DidRequestCookieResponse did_request_cookie(AK::URL const&, u8) override; virtual void did_set_cookie(AK::URL const&, Web::Cookie::ParsedCookie const&, u8) override; + virtual void did_update_resource_count(i32 count_waiting) override; OutOfProcessWebView& m_view; }; diff --git a/Userland/Libraries/LibWeb/WebViewHooks.h b/Userland/Libraries/LibWeb/WebViewHooks.h index 0a9630b78b..88f728695f 100644 --- a/Userland/Libraries/LibWeb/WebViewHooks.h +++ b/Userland/Libraries/LibWeb/WebViewHooks.h @@ -34,6 +34,7 @@ public: Function const& message_types, Vector const& messages)> on_get_js_console_messages; Function on_get_cookie; Function on_set_cookie; + Function on_resource_status_change; }; } diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp index dd8695743c..39b2e1cba5 100644 --- a/Userland/Services/WebContent/PageHost.cpp +++ b/Userland/Services/WebContent/PageHost.cpp @@ -256,4 +256,9 @@ void PageHost::page_did_set_cookie(const URL& url, const Web::Cookie::ParsedCook m_client.async_did_set_cookie(url, cookie, static_cast(source)); } +void PageHost::page_did_update_resource_count(i32 count_waiting) +{ + m_client.async_did_update_resource_count(count_waiting); +} + } diff --git a/Userland/Services/WebContent/PageHost.h b/Userland/Services/WebContent/PageHost.h index cdb93dd168..abaef859d3 100644 --- a/Userland/Services/WebContent/PageHost.h +++ b/Userland/Services/WebContent/PageHost.h @@ -64,6 +64,7 @@ private: virtual void page_did_request_image_context_menu(const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers, const Gfx::Bitmap*) override; virtual String page_did_request_cookie(const URL&, Web::Cookie::Source) override; virtual void page_did_set_cookie(const URL&, const Web::Cookie::ParsedCookie&, Web::Cookie::Source) override; + virtual void page_did_update_resource_count(i32) override; explicit PageHost(ConnectionFromClient&); diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc index 04ab5c4ecf..a0f329fc97 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -33,6 +33,7 @@ endpoint WebContentClient did_change_favicon(Gfx::ShareableBitmap favicon) =| did_request_cookie(URL url, u8 source) => (String cookie) did_set_cookie(URL url, Web::Cookie::ParsedCookie cookie, u8 source) =| + did_update_resource_count(i32 count_waiting) =| did_output_js_console_message(i32 message_index) =| did_get_js_console_messages(i32 start_index, Vector message_types, Vector messages) =|