mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00: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::script_thread::ScriptThread;
|
||||
use dom_struct::dom_struct;
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use msg::constellation_msg::TopLevelBrowsingContextId;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -28,22 +28,20 @@ pub struct MediaSession {
|
|||
|
||||
impl MediaSession {
|
||||
#[allow(unrooted_must_root)]
|
||||
fn new_inherited(pipeline_id: PipelineId) -> MediaSession {
|
||||
fn new_inherited(browsing_context_id: TopLevelBrowsingContextId) -> MediaSession {
|
||||
let media_session = MediaSession {
|
||||
reflector_: Reflector::new(),
|
||||
metadata: Default::default(),
|
||||
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
|
||||
}
|
||||
|
||||
pub fn new(window: &Window) -> DomRoot<MediaSession> {
|
||||
let pipeline_id = window
|
||||
.pipeline_id()
|
||||
.expect("Cannot create MediaSession without a PipelineId");
|
||||
let browsing_context_id = window.window_proxy().top_level_browsing_context_id();
|
||||
reflect_dom_object(
|
||||
Box::new(MediaSession::new_inherited(pipeline_id)),
|
||||
Box::new(MediaSession::new_inherited(browsing_context_id)),
|
||||
window,
|
||||
MediaSessionBinding::Wrap,
|
||||
)
|
||||
|
@ -83,10 +81,10 @@ impl MediaSessionMethods for MediaSession {
|
|||
impl Drop for MediaSession {
|
||||
fn drop(&mut self) {
|
||||
let global = self.global();
|
||||
let pipeline_id = global
|
||||
let browsing_context_id = global
|
||||
.as_window()
|
||||
.pipeline_id()
|
||||
.expect("No PipelineId while dropping MediaSession");
|
||||
ScriptThread::remove_media_session(pipeline_id);
|
||||
.window_proxy()
|
||||
.top_level_browsing_context_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
|
||||
is_user_interacting: Cell<bool>,
|
||||
|
||||
/// The MediaSessions registered for this Pipeline, if any.
|
||||
/// There can only be one active MediaSession. The constellation
|
||||
/// has the PipelineId of the active MediaSession, if any.
|
||||
media_sessions: DomRefCell<HashMap<PipelineId, Dom<MediaSession>>>,
|
||||
/// 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>>>,
|
||||
}
|
||||
|
||||
/// 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| {
|
||||
let script_thread = unsafe { &*root.get().unwrap() };
|
||||
script_thread
|
||||
.media_sessions
|
||||
.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| {
|
||||
let script_thread = unsafe { &*root.get().unwrap() };
|
||||
script_thread
|
||||
.media_sessions
|
||||
.borrow_mut()
|
||||
.remove(&pipeline_id);
|
||||
.remove(&browsing_context_id);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue