diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-01-27 16:30:37 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-27 16:30:37 -0800 |
commit | b5c94bad371114ab9f03e910f66c00a042997fc2 (patch) | |
tree | 46aec036b4e1681f7d22762817b3afd3a615a7e0 /components/script/script_thread.rs | |
parent | d4ee8a3599a57078735766640b31df31c67d8201 (diff) | |
parent | ca9cee084e5ee8282c5d074f763b23936efc394f (diff) | |
download | servo-b5c94bad371114ab9f03e910f66c00a042997fc2.tar.gz servo-b5c94bad371114ab9f03e910f66c00a042997fc2.zip |
Auto merge of #14971 - asajeffrey:script-track-active-documents, r=cbrewster
Constellation informs script about documents becoming inactive, active or fully active.
<!-- Please describe your changes on the following line: -->
This PR replaces the current freeze/thaw mechanism by messages from the constellation to script informing it about when documents become inactive, active or fully active.
This means we can now implement |Document::is_active()| which is used in |document.write|.
This PR also changes how timers work: previously they were initialized running, and were then frozen/thawed. This means there was a transitory period when timers were running even though the document was not fully active. With this PR, timers are initially suspended, and are only resumed when the document is made fully active.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14876
- [X] These changes do not require tests because it's an interal refactoring.
<!-- 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/14971)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r-- | components/script/script_thread.rs | 53 |
1 files changed, 16 insertions, 37 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 9bab1679aa6..2bdb75a486f 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -83,7 +83,8 @@ use profile_traits::time::{self, ProfilerCategory, profile}; use script_layout_interface::message::{self, NewLayoutThreadInfo, ReflowQueryType}; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory, EnqueuedPromiseCallback}; use script_runtime::{ScriptPort, StackRootTLS, get_reports, new_rt_and_cx, PromiseJobQueue}; -use script_traits::{CompositorEvent, ConstellationControlMsg, DiscardBrowsingContext, EventResult}; +use script_traits::{CompositorEvent, ConstellationControlMsg}; +use script_traits::{DocumentActivity, DiscardBrowsingContext, EventResult}; use script_traits::{InitialScriptState, LayoutMsg, LoadData, MouseButton, MouseEventType, MozBrowserEvent}; use script_traits::{NewLayoutInfo, ScriptMsg as ConstellationMsg}; use script_traits::{ScriptThreadFactory, TimerEvent, TimerEventRequest, TimerSource}; @@ -148,8 +149,8 @@ struct InProgressLoad { window_size: Option<WindowSizeData>, /// Channel to the layout thread associated with this pipeline. layout_chan: Sender<message::Msg>, - /// Window is frozen (navigated away while loading for example). - is_frozen: bool, + /// The activity level of the document (inactive, active or fully active). + activity: DocumentActivity, /// Window is visible. is_visible: bool, /// The requested URL of the load. @@ -172,7 +173,7 @@ impl InProgressLoad { parent_info: parent_info, layout_chan: layout_chan, window_size: window_size, - is_frozen: false, + activity: DocumentActivity::FullyActive, is_visible: true, url: url, origin: origin, @@ -963,10 +964,8 @@ impl ScriptThread { self.handle_resize_inactive_msg(id, new_size), ConstellationControlMsg::GetTitle(pipeline_id) => self.handle_get_title_msg(pipeline_id), - ConstellationControlMsg::Freeze(pipeline_id) => - self.handle_freeze_msg(pipeline_id), - ConstellationControlMsg::Thaw(pipeline_id) => - self.handle_thaw_msg(pipeline_id), + ConstellationControlMsg::SetDocumentActivity(pipeline_id, activity) => + self.handle_set_document_activity_msg(pipeline_id, activity), ConstellationControlMsg::ChangeFrameVisibilityStatus(pipeline_id, visible) => self.handle_visibility_change_msg(pipeline_id, visible), ConstellationControlMsg::NotifyVisibilityChange(parent_pipeline_id, frame_id, visible) => @@ -1303,37 +1302,20 @@ impl ScriptThread { warn!("change visibility message sent to nonexistent pipeline"); } - /// Handles freeze message - fn handle_freeze_msg(&self, id: PipelineId) { + /// Handles activity change message + fn handle_set_document_activity_msg(&self, id: PipelineId, activity: DocumentActivity) { + debug!("Setting activity of {} to be {:?}.", id, activity); let document = self.documents.borrow().find_document(id); if let Some(document) = document { - document.window().freeze(); - document.fully_deactivate(); + document.set_activity(activity); return; } 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_frozen = true; + load.activity = activity; return; } - warn!("freeze sent to nonexistent pipeline"); - } - - /// Handles thaw message - fn handle_thaw_msg(&self, id: PipelineId) { - let document = self.documents.borrow().find_document(id); - if let Some(document) = document { - self.rebuild_and_force_reflow(&document, ReflowReason::CachedPageNeededReflow); - document.window().thaw(); - document.fully_activate(); - return; - } - 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_frozen = false; - return; - } - warn!("thaw sent to nonexistent pipeline"); + warn!("change of activity sent to nonexistent pipeline"); } fn handle_focus_iframe_msg(&self, @@ -1759,16 +1741,13 @@ impl ScriptThread { is_html_document, content_type, last_modified, + incomplete.activity, DocumentSource::FromParser, loader, referrer, referrer_policy); document.set_ready_state(DocumentReadyState::Loading); - if !incomplete.is_frozen { - document.fully_activate(); - } - self.documents.borrow_mut().insert(incomplete.pipeline_id, &*document); window.init_document(&document); @@ -1822,8 +1801,8 @@ impl ScriptThread { ServoParser::parse_html_document(&document, parse_input, final_url); } - if incomplete.is_frozen { - window.upcast::<GlobalScope>().suspend(); + if incomplete.activity != DocumentActivity::FullyActive { + window.suspend(); } if !incomplete.is_visible { |