mirror of
https://github.com/servo/servo.git
synced 2025-08-10 16:05:43 +01:00
Track hash changes in session history
Notify history changed on pushState and scroll to frag
This commit is contained in:
parent
c1cc2aaf9c
commit
61442cce4b
22 changed files with 110 additions and 87 deletions
|
@ -1063,6 +1063,10 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
FromScriptMsg::LoadComplete => {
|
||||
self.handle_load_complete_msg(source_top_ctx_id, source_pipeline_id)
|
||||
}
|
||||
// Handle navigating to a fragment
|
||||
FromScriptMsg::NavigatedToFragment(new_url, replacement_enabled) => {
|
||||
self.handle_navigated_to_fragment(source_pipeline_id, new_url, replacement_enabled);
|
||||
}
|
||||
// Handle a forward or back request
|
||||
FromScriptMsg::TraverseHistory(direction) => {
|
||||
self.handle_traverse_history_msg(source_top_ctx_id, direction);
|
||||
|
@ -1853,6 +1857,26 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
self.handle_subframe_loaded(pipeline_id);
|
||||
}
|
||||
|
||||
fn handle_navigated_to_fragment(&mut self, pipeline_id: PipelineId, new_url: ServoUrl, replacement_enabled: bool) {
|
||||
let (top_level_browsing_context_id, old_url) = match self.pipelines.get_mut(&pipeline_id) {
|
||||
Some(pipeline) => {
|
||||
let old_url = replace(&mut pipeline.url, new_url.clone());
|
||||
(pipeline.top_level_browsing_context_id, old_url)
|
||||
}
|
||||
None => return warn!("Pipeline {} navigated to fragment after closure", pipeline_id),
|
||||
};
|
||||
|
||||
if !replacement_enabled {
|
||||
let diff = SessionHistoryDiff::HashDiff {
|
||||
pipeline_reloader: NeedsToReload::No(pipeline_id),
|
||||
new_url,
|
||||
old_url,
|
||||
};
|
||||
self.get_joint_session_history(top_level_browsing_context_id).push_diff(diff);
|
||||
self.notify_history_changed(top_level_browsing_context_id);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_traverse_history_msg(&mut self,
|
||||
top_level_browsing_context_id: TopLevelBrowsingContextId,
|
||||
direction: TraversalDirection)
|
||||
|
@ -1874,7 +1898,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
match diff {
|
||||
SessionHistoryDiff::BrowsingContextDiff { browsing_context_id, ref new_reloader, .. } => {
|
||||
browsing_context_changes.insert(browsing_context_id, new_reloader.clone());
|
||||
}
|
||||
},
|
||||
SessionHistoryDiff::PipelineDiff {
|
||||
ref pipeline_reloader,
|
||||
new_history_state_id,
|
||||
|
@ -1883,10 +1907,23 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
} => match *pipeline_reloader {
|
||||
NeedsToReload::No(pipeline_id) => {
|
||||
pipeline_changes.insert(pipeline_id, (Some(new_history_state_id), new_url.clone()));
|
||||
}
|
||||
},
|
||||
NeedsToReload::Yes(pipeline_id, ..) => {
|
||||
url_to_load.insert(pipeline_id, new_url.clone());
|
||||
}
|
||||
},
|
||||
},
|
||||
SessionHistoryDiff::HashDiff {
|
||||
ref pipeline_reloader,
|
||||
ref new_url,
|
||||
..
|
||||
} => match *pipeline_reloader {
|
||||
NeedsToReload::No(pipeline_id) => {
|
||||
let state = pipeline_changes.get(&pipeline_id).and_then(|change| change.0);
|
||||
pipeline_changes.insert(pipeline_id, (state, new_url.clone()));
|
||||
},
|
||||
NeedsToReload::Yes(pipeline_id, ..) => {
|
||||
url_to_load.insert(pipeline_id, new_url.clone());
|
||||
},
|
||||
},
|
||||
}
|
||||
session_history.past.push(diff);
|
||||
|
@ -1912,10 +1949,23 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
} => match *pipeline_reloader {
|
||||
NeedsToReload::No(pipeline_id) => {
|
||||
pipeline_changes.insert(pipeline_id, (old_history_state_id, old_url.clone()));
|
||||
}
|
||||
},
|
||||
NeedsToReload::Yes(pipeline_id, ..) => {
|
||||
url_to_load.insert(pipeline_id, old_url.clone());
|
||||
}
|
||||
},
|
||||
},
|
||||
SessionHistoryDiff::HashDiff {
|
||||
ref pipeline_reloader,
|
||||
ref old_url,
|
||||
..
|
||||
} => match *pipeline_reloader {
|
||||
NeedsToReload::No(pipeline_id) => {
|
||||
let state = pipeline_changes.get(&pipeline_id).and_then(|change| change.0);
|
||||
pipeline_changes.insert(pipeline_id, (state, old_url.clone()));
|
||||
},
|
||||
NeedsToReload::Yes(pipeline_id, ..) => {
|
||||
url_to_load.insert(pipeline_id, old_url.clone());
|
||||
},
|
||||
},
|
||||
}
|
||||
session_history.future.push(diff);
|
||||
|
@ -2054,7 +2104,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
None => return warn!("Push history state {} for closed pipeline {}", history_state_id, pipeline_id),
|
||||
};
|
||||
|
||||
let session_history = self.get_joint_session_history(top_level_browsing_context_id);
|
||||
let diff = SessionHistoryDiff::PipelineDiff {
|
||||
pipeline_reloader: NeedsToReload::No(pipeline_id),
|
||||
new_history_state_id: history_state_id,
|
||||
|
@ -2062,7 +2111,8 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
old_history_state_id: old_state_id,
|
||||
old_url: old_url,
|
||||
};
|
||||
session_history.push_diff(diff);
|
||||
self.get_joint_session_history(top_level_browsing_context_id).push_diff(diff);
|
||||
self.notify_history_changed(top_level_browsing_context_id);
|
||||
}
|
||||
|
||||
fn handle_replace_history_state_msg(
|
||||
|
@ -2367,7 +2417,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
Some(previous_load_data.clone())
|
||||
}
|
||||
},
|
||||
SessionHistoryDiff::PipelineDiff { .. } => Some(previous_load_data.clone()),
|
||||
_ => Some(previous_load_data.clone()),
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2388,7 +2438,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
Some(previous_load_data.clone())
|
||||
}
|
||||
},
|
||||
SessionHistoryDiff::PipelineDiff { .. } => Some(previous_load_data.clone()),
|
||||
_ => Some(previous_load_data.clone()),
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2491,13 +2541,14 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
if let Some(pipeline_id) = new_reloader.alive_pipeline_id() {
|
||||
pipelines_to_close.push(pipeline_id);
|
||||
}
|
||||
}
|
||||
},
|
||||
SessionHistoryDiff::PipelineDiff { pipeline_reloader, new_history_state_id, .. } => {
|
||||
if let Some(pipeline_id) = pipeline_reloader.alive_pipeline_id() {
|
||||
let states = states_to_close.entry(pipeline_id).or_insert(Vec::new());
|
||||
states.push(new_history_state_id);
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue