diff options
author | Paul Rouget <me@paulrouget.com> | 2019-09-13 13:11:28 +0200 |
---|---|---|
committer | Paul Rouget <me@paulrouget.com> | 2019-09-20 07:52:26 +0200 |
commit | ea7b58153723f7ef6a6fa2a9b73c71c3bf3295e0 (patch) | |
tree | 3e89d64513d44883d43ba78c606822ea604d4444 /components/script/script_thread.rs | |
parent | 9138d1dfed2dc2c28ab2af0052e009202a2ebc09 (diff) | |
download | servo-ea7b58153723f7ef6a6fa2a9b73c71c3bf3295e0.tar.gz servo-ea7b58153723f7ef6a6fa2a9b73c71c3bf3295e0.zip |
Do not allow XR session on non user-activated events
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r-- | components/script/script_thread.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 4cda69cdced..440de991ceb 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -690,6 +690,9 @@ pub struct ScriptThread { /// A set of all nodes ever created in this script thread node_ids: DomRefCell<HashSet<String>>, + + /// Code is running as a consequence of a user interaction + is_user_interacting: Cell<bool>, } /// In the event of thread panic, all data on the stack runs its destructor. However, there @@ -1030,6 +1033,24 @@ impl ScriptThread { }) } + pub fn set_user_interacting(interacting: bool) { + SCRIPT_THREAD_ROOT.with(|root| { + if let Some(script_thread) = root.get() { + let script_thread = unsafe { &*script_thread }; + script_thread.is_user_interacting.set(interacting); + } + }); + } + + pub fn is_user_interacting() -> bool { + SCRIPT_THREAD_ROOT.with(|root| { + root.get().map_or(false, |script_thread| { + let script_thread = unsafe { &*script_thread }; + script_thread.is_user_interacting.get() + }) + }) + } + pub fn get_fully_active_document_ids() -> HashSet<PipelineId> { SCRIPT_THREAD_ROOT.with(|root| { root.get().map_or(HashSet::new(), |script_thread| { @@ -1339,6 +1360,7 @@ impl ScriptThread { event_loop_waker: state.event_loop_waker, node_ids: Default::default(), + is_user_interacting: Cell::new(false), } } @@ -3356,6 +3378,9 @@ impl ScriptThread { /// /// TODO: Actually perform DOM event dispatch. fn handle_event(&self, pipeline_id: PipelineId, event: CompositorEvent) { + // Assuming all CompositionEvent are generated by user interactions. + ScriptThread::set_user_interacting(true); + match event { ResizeEvent(new_size, size_type) => { self.handle_resize_event(pipeline_id, new_size, size_type); @@ -3489,6 +3514,8 @@ impl ScriptThread { document.dispatch_composition_event(composition_event); }, } + + ScriptThread::set_user_interacting(false); } fn handle_mouse_event( |