mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 01:27:42 +00:00
LibWeb: Try fetching a favicon when loading a non-file URL in HtmlView
If valid and decodable, the favicon will be provided to clients via the on_favicon_change hook. :^)
This commit is contained in:
parent
3fcfab4404
commit
2be184f49c
2 changed files with 25 additions and 0 deletions
|
@ -379,6 +379,30 @@ void HtmlView::load(const URL& url)
|
||||||
[this, url](auto error) {
|
[this, url](auto error) {
|
||||||
load_error_page(url, error);
|
load_error_page(url, error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (url.protocol() != "file") {
|
||||||
|
URL favicon_url;
|
||||||
|
favicon_url.set_protocol(url.protocol());
|
||||||
|
favicon_url.set_host(url.host());
|
||||||
|
favicon_url.set_port(url.port());
|
||||||
|
favicon_url.set_path("/favicon.ico");
|
||||||
|
|
||||||
|
ResourceLoader::the().load(
|
||||||
|
favicon_url,
|
||||||
|
[this, favicon_url](auto data) {
|
||||||
|
dbg() << "Favicon downloaded, " << data.size() << " bytes from " << favicon_url.to_string();
|
||||||
|
auto decoder = Gfx::ImageDecoder::create(data.data(), data.size());
|
||||||
|
auto bitmap = decoder->bitmap();
|
||||||
|
if (!bitmap) {
|
||||||
|
dbg() << "Could not decode favicon " << favicon_url.to_string();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dbg() << "Decoded favicon, " << bitmap->size();
|
||||||
|
if (on_favicon_change)
|
||||||
|
on_favicon_change(*bitmap);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this->scroll_to_top();
|
this->scroll_to_top();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,7 @@ public:
|
||||||
Function<void(const String&)> on_link_hover;
|
Function<void(const String&)> on_link_hover;
|
||||||
Function<void(const String&)> on_title_change;
|
Function<void(const String&)> on_title_change;
|
||||||
Function<void(const URL&)> on_load_start;
|
Function<void(const URL&)> on_load_start;
|
||||||
|
Function<void(const Gfx::Bitmap&)> on_favicon_change;
|
||||||
|
|
||||||
virtual bool accepts_focus() const override { return true; }
|
virtual bool accepts_focus() const override { return true; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue