1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:57:36 +00:00

Browser: Show currently loading host and remaining resource count

This commit is contained in:
Ben Abraham 2022-02-20 17:03:39 -05:00 committed by Linus Groh
parent fb6c8781a2
commit 7594350376
13 changed files with 85 additions and 8 deletions

View file

@ -80,6 +80,29 @@ void Tab::view_source(const URL& url, const String& source)
window->show(); window->show();
} }
void Tab::update_status(Optional<String> 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) Tab::Tab(BrowserWindow& window)
{ {
load_from_gml(tab_gml); load_from_gml(tab_gml);
@ -165,6 +188,11 @@ Tab::Tab(BrowserWindow& window)
this); this);
hooks().on_load_start = [this](auto& url) { 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_icon(nullptr);
m_location_box->set_text(url.to_string()); m_location_box->set_text(url.to_string());
@ -184,6 +212,11 @@ Tab::Tab(BrowserWindow& window)
}; };
hooks().on_load_finish = [this](auto&) { hooks().on_load_finish = [this](auto&) {
m_navigating_url = {};
m_loaded = true;
update_status();
if (m_dom_inspector_widget) if (m_dom_inspector_widget)
m_web_content_view->inspect_dom_tree(); 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(); m_link_context_menu = GUI::Menu::construct();
auto link_default_action = GUI::Action::create("&Open", [this](auto&) { auto link_default_action = GUI::Action::create("&Open", [this](auto&) {
hooks().on_link_click(m_link_context_menu_url, "", 0); 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) { hooks().on_link_hover = [this](auto& url) {
if (url.is_valid()) if (url.is_valid())
m_statusbar->set_text(url.to_string()); update_status(url.to_string());
else else
m_statusbar->set_text(""); update_status();
}; };
hooks().on_url_drop = [this](auto& url) { hooks().on_url_drop = [this](auto& url) {

View file

@ -8,6 +8,7 @@
#pragma once #pragma once
#include "History.h" #include "History.h"
#include <AK/Optional.h>
#include <AK/URL.h> #include <AK/URL.h>
#include <LibGUI/ActionGroup.h> #include <LibGUI/ActionGroup.h>
#include <LibGUI/Widget.h> #include <LibGUI/Widget.h>
@ -91,6 +92,7 @@ private:
void update_bookmark_button(const String& url); void update_bookmark_button(const String& url);
void start_download(const URL& url); void start_download(const URL& url);
void view_source(const URL& url, const String& source); void view_source(const URL& url, const String& source);
void update_status(Optional<String> text_override = {}, i32 count_waiting = 0);
History m_history; History m_history;
@ -119,6 +121,9 @@ private:
String m_title; String m_title;
RefPtr<const Gfx::Bitmap> m_icon; RefPtr<const Gfx::Bitmap> m_icon;
Optional<URL> m_navigating_url;
bool m_loaded { false };
bool m_is_history_navigation { false }; bool m_is_history_navigation { false };
}; };

View file

@ -1496,4 +1496,21 @@ void Document::unregister_node_iterator(Badge<NodeIterator>, NodeIterator& node_
VERIFY(was_removed); VERIFY(was_removed);
} }
void Document::increment_number_of_things_delaying_the_load_event(Badge<DocumentLoadEventDelayer>)
{
++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<DocumentLoadEventDelayer>)
{
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);
}
} }

View file

@ -294,12 +294,8 @@ public:
Bindings::LocationObject* location(); Bindings::LocationObject* location();
size_t number_of_things_delaying_the_load_event() { return m_number_of_things_delaying_the_load_event; } 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<DocumentLoadEventDelayer>) { ++m_number_of_things_delaying_the_load_event; } void increment_number_of_things_delaying_the_load_event(Badge<DocumentLoadEventDelayer>);
void decrement_number_of_things_delaying_the_load_event(Badge<DocumentLoadEventDelayer>) void decrement_number_of_things_delaying_the_load_event(Badge<DocumentLoadEventDelayer>);
{
VERIFY(m_number_of_things_delaying_the_load_event);
--m_number_of_things_delaying_the_load_event;
}
bool page_showing() const { return m_page_showing; } bool page_showing() const { return m_page_showing; }
void set_page_showing(bool value) { m_page_showing = value; } void set_page_showing(bool value) { m_page_showing = value; }

