summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Loader
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-27 01:12:53 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-27 01:17:05 +0200
commitd01b4327fabeabe77a3e57ab5d8a7dfb82eb3c52 (patch)
treeea3ef4de49e4b42280e64b3593295c1a35efa765 /Userland/Libraries/LibWeb/Loader
parentc6f4ecced9abd2b1ba78959ad1a698399e2ce542 (diff)
downloadserenity-d01b4327fabeabe77a3e57ab5d8a7dfb82eb3c52.zip
LibGfx: Improve ImageDecoder construction
Previously, ImageDecoder::create() would return a NonnullRefPtr and could not "fail", although the returned decoder may be "invalid" which you then had to check anyway. The new interface looks like this: static RefPtr<Gfx::ImageDecoder> try_create(ReadonlyBytes); This simplifies ImageDecoder since it no longer has to worry about its validity. Client code gets slightly clearer as well.
Diffstat (limited to 'Userland/Libraries/LibWeb/Loader')
-rw-r--r--Userland/Libraries/LibWeb/Loader/FrameLoader.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
index 6db5f9b13c..1fc5755223 100644
--- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
+++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
@@ -68,7 +68,9 @@ static bool build_text_document(DOM::Document& document, const ByteBuffer& data)
static bool build_image_document(DOM::Document& document, const ByteBuffer& data)
{
- auto image_decoder = Gfx::ImageDecoder::create(data.data(), data.size());
+ auto image_decoder = Gfx::ImageDecoder::try_create(data.bytes());
+ if (!image_decoder)
+ return false;
auto bitmap = image_decoder->bitmap();
if (!bitmap)
return false;
@@ -164,7 +166,11 @@ bool FrameLoader::load(const LoadRequest& request, Type type)
favicon_url,
[this, favicon_url](auto data, auto&, auto) {
dbgln("Favicon downloaded, {} bytes from {}", data.size(), favicon_url);
- auto decoder = Gfx::ImageDecoder::create(data.data(), data.size());
+ auto decoder = Gfx::ImageDecoder::try_create(data);
+ if (!decoder) {
+ dbgln("No image decoder plugin for favicon {}", favicon_url);
+ return;
+ }
auto bitmap = decoder->bitmap();
if (!bitmap) {
dbgln("Could not decode favicon {}", favicon_url);