aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/window.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-07-10 08:23:34 -0400
committerGitHub <noreply@github.com>2018-07-10 08:23:34 -0400
commit8988d674d0cbea59eaaa8c80f36f29d214682a0b (patch)
treeb661e8bbf9be062af35f5d1eb8eda80de7918dfd /components/script/dom/window.rs
parent2bc70e738b01051a64f2183691e0abd9a0f84072 (diff)
parent671627e97e20ae4baf728ae6dda61ef6f857c193 (diff)
downloadservo-8988d674d0cbea59eaaa8c80f36f29d214682a0b.tar.gz
servo-8988d674d0cbea59eaaa8c80f36f29d214682a0b.zip
Auto merge of #21126 - gterzian:tasksource_specific_cancelation, r=jdm
Introduce "per task source" cancellation <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #21119 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/21126) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/window.rs')
-rw-r--r--components/script/dom/window.rs34
1 files changed, 25 insertions, 9 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index b536f28345f..d0d6e499639 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -109,6 +109,7 @@ use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::CssRuleType;
use style_traits::{CSSPixel, DevicePixel, ParsingMode};
use task::TaskCanceller;
+use task_source::TaskSourceName;
use task_source::dom_manipulation::DOMManipulationTaskSource;
use task_source::file_reading::FileReadingTaskSource;
use task_source::history_traversal::HistoryTraversalTaskSource;
@@ -246,9 +247,9 @@ pub struct Window {
current_viewport: Cell<Rect<Au>>,
- /// A flag to prevent async events from attempting to interact with this window.
+ /// 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<Arc<AtomicBool>>,
+ ignore_further_async_events: DomRefCell<HashMap<TaskSourceName, Arc<AtomicBool>>>,
error_reporter: CSSErrorReporter,
@@ -308,7 +309,15 @@ impl Window {
*self.js_runtime.borrow_for_script_deallocation() = None;
self.window_proxy.set(None);
self.current_state.set(WindowState::Zombie);
- self.ignore_further_async_events.borrow().store(true, Ordering::Relaxed);
+ self.ignore_all_events();
+ }
+ }
+
+ fn ignore_all_events(&self) {
+ let mut ignore_flags = self.ignore_further_async_events.borrow_mut();
+ for task_source_name in TaskSourceName::all() {
+ let flag = ignore_flags.entry(task_source_name).or_insert(Default::default());
+ flag.store(true, Ordering::Relaxed);
}
}
@@ -1065,9 +1074,11 @@ impl Window {
self.paint_worklet.or_init(|| self.new_paint_worklet())
}
- pub fn task_canceller(&self) -> TaskCanceller {
+ 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(self.ignore_further_async_events.borrow().clone()),
+ cancelled: Some(cancel_flag.clone()),
}
}
@@ -1084,8 +1095,12 @@ impl Window {
/// This sets the current `ignore_further_async_events` sentinel value to
/// `true` and replaces it with a brand new one for future tasks.
pub fn cancel_all_tasks(&self) {
- let cancelled = mem::replace(&mut *self.ignore_further_async_events.borrow_mut(), Default::default());
- cancelled.store(true, Ordering::Relaxed);
+ let mut ignore_flags = self.ignore_further_async_events.borrow_mut();
+ for task_source_name in TaskSourceName::all() {
+ let mut flag = ignore_flags.entry(task_source_name).or_insert(Default::default());
+ let cancelled = mem::replace(&mut *flag, Default::default());
+ cancelled.store(true, Ordering::Relaxed);
+ }
}
pub fn clear_js_runtime(&self) {
@@ -1117,7 +1132,7 @@ impl Window {
self.current_state.set(WindowState::Zombie);
*self.js_runtime.borrow_mut() = None;
self.window_proxy.set(None);
- self.ignore_further_async_events.borrow().store(true, Ordering::SeqCst);
+ self.ignore_all_events();
}
/// <https://drafts.csswg.org/cssom-view/#dom-window-scroll>
@@ -1998,9 +2013,10 @@ impl Window {
});
// FIXME(nox): Why are errors silenced here?
// TODO(#12718): Use the "posted message task source".
+ // TODO: When switching to the right task source, update the task_canceller call too.
let _ = self.script_chan.send(CommonScriptMsg::Task(
ScriptThreadEventCategory::DomEvent,
- Box::new(self.task_canceller().wrap_task(task)),
+ Box::new(self.task_canceller(TaskSourceName::DOMManipulation).wrap_task(task)),
self.pipeline_id()
));
}