Auto merge of #11430 - asajeffrey:constellation-record-mozbrowser-parent-info, r=ConnorGBrewster

Record the frame type (IFrame or MozBrowserIFrame) in the pipeline.

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 do not require tests because this is a refactoring

Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process.

This is a first step towards supporting the notion of multiple top-level browsing contexts in Servo, by making the constellation aware of which content is loaded in a mozbrowser iframe.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11430)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-05-26 14:53:09 -05:00
commit 64cca225e5
6 changed files with 66 additions and 55 deletions

View file

@ -31,7 +31,7 @@ use ipc_channel::ipc::{self, IpcSender};
use ipc_channel::router::ROUTER;
use layout_traits::{LayoutControlChan, LayoutThreadFactory};
use msg::constellation_msg::WebDriverCommandMsg;
use msg::constellation_msg::{FrameId, PipelineId};
use msg::constellation_msg::{FrameId, FrameType, PipelineId};
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData};
use msg::constellation_msg::{PipelineNamespace, PipelineNamespaceId, NavigationDirection};
use msg::constellation_msg::{SubpageId, WindowSizeData, WindowSizeType};
@ -419,7 +419,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
/// Helper function for creating a pipeline
fn new_pipeline(&mut self,
pipeline_id: PipelineId,
parent_info: Option<(PipelineId, SubpageId)>,
parent_info: Option<(PipelineId, SubpageId, FrameType)>,
initial_window_size: Option<TypedSize2D<PagePx, f32>>,
script_channel: Option<IpcSender<ConstellationControlMsg>>,
load_data: LoadData) {
@ -1084,7 +1084,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
// Create the new pipeline, attached to the parent and push to pending frames
self.new_pipeline(load_info.new_pipeline_id,
Some((load_info.containing_pipeline_id, load_info.new_subpage_id)),
Some((load_info.containing_pipeline_id, load_info.new_subpage_id, load_info.frame_type)),
window_size,
script_chan,
load_data);
@ -1136,15 +1136,15 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
.and_then(|root_frame_id| self.frames.get(&root_frame_id))
.map(|root_frame| root_frame.current);
let ancestor_info = self.get_root_pipeline_and_containing_parent(&pipeline_id);
if let Some(ancestor_info) = ancestor_info {
if root_pipeline_id == Some(ancestor_info.0) {
let ancestor_info = self.get_mozbrowser_ancestor_info(pipeline_id);
if let Some((ancestor_id, subpage_id)) = ancestor_info {
if root_pipeline_id == Some(ancestor_id) {
match root_pipeline_id.and_then(|pipeline_id| self.pipelines.get(&pipeline_id)) {
Some(root_pipeline) => {
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowsershowmodalprompt
let event = MozBrowserEvent::ShowModalPrompt("alert".to_owned(), "Alert".to_owned(),
String::from(message), "".to_owned());
root_pipeline.trigger_mozbrowser_event(ancestor_info.1, event);
root_pipeline.trigger_mozbrowser_event(subpage_id, event);
}
None => return warn!("Alert sent to Pipeline {:?} after closure.", root_pipeline_id),
}
@ -1177,7 +1177,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
// requested change so it can update its internal state.
let parent_info = self.pipelines.get(&source_id).and_then(|source| source.parent_info);
match parent_info {
Some((parent_pipeline_id, subpage_id)) => {
Some((parent_pipeline_id, subpage_id, _)) => {
self.handle_load_start_msg(&source_id);
// Message the constellation to find the script thread for this iframe
// and issue an iframe load through there.
@ -1358,7 +1358,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
None => return warn!("Pipeline {:?} navigated to after closure.", next_pipeline_id),
Some(pipeline) => match pipeline.parent_info {
None => return warn!("Pipeline {:?} has no parent info.", next_pipeline_id),
Some((_, new_subpage_id)) => new_subpage_id,
Some((_, new_subpage_id, _)) => new_subpage_id,
},
};
let msg = ConstellationControlMsg::UpdateSubpageId(parent_pipeline_id,
@ -1463,7 +1463,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
Some(pipeline) => pipeline.parent_info,
None => return warn!("Pipeline {:?} focus parent after closure.", pipeline_id),
};
let (containing_pipeline_id, subpage_id) = match parent_info {
let (containing_pipeline_id, subpage_id, _) = match parent_info {
Some(info) => info,
None => return warn!("Pipeline {:?} focus has no parent.", pipeline_id),
};
@ -1630,7 +1630,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
// If a child frame, add it to the parent pipeline. Otherwise
// it must surely be the root frame being created!
match self.pipelines.get(&frame_change.new_pipeline_id).and_then(|pipeline| pipeline.parent_info) {
Some((parent_id, _)) => {
Some((parent_id, _, _)) => {
if let Some(parent) = self.pipelines.get_mut(&parent_id) {
parent.add_child(frame_id);
}
@ -1881,15 +1881,21 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
/// Checks whether the pipeline or its ancestors are private
#[allow(dead_code)]
fn check_is_pipeline_private(&self, pipeline_id: PipelineId) -> bool {
let mut pipeline_id = Some(pipeline_id);
while let Some(pipeline) = pipeline_id.and_then(|id| self.pipelines.get(&id)) {
if pipeline.is_private {
return true;
fn check_is_pipeline_private(&self, mut pipeline_id: PipelineId) -> bool {
loop {
match self.pipelines.get(&pipeline_id) {
Some(pipeline) if pipeline.is_private => return true,
Some(pipeline) => match pipeline.parent_info {
None => return false,
Some((_, _, FrameType::MozBrowserIFrame)) => return false,
Some((parent_id, _, _)) => pipeline_id = parent_id,
},
None => {
warn!("Finding private ancestor for pipeline {} after closure.", pipeline_id);
return false;
},
}
pipeline_id = pipeline.parent_info.map(|(parent_pipeline_id, _)| parent_pipeline_id);
}
false
}
// Close a frame (and all children)
@ -1922,7 +1928,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
warn!("Closing frame {:?} twice.", frame_id);
}
if let Some((parent_pipeline_id, _)) = parent_info {
if let Some((parent_pipeline_id, _, _)) = parent_info {
let parent_pipeline = match self.pipelines.get_mut(&parent_pipeline_id) {
None => return warn!("Pipeline {:?} child closed after parent.", parent_pipeline_id),
Some(parent_pipeline) => parent_pipeline,
@ -1958,8 +1964,8 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
};
// If a child pipeline, remove from subpage map
if let Some(info) = pipeline.parent_info {
self.subpage_map.remove(&info);
if let Some((parent_id, subpage_id, _)) = pipeline.parent_info {
self.subpage_map.remove(&(parent_id, subpage_id));
}
// Remove assocation between this pipeline and its holding frame
@ -2062,42 +2068,37 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
}
/// For a given pipeline, determine the iframe in the root pipeline that transitively contains
/// For a given pipeline, determine the mozbrowser iframe that transitively contains
/// it. There could be arbitrary levels of nested iframes in between them.
fn get_root_pipeline_and_containing_parent(&self, pipeline_id: &PipelineId) -> Option<(PipelineId, SubpageId)> {
if let Some(pipeline) = self.pipelines.get(pipeline_id) {
if let Some(mut ancestor_info) = pipeline.parent_info {
if let Some(mut ancestor) = self.pipelines.get(&ancestor_info.0) {
while let Some(next_info) = ancestor.parent_info {
ancestor_info = next_info;
ancestor = match self.pipelines.get(&ancestor_info.0) {
Some(ancestor) => ancestor,
None => {
warn!("Get parent pipeline before root via closed pipeline {:?}.", ancestor_info.0);
return None;
},
};
}
return Some(ancestor_info);
}
fn get_mozbrowser_ancestor_info(&self, mut pipeline_id: PipelineId) -> Option<(PipelineId, SubpageId)> {
loop {
match self.pipelines.get(&pipeline_id) {
Some(pipeline) => match pipeline.parent_info {
Some((parent_id, subpage_id, FrameType::MozBrowserIFrame)) => return Some((parent_id, subpage_id)),
Some((parent_id, _, _)) => pipeline_id = parent_id,
None => return None,
},
None => {
warn!("Finding mozbrowser ancestor for pipeline {} after closure.", pipeline_id);
return None;
},
}
}
None
}
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserlocationchange
// Note that this is a no-op if the pipeline is not an immediate child iframe of the root
// Note that this is a no-op if the pipeline is not a mozbrowser iframe
fn trigger_mozbrowserlocationchange(&self, pipeline_id: PipelineId) {
if !prefs::get_pref("dom.mozbrowser.enabled").as_boolean().unwrap_or(false) { return; }
let event_info = self.pipelines.get(&pipeline_id).and_then(|pipeline| {
pipeline.parent_info.map(|(containing_pipeline_id, subpage_id)| {
(containing_pipeline_id, subpage_id, pipeline.url.to_string())
pipeline.parent_info.map(|(containing_pipeline_id, subpage_id, frame_type)| {
(containing_pipeline_id, subpage_id, frame_type, pipeline.url.to_string())
})
});
// If this is an iframe, then send the event with new url
if let Some((containing_pipeline_id, subpage_id, url)) = event_info {
// If this is a mozbrowser iframe, then send the event with new url
if let Some((containing_pipeline_id, subpage_id, FrameType::MozBrowserIFrame, url)) = event_info {
if let Some(parent_pipeline) = self.pipelines.get(&containing_pipeline_id) {
if let Some(frame_id) = self.pipeline_to_frame_map.get(&pipeline_id) {
if let Some(frame) = self.frames.get(&frame_id) {
@ -2116,7 +2117,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
fn trigger_mozbrowsererror(&self, pipeline_id: PipelineId, reason: String, backtrace: String) {
if !prefs::get_pref("dom.mozbrowser.enabled").as_boolean().unwrap_or(false) { return; }
let ancestor_info = self.get_root_pipeline_and_containing_parent(&pipeline_id);
let ancestor_info = self.get_mozbrowser_ancestor_info(pipeline_id);
if let Some(ancestor_info) = ancestor_info {
match self.pipelines.get(&ancestor_info.0) {