mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:38:11 +00:00
LibWeb: Make HTML::ImageRequest GC allocated
This commit is contained in:
parent
333949894e
commit
bbfedf2e5a
4 changed files with 27 additions and 15 deletions
|
@ -57,7 +57,14 @@ void HTMLImageElement::initialize(JS::Realm& realm)
|
||||||
Base::initialize(realm);
|
Base::initialize(realm);
|
||||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLImageElementPrototype>(realm, "HTMLImageElement"));
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLImageElementPrototype>(realm, "HTMLImageElement"));
|
||||||
|
|
||||||
m_current_request = MUST(ImageRequest::create(*document().page()));
|
m_current_request = ImageRequest::create(realm, *document().page());
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTMLImageElement::visit_edges(Cell::Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
visitor.visit(m_current_request);
|
||||||
|
visitor.visit(m_pending_request);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLImageElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
void HTMLImageElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||||
|
@ -368,7 +375,7 @@ ErrorOr<void> HTMLImageElement::update_the_image_data(bool restart_animations, b
|
||||||
m_pending_request = nullptr;
|
m_pending_request = nullptr;
|
||||||
|
|
||||||
// 4. Let current request be a new image request whose image data is that of the entry and whose state is completely available.
|
// 4. Let current request be a new image request whose image data is that of the entry and whose state is completely available.
|
||||||
m_current_request = ImageRequest::create(*document().page()).release_value_but_fixme_should_propagate_errors();
|
m_current_request = ImageRequest::create(realm(), *document().page());
|
||||||
m_current_request->set_image_data(entry->image_data);
|
m_current_request->set_image_data(entry->image_data);
|
||||||
m_current_request->set_state(ImageRequest::State::CompletelyAvailable);
|
m_current_request->set_state(ImageRequest::State::CompletelyAvailable);
|
||||||
|
|
||||||
|
@ -495,7 +502,7 @@ after_step_7:
|
||||||
// multiple image elements (as well as CSS background-images, etc.)
|
// multiple image elements (as well as CSS background-images, etc.)
|
||||||
|
|
||||||
// 16. Set image request to a new image request whose current URL is urlString.
|
// 16. Set image request to a new image request whose current URL is urlString.
|
||||||
auto image_request = ImageRequest::create(*document().page()).release_value_but_fixme_should_propagate_errors();
|
auto image_request = ImageRequest::create(realm(), *document().page());
|
||||||
image_request->set_current_url(url_string);
|
image_request->set_current_url(url_string);
|
||||||
|
|
||||||
// 17. If current request's state is unavailable or broken, then set the current request to image request.
|
// 17. If current request's state is unavailable or broken, then set the current request to image request.
|
||||||
|
@ -513,7 +520,7 @@ after_step_7:
|
||||||
if (delay_load_event)
|
if (delay_load_event)
|
||||||
m_load_event_delayer.emplace(document());
|
m_load_event_delayer.emplace(document());
|
||||||
|
|
||||||
add_callbacks_to_image_request(image_request, maybe_omit_events, url_string, previous_url);
|
add_callbacks_to_image_request(*image_request, maybe_omit_events, url_string, previous_url);
|
||||||
|
|
||||||
// AD-HOC: If the image request is already available or fetching, no need to start another fetch.
|
// AD-HOC: If the image request is already available or fetching, no need to start another fetch.
|
||||||
if (image_request->is_available() || image_request->is_fetching())
|
if (image_request->is_available() || image_request->is_fetching())
|
||||||
|
@ -554,7 +561,7 @@ after_step_7:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLImageElement::add_callbacks_to_image_request(NonnullRefPtr<ImageRequest> image_request, bool maybe_omit_events, AK::URL const& url_string, AK::URL const& previous_url)
|
void HTMLImageElement::add_callbacks_to_image_request(JS::NonnullGCPtr<ImageRequest> image_request, bool maybe_omit_events, AK::URL const& url_string, AK::URL const& previous_url)
|
||||||
{
|
{
|
||||||
image_request->add_callbacks(
|
image_request->add_callbacks(
|
||||||
[this, image_request, maybe_omit_events, url_string, previous_url]() {
|
[this, image_request, maybe_omit_events, url_string, previous_url]() {
|
||||||
|
@ -690,7 +697,7 @@ void HTMLImageElement::react_to_changes_in_the_environment()
|
||||||
key.origin = document().origin();
|
key.origin = document().origin();
|
||||||
|
|
||||||
// 11. ⌛ Let image request be a new image request whose current URL is urlString
|
// 11. ⌛ Let image request be a new image request whose current URL is urlString
|
||||||
auto image_request = ImageRequest::create(*document().page()).release_value_but_fixme_should_propagate_errors();
|
auto image_request = ImageRequest::create(realm(), *document().page());
|
||||||
image_request->set_current_url(url_string);
|
image_request->set_current_url(url_string);
|
||||||
|
|
||||||
// 12. ⌛ Let the element's pending request be image request.
|
// 12. ⌛ Let the element's pending request be image request.
|
||||||
|
@ -698,7 +705,7 @@ void HTMLImageElement::react_to_changes_in_the_environment()
|
||||||
|
|
||||||
// FIXME: 13. End the synchronous section, continuing the remaining steps in parallel.
|
// FIXME: 13. End the synchronous section, continuing the remaining steps in parallel.
|
||||||
|
|
||||||
auto step_15 = [this](String const& selected_source, NonnullRefPtr<ImageRequest> const& image_request, ListOfAvailableImages::Key const& key, NonnullRefPtr<DecodedImageData> const& image_data) {
|
auto step_15 = [this](String const& selected_source, JS::NonnullGCPtr<ImageRequest> image_request, ListOfAvailableImages::Key const& key, NonnullRefPtr<DecodedImageData> const& image_data) {
|
||||||
// 15. Queue an element task on the DOM manipulation task source given the img element and the following steps:
|
// 15. Queue an element task on the DOM manipulation task source given the img element and the following steps:
|
||||||
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this, selected_source, image_request, key, image_data] {
|
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this, selected_source, image_request, key, image_data] {
|
||||||
// 1. FIXME: If the img element has experienced relevant mutations since this algorithm started, then let pending request be null and abort these steps.
|
// 1. FIXME: If the img element has experienced relevant mutations since this algorithm started, then let pending request be null and abort these steps.
|
||||||
|
@ -734,7 +741,7 @@ void HTMLImageElement::react_to_changes_in_the_environment()
|
||||||
// Continue to the next step.
|
// Continue to the next step.
|
||||||
if (auto entry = document().list_of_available_images().get(key)) {
|
if (auto entry = document().list_of_available_images().get(key)) {
|
||||||
image_request->set_image_data(entry->image_data);
|
image_request->set_image_data(entry->image_data);
|
||||||
step_15(selected_source.value(), image_request, key, entry->image_data);
|
step_15(selected_source.value(), *image_request, key, entry->image_data);
|
||||||
}
|
}
|
||||||
// Otherwise:
|
// Otherwise:
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -91,6 +91,8 @@ public:
|
||||||
|
|
||||||
JS::SafeFunction<void()> take_lazy_load_resumption_steps(Badge<DOM::Document>);
|
JS::SafeFunction<void()> take_lazy_load_resumption_steps(Badge<DOM::Document>);
|
||||||
|
|
||||||
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HTMLImageElement(DOM::Document&, DOM::QualifiedName);
|
HTMLImageElement(DOM::Document&, DOM::QualifiedName);
|
||||||
|
|
||||||
|
@ -105,7 +107,7 @@ private:
|
||||||
|
|
||||||
void handle_successful_fetch(AK::URL const&, StringView mime_type, ImageRequest&, ByteBuffer, bool maybe_omit_events, AK::URL const& previous_url);
|
void handle_successful_fetch(AK::URL const&, StringView mime_type, ImageRequest&, ByteBuffer, bool maybe_omit_events, AK::URL const& previous_url);
|
||||||
void handle_failed_fetch();
|
void handle_failed_fetch();
|
||||||
void add_callbacks_to_image_request(NonnullRefPtr<ImageRequest>, bool maybe_omit_events, AK::URL const& url_string, AK::URL const& previous_url);
|
void add_callbacks_to_image_request(JS::NonnullGCPtr<ImageRequest>, bool maybe_omit_events, AK::URL const& url_string, AK::URL const& previous_url);
|
||||||
|
|
||||||
void animate();
|
void animate();
|
||||||
|
|
||||||
|
@ -122,10 +124,10 @@ private:
|
||||||
Optional<String> m_last_selected_source;
|
Optional<String> m_last_selected_source;
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/images.html#current-request
|
// https://html.spec.whatwg.org/multipage/images.html#current-request
|
||||||
RefPtr<ImageRequest> m_current_request;
|
JS::GCPtr<ImageRequest> m_current_request;
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/images.html#pending-request
|
// https://html.spec.whatwg.org/multipage/images.html#pending-request
|
||||||
RefPtr<ImageRequest> m_pending_request;
|
JS::GCPtr<ImageRequest> m_pending_request;
|
||||||
|
|
||||||
SourceSet m_source_set;
|
SourceSet m_source_set;
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<ImageRequest>> ImageRequest::create(Page& page)
|
JS::NonnullGCPtr<ImageRequest> ImageRequest::create(JS::Realm& realm, Page& page)
|
||||||
{
|
{
|
||||||
return adopt_nonnull_ref_or_enomem(new (nothrow) ImageRequest(page));
|
return realm.heap().allocate<ImageRequest>(realm, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageRequest::ImageRequest(Page& page)
|
ImageRequest::ImageRequest(Page& page)
|
||||||
|
|
|
@ -17,9 +17,12 @@
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/images.html#image-request
|
// https://html.spec.whatwg.org/multipage/images.html#image-request
|
||||||
class ImageRequest : public RefCounted<ImageRequest> {
|
class ImageRequest final : public JS::Cell {
|
||||||
|
JS_CELL(ImageRequest, JS::Cell);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static ErrorOr<NonnullRefPtr<ImageRequest>> create(Page&);
|
[[nodiscard]] static JS::NonnullGCPtr<ImageRequest> create(JS::Realm&, Page&);
|
||||||
|
|
||||||
~ImageRequest();
|
~ImageRequest();
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/images.html#img-req-state
|
// https://html.spec.whatwg.org/multipage/images.html#img-req-state
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue