diff options
author | Alan Jeffrey <ajeffrey@mozilla.com> | 2017-03-03 16:42:37 -0600 |
---|---|---|
committer | Alan Jeffrey <ajeffrey@mozilla.com> | 2017-03-14 14:28:21 -0500 |
commit | 1a44a76b5754d89c88e54449cc6eea38f8a1a41e (patch) | |
tree | d248cda408d23022fc53949a614847687bfafc4f | |
parent | d3fa0a3dd61273b8216a1c6f1312ba418dc52c85 (diff) | |
download | servo-1a44a76b5754d89c88e54449cc6eea38f8a1a41e.tar.gz servo-1a44a76b5754d89c88e54449cc6eea38f8a1a41e.zip |
Frames in the constellation store LoadData rather than just URLs.
-rw-r--r-- | components/constellation/constellation.rs | 122 | ||||
-rw-r--r-- | components/constellation/frame.rs | 47 | ||||
-rw-r--r-- | components/constellation/pipeline.rs | 133 |
3 files changed, 151 insertions, 151 deletions
diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 9e182194eef..42c263e6233 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -587,6 +587,10 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> frame_id: FrameId, parent_info: Option<(PipelineId, FrameType)>, initial_window_size: Option<TypedSize2D<f32, CSSPixel>>, + // TODO: we have to provide ownership of the LoadData + // here, because it will be send on an ipc channel, + // and ipc channels take onership of their data. + // https://github.com/servo/ipc-channel/issues/138 load_data: LoadData, sandbox: IFrameSandboxState, is_private: bool) { @@ -747,8 +751,8 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> } /// Create a new frame and update the internal bookkeeping. - fn new_frame(&mut self, frame_id: FrameId, pipeline_id: PipelineId, url: ServoUrl) { - let frame = Frame::new(frame_id, pipeline_id, url); + fn new_frame(&mut self, frame_id: FrameId, pipeline_id: PipelineId, load_data: LoadData) { + let frame = Frame::new(frame_id, pipeline_id, load_data); self.frames.insert(frame_id, frame); // If a child frame, add it to the parent pipeline. @@ -1291,15 +1295,15 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> warn!("creating replacement pipeline for about:failure"); let new_pipeline_id = PipelineId::new(); - let load_data = LoadData::new(failure_url.clone(), None, None); + let load_data = LoadData::new(failure_url, None, None); let sandbox = IFrameSandboxState::IFrameSandboxed; - self.new_pipeline(new_pipeline_id, top_level_frame_id, parent_info, window_size, load_data, sandbox, false); + self.new_pipeline(new_pipeline_id, top_level_frame_id, parent_info, + window_size, load_data.clone(), sandbox, false); self.pending_frames.push(FrameChange { frame_id: top_level_frame_id, - old_pipeline_id: pipeline_id, new_pipeline_id: new_pipeline_id, - url: failure_url, - replace: None, + load_data: load_data, + replace_instant: None, }); } @@ -1338,14 +1342,13 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> let root_frame_id = self.root_frame_id; let load_data = LoadData::new(url.clone(), None, None); let sandbox = IFrameSandboxState::IFrameUnsandboxed; - self.new_pipeline(root_pipeline_id, root_frame_id, None, Some(window_size), load_data, sandbox, false); + self.new_pipeline(root_pipeline_id, root_frame_id, None, Some(window_size), load_data.clone(), sandbox, false); self.handle_load_start_msg(root_pipeline_id); self.pending_frames.push(FrameChange { frame_id: self.root_frame_id, - old_pipeline_id: None, new_pipeline_id: root_pipeline_id, - url: url.clone(), - replace: None, + load_data: load_data, + replace_instant: None, }); self.compositor_proxy.send(ToCompositorMsg::ChangePageUrl(root_pipeline_id, url)); } @@ -1431,8 +1434,8 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> (load_data, window_size, is_private) }; - let replace = if load_info.info.replace { - self.frames.get(&load_info.info.frame_id).map(|frame| frame.current()) + let replace_instant = if load_info.info.replace { + self.frames.get(&load_info.info.frame_id).map(|frame| frame.instant) } else { None }; @@ -1440,10 +1443,9 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> // Create the new pipeline, attached to the parent and push to pending frames self.pending_frames.push(FrameChange { frame_id: load_info.info.frame_id, - old_pipeline_id: load_info.old_pipeline_id, new_pipeline_id: load_info.info.new_pipeline_id, - url: load_data.url.clone(), - replace: replace, + load_data: load_data.clone(), + replace_instant: replace_instant, }); self.new_pipeline(load_info.info.new_pipeline_id, @@ -1489,8 +1491,11 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> parent_pipeline.visible) }; - let replace = if replace { - self.frames.get(&frame_id).map(|frame| frame.current()) + // TODO: Referrer? + let load_data = LoadData::new(url, None, None); + + let replace_instant = if replace { + self.frames.get(&frame_id).map(|frame| frame.instant) } else { None }; @@ -1500,10 +1505,9 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> self.pending_frames.push(FrameChange { frame_id: frame_id, - old_pipeline_id: None, new_pipeline_id: new_pipeline_id, - url: url, - replace: replace, + load_data: load_data, + replace_instant: replace_instant, }); } @@ -1608,9 +1612,11 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> Some(source_id) } None => { + let root_frame_id = self.root_frame_id; + // Make sure no pending page would be overridden. for frame_change in &self.pending_frames { - if frame_change.old_pipeline_id == Some(source_id) { + if frame_change.frame_id == root_frame_id { // id that sent load msg is being changed already; abort return None; } @@ -1631,19 +1637,17 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> // Create the new pipeline let window_size = self.pipelines.get(&source_id).and_then(|source| source.size); let new_pipeline_id = PipelineId::new(); - let root_frame_id = self.root_frame_id; let sandbox = IFrameSandboxState::IFrameUnsandboxed; - let replace = if replace { - self.frames.get(&frame_id).map(|frame| frame.current()) + let replace_instant = if replace { + self.frames.get(&frame_id).map(|frame| frame.instant) } else { None }; self.pending_frames.push(FrameChange { frame_id: root_frame_id, - old_pipeline_id: Some(source_id), new_pipeline_id: new_pipeline_id, - url: load_data.url.clone(), - replace: replace, + load_data: load_data.clone(), + replace_instant: replace_instant, }); self.new_pipeline(new_pipeline_id, root_frame_id, None, window_size, load_data, sandbox, false); @@ -1804,7 +1808,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> let current_pipeline_id = self.frames.get(&frame_id) .map(|frame| frame.pipeline_id); let pipeline_id_loaded = self.pending_frames.iter().rev() - .find(|x| x.old_pipeline_id == current_pipeline_id) + .find(|x| x.frame_id == frame_id) .map(|x| x.new_pipeline_id) .or(current_pipeline_id); if let Err(e) = resp_chan.send(pipeline_id_loaded) { @@ -1994,26 +1998,25 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> // entry has been discarded, so we navigate to the entry // URL instead. When the document has activated, it will // traverse to the entry, but with the new pipeline id. - debug!("Reloading document {} for frame {}.", entry.url, frame_id); - // TODO: referrer? - let load_data = LoadData::new(entry.url.clone(), None, None); + debug!("Reloading document {} for frame {}.", entry.load_data.url, entry.frame_id); // TODO: save the sandbox state so it can be restored here. let sandbox = IFrameSandboxState::IFrameUnsandboxed; let new_pipeline_id = PipelineId::new(); - let (old_pipeline_id, parent_info, window_size, is_private) = match self.frames.get(&frame_id) { + let load_data = entry.load_data; + let (parent_info, window_size, is_private) = match self.frames.get(&frame_id) { Some(frame) => match self.pipelines.get(&frame.pipeline_id) { - Some(pipeline) => (frame.pipeline_id, pipeline.parent_info, pipeline.size, pipeline.is_private), - None => (frame.pipeline_id, None, None, false), + Some(pipeline) => (pipeline.parent_info, pipeline.size, pipeline.is_private), + None => (None, None, false), }, None => return warn!("no frame to traverse"), }; - self.new_pipeline(new_pipeline_id, frame_id, parent_info, window_size, load_data, sandbox, is_private); + self.new_pipeline(new_pipeline_id, frame_id, parent_info, + window_size, load_data.clone(), sandbox, is_private); self.pending_frames.push(FrameChange { frame_id: frame_id, - old_pipeline_id: Some(old_pipeline_id), new_pipeline_id: new_pipeline_id, - url: entry.url.clone(), - replace: Some(entry), + load_data: load_data, + replace_instant: Some(entry.instant), }); return; } @@ -2024,7 +2027,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> // frame tree is modified below. let update_focus_pipeline = self.focused_pipeline_in_tree(entry.frame_id); - let old_pipeline_id = match self.frames.get_mut(&frame_id) { + let (old_pipeline_id, replaced_pipeline_id) = match self.frames.get_mut(&frame_id) { Some(frame) => { let old_pipeline_id = frame.pipeline_id; let mut curr_entry = frame.current(); @@ -2047,9 +2050,11 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> debug_assert_eq!(entry.instant, curr_entry.instant); - frame.update_current(pipeline_id, &entry); + let replaced_pipeline_id = curr_entry.pipeline_id; - old_pipeline_id + frame.update_current(pipeline_id, entry); + + (old_pipeline_id, replaced_pipeline_id) }, None => return warn!("no frame to traverse"), }; @@ -2064,6 +2069,13 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> self.focus_pipeline_id = Some(pipeline_id); } + // If we replaced a pipeline, close it. + if let Some(replaced_pipeline_id) = replaced_pipeline_id { + if replaced_pipeline_id != pipeline_id { + self.close_pipeline(replaced_pipeline_id, DiscardBrowsingContext::No, ExitPipelineMode::Normal); + } + } + // Deactivate the old pipeline, and activate the new one. self.update_activity(old_pipeline_id); self.update_activity(pipeline_id); @@ -2127,24 +2139,24 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> // If the currently focused pipeline is the one being changed (or a child // of the pipeline being changed) then update the focus pipeline to be // the replacement. - if let Some(old_pipeline_id) = frame_change.old_pipeline_id { - if let Some(old_frame_id) = self.pipelines.get(&old_pipeline_id).map(|pipeline| pipeline.frame_id) { - if self.focused_pipeline_in_tree(old_frame_id) { - self.focus_pipeline_id = Some(frame_change.new_pipeline_id); - } - } + if self.focused_pipeline_in_tree(frame_change.frame_id) { + self.focus_pipeline_id = Some(frame_change.new_pipeline_id); } - let (evicted_id, new_frame, navigated, location_changed) = if let Some(mut entry) = frame_change.replace { - debug!("Replacing pipeline in existing frame."); - let evicted_id = entry.pipeline_id; - entry.replace_pipeline(frame_change.new_pipeline_id, frame_change.url.clone()); + let (evicted_id, new_frame, navigated, location_changed) = if let Some(instant) = frame_change.replace_instant { + debug!("Replacing pipeline in existing frame with timestamp {:?}.", instant); + let entry = FrameState { + frame_id: frame_change.frame_id, + pipeline_id: Some(frame_change.new_pipeline_id), + load_data: frame_change.load_data.clone(), + instant: instant, + }; self.traverse_to_entry(entry); - (evicted_id, false, None, false) + (None, false, None, false) } else if let Some(frame) = self.frames.get_mut(&frame_change.frame_id) { debug!("Adding pipeline to existing frame."); let old_pipeline_id = frame.pipeline_id; - frame.load(frame_change.new_pipeline_id, frame_change.url.clone()); + frame.load(frame_change.new_pipeline_id, frame_change.load_data.clone()); let evicted_id = frame.prev.len() .checked_sub(PREFS.get("session-history.max-length").as_u64().unwrap_or(20) as usize) .and_then(|index| frame.prev.get_mut(index)) @@ -2160,7 +2172,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> } if new_frame { - self.new_frame(frame_change.frame_id, frame_change.new_pipeline_id, frame_change.url); + self.new_frame(frame_change.frame_id, frame_change.new_pipeline_id, frame_change.load_data); self.update_activity(frame_change.new_pipeline_id); }; diff --git a/components/constellation/frame.rs b/components/constellation/frame.rs index daa443b2b80..74aabee2de0 100644 --- a/components/constellation/frame.rs +++ b/components/constellation/frame.rs @@ -4,7 +4,7 @@ use msg::constellation_msg::{FrameId, PipelineId}; use pipeline::Pipeline; -use servo_url::ServoUrl; +use script_traits::LoadData; use std::collections::HashMap; use std::iter::once; use std::mem::replace; @@ -18,7 +18,6 @@ use std::time::Instant; /// chronologically, the future is sorted reverse chronologically: /// in particular prev.pop() is the latest past entry, and /// next.pop() is the earliest future entry. -#[derive(Debug, Clone)] pub struct Frame { /// The frame id. pub id: FrameId, @@ -29,8 +28,8 @@ pub struct Frame { /// The pipeline for the current session history entry pub pipeline_id: PipelineId, - /// The URL for the current session history entry - pub url: ServoUrl, + /// The load data for the current session history entry + pub load_data: LoadData, /// The past session history, ordered chronologically. pub prev: Vec<FrameState>, @@ -42,12 +41,12 @@ pub struct Frame { 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, url: ServoUrl) -> Frame { + pub fn new(id: FrameId, pipeline_id: PipelineId, load_data: LoadData) -> Frame { Frame { id: id, pipeline_id: pipeline_id, instant: Instant::now(), - url: url, + load_data: load_data, prev: vec!(), next: vec!(), } @@ -59,17 +58,17 @@ impl Frame { instant: self.instant, frame_id: self.id, pipeline_id: Some(self.pipeline_id), - url: self.url.clone(), + load_data: self.load_data.clone(), } } /// Set the current frame entry, and push the current frame entry into the past. - pub fn load(&mut self, pipeline_id: PipelineId, url: ServoUrl) { + pub fn load(&mut self, pipeline_id: PipelineId, load_data: LoadData) { let current = self.current(); self.prev.push(current); self.instant = Instant::now(); self.pipeline_id = pipeline_id; - self.url = url; + self.load_data = load_data; } /// Set the future to be empty. @@ -78,10 +77,10 @@ impl Frame { } /// 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) { + pub fn update_current(&mut self, pipeline_id: PipelineId, entry: FrameState) { self.pipeline_id = pipeline_id; self.instant = entry.instant; - self.url = entry.url.clone(); + self.load_data = entry.load_data; } } @@ -90,7 +89,7 @@ impl Frame { /// /// 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. -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct FrameState { /// The timestamp for when the session history entry was created pub instant: Instant, @@ -99,41 +98,29 @@ pub struct FrameState { /// None if the entry has been discarded pub pipeline_id: Option<PipelineId>, - /// The URL for this entry, used to reload the pipeline if it has been discarded - pub url: ServoUrl, + /// The load data for this entry, used to reload the pipeline if it has been discarded + pub load_data: LoadData, /// The frame that this session history entry is part of pub frame_id: FrameId, } -impl FrameState { - /// Updates the entry's pipeline and url. This is used when navigating with replacement - /// enabled. - pub fn replace_pipeline(&mut self, pipeline_id: PipelineId, url: ServoUrl) { - self.pipeline_id = Some(pipeline_id); - self.url = url; - } -} - /// Represents a pending change in the frame tree, 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, - /// The pipeline that was currently active at the time the change started. - /// TODO: can this field be removed? - pub old_pipeline_id: Option<PipelineId>, - /// The pipeline for the document being loaded. pub new_pipeline_id: PipelineId, - /// The URL for the document being loaded. - pub url: ServoUrl, + /// The data for the document being loaded. + pub load_data: LoadData, /// Is the new document replacing the current document (e.g. a reload) /// or pushing it into the session history (e.g. a navigation)? - pub replace: Option<FrameState>, + /// If it is replacing an existing entry, we store its timestamp. + pub replace_instant: Option<Instant>, } /// An iterator over a frame tree, returning the fully active frames in diff --git a/components/constellation/pipeline.rs b/components/constellation/pipeline.rs index d0af8d534cc..877c850a3cb 100644 --- a/components/constellation/pipeline.rs +++ b/components/constellation/pipeline.rs @@ -198,13 +198,15 @@ impl Pipeline { } }); - let (script_chan, content_ports) = match state.event_loop { + let url = state.load_data.url.clone(); + + let script_chan = match state.event_loop { Some(script_chan) => { let new_layout_info = NewLayoutInfo { parent_info: state.parent_info, new_pipeline_id: state.id, frame_id: state.frame_id, - load_data: state.load_data.clone(), + load_data: state.load_data, window_size: window_size, pipeline_port: pipeline_port, content_process_shutdown_chan: Some(layout_content_process_shutdown_chan.clone()), @@ -214,75 +216,74 @@ impl Pipeline { if let Err(e) = script_chan.send(ConstellationControlMsg::AttachLayout(new_layout_info)) { warn!("Sending to script during pipeline creation failed ({})", e); } - (script_chan, None) + script_chan } None => { let (script_chan, script_port) = ipc::channel().expect("Pipeline script chan"); - (EventLoop::new(script_chan), Some((script_port, pipeline_port))) - } - }; - if let Some((script_port, pipeline_port)) = content_ports { - // Route messages coming from content to devtools as appropriate. - let script_to_devtools_chan = state.devtools_chan.as_ref().map(|devtools_chan| { - let (script_to_devtools_chan, script_to_devtools_port) = ipc::channel() - .expect("Pipeline script to devtools chan"); - let devtools_chan = (*devtools_chan).clone(); - ROUTER.add_route(script_to_devtools_port.to_opaque(), box move |message| { - match message.to::<ScriptToDevtoolsControlMsg>() { - Err(e) => error!("Cast to ScriptToDevtoolsControlMsg failed ({}).", e), - Ok(message) => if let Err(e) = devtools_chan.send(DevtoolsControlMsg::FromScript(message)) { - warn!("Sending to devtools failed ({})", e) - }, - } + // Route messages coming from content to devtools as appropriate. + let script_to_devtools_chan = state.devtools_chan.as_ref().map(|devtools_chan| { + let (script_to_devtools_chan, script_to_devtools_port) = ipc::channel() + .expect("Pipeline script to devtools chan"); + let devtools_chan = (*devtools_chan).clone(); + ROUTER.add_route(script_to_devtools_port.to_opaque(), box move |message| { + match message.to::<ScriptToDevtoolsControlMsg>() { + Err(e) => error!("Cast to ScriptToDevtoolsControlMsg failed ({}).", e), + Ok(message) => if let Err(e) = devtools_chan.send(DevtoolsControlMsg::FromScript(message)) { + warn!("Sending to devtools failed ({})", e) + }, + } + }); + script_to_devtools_chan }); - script_to_devtools_chan - }); - - let (script_content_process_shutdown_chan, script_content_process_shutdown_port) = - ipc::channel().expect("Pipeline script content process shutdown chan"); - - let unprivileged_pipeline_content = UnprivilegedPipelineContent { - id: state.id, - frame_id: state.frame_id, - top_level_frame_id: state.top_level_frame_id, - parent_info: state.parent_info, - constellation_chan: state.constellation_chan, - scheduler_chan: state.scheduler_chan, - devtools_chan: script_to_devtools_chan, - bluetooth_thread: state.bluetooth_thread, - swmanager_thread: state.swmanager_thread, - image_cache_thread: state.image_cache_thread, - font_cache_thread: state.font_cache_thread, - resource_threads: state.resource_threads, - time_profiler_chan: state.time_profiler_chan, - mem_profiler_chan: state.mem_profiler_chan, - window_size: window_size, - layout_to_constellation_chan: state.layout_to_constellation_chan, - script_chan: script_chan.sender(), - load_data: state.load_data.clone(), - script_port: script_port, - opts: (*opts::get()).clone(), - prefs: PREFS.cloned(), - pipeline_port: pipeline_port, - pipeline_namespace_id: state.pipeline_namespace_id, - layout_content_process_shutdown_chan: layout_content_process_shutdown_chan, - layout_content_process_shutdown_port: layout_content_process_shutdown_port, - script_content_process_shutdown_chan: script_content_process_shutdown_chan, - script_content_process_shutdown_port: script_content_process_shutdown_port, - webrender_api_sender: state.webrender_api_sender, - webvr_thread: state.webvr_thread, - }; - - // Spawn the child process. - // - // Yes, that's all there is to it! - if opts::multiprocess() { - let _ = try!(unprivileged_pipeline_content.spawn_multiprocess()); - } else { - unprivileged_pipeline_content.start_all::<Message, LTF, STF>(false); + + let (script_content_process_shutdown_chan, script_content_process_shutdown_port) = + ipc::channel().expect("Pipeline script content process shutdown chan"); + + let unprivileged_pipeline_content = UnprivilegedPipelineContent { + id: state.id, + frame_id: state.frame_id, + top_level_frame_id: state.top_level_frame_id, + parent_info: state.parent_info, + constellation_chan: state.constellation_chan, + scheduler_chan: state.scheduler_chan, + devtools_chan: script_to_devtools_chan, + bluetooth_thread: state.bluetooth_thread, + swmanager_thread: state.swmanager_thread, + image_cache_thread: state.image_cache_thread, + font_cache_thread: state.font_cache_thread, + resource_threads: state.resource_threads, + time_profiler_chan: state.time_profiler_chan, + mem_profiler_chan: state.mem_profiler_chan, + window_size: window_size, + layout_to_constellation_chan: state.layout_to_constellation_chan, + script_chan: script_chan.clone(), + load_data: state.load_data, + script_port: script_port, + opts: (*opts::get()).clone(), + prefs: PREFS.cloned(), + pipeline_port: pipeline_port, + pipeline_namespace_id: state.pipeline_namespace_id, + layout_content_process_shutdown_chan: layout_content_process_shutdown_chan, + layout_content_process_shutdown_port: layout_content_process_shutdown_port, + script_content_process_shutdown_chan: script_content_process_shutdown_chan, + script_content_process_shutdown_port: script_content_process_shutdown_port, + webrender_api_sender: state.webrender_api_sender, + webvr_thread: state.webvr_thread, + }; + + // Spawn the child process. + // + // Yes, that's all there is to it! + if opts::multiprocess() { + let _ = try!(unprivileged_pipeline_content.spawn_multiprocess()); + } else { + unprivileged_pipeline_content.start_all::<Message, LTF, STF>(false); + } + + EventLoop::new(script_chan) } - } + }; Ok(Pipeline::new(state.id, state.frame_id, @@ -291,7 +292,7 @@ impl Pipeline { pipeline_chan, state.compositor_proxy, state.is_private, - state.load_data.url, + url, state.window_size, state.prev_visibility.unwrap_or(true))) } |