Add mozbrowser events for location + title change.

This commit is contained in:
Glenn Watson 2015-03-24 11:09:58 +10:00
parent da2231a8fa
commit 7163a3c580
6 changed files with 83 additions and 23 deletions

View file

@ -606,6 +606,10 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
script_chan.send(ConstellationControlMsg::UpdateSubpageId(parent_pipeline_id,
subpage_id,
new_subpage_id)).unwrap();
// If this is an iframe, send a mozbrowser location change event.
// This is the result of a back/forward navigation.
self.trigger_mozbrowserlocationchange(next_pipeline_id);
}
}
@ -637,7 +641,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
}
fn handle_mozbrowser_event_msg(&mut self,
pipeline_id: PipelineId,
containing_pipeline_id: PipelineId,
subpage_id: SubpageId,
event_name: String,
event_detail: Option<String>) {
@ -645,13 +649,8 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
// Find the script channel for the given parent pipeline,
// and pass the event to that script task.
let pipeline = self.pipeline(pipeline_id);
let ScriptControlChan(ref script_channel) = pipeline.script_chan;
let event = ConstellationControlMsg::MozBrowserEvent(pipeline_id,
subpage_id,
event_name,
event_detail);
script_channel.send(event).unwrap();
let pipeline = self.pipeline(containing_pipeline_id);
pipeline.trigger_mozbrowser_event(subpage_id, event_name, event_detail);
}
fn add_or_replace_pipeline_in_frame_tree(&mut self, frame_change: FrameChange) {
@ -692,6 +691,10 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
// Build frame tree and send permission
self.send_frame_tree_and_grant_paint_permission();
// If this is an iframe, send a mozbrowser location change event.
// This is the result of a link being clicked and a navigation completing.
self.trigger_mozbrowserlocationchange(frame_change.new_pipeline_id);
// Remove any evicted frames
if let Some(evicted_frames) = evicted_frames {
for pipeline_id in &evicted_frames {
@ -862,6 +865,28 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
}
}
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserlocationchange
fn trigger_mozbrowserlocationchange(&self, pipeline_id: PipelineId) {
if opts::experimental_enabled() {
// Work around borrow checker
let event_info = {
let pipeline = self.pipeline(pipeline_id);
pipeline.parent_info.map(|(containing_pipeline_id, subpage_id)| {
(containing_pipeline_id, subpage_id, pipeline.url.serialize())
})
};
// If this is an iframe, then send the event with new url
if let Some((containing_pipeline_id, subpage_id, url)) = event_info {
let parent_pipeline = self.pipeline(containing_pipeline_id);
parent_pipeline.trigger_mozbrowser_event(subpage_id,
"mozbrowserlocationchange".to_owned(),
Some(url));
}
}
}
fn pipeline_is_in_current_frame(&self, pipeline_id: PipelineId) -> bool {
self.current_frame_tree_iter(self.root_frame_id)
.any(|current_frame| current_frame.current == pipeline_id)