mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
LibWeb: Pause HTMLMediaElement when its document becomes inactive
For example, when navigating to another page, this ensures any media resource will not continue playing.
This commit is contained in:
parent
f78eadf00f
commit
ac8b892a25
Notes:
sideshowbarker
2024-07-17 17:40:13 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/ac8b892a25 Pull-request: https://github.com/SerenityOS/serenity/pull/18638 Reviewed-by: https://github.com/awesomekling
@ -10,6 +10,7 @@
|
||||
#include <LibWeb/Bindings/HTMLMediaElementPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/DocumentObserver.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/Fetch/Fetching/Fetching.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
|
||||
@ -46,6 +47,14 @@ JS::ThrowCompletionOr<void> HTMLMediaElement::initialize(JS::Realm& realm)
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLMediaElementPrototype>(realm, "HTMLMediaElement"));
|
||||
|
||||
m_video_tracks = TRY(realm.heap().allocate<VideoTrackList>(realm, realm));
|
||||
m_document_observer = TRY(realm.heap().allocate<DOM::DocumentObserver>(realm, realm, document()));
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#playing-the-media-resource:media-element-82
|
||||
m_document_observer->document_became_inactive = [this]() {
|
||||
// If the media element's node document stops being a fully active document, then the playback will stop until
|
||||
// the document is active again.
|
||||
pause_element().release_value_but_fixme_should_propagate_errors();
|
||||
};
|
||||
|
||||
return {};
|
||||
}
|
||||
@ -64,6 +73,7 @@ void HTMLMediaElement::visit_edges(Cell::Visitor& visitor)
|
||||
visitor.visit(m_error);
|
||||
visitor.visit(m_fetch_controller);
|
||||
visitor.visit(m_video_tracks);
|
||||
visitor.visit(m_document_observer);
|
||||
}
|
||||
|
||||
void HTMLMediaElement::parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value)
|
||||
|
@ -208,6 +208,8 @@ private:
|
||||
bool m_running_time_update_event_handler { false };
|
||||
Optional<Time> m_last_time_update_event_time;
|
||||
|
||||
JS::GCPtr<DOM::DocumentObserver> m_document_observer;
|
||||
|
||||
JS::GCPtr<Fetch::Infrastructure::FetchController> m_fetch_controller;
|
||||
|
||||
bool m_seek_in_progress = false;
|
||||
|
Loading…
Reference in New Issue
Block a user