mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Move active media session logic to constellation
This commit is contained in:
parent
08f9f17ed3
commit
85ec66b43e
7 changed files with 46 additions and 51 deletions
|
@ -16,9 +16,10 @@ use crate::dom::mediametadata::MediaMetadata;
|
|||
use crate::dom::window::Window;
|
||||
use crate::script_thread::ScriptThread;
|
||||
use dom_struct::dom_struct;
|
||||
use embedder_traits::{EmbedderMsg, MediaSessionEvent};
|
||||
use msg::constellation_msg::TopLevelBrowsingContextId;
|
||||
use embedder_traits::MediaSessionEvent;
|
||||
use msg::constellation_msg::BrowsingContextId;
|
||||
use script_traits::MediaSessionActionType;
|
||||
use script_traits::ScriptMsg;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
@ -39,7 +40,7 @@ pub struct MediaSession {
|
|||
|
||||
impl MediaSession {
|
||||
#[allow(unrooted_must_root)]
|
||||
fn new_inherited(browsing_context_id: TopLevelBrowsingContextId) -> MediaSession {
|
||||
fn new_inherited(browsing_context_id: BrowsingContextId) -> MediaSession {
|
||||
let media_session = MediaSession {
|
||||
reflector_: Reflector::new(),
|
||||
metadata: Default::default(),
|
||||
|
@ -52,7 +53,7 @@ impl MediaSession {
|
|||
}
|
||||
|
||||
pub fn new(window: &Window) -> DomRoot<MediaSession> {
|
||||
let browsing_context_id = window.window_proxy().top_level_browsing_context_id();
|
||||
let browsing_context_id = window.window_proxy().browsing_context_id();
|
||||
reflect_dom_object(
|
||||
Box::new(MediaSession::new_inherited(browsing_context_id)),
|
||||
window,
|
||||
|
@ -74,7 +75,8 @@ impl MediaSession {
|
|||
pub fn send_event(&self, event: MediaSessionEvent) {
|
||||
let global = self.global();
|
||||
let window = global.as_window();
|
||||
window.send_to_embedder(EmbedderMsg::MediaSessionEvent(event));
|
||||
let browsing_context_id = window.window_proxy().browsing_context_id();
|
||||
window.send_to_constellation(ScriptMsg::MediaSessionEvent(browsing_context_id, event));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,10 +123,7 @@ impl MediaSessionMethods for MediaSession {
|
|||
impl Drop for MediaSession {
|
||||
fn drop(&mut self) {
|
||||
let global = self.global();
|
||||
let browsing_context_id = global
|
||||
.as_window()
|
||||
.window_proxy()
|
||||
.top_level_browsing_context_id();
|
||||
let browsing_context_id = global.as_window().window_proxy().browsing_context_id();
|
||||
ScriptThread::remove_media_session(browsing_context_id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ impl NavigatorMethods for Navigator {
|
|||
/// https://w3c.github.io/mediasession/#dom-navigator-mediasession
|
||||
fn MediaSession(&self) -> DomRoot<MediaSession> {
|
||||
self.mediasession.or_init(|| {
|
||||
// There is a single MediaSession instance per top level browsing context
|
||||
// There is a single MediaSession instance per browsing context
|
||||
// and only one active MediaSession globally.
|
||||
//
|
||||
// MediaSession creation can happen in two cases:
|
||||
|
@ -206,7 +206,7 @@ impl NavigatorMethods for Navigator {
|
|||
// the script thread.
|
||||
let global = self.global();
|
||||
let window = global.as_window();
|
||||
let browsing_context_id = window.window_proxy().top_level_browsing_context_id();
|
||||
let browsing_context_id = window.window_proxy().browsing_context_id();
|
||||
match ScriptThread::get_media_session(browsing_context_id) {
|
||||
Some(session) => session,
|
||||
None => MediaSession::new(window),
|
||||
|
|
|
@ -701,7 +701,7 @@ pub struct ScriptThread {
|
|||
/// The MediaSessions known by this thread, if any.
|
||||
/// There can only be one active MediaSession.
|
||||
/// The constellation has the BrowsingContextId of the active MediaSession, if any.
|
||||
media_sessions: DomRefCell<HashMap<TopLevelBrowsingContextId, Dom<MediaSession>>>,
|
||||
media_sessions: DomRefCell<HashMap<BrowsingContextId, Dom<MediaSession>>>,
|
||||
}
|
||||
|
||||
/// In the event of thread panic, all data on the stack runs its destructor. However, there
|
||||
|
@ -3938,7 +3938,7 @@ impl ScriptThread {
|
|||
|
||||
fn handle_media_session_action(
|
||||
&self,
|
||||
browsing_context_id: TopLevelBrowsingContextId,
|
||||
browsing_context_id: BrowsingContextId,
|
||||
action: MediaSessionActionType,
|
||||
) {
|
||||
match self.media_sessions.borrow().get(&browsing_context_id) {
|
||||
|
@ -3973,7 +3973,7 @@ impl ScriptThread {
|
|||
|
||||
pub fn register_media_session(
|
||||
media_session: &MediaSession,
|
||||
browsing_context_id: TopLevelBrowsingContextId,
|
||||
browsing_context_id: BrowsingContextId,
|
||||
) {
|
||||
SCRIPT_THREAD_ROOT.with(|root| {
|
||||
let script_thread = unsafe { &*root.get().unwrap() };
|
||||
|
@ -3984,7 +3984,7 @@ impl ScriptThread {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn remove_media_session(browsing_context_id: TopLevelBrowsingContextId) {
|
||||
pub fn remove_media_session(browsing_context_id: BrowsingContextId) {
|
||||
SCRIPT_THREAD_ROOT.with(|root| {
|
||||
let script_thread = unsafe { &*root.get().unwrap() };
|
||||
script_thread
|
||||
|
@ -3995,7 +3995,7 @@ impl ScriptThread {
|
|||
}
|
||||
|
||||
pub fn get_media_session(
|
||||
browsing_context_id: TopLevelBrowsingContextId,
|
||||
browsing_context_id: BrowsingContextId,
|
||||
) -> Option<DomRoot<MediaSession>> {
|
||||
SCRIPT_THREAD_ROOT.with(|root| {
|
||||
let script_thread = unsafe { &*root.get().unwrap() };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue