Renamed constellation::Frame to constellation::BrowsingContext.

This commit is contained in:
Alan Jeffrey 2017-05-12 16:15:15 -05:00
parent 5403c2fff0
commit 607e011b05
24 changed files with 778 additions and 721 deletions

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use euclid::size::TypedSize2D;
use msg::constellation_msg::{FrameId, PipelineId};
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use pipeline::Pipeline;
use script_traits::LoadData;
use std::collections::HashMap;
@ -12,17 +12,16 @@ use std::mem::replace;
use std::time::Instant;
use style_traits::CSSPixel;
/// A frame in the frame tree.
/// Each frame is the constellation's view of a browsing context.
/// The constellation's view of a browsing context.
/// Each browsing context has a session history, caused by
/// navigation and traversing the history. Each frame has its
/// navigation and traversing the history. Each browsing contest has its
/// current entry, plus past and future entries. The past is sorted
/// chronologically, the future is sorted reverse chronologically:
/// in particular prev.pop() is the latest past entry, and
/// next.pop() is the earliest future entry.
pub struct Frame {
/// The frame id.
pub id: FrameId,
pub struct BrowsingContext {
/// The browsing context id.
pub id: BrowsingContextId,
/// The size of the frame.
pub size: Option<TypedSize2D<f32, CSSPixel>>,
@ -37,17 +36,17 @@ pub struct Frame {
pub load_data: LoadData,
/// The past session history, ordered chronologically.
pub prev: Vec<FrameState>,
pub prev: Vec<SessionHistoryEntry>,
/// The future session history, ordered reverse chronologically.
pub next: Vec<FrameState>,
pub next: Vec<SessionHistoryEntry>,
}
impl Frame {
/// Create a new frame.
/// Note this just creates the frame, it doesn't add it to the frame tree.
pub fn new(id: FrameId, pipeline_id: PipelineId, load_data: LoadData) -> Frame {
Frame {
impl BrowsingContext {
/// Create a new browsing context.
/// Note this just creates the browsing context, it doesn't add it to the constellation's set of browsing contexts.
pub fn new(id: BrowsingContextId, pipeline_id: PipelineId, load_data: LoadData) -> BrowsingContext {
BrowsingContext {
id: id,
size: None,
pipeline_id: pipeline_id,
@ -58,17 +57,17 @@ impl Frame {
}
}
/// Get the current frame state.
pub fn current(&self) -> FrameState {
FrameState {
/// Get the current session history entry.
pub fn current(&self) -> SessionHistoryEntry {
SessionHistoryEntry {
instant: self.instant,
frame_id: self.id,
browsing_context_id: self.id,
pipeline_id: Some(self.pipeline_id),
load_data: self.load_data.clone(),
}
}
/// Set the current frame entry, and push the current frame entry into the past.
/// Set the current session history entry, and push the current frame entry into the past.
pub fn load(&mut self, pipeline_id: PipelineId, load_data: LoadData) {
let current = self.current();
self.prev.push(current);
@ -78,25 +77,27 @@ impl Frame {
}
/// Set the future to be empty.
pub fn remove_forward_entries(&mut self) -> Vec<FrameState> {
pub fn remove_forward_entries(&mut self) -> Vec<SessionHistoryEntry> {
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) {
/// Update the current entry of the BrowsingContext from an entry that has been traversed to.
pub fn update_current(&mut self, pipeline_id: PipelineId, entry: SessionHistoryEntry) {
self.pipeline_id = pipeline_id;
self.instant = entry.instant;
self.load_data = entry.load_data;
}
}
/// An entry in a frame's session history.
/// An entry in a browsing context's session history.
/// Each entry stores the pipeline id for a document in the session history.
///
/// When we operate on the joint session history, entries are sorted chronologically,
/// so we timestamp the entries by when the entry was added to the session history.
///
/// https://html.spec.whatwg.org/multipage/#session-history-entry
#[derive(Clone)]
pub struct FrameState {
pub struct SessionHistoryEntry {
/// The timestamp for when the session history entry was created
pub instant: Instant,
@ -108,14 +109,14 @@ pub struct FrameState {
pub load_data: LoadData,
/// The frame that this session history entry is part of
pub frame_id: FrameId,
pub browsing_context_id: BrowsingContextId,
}
/// Represents a pending change in the frame tree, that will be applied
/// Represents a pending change in a session history, that will be applied
/// once the new pipeline has loaded and completed initial layout / paint.
pub struct FrameChange {
/// The frame to change.
pub frame_id: FrameId,
pub struct SessionHistoryChange {
/// The browsing context to change.
pub browsing_context_id: BrowsingContextId,
/// The pipeline for the document being loaded.
pub new_pipeline_id: PipelineId,
@ -129,16 +130,15 @@ pub struct FrameChange {
pub replace_instant: Option<Instant>,
}
/// An iterator over a frame tree, returning the fully active frames in
/// depth-first order. Note that this iterator only returns the fully
/// active frames, that is ones where every ancestor frame is
/// in the currently active pipeline of its parent frame.
pub struct FrameTreeIterator<'a> {
/// The frames still to iterate over.
pub stack: Vec<FrameId>,
/// An iterator over browsing contexts, returning the descendant
/// contexts whose active documents are fully active, in depth-first
/// order.
pub struct FullyActiveBrowsingContextsIterator<'a> {
/// The browsing contexts still to iterate over.
pub stack: Vec<BrowsingContextId>,
/// The set of all frames.
pub frames: &'a HashMap<FrameId, Frame>,
/// The set of all browsing contexts.
pub browsing_contexts: &'a HashMap<BrowsingContextId, BrowsingContext>,
/// The set of all pipelines. We use this to find the active
/// children of a frame, which are the iframes in the currently
@ -146,73 +146,73 @@ pub struct FrameTreeIterator<'a> {
pub pipelines: &'a HashMap<PipelineId, Pipeline>,
}
impl<'a> Iterator for FrameTreeIterator<'a> {
type Item = &'a Frame;
fn next(&mut self) -> Option<&'a Frame> {
impl<'a> Iterator for FullyActiveBrowsingContextsIterator<'a> {
type Item = &'a BrowsingContext;
fn next(&mut self) -> Option<&'a BrowsingContext> {
loop {
let frame_id = match self.stack.pop() {
Some(frame_id) => frame_id,
let browsing_context_id = match self.stack.pop() {
Some(browsing_context_id) => browsing_context_id,
None => return None,
};
let frame = match self.frames.get(&frame_id) {
Some(frame) => frame,
let browsing_context = match self.browsing_contexts.get(&browsing_context_id) {
Some(browsing_context) => browsing_context,
None => {
warn!("Frame {:?} iterated after closure.", frame_id);
warn!("BrowsingContext {:?} iterated after closure.", browsing_context_id);
continue;
},
};
let pipeline = match self.pipelines.get(&frame.pipeline_id) {
let pipeline = match self.pipelines.get(&browsing_context.pipeline_id) {
Some(pipeline) => pipeline,
None => {
warn!("Pipeline {:?} iterated after closure.", frame.pipeline_id);
warn!("Pipeline {:?} iterated after closure.", browsing_context.pipeline_id);
continue;
},
};
self.stack.extend(pipeline.children.iter());
return Some(frame)
return Some(browsing_context)
}
}
}
/// An iterator over a frame tree, returning all frames in depth-first
/// order. Note that this iterator returns all frames, not just the
/// fully active ones.
pub struct FullFrameTreeIterator<'a> {
/// The frames still to iterate over.
pub stack: Vec<FrameId>,
/// An iterator over browsing contexts, returning all descendant
/// contexts in depth-first order. Note that this iterator returns all
/// contexts, not just the fully active ones.
pub struct AllBrowsingContextsIterator<'a> {
/// The browsing contexts still to iterate over.
pub stack: Vec<BrowsingContextId>,
/// The set of all frames.
pub frames: &'a HashMap<FrameId, Frame>,
/// The set of all browsing contexts.
pub browsing_contexts: &'a HashMap<BrowsingContextId, BrowsingContext>,
/// The set of all pipelines. We use this to find the
/// children of a frame, which are the iframes in all documents
/// children of a browsing context, which are the iframes in all documents
/// in the session history.
pub pipelines: &'a HashMap<PipelineId, Pipeline>,
}
impl<'a> Iterator for FullFrameTreeIterator<'a> {
type Item = &'a Frame;
fn next(&mut self) -> Option<&'a Frame> {
impl<'a> Iterator for AllBrowsingContextsIterator<'a> {
type Item = &'a BrowsingContext;
fn next(&mut self) -> Option<&'a BrowsingContext> {
let pipelines = self.pipelines;
loop {
let frame_id = match self.stack.pop() {
Some(frame_id) => frame_id,
let browsing_context_id = match self.stack.pop() {
Some(browsing_context_id) => browsing_context_id,
None => return None,
};
let frame = match self.frames.get(&frame_id) {
Some(frame) => frame,
let browsing_context = match self.browsing_contexts.get(&browsing_context_id) {
Some(browsing_context) => browsing_context,
None => {
warn!("Frame {:?} iterated after closure.", frame_id);
warn!("BrowsingContext {:?} iterated after closure.", browsing_context_id);
continue;
},
};
let child_frame_ids = frame.prev.iter().chain(frame.next.iter())
let child_browsing_context_ids = browsing_context.prev.iter().chain(browsing_context.next.iter())
.filter_map(|entry| entry.pipeline_id)
.chain(once(frame.pipeline_id))
.chain(once(browsing_context.pipeline_id))
.filter_map(|pipeline_id| pipelines.get(&pipeline_id))
.flat_map(|pipeline| pipeline.children.iter());
self.stack.extend(child_frame_ids);
return Some(frame)
self.stack.extend(child_browsing_context_ids);
return Some(browsing_context)
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -41,9 +41,9 @@ extern crate style_traits;
extern crate webrender_traits;
extern crate webvr_traits;
mod browsingcontext;
mod constellation;
mod event_loop;
mod frame;
mod pipeline;
#[cfg(not(target_os = "windows"))]
mod sandboxing;

View file

@ -15,7 +15,7 @@ use ipc_channel::Error;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use layout_traits::LayoutThreadFactory;
use msg::constellation_msg::{FrameId, FrameType, PipelineId, PipelineNamespaceId};
use msg::constellation_msg::{BrowsingContextId, FrameType, PipelineId, PipelineNamespaceId};
use net::image_cache::ImageCacheImpl;
use net_traits::{IpcSend, ResourceThreads};
use net_traits::image_cache::ImageCache;
@ -49,14 +49,14 @@ pub struct Pipeline {
/// The ID of the pipeline.
pub id: PipelineId,
/// The ID of the frame that contains this Pipeline.
pub frame_id: FrameId,
/// The ID of the browsing context that contains this Pipeline.
pub browsing_context_id: BrowsingContextId,
/// The parent pipeline of this one. `None` if this is a root pipeline.
/// Note that because of mozbrowser iframes, even top-level pipelines
/// may have a parent (in which case the frame type will be
/// `MozbrowserIFrame`).
/// TODO: move this field to `Frame`.
/// TODO: move this field to `BrowsingContext`.
pub parent_info: Option<(PipelineId, FrameType)>,
/// The event loop handling this pipeline.
@ -80,11 +80,11 @@ pub struct Pipeline {
/// animations cause composites to be continually scheduled.
pub running_animations: bool,
/// The child frames of this pipeline (these are iframes in the document).
pub children: Vec<FrameId>,
/// The child browsing contexts of this pipeline (these are iframes in the document).
pub children: Vec<BrowsingContextId>,
/// Whether this pipeline is in private browsing mode.
/// TODO: move this field to `Frame`.
/// TODO: move this field to `BrowsingContext`.
pub is_private: bool,
/// Whether this pipeline should be treated as visible for the purposes of scheduling and
@ -100,11 +100,11 @@ pub struct InitialPipelineState {
/// The ID of the pipeline to create.
pub id: PipelineId,
/// The ID of the frame that contains this Pipeline.
pub frame_id: FrameId,
/// The ID of the browsing context that contains this Pipeline.
pub browsing_context_id: BrowsingContextId,
/// The ID of the top-level frame that contains this Pipeline.
pub top_level_frame_id: FrameId,
/// The ID of the top-level browsing context that contains this Pipeline.
pub top_level_browsing_context_id: BrowsingContextId,
/// The ID of the parent pipeline and frame type, if any.
/// If `None`, this is the root.
@ -200,7 +200,7 @@ impl Pipeline {
let new_layout_info = NewLayoutInfo {
parent_info: state.parent_info,
new_pipeline_id: state.id,
frame_id: state.frame_id,
browsing_context_id: state.browsing_context_id,
load_data: state.load_data,
window_size: window_size,
pipeline_port: pipeline_port,
@ -237,8 +237,8 @@ impl Pipeline {
let unprivileged_pipeline_content = UnprivilegedPipelineContent {
id: state.id,
frame_id: state.frame_id,
top_level_frame_id: state.top_level_frame_id,
browsing_context_id: state.browsing_context_id,
top_level_browsing_context_id: state.top_level_browsing_context_id,
parent_info: state.parent_info,
constellation_chan: state.constellation_chan,
scheduler_chan: state.scheduler_chan,
@ -280,7 +280,7 @@ impl Pipeline {
};
Ok(Pipeline::new(state.id,
state.frame_id,
state.browsing_context_id,
state.parent_info,
script_chan,
pipeline_chan,
@ -293,7 +293,7 @@ impl Pipeline {
/// Creates a new `Pipeline`, after the script and layout threads have been
/// spawned.
pub fn new(id: PipelineId,
frame_id: FrameId,
browsing_context_id: BrowsingContextId,
parent_info: Option<(PipelineId, FrameType)>,
event_loop: Rc<EventLoop>,
layout_chan: IpcSender<LayoutControlMsg>,
@ -304,7 +304,7 @@ impl Pipeline {
-> Pipeline {
let pipeline = Pipeline {
id: id,
frame_id: frame_id,
browsing_context_id: browsing_context_id,
parent_info: parent_info,
event_loop: event_loop,
layout_chan: layout_chan,
@ -376,15 +376,15 @@ impl Pipeline {
}
}
/// Add a new child frame.
pub fn add_child(&mut self, frame_id: FrameId) {
self.children.push(frame_id);
/// Add a new child browsing context.
pub fn add_child(&mut self, browsing_context_id: BrowsingContextId) {
self.children.push(browsing_context_id);
}
/// Remove a child frame.
pub fn remove_child(&mut self, frame_id: FrameId) {
match self.children.iter().position(|id| *id == frame_id) {
None => return warn!("Pipeline remove child already removed ({:?}).", frame_id),
/// Remove a child browsing context.
pub fn remove_child(&mut self, browsing_context_id: BrowsingContextId) {
match self.children.iter().position(|id| *id == browsing_context_id) {
None => return warn!("Pipeline remove child already removed ({:?}).", browsing_context_id),
Some(index) => self.children.remove(index),
};
}
@ -393,7 +393,7 @@ impl Pipeline {
/// This will cause an event to be fired on an iframe in the document,
/// or on the `Window` if no frame is given.
pub fn trigger_mozbrowser_event(&self,
child_id: Option<FrameId>,
child_id: Option<BrowsingContextId>,
event: MozBrowserEvent) {
assert!(PREFS.is_mozbrowser_enabled());
@ -433,8 +433,8 @@ impl Pipeline {
#[derive(Deserialize, Serialize)]
pub struct UnprivilegedPipelineContent {
id: PipelineId,
frame_id: FrameId,
top_level_frame_id: FrameId,
browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: BrowsingContextId,
parent_info: Option<(PipelineId, FrameType)>,
constellation_chan: IpcSender<ScriptMsg>,
layout_to_constellation_chan: IpcSender<LayoutMsg>,
@ -470,8 +470,8 @@ impl UnprivilegedPipelineContent {
let image_cache = Arc::new(ImageCacheImpl::new(self.webrender_api_sender.create_api()));
let layout_pair = STF::create(InitialScriptState {
id: self.id,
frame_id: self.frame_id,
top_level_frame_id: self.top_level_frame_id,
browsing_context_id: self.browsing_context_id,
top_level_browsing_context_id: self.top_level_browsing_context_id,
parent_info: self.parent_info,
control_chan: self.script_chan.clone(),
control_port: self.script_port,
@ -491,7 +491,7 @@ impl UnprivilegedPipelineContent {
}, self.load_data.clone());
LTF::create(self.id,
Some(self.top_level_frame_id),
Some(self.top_level_browsing_context_id),
self.load_data.url,
self.parent_info.is_some(),
layout_pair,