diff options
author | Ms2ger <Ms2ger@gmail.com> | 2017-01-24 17:55:00 +0100 |
---|---|---|
committer | Ms2ger <Ms2ger@gmail.com> | 2017-01-26 16:57:00 +0100 |
commit | a689cf1d34067bbeb127bf32520ef3b027d01e49 (patch) | |
tree | 12e1d01192cb8b54bdb0086002ec17393538fb0a | |
parent | c3f0c9054feb97f4b3c106393930887d9841df1f (diff) | |
download | servo-a689cf1d34067bbeb127bf32520ef3b027d01e49.tar.gz servo-a689cf1d34067bbeb127bf32520ef3b027d01e49.zip |
Refactor away ScriptThread::alter_resource_utilization().
It's used in two places, one of which already has access to the Window.
-rw-r--r-- | components/script/dom/window.rs | 9 | ||||
-rw-r--r-- | components/script/script_thread.rs | 36 |
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() |