mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:27:35 +00:00
LibWeb: Update HTML image loading algorithm with null checks from spec
The spec has been updated to fix the missing null checks we found:
8f3d1fc6d1
This commit is contained in:
parent
2b89020b6c
commit
2e9b12d327
3 changed files with 29 additions and 31 deletions
|
@ -319,11 +319,8 @@ ErrorOr<void> HTMLImageElement::update_the_image_data(bool restart_animations)
|
||||||
entry->ignore_higher_layer_caching = true;
|
entry->ignore_higher_layer_caching = true;
|
||||||
|
|
||||||
// 2. Abort the image request for the current request and the pending request.
|
// 2. Abort the image request for the current request and the pending request.
|
||||||
m_current_request->abort(realm());
|
abort_the_image_request(realm(), m_current_request);
|
||||||
|
abort_the_image_request(realm(), m_pending_request);
|
||||||
// FIXME: Spec bug? Seems like pending request can be null here.
|
|
||||||
if (m_pending_request)
|
|
||||||
m_pending_request->abort(realm());
|
|
||||||
|
|
||||||
// 3. Set pending request to null.
|
// 3. Set pending request to null.
|
||||||
m_pending_request = nullptr;
|
m_pending_request = nullptr;
|
||||||
|
@ -379,11 +376,8 @@ after_step_6:
|
||||||
// abort the image request for the current request and the pending request,
|
// abort the image request for the current request and the pending request,
|
||||||
// and set pending request to null.
|
// and set pending request to null.
|
||||||
m_current_request->set_state(ImageRequest::State::Broken);
|
m_current_request->set_state(ImageRequest::State::Broken);
|
||||||
m_current_request->abort(realm());
|
abort_the_image_request(realm(), m_current_request);
|
||||||
|
abort_the_image_request(realm(), m_pending_request);
|
||||||
// FIXME: Spec bug? Seems like the image's pending request can be null here.
|
|
||||||
if (m_pending_request)
|
|
||||||
m_pending_request->abort(realm());
|
|
||||||
m_pending_request = nullptr;
|
m_pending_request = nullptr;
|
||||||
|
|
||||||
// 2. Queue an element task on the DOM manipulation task source given the img element and the following steps:
|
// 2. Queue an element task on the DOM manipulation task source given the img element and the following steps:
|
||||||
|
@ -406,11 +400,8 @@ after_step_6:
|
||||||
// If that is not successful, then:
|
// If that is not successful, then:
|
||||||
if (!url_string.is_valid()) {
|
if (!url_string.is_valid()) {
|
||||||
// 1. Abort the image request for the current request and the pending request.
|
// 1. Abort the image request for the current request and the pending request.
|
||||||
m_current_request->abort(realm());
|
abort_the_image_request(realm(), m_current_request);
|
||||||
|
abort_the_image_request(realm(), m_pending_request);
|
||||||
// FIXME: Spec bug? Seems like pending request can be null here.
|
|
||||||
if (m_pending_request)
|
|
||||||
m_pending_request->abort(realm());
|
|
||||||
|
|
||||||
// 2. Set the current request's state to broken.
|
// 2. Set the current request's state to broken.
|
||||||
m_current_request->set_state(ImageRequest::State::Broken);
|
m_current_request->set_state(ImageRequest::State::Broken);
|
||||||
|
@ -440,9 +431,7 @@ after_step_6:
|
||||||
// queue an element task on the DOM manipulation task source given the img element
|
// queue an element task on the DOM manipulation task source given the img element
|
||||||
// to restart the animation if restart animation is set, and return.
|
// to restart the animation if restart animation is set, and return.
|
||||||
if (url_string == m_current_request->current_url() && m_current_request->state() == ImageRequest::State::PartiallyAvailable) {
|
if (url_string == m_current_request->current_url() && m_current_request->state() == ImageRequest::State::PartiallyAvailable) {
|
||||||
// FIXME: Spec bug? Seems like pending request can be null here.
|
abort_the_image_request(realm(), m_pending_request);
|
||||||
if (m_pending_request)
|
|
||||||
m_pending_request->abort(realm());
|
|
||||||
if (restart_animations) {
|
if (restart_animations) {
|
||||||
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] {
|
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] {
|
||||||
restart_the_animation();
|
restart_the_animation();
|
||||||
|
@ -452,8 +441,7 @@ after_step_6:
|
||||||
}
|
}
|
||||||
|
|
||||||
// 14. If the pending request is not null, then abort the image request for the pending request.
|
// 14. If the pending request is not null, then abort the image request for the pending request.
|
||||||
if (m_pending_request)
|
abort_the_image_request(realm(), m_pending_request);
|
||||||
m_pending_request->abort(realm());
|
|
||||||
|
|
||||||
// 15. Set image request to a new image request whose current URL is urlString.
|
// 15. Set image request to a new image request whose current URL is urlString.
|
||||||
auto image_request = ImageRequest::create().release_value_but_fixme_should_propagate_errors();
|
auto image_request = ImageRequest::create().release_value_but_fixme_should_propagate_errors();
|
||||||
|
@ -587,7 +575,7 @@ void HTMLImageElement::handle_successful_fetch(AK::URL const& url_string, String
|
||||||
// upgrade the pending request to the current request
|
// upgrade the pending request to the current request
|
||||||
// and prepare image request for presentation given the img element.
|
// and prepare image request for presentation given the img element.
|
||||||
if (image_request == m_pending_request) {
|
if (image_request == m_pending_request) {
|
||||||
m_current_request->abort(realm());
|
abort_the_image_request(realm(), m_current_request);
|
||||||
upgrade_pending_request_to_current_request();
|
upgrade_pending_request_to_current_request();
|
||||||
image_request.prepare_for_presentation(*this);
|
image_request.prepare_for_presentation(*this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,17 +48,21 @@ void ImageRequest::set_current_url(AK::URL url)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/images.html#abort-the-image-request
|
// https://html.spec.whatwg.org/multipage/images.html#abort-the-image-request
|
||||||
void ImageRequest::abort(JS::Realm& realm)
|
void abort_the_image_request(JS::Realm& realm, ImageRequest* image_request)
|
||||||
{
|
{
|
||||||
// 1. Forget image request's image data, if any.
|
// 1. If image request is null, then return.
|
||||||
m_image_data = nullptr;
|
if (!image_request)
|
||||||
|
return;
|
||||||
|
|
||||||
// 2. Abort any instance of the fetching algorithm for image request,
|
// 2. Forget image request's image data, if any.
|
||||||
|
image_request->set_image_data(nullptr);
|
||||||
|
|
||||||
|
// 3. Abort any instance of the fetching algorithm for image request,
|
||||||
// discarding any pending tasks generated by that algorithm.
|
// discarding any pending tasks generated by that algorithm.
|
||||||
if (m_fetch_controller)
|
if (auto fetch_controller = image_request->fetch_controller())
|
||||||
m_fetch_controller->abort(realm, {});
|
fetch_controller->abort(realm, {});
|
||||||
|
|
||||||
m_fetch_controller = nullptr;
|
image_request->set_fetch_controller(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<DecodedImageData const> ImageRequest::image_data() const
|
RefPtr<DecodedImageData const> ImageRequest::image_data() const
|
||||||
|
@ -92,6 +96,11 @@ void ImageRequest::prepare_for_presentation(HTMLImageElement&)
|
||||||
// FIXME: 16. Update req's img element's presentation appropriately.
|
// FIXME: 16. Update req's img element's presentation appropriately.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JS::GCPtr<Fetch::Infrastructure::FetchController> ImageRequest::fetch_controller()
|
||||||
|
{
|
||||||
|
return m_fetch_controller.ptr();
|
||||||
|
}
|
||||||
|
|
||||||
void ImageRequest::set_fetch_controller(JS::GCPtr<Fetch::Infrastructure::FetchController> fetch_controller)
|
void ImageRequest::set_fetch_controller(JS::GCPtr<Fetch::Infrastructure::FetchController> fetch_controller)
|
||||||
{
|
{
|
||||||
m_fetch_controller = move(fetch_controller);
|
m_fetch_controller = move(fetch_controller);
|
||||||
|
|
|
@ -37,9 +37,6 @@ public:
|
||||||
AK::URL const& current_url() const;
|
AK::URL const& current_url() const;
|
||||||
void set_current_url(AK::URL);
|
void set_current_url(AK::URL);
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/images.html#abort-the-image-request
|
|
||||||
void abort(JS::Realm&);
|
|
||||||
|
|
||||||
[[nodiscard]] RefPtr<DecodedImageData const> image_data() const;
|
[[nodiscard]] RefPtr<DecodedImageData const> image_data() const;
|
||||||
void set_image_data(RefPtr<DecodedImageData const>);
|
void set_image_data(RefPtr<DecodedImageData const>);
|
||||||
|
|
||||||
|
@ -52,6 +49,7 @@ public:
|
||||||
// https://html.spec.whatwg.org/multipage/images.html#prepare-an-image-for-presentation
|
// https://html.spec.whatwg.org/multipage/images.html#prepare-an-image-for-presentation
|
||||||
void prepare_for_presentation(HTMLImageElement&);
|
void prepare_for_presentation(HTMLImageElement&);
|
||||||
|
|
||||||
|
[[nodiscard]] JS::GCPtr<Fetch::Infrastructure::FetchController> fetch_controller();
|
||||||
void set_fetch_controller(JS::GCPtr<Fetch::Infrastructure::FetchController>);
|
void set_fetch_controller(JS::GCPtr<Fetch::Infrastructure::FetchController>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -80,4 +78,7 @@ private:
|
||||||
JS::Handle<Fetch::Infrastructure::FetchController> m_fetch_controller;
|
JS::Handle<Fetch::Infrastructure::FetchController> m_fetch_controller;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/images.html#abort-the-image-request
|
||||||
|
void abort_the_image_request(JS::Realm&, ImageRequest*);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue