aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/window.rs9
-rw-r--r--components/script/script_thread.rs36
2 files changed, 21 insertions, 24 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index c8e4ccc832d..cb9d5abdf07 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -1583,6 +1583,15 @@ impl Window {
pub fn evaluate_media_queries_and_report_changes(&self) {
self.media_query_lists.evaluate_and_report_changes();
}
+
+ /// Slow down/speed up timers based on visibility.
+ pub fn alter_resource_utilization(&self, visible: bool) {
+ if visible {
+ self.upcast::<GlobalScope>().speed_up_timers();
+ } else {
+ self.upcast::<GlobalScope>().slow_down_timers();
+ }
+ }
}
impl Window {
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index db9a53816a2..e7ada5377f4 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -1270,21 +1270,6 @@ impl ScriptThread {
reports_chan.send(reports);
}
- /// To slow/speed up timers and manage any other script thread resource based on visibility.
- /// Returns true if successful.
- fn alter_resource_utilization(&self, id: PipelineId, visible: bool) -> bool {
- let window = self.documents.borrow().find_window(id);
- if let Some(window) = window {
- if visible {
- window.upcast::<GlobalScope>().speed_up_timers();
- } else {
- window.upcast::<GlobalScope>().slow_down_timers();
- }
- return true;
- }
- false
- }
-
/// Updates iframe element after a change in visibility
fn handle_visibility_change_complete_msg(&self, parent_pipeline_id: PipelineId, id: FrameId, visible: bool) {
let iframe = self.documents.borrow().find_iframe(parent_pipeline_id, id);
@@ -1295,20 +1280,23 @@ impl ScriptThread {
/// Handle visibility change message
fn handle_visibility_change_msg(&self, id: PipelineId, visible: bool) {
- let resources_altered = self.alter_resource_utilization(id, visible);
-
// Separate message sent since parent script thread could be different (Iframe of different
// domain)
self.constellation_chan.send(ConstellationMsg::VisibilityChangeComplete(id, visible)).unwrap();
- if !resources_altered {
- let mut loads = self.incomplete_loads.borrow_mut();
- if let Some(ref mut load) = loads.iter_mut().find(|load| load.pipeline_id == id) {
- load.is_visible = visible;
+ let window = self.documents.borrow().find_window(id);
+ match window {
+ Some(window) => {
+ window.alter_resource_utilization(visible);
return;
}
- } else {
- return;
+ None => {
+ let mut loads = self.incomplete_loads.borrow_mut();
+ if let Some(ref mut load) = loads.iter_mut().find(|load| load.pipeline_id == id) {
+ load.is_visible = visible;
+ return;
+ }
+ }
}
warn!("change visibility message sent to nonexistent pipeline");
@@ -1863,7 +1851,7 @@ impl ScriptThread {
}
if !incomplete.is_visible {
- self.alter_resource_utilization(incomplete.pipeline_id, false);
+ window.alter_resource_utilization(false);
}
document.get_current_parser().unwrap()