mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-12 17:30:38 +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
Notes:
sideshowbarker
2024-07-19 07:19:33 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2be184f49c8
2 changed files with 25 additions and 0 deletions
|
@ -379,6 +379,30 @@ void HtmlView::load(const URL& url)
|
|||
[this, url](auto 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
Function<void(const String&)> on_link_hover;
|
||||
Function<void(const String&)> on_title_change;
|
||||
Function<void(const URL&)> on_load_start;
|
||||
Function<void(const Gfx::Bitmap&)> on_favicon_change;
|
||||
|
||||
virtual bool accepts_focus() const override { return true; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue