1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:08:10 +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:
Andreas Kling 2020-04-24 22:26:53 +02:00
parent 3fcfab4404
commit 2be184f49c
2 changed files with 25 additions and 0 deletions

View file

@ -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();
}