Auto merge of #15091 - cbrewster:frame_state_consistency, r=asajeffrey

Ensure FrameState consistency

<!-- Please describe your changes on the following line: -->
As we begin to add more state to `FrameState`, we need to make sure that when we do replacements and when we finish traversals that the state is properly updated. This also fixes an issue where we were not updating the `url` of the `FrameState` when navigating with replacement enabled (I wonder if it would be possible to write a test to detect this. The url only matters when reloading a document after it was discarded by the max session history).

---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/15091)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-01-18 07:47:54 -08:00 committed by GitHub
commit 68fa988bf3
2 changed files with 18 additions and 4 deletions

View file

@ -2033,9 +2033,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
debug_assert_eq!(entry.instant, curr_entry.instant); debug_assert_eq!(entry.instant, curr_entry.instant);
frame.pipeline_id = pipeline_id; frame.update_current(pipeline_id, &entry);
frame.instant = entry.instant;
frame.url = entry.url.clone();
old_pipeline_id old_pipeline_id
}, },
@ -2130,7 +2128,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
let (evicted_id, new_frame, clear_future, location_changed) = if let Some(mut entry) = frame_change.replace { let (evicted_id, new_frame, clear_future, location_changed) = if let Some(mut entry) = frame_change.replace {
debug!("Replacing pipeline in existing frame."); debug!("Replacing pipeline in existing frame.");
let evicted_id = entry.pipeline_id; let evicted_id = entry.pipeline_id;
entry.pipeline_id = Some(frame_change.new_pipeline_id); entry.replace_pipeline(frame_change.new_pipeline_id, frame_change.url.clone());
self.traverse_to_entry(entry); self.traverse_to_entry(entry);
(evicted_id, false, false, false) (evicted_id, false, false, false)
} else if let Some(frame) = self.frames.get_mut(&frame_change.frame_id) { } else if let Some(frame) = self.frames.get_mut(&frame_change.frame_id) {

View file

@ -76,6 +76,13 @@ impl Frame {
pub fn remove_forward_entries(&mut self) -> Vec<FrameState> { pub fn remove_forward_entries(&mut self) -> Vec<FrameState> {
replace(&mut self.next, vec!()) replace(&mut self.next, vec!())
} }
/// Update the current entry of the Frame from an entry that has been traversed to.
pub fn update_current(&mut self, pipeline_id: PipelineId, entry: &FrameState) {
self.pipeline_id = pipeline_id;
self.instant = entry.instant;
self.url = entry.url.clone();
}
} }
/// An entry in a frame's session history. /// An entry in a frame's session history.
@ -99,6 +106,15 @@ pub struct FrameState {
pub frame_id: FrameId, pub frame_id: FrameId,
} }
impl FrameState {
/// Updates the entry's pipeline and url. This is used when navigating with replacement
/// enabled.
pub fn replace_pipeline(&mut self, pipeline_id: PipelineId, url: ServoUrl) {
self.pipeline_id = Some(pipeline_id);
self.url = url;
}
}
/// Represents a pending change in the frame tree, that will be applied /// Represents a pending change in the frame tree, that will be applied
/// once the new pipeline has loaded and completed initial layout / paint. /// once the new pipeline has loaded and completed initial layout / paint.
pub struct FrameChange { pub struct FrameChange {