diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-11-16 09:54:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-16 09:54:40 -0500 |
commit | a2937d948818665ecda16a06fe6c8fa751d265fd (patch) | |
tree | 7c925d0d1517807e56963847da4c3ca25d7b2626 /components/script/dom/window.rs | |
parent | 050b2bca70b09a84901de84b4538f19da3250eee (diff) | |
parent | 75eb94afcaae2f868ecccba5b5dcea4066998d7a (diff) | |
download | servo-a2937d948818665ecda16a06fe6c8fa751d265fd.tar.gz servo-a2937d948818665ecda16a06fe6c8fa751d265fd.zip |
Auto merge of #21804 - AgustinCB:unify-task-source-canceller-api, r=gterzian
Unify the task source and task canceller API
To do so, I created a struct `TaskManagement(TaskSource,
TaskCanceller)` and made `*_task_source` return that instead of just
the task source.
Next, I refactored all places in which `task_canceller` by basically
removing them in favour of a previously called `*_task_source`.
I tried to make `task_canceller` a private method in `Window`, with the
hope of enforcing the use of `*_task_source`. However, it's used in
components/script/dom/globalscope.rs:575 in such a way that will make it
harder to avoid. I decided to leave it that way.
It'd be possible to unify `*_task_source` in such a way that we would
have only one method. However, I decided not to do it because one of the
`TaskSource` implementations is special:
`history_traversal_task_source`. Not wanting to over complicate things,
I decided to leave the structure this way.
---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21154 (github issue number if applicable).
- [x] These changes do not require tests because it's refactoring code that should already be tested.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21804)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/window.rs')
-rw-r--r-- | components/script/dom/window.rs | 119 |
1 files changed, 17 insertions, 102 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index e1a287df603..51c379145c2 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -64,16 +64,7 @@ use crate::script_runtime::{ }; use crate::script_thread::{ImageCacheMsg, MainThreadScriptChan, MainThreadScriptMsg}; use crate::script_thread::{ScriptThread, SendableMainThreadScriptChan}; -use crate::task::TaskCanceller; -use crate::task_source::dom_manipulation::DOMManipulationTaskSource; -use crate::task_source::file_reading::FileReadingTaskSource; -use crate::task_source::history_traversal::HistoryTraversalTaskSource; -use crate::task_source::media_element::MediaElementTaskSource; -use crate::task_source::networking::NetworkingTaskSource; -use crate::task_source::performance_timeline::PerformanceTimelineTaskSource; -use crate::task_source::remote_event::RemoteEventTaskSource; -use crate::task_source::user_interaction::UserInteractionTaskSource; -use crate::task_source::websocket::WebsocketTaskSource; +use crate::task_manager::TaskManager; use crate::task_source::TaskSourceName; use crate::timers::{IsInterval, TimerCallback}; use crate::webdriver_handlers::jsval_to_webdriver; @@ -127,7 +118,7 @@ use std::fs; use std::io::{stderr, stdout, Write}; use std::mem; use std::rc::Rc; -use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::atomic::Ordering; use std::sync::{Arc, Mutex}; use style::error_reporting::ParseErrorReporter; use style::media_queries; @@ -180,24 +171,7 @@ pub struct Window { globalscope: GlobalScope, #[ignore_malloc_size_of = "trait objects are hard"] script_chan: MainThreadScriptChan, - #[ignore_malloc_size_of = "task sources are hard"] - dom_manipulation_task_source: DOMManipulationTaskSource, - #[ignore_malloc_size_of = "task sources are hard"] - media_element_task_source: MediaElementTaskSource, - #[ignore_malloc_size_of = "task sources are hard"] - user_interaction_task_source: UserInteractionTaskSource, - #[ignore_malloc_size_of = "task sources are hard"] - networking_task_source: NetworkingTaskSource, - #[ignore_malloc_size_of = "task sources are hard"] - history_traversal_task_source: HistoryTraversalTaskSource, - #[ignore_malloc_size_of = "task sources are hard"] - file_reading_task_source: FileReadingTaskSource, - #[ignore_malloc_size_of = "task sources are hard"] - performance_timeline_task_source: PerformanceTimelineTaskSource, - #[ignore_malloc_size_of = "task sources are hard"] - remote_event_task_source: RemoteEventTaskSource, - #[ignore_malloc_size_of = "task sources are hard"] - websocket_task_source: WebsocketTaskSource, + task_manager: TaskManager, navigator: MutNullableDom<Navigator>, #[ignore_malloc_size_of = "Arc"] image_cache: Arc<ImageCache>, @@ -273,10 +247,6 @@ pub struct Window { current_viewport: Cell<Rect<Au>>, - /// A map of flags to prevent events from a given task source from attempting to interact with this window. - #[ignore_malloc_size_of = "defined in std"] - ignore_further_async_events: DomRefCell<HashMap<TaskSourceName, Arc<AtomicBool>>>, - error_reporter: CSSErrorReporter, /// A list of scroll offsets for each scrollable element. @@ -324,6 +294,10 @@ pub struct Window { } impl Window { + pub fn task_manager(&self) -> &TaskManager { + &self.task_manager + } + pub fn get_exists_mut_observer(&self) -> bool { self.exists_mut_observer.get() } @@ -343,7 +317,7 @@ impl Window { } fn ignore_all_events(&self) { - let mut ignore_flags = self.ignore_further_async_events.borrow_mut(); + let mut ignore_flags = self.task_manager.task_cancellers.borrow_mut(); for task_source_name in TaskSourceName::all() { let flag = ignore_flags .entry(task_source_name) @@ -365,42 +339,6 @@ impl Window { self.js_runtime.borrow().as_ref().unwrap().cx() } - pub fn dom_manipulation_task_source(&self) -> DOMManipulationTaskSource { - self.dom_manipulation_task_source.clone() - } - - pub fn media_element_task_source(&self) -> MediaElementTaskSource { - self.media_element_task_source.clone() - } - - pub fn user_interaction_task_source(&self) -> UserInteractionTaskSource { - self.user_interaction_task_source.clone() - } - - pub fn networking_task_source(&self) -> NetworkingTaskSource { - self.networking_task_source.clone() - } - - pub fn history_traversal_task_source(&self) -> Box<dyn ScriptChan + Send> { - self.history_traversal_task_source.clone() - } - - pub fn file_reading_task_source(&self) -> FileReadingTaskSource { - self.file_reading_task_source.clone() - } - - pub fn performance_timeline_task_source(&self) -> PerformanceTimelineTaskSource { - self.performance_timeline_task_source.clone() - } - - pub fn remote_event_task_source(&self) -> RemoteEventTaskSource { - self.remote_event_task_source.clone() - } - - pub fn websocket_task_source(&self) -> WebsocketTaskSource { - self.websocket_task_source.clone() - } - pub fn main_thread_script_chan(&self) -> &Sender<MainThreadScriptMsg> { &self.script_chan.0 } @@ -1234,14 +1172,6 @@ impl Window { self.paint_worklet.or_init(|| self.new_paint_worklet()) } - pub fn task_canceller(&self, name: TaskSourceName) -> TaskCanceller { - let mut flags = self.ignore_further_async_events.borrow_mut(); - let cancel_flag = flags.entry(name).or_insert(Default::default()); - TaskCanceller { - cancelled: Some(cancel_flag.clone()), - } - } - pub fn get_navigation_start(&self) -> u64 { self.navigation_start_precise.get() } @@ -1252,10 +1182,10 @@ impl Window { /// Cancels all the tasks associated with that window. /// - /// This sets the current `ignore_further_async_events` sentinel value to + /// This sets the current `task_manager.task_cancellers` sentinel value to /// `true` and replaces it with a brand new one for future tasks. pub fn cancel_all_tasks(&self) { - let mut ignore_flags = self.ignore_further_async_events.borrow_mut(); + let mut ignore_flags = self.task_manager.task_cancellers.borrow_mut(); for task_source_name in TaskSourceName::all() { let flag = ignore_flags .entry(task_source_name) @@ -1269,7 +1199,7 @@ impl Window { /// This sets the current sentinel value to /// `true` and replaces it with a brand new one for future tasks. pub fn cancel_all_tasks_from_source(&self, task_source_name: TaskSourceName) { - let mut ignore_flags = self.ignore_further_async_events.borrow_mut(); + let mut ignore_flags = self.task_manager.task_cancellers.borrow_mut(); let flag = ignore_flags .entry(task_source_name) .or_insert(Default::default()); @@ -1830,7 +1760,8 @@ impl Window { let _ = self.script_chan.send(CommonScriptMsg::Task( ScriptThreadEventCategory::DomEvent, Box::new( - self.task_canceller(TaskSourceName::DOMManipulation) + self.task_manager + .task_canceller(TaskSourceName::DOMManipulation) .wrap_task(task), ), self.pipeline_id(), @@ -2076,15 +2007,7 @@ impl Window { pub fn new( runtime: Rc<Runtime>, script_chan: MainThreadScriptChan, - dom_manipulation_task_source: DOMManipulationTaskSource, - media_element_task_source: MediaElementTaskSource, - user_interaction_task_source: UserInteractionTaskSource, - networking_task_source: NetworkingTaskSource, - history_traversal_task_source: HistoryTraversalTaskSource, - file_reading_task_source: FileReadingTaskSource, - performance_timeline_task_source: PerformanceTimelineTaskSource, - remote_event_task_source: RemoteEventTaskSource, - websocket_task_source: WebsocketTaskSource, + task_manager: TaskManager, image_cache_chan: Sender<ImageCacheMsg>, image_cache: Arc<dyn ImageCache>, resource_threads: ResourceThreads, @@ -2132,15 +2055,7 @@ impl Window { microtask_queue, ), script_chan, - dom_manipulation_task_source, - media_element_task_source, - user_interaction_task_source, - networking_task_source, - history_traversal_task_source, - file_reading_task_source, - performance_timeline_task_source, - remote_event_task_source, - websocket_task_source, + task_manager, image_cache_chan, image_cache, navigator: Default::default(), @@ -2173,7 +2088,6 @@ impl Window { devtools_marker_sender: Default::default(), devtools_markers: Default::default(), webdriver_script_chan: Default::default(), - ignore_further_async_events: Default::default(), error_reporter, scroll_offsets: Default::default(), media_query_lists: DOMTracker::new(), @@ -2314,7 +2228,8 @@ impl Window { let _ = self.script_chan.send(CommonScriptMsg::Task( ScriptThreadEventCategory::DomEvent, Box::new( - self.task_canceller(TaskSourceName::DOMManipulation) + self.task_manager + .task_canceller(TaskSourceName::DOMManipulation) .wrap_task(task), ), self.pipeline_id(), |