LibWeb: Store the ID of all media elements on a page

This will be used to inform the media elements when the user has muted
the page.
This commit is contained in:
Timothy Flynn 2024-03-30 09:38:00 -04:00 committed by Andreas Kling
parent 9fc8c37414
commit 7c31343df0
4 changed files with 24 additions and 0 deletions

View file

@ -65,6 +65,13 @@ void HTMLMediaElement::initialize(JS::Realm& realm)
// the document is active again.
pause_element().release_value_but_fixme_should_propagate_errors();
});
document().page().register_media_element({}, unique_id());
}
void HTMLMediaElement::finalize()
{
document().page().unregister_media_element({}, unique_id());
}
// https://html.spec.whatwg.org/multipage/media.html#queue-a-media-element-task

View file

@ -132,6 +132,7 @@ protected:
HTMLMediaElement(DOM::Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
virtual void finalize() override;
virtual void visit_edges(Cell::Visitor&) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;

View file

@ -390,6 +390,18 @@ void Page::select_dropdown_closed(Optional<String> value)
}
}
void Page::register_media_element(Badge<HTML::HTMLMediaElement>, int media_id)
{
m_media_elements.append(media_id);
}
void Page::unregister_media_element(Badge<HTML::HTMLMediaElement>, int media_id)
{
m_media_elements.remove_all_matching([&](auto candidate_id) {
return candidate_id == media_id;
});
}
void Page::did_request_media_context_menu(i32 media_id, CSSPixelPoint position, ByteString const& target, unsigned modifiers, MediaContextMenu menu)
{
m_media_context_menu_element_id = media_id;

View file

@ -150,6 +150,9 @@ public:
Select,
};
void register_media_element(Badge<HTML::HTMLMediaElement>, int media_id);
void unregister_media_element(Badge<HTML::HTMLMediaElement>, int media_id);
struct MediaContextMenu {
URL::URL media_url;
bool is_video { false };
@ -204,6 +207,7 @@ private:
PendingNonBlockingDialog m_pending_non_blocking_dialog { PendingNonBlockingDialog::None };
WeakPtr<HTML::HTMLElement> m_pending_non_blocking_dialog_target;
Vector<int> m_media_elements;
Optional<int> m_media_context_menu_element_id;
Optional<String> m_user_style_sheet_source;