mirror of
https://github.com/servo/servo.git
synced 2025-08-01 19:50:30 +01:00
Use BrowsingContextId for MediaSession registration
This commit is contained in:
parent
f8246801ba
commit
7101a9d070
2 changed files with 20 additions and 19 deletions
|
@ -14,7 +14,7 @@ use crate::dom::mediametadata::MediaMetadata;
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
use crate::script_thread::ScriptThread;
|
use crate::script_thread::ScriptThread;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::TopLevelBrowsingContextId;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
@ -28,22 +28,20 @@ pub struct MediaSession {
|
||||||
|
|
||||||
impl MediaSession {
|
impl MediaSession {
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
fn new_inherited(pipeline_id: PipelineId) -> MediaSession {
|
fn new_inherited(browsing_context_id: TopLevelBrowsingContextId) -> MediaSession {
|
||||||
let media_session = MediaSession {
|
let media_session = MediaSession {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
metadata: Default::default(),
|
metadata: Default::default(),
|
||||||
playback_state: DomRefCell::new(MediaSessionPlaybackState::None),
|
playback_state: DomRefCell::new(MediaSessionPlaybackState::None),
|
||||||
};
|
};
|
||||||
ScriptThread::register_media_session(&media_session, pipeline_id);
|
ScriptThread::register_media_session(&media_session, browsing_context_id);
|
||||||
media_session
|
media_session
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(window: &Window) -> DomRoot<MediaSession> {
|
pub fn new(window: &Window) -> DomRoot<MediaSession> {
|
||||||
let pipeline_id = window
|
let browsing_context_id = window.window_proxy().top_level_browsing_context_id();
|
||||||
.pipeline_id()
|
|
||||||
.expect("Cannot create MediaSession without a PipelineId");
|
|
||||||
reflect_dom_object(
|
reflect_dom_object(
|
||||||
Box::new(MediaSession::new_inherited(pipeline_id)),
|
Box::new(MediaSession::new_inherited(browsing_context_id)),
|
||||||
window,
|
window,
|
||||||
MediaSessionBinding::Wrap,
|
MediaSessionBinding::Wrap,
|
||||||
)
|
)
|
||||||
|
@ -83,10 +81,10 @@ impl MediaSessionMethods for MediaSession {
|
||||||
impl Drop for MediaSession {
|
impl Drop for MediaSession {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let global = self.global();
|
let global = self.global();
|
||||||
let pipeline_id = global
|
let browsing_context_id = global
|
||||||
.as_window()
|
.as_window()
|
||||||
.pipeline_id()
|
.window_proxy()
|
||||||
.expect("No PipelineId while dropping MediaSession");
|
.top_level_browsing_context_id();
|
||||||
ScriptThread::remove_media_session(pipeline_id);
|
ScriptThread::remove_media_session(browsing_context_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -698,10 +698,10 @@ pub struct ScriptThread {
|
||||||
/// Code is running as a consequence of a user interaction
|
/// Code is running as a consequence of a user interaction
|
||||||
is_user_interacting: Cell<bool>,
|
is_user_interacting: Cell<bool>,
|
||||||
|
|
||||||
/// The MediaSessions registered for this Pipeline, if any.
|
/// The MediaSessions known by this thread, if any.
|
||||||
/// There can only be one active MediaSession. The constellation
|
/// There can only be one active MediaSession.
|
||||||
/// has the PipelineId of the active MediaSession, if any.
|
/// The constellation has the BrowsingContextId of the active MediaSession, if any.
|
||||||
media_sessions: DomRefCell<HashMap<PipelineId, Dom<MediaSession>>>,
|
media_sessions: DomRefCell<HashMap<TopLevelBrowsingContextId, Dom<MediaSession>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// In the event of thread panic, all data on the stack runs its destructor. However, there
|
/// In the event of thread panic, all data on the stack runs its destructor. However, there
|
||||||
|
@ -3956,23 +3956,26 @@ impl ScriptThread {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_media_session(media_session: &MediaSession, pipeline_id: PipelineId) {
|
pub fn register_media_session(
|
||||||
|
media_session: &MediaSession,
|
||||||
|
browsing_context_id: TopLevelBrowsingContextId,
|
||||||
|
) {
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
let script_thread = unsafe { &*root.get().unwrap() };
|
let script_thread = unsafe { &*root.get().unwrap() };
|
||||||
script_thread
|
script_thread
|
||||||
.media_sessions
|
.media_sessions
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.insert(pipeline_id, Dom::from_ref(media_session));
|
.insert(browsing_context_id, Dom::from_ref(media_session));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_media_session(pipeline_id: PipelineId) {
|
pub fn remove_media_session(browsing_context_id: TopLevelBrowsingContextId) {
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
let script_thread = unsafe { &*root.get().unwrap() };
|
let script_thread = unsafe { &*root.get().unwrap() };
|
||||||
script_thread
|
script_thread
|
||||||
.media_sessions
|
.media_sessions
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.remove(&pipeline_id);
|
.remove(&browsing_context_id);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue