mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-18 15:32:22 +00:00
LibWeb: Handle document/navigable disconnection during favicon decode
If the document is disconnected from the navigable by the time a favicon decode completes successfully, we don't want to show the favicon for whatever document is now loaded in the navigable. Fix this by deferring getting the navigable until after the decode has completed.
This commit is contained in:
parent
bde2d3dc7b
commit
5606ce412e
Notes:
github-actions[bot]
2024-08-22 07:35:49 +00:00
Author: https://github.com/awesomekling
Commit: 5606ce412e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1155
1 changed files with 5 additions and 4 deletions
|
@ -520,16 +520,17 @@ void HTMLLinkElement::resource_did_load_favicon()
|
||||||
document().check_favicon_after_loading_link_resource();
|
document().check_favicon_after_loading_link_resource();
|
||||||
}
|
}
|
||||||
|
|
||||||
static NonnullRefPtr<Core::Promise<Web::Platform::DecodedImage>> decode_favicon(ReadonlyBytes favicon_data, URL::URL const& favicon_url, JS::GCPtr<Navigable> navigable)
|
static NonnullRefPtr<Core::Promise<Web::Platform::DecodedImage>> decode_favicon(ReadonlyBytes favicon_data, URL::URL const& favicon_url, JS::NonnullGCPtr<DOM::Document> document)
|
||||||
{
|
{
|
||||||
auto on_failed_decode = [favicon_url]([[maybe_unused]] Error& error) {
|
auto on_failed_decode = [favicon_url]([[maybe_unused]] Error& error) {
|
||||||
dbgln_if(IMAGE_DECODER_DEBUG, "Failed to decode favicon {}: {}", favicon_url, error);
|
dbgln_if(IMAGE_DECODER_DEBUG, "Failed to decode favicon {}: {}", favicon_url, error);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto on_successful_decode = [navigable = JS::Handle(*navigable)](Web::Platform::DecodedImage& decoded_image) -> ErrorOr<void> {
|
auto on_successful_decode = [document = JS::Handle(document)](Web::Platform::DecodedImage& decoded_image) -> ErrorOr<void> {
|
||||||
auto favicon_bitmap = decoded_image.frames[0].bitmap;
|
auto favicon_bitmap = decoded_image.frames[0].bitmap;
|
||||||
dbgln_if(IMAGE_DECODER_DEBUG, "Decoded favicon, {}", favicon_bitmap->size());
|
dbgln_if(IMAGE_DECODER_DEBUG, "Decoded favicon, {}", favicon_bitmap->size());
|
||||||
|
|
||||||
|
auto navigable = document->navigable();
|
||||||
if (navigable && navigable->is_traversable())
|
if (navigable && navigable->is_traversable())
|
||||||
navigable->traversable_navigable()->page().client().page_did_change_favicon(*favicon_bitmap);
|
navigable->traversable_navigable()->page().client().page_did_change_favicon(*favicon_bitmap);
|
||||||
|
|
||||||
|
@ -547,7 +548,7 @@ bool HTMLLinkElement::load_favicon_and_use_if_window_is_active()
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// FIXME: Refactor the caller(s) to handle the async nature of image loading
|
// FIXME: Refactor the caller(s) to handle the async nature of image loading
|
||||||
auto promise = decode_favicon(resource()->encoded_data(), resource()->url(), navigable());
|
auto promise = decode_favicon(resource()->encoded_data(), resource()->url(), document());
|
||||||
auto result = promise->await();
|
auto result = promise->await();
|
||||||
return !result.is_error();
|
return !result.is_error();
|
||||||
}
|
}
|
||||||
|
@ -583,7 +584,7 @@ WebIDL::ExceptionOr<void> HTMLLinkElement::load_fallback_favicon_if_needed(JS::N
|
||||||
auto global = JS::NonnullGCPtr { realm.global_object() };
|
auto global = JS::NonnullGCPtr { realm.global_object() };
|
||||||
|
|
||||||
auto process_body = JS::create_heap_function(realm.heap(), [document, request](ByteBuffer body) {
|
auto process_body = JS::create_heap_function(realm.heap(), [document, request](ByteBuffer body) {
|
||||||
(void)decode_favicon(body, request->url(), document->navigable());
|
(void)decode_favicon(body, request->url(), document);
|
||||||
});
|
});
|
||||||
auto process_body_error = JS::create_heap_function(realm.heap(), [](JS::Value) {
|
auto process_body_error = JS::create_heap_function(realm.heap(), [](JS::Value) {
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue