aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_thread.rs
diff options
context:
space:
mode:
authorFernando Jiménez Moreno <ferjmoreno@gmail.com>2019-11-12 22:09:39 +0100
committerFernando Jiménez Moreno <ferjmoreno@gmail.com>2019-11-20 13:34:29 +0100
commitb048d7faf717bb5ac90f02301b567b25d37681f3 (patch)
treea717bffa9cab78447eaccc1982e93d92a3d263ec /components/script/script_thread.rs
parent9da1dd359290bf59a0990a8664b58b5cfbb1f091 (diff)
downloadservo-b048d7faf717bb5ac90f02301b567b25d37681f3.tar.gz
servo-b048d7faf717bb5ac90f02301b567b25d37681f3.zip
Fix media session action handling
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r--components/script/script_thread.rs61
1 files changed, 8 insertions, 53 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 886977e1945..c0155ea63a5 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -51,7 +51,6 @@ use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlanchorelement::HTMLAnchorElement;
use crate::dom::htmliframeelement::{HTMLIFrameElement, NavigationType};
-use crate::dom::mediasession::MediaSession;
use crate::dom::mutationobserver::MutationObserver;
use crate::dom::node::{
from_untrusted_node_address, window_from_node, Node, NodeDamage, ShadowIncluding,
@@ -697,11 +696,6 @@ pub struct ScriptThread {
/// Code is running as a consequence of a user interaction
is_user_interacting: Cell<bool>,
-
- /// 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<BrowsingContextId, Dom<MediaSession>>>,
}
/// In the event of thread panic, all data on the stack runs its destructor. However, there
@@ -1371,7 +1365,6 @@ impl ScriptThread {
node_ids: Default::default(),
is_user_interacting: Cell::new(false),
- media_sessions: DomRefCell::new(HashMap::new()),
}
}
@@ -1950,8 +1943,8 @@ impl ScriptThread {
ConstellationControlMsg::PaintMetric(pipeline_id, metric_type, metric_value) => {
self.handle_paint_metric(pipeline_id, metric_type, metric_value)
},
- ConstellationControlMsg::MediaSessionAction(browsing_context_id, action) => {
- self.handle_media_session_action(browsing_context_id, action)
+ ConstellationControlMsg::MediaSessionAction(pipeline_id, action) => {
+ self.handle_media_session_action(pipeline_id, action)
},
msg @ ConstellationControlMsg::AttachLayout(..) |
msg @ ConstellationControlMsg::Viewport(..) |
@@ -3936,14 +3929,12 @@ impl ScriptThread {
}
}
- fn handle_media_session_action(
- &self,
- browsing_context_id: BrowsingContextId,
- action: MediaSessionActionType,
- ) {
- match self.media_sessions.borrow().get(&browsing_context_id) {
- Some(session) => session.handle_action(action),
- None => warn!("No MediaSession for this browsing context"),
+ fn handle_media_session_action(&self, pipeline_id: PipelineId, action: MediaSessionActionType) {
+ if let Some(window) = self.documents.borrow().find_window(pipeline_id) {
+ let media_session = window.Navigator().MediaSession();
+ media_session.handle_action(action);
+ } else {
+ warn!("No MediaSession for this pipeline ID");
};
}
@@ -3970,42 +3961,6 @@ impl ScriptThread {
globals,
)
}
-
- pub fn register_media_session(
- media_session: &MediaSession,
- browsing_context_id: BrowsingContextId,
- ) {
- SCRIPT_THREAD_ROOT.with(|root| {
- let script_thread = unsafe { &*root.get().unwrap() };
- script_thread
- .media_sessions
- .borrow_mut()
- .insert(browsing_context_id, Dom::from_ref(media_session));
- })
- }
-
- pub fn remove_media_session(browsing_context_id: BrowsingContextId) {
- SCRIPT_THREAD_ROOT.with(|root| {
- let script_thread = unsafe { &*root.get().unwrap() };
- script_thread
- .media_sessions
- .borrow_mut()
- .remove(&browsing_context_id);
- })
- }
-
- pub fn get_media_session(
- browsing_context_id: BrowsingContextId,
- ) -> Option<DomRoot<MediaSession>> {
- SCRIPT_THREAD_ROOT.with(|root| {
- let script_thread = unsafe { &*root.get().unwrap() };
- script_thread
- .media_sessions
- .borrow()
- .get(&browsing_context_id)
- .map(|s| DomRoot::from_ref(&**s))
- })
- }
}
impl Drop for ScriptThread {