View file

@ -391,6 +391,12 @@ void OutOfProcessWebView::notify_server_did_set_cookie(Badge<WebContentClient>,
on_set_cookie(url, cookie, source); 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() void OutOfProcessWebView::did_scroll()
{ {
client().async_set_viewport_rect(visible_content_rect()); client().async_set_viewport_rect(visible_content_rect());

View file

@ -88,6 +88,7 @@ public:
void notify_server_did_change_favicon(const Gfx::Bitmap& favicon); void notify_server_did_change_favicon(const Gfx::Bitmap& favicon);
String notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Cookie::Source source); String notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Cookie::Source source);
void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, const Cookie::ParsedCookie& cookie, Cookie::Source source); void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, const Cookie::ParsedCookie& cookie, Cookie::Source source);
void notify_server_did_update_resource_count(i32 count_waiting);
private: private:
OutOfProcessWebView(); OutOfProcessWebView();

View file

@ -103,6 +103,7 @@ public:
virtual String page_did_request_prompt(const String&, const String&) { return {}; } virtual String page_did_request_prompt(const String&, const String&) { return {}; }
virtual String page_did_request_cookie(const AK::URL&, Cookie::Source) { 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_set_cookie(const AK::URL&, const Cookie::ParsedCookie&, Cookie::Source) { }
virtual void page_did_update_resource_count(i32) { }
protected: protected:
virtual ~PageClient() = default; virtual ~PageClient() = default;

View file

@ -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<Cookie::Source>(source)); m_view.notify_server_did_set_cookie({}, url, cookie, static_cast<Cookie::Source>(source));
} }
void WebContentClient::did_update_resource_count(i32 count_waiting)
{
m_view.notify_server_did_update_resource_count(count_waiting);
}
} }

View file

@ -60,6 +60,7 @@ private:
virtual Messages::WebContentClient::DidRequestPromptResponse did_request_prompt(String const&, String const&) override; 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 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_set_cookie(AK::URL const&, Web::Cookie::ParsedCookie const&, u8) override;
virtual void did_update_resource_count(i32 count_waiting) override;
OutOfProcessWebView& m_view; OutOfProcessWebView& m_view;
}; };

View file

@ -34,6 +34,7 @@ public:
Function<void(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages)> on_get_js_console_messages; Function<void(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages)> on_get_js_console_messages;
Function<String(const AK::URL& url, Cookie::Source source)> on_get_cookie; Function<String(const AK::URL& url, Cookie::Source source)> on_get_cookie;
Function<void(const AK::URL& url, const Cookie::ParsedCookie& cookie, Cookie::Source source)> on_set_cookie; Function<void(const AK::URL& url, const Cookie::ParsedCookie& cookie, Cookie::Source source)> on_set_cookie;
Function<void(i32 count_waiting)> on_resource_status_change;
}; };
} }

View file

@ -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<u8>(source)); m_client.async_did_set_cookie(url, cookie, static_cast<u8>(source));
} }
void PageHost::page_did_update_resource_count(i32 count_waiting)
{
m_client.async_did_update_resource_count(count_waiting);
}
} }

View file

@ -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 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 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_set_cookie(const URL&, const Web::Cookie::ParsedCookie&, Web::Cookie::Source) override;
virtual void page_did_update_resource_count(i32) override;
explicit PageHost(ConnectionFromClient&); explicit PageHost(ConnectionFromClient&);

View file

@ -33,6 +33,7 @@ endpoint WebContentClient
did_change_favicon(Gfx::ShareableBitmap favicon) =| did_change_favicon(Gfx::ShareableBitmap favicon) =|
did_request_cookie(URL url, u8 source) => (String cookie) did_request_cookie(URL url, u8 source) => (String cookie)
did_set_cookie(URL url, Web::Cookie::ParsedCookie cookie, u8 source) =| 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_output_js_console_message(i32 message_index) =|
did_get_js_console_messages(i32 start_index, Vector<String> message_types, Vector<String> messages) =| did_get_js_console_messages(i32 start_index, Vector<String> message_types, Vector<String> messages) =|