Add TopLevelBrowsingContextId to messages between Embedder <-> Compositor <-> Constellation

This commit is contained in:
Paul Rouget 2017-07-18 08:16:45 +02:00
parent 16704bbaaa
commit 899aa0c371
6 changed files with 148 additions and 160 deletions

View file

@ -807,9 +807,8 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
}
fn add_pending_change(&mut self, change: SessionHistoryChange)
{
self.handle_load_start_msg(change.new_pipeline_id);
fn add_pending_change(&mut self, change: SessionHistoryChange) {
self.handle_load_start_msg(change.top_level_browsing_context_id, change.new_pipeline_id);
self.pending_changes.push(change);
}
@ -934,9 +933,15 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
// Load a new page from a typed url
// If there is already a pending page (self.pending_changes), it will not be overridden;
// However, if the id is not encompassed by another change, it will be.
FromCompositorMsg::LoadUrl(source_id, load_data) => {
FromCompositorMsg::LoadUrl(top_level_browsing_context_id, url) => {
debug!("constellation got URL load message from compositor");
self.handle_load_url_msg(source_id, load_data, false);
let load_data = LoadData::new(url, None, None, None);
let ctx_id = BrowsingContextId::from(top_level_browsing_context_id);
let pipeline_id = match self.browsing_contexts.get(&ctx_id) {
Some(ctx) => ctx.pipeline_id,
None => return warn!("LoadUrl for unknow browsing context: {:?}", top_level_browsing_context_id),
};
self.handle_load_url_msg(top_level_browsing_context_id, pipeline_id, load_data, false);
}
FromCompositorMsg::IsReadyToSaveImage(pipeline_states) => {
let is_ready = self.handle_is_ready_to_save_image(pipeline_states);
@ -1718,14 +1723,17 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
}
fn handle_load_url_msg(&mut self, source_id: PipelineId, load_data: LoadData, replace: bool) {
self.load_url(source_id, load_data, replace);
fn handle_load_url_msg(&mut self, top_level_browsing_context_id: TopLevelBrowsingContextId, source_id: PipelineId,
load_data: LoadData, replace: bool) {
self.load_url(top_level_browsing_context_id, source_id, load_data, replace);
}
fn load_url(&mut self, source_id: PipelineId, load_data: LoadData, replace: bool) -> Option<PipelineId> {
fn load_url(&mut self, top_level_browsing_context_id: TopLevelBrowsingContextId, source_id: PipelineId,
load_data: LoadData, replace: bool) -> Option<PipelineId> {
// Allow the embedder to handle the url itself
let (chan, port) = ipc::channel().expect("Failed to create IPC channel!");
self.compositor_proxy.send(ToCompositorMsg::AllowNavigation(load_data.url.clone(), chan));
let msg = ToCompositorMsg::AllowNavigation(top_level_browsing_context_id, load_data.url.clone(), chan);
self.compositor_proxy.send(msg);
if let Ok(false) = port.recv() {
return None;
}
@ -1815,11 +1823,16 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
}
fn handle_load_start_msg(&mut self, _pipeline_id: PipelineId) {
self.compositor_proxy.send(ToCompositorMsg::LoadStart);
fn handle_load_start_msg(&mut self, top_level_browsing_context_id: TopLevelBrowsingContextId,
pipeline_id: PipelineId) {
if self.pipelines.get(&pipeline_id).and_then(|p| p.parent_info).is_none() {
// Notify embedder top level document started loading.
self.compositor_proxy.send(ToCompositorMsg::LoadStart(top_level_browsing_context_id));
}
}
fn handle_load_complete_msg(&mut self, pipeline_id: PipelineId) {
fn handle_load_complete_msg(&mut self, top_level_browsing_context_id: TopLevelBrowsingContextId,
pipeline_id: PipelineId) {
let mut webdriver_reset = false;
if let Some((expected_pipeline_id, ref reply_chan)) = self.webdriver.load_channel {
debug!("Sending load to WebDriver");
@ -1831,7 +1844,25 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
if webdriver_reset {
self.webdriver.load_channel = None;
}
self.compositor_proxy.send(ToCompositorMsg::LoadComplete);
// Notify the embedder that the TopLevelBrowsingContext current document
// has finished loading.
// We need to make sure the pipeline that has finished loading is the current
// pipeline and that no pending pipeline will replace the current one.
let pipeline_is_top_level_pipeline = self.browsing_contexts
.get(&BrowsingContextId::from(top_level_browsing_context_id))
.map(|ctx| ctx.pipeline_id == pipeline_id)
.unwrap_or(false);
if pipeline_is_top_level_pipeline {
// Is there any pending pipeline that will replace the current top level pipeline
let current_top_level_pipeline_will_be_replaced = self.pending_changes.iter()
.any(|change| change.browsing_context_id == top_level_browsing_context_id);
if !current_top_level_pipeline_will_be_replaced {
// Notify embedder top level document finished loading.
self.compositor_proxy.send(ToCompositorMsg::LoadComplete(top_level_browsing_context_id));
}
}
self.handle_subframe_loaded(pipeline_id);
}
@ -1897,7 +1928,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
},
None => {
let event = ToCompositorMsg::KeyEvent(ch, key, state, mods);
let event = ToCompositorMsg::KeyEvent(None, ch, key, state, mods);
self.compositor_proxy.clone_compositor_proxy().send(event);
}
}
@ -2088,9 +2119,9 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
WebDriverCommandMsg::GetWindowSize(_, reply) => {
let _ = reply.send(self.window_size);
},
WebDriverCommandMsg::SetWindowSize(_, size, reply) => {
WebDriverCommandMsg::SetWindowSize(top_level_browsing_context_id, size, reply) => {
self.webdriver.resize_channel = Some(reply);
self.compositor_proxy.send(ToCompositorMsg::ResizeTo(size));
self.compositor_proxy.send(ToCompositorMsg::ResizeTo(top_level_browsing_context_id, size));
},
WebDriverCommandMsg::LoadUrl(top_level_browsing_context_id, load_data, reply) => {
self.load_url_for_webdriver(top_level_browsing_context_id, load_data, reply, false);
@ -2324,7 +2355,8 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
.map(&keep_load_data_if_top_browsing_context)
.scan(current_load_data.clone(), &resolve_load_data));
self.compositor_proxy.send(ToCompositorMsg::HistoryChanged(entries, current_index));
let msg = ToCompositorMsg::HistoryChanged(top_level_browsing_context_id, entries, current_index);
self.compositor_proxy.send(msg);
}
fn load_url_for_webdriver(&mut self,
@ -2338,7 +2370,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
Some(browsing_context) => browsing_context.pipeline_id,
None => return warn!("Webdriver load for closed browsing context {}.", browsing_context_id),
};
if let Some(new_pipeline_id) = self.load_url(pipeline_id, load_data, replace) {
if let Some(new_pipeline_id) = self.load_url(top_level_browsing_context_id, pipeline_id, load_data, replace) {
self.webdriver.load_channel = Some((new_pipeline_id, reply));
}
}