Rustfmt the constellation

This commit is contained in:
Connor Brewster 2018-07-21 15:03:23 -06:00
parent a97d8b99ef
commit a2064cef28
9 changed files with 1605 additions and 878 deletions

View file

@ -34,11 +34,11 @@ pub struct BrowsingContext {
impl BrowsingContext { impl BrowsingContext {
/// Create a new browsing context. /// 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. /// 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, pub fn new(
id: BrowsingContextId,
top_level_id: TopLevelBrowsingContextId, top_level_id: TopLevelBrowsingContextId,
pipeline_id: PipelineId) pipeline_id: PipelineId,
-> BrowsingContext ) -> BrowsingContext {
{
let mut pipelines = HashSet::new(); let mut pipelines = HashSet::new();
pipelines.insert(pipeline_id); pipelines.insert(pipeline_id);
BrowsingContext { BrowsingContext {
@ -84,19 +84,25 @@ impl<'a> Iterator for FullyActiveBrowsingContextsIterator<'a> {
let browsing_context = match self.browsing_contexts.get(&browsing_context_id) { let browsing_context = match self.browsing_contexts.get(&browsing_context_id) {
Some(browsing_context) => browsing_context, Some(browsing_context) => browsing_context,
None => { None => {
warn!("BrowsingContext {:?} iterated after closure.", browsing_context_id); warn!(
"BrowsingContext {:?} iterated after closure.",
browsing_context_id
);
continue; continue;
}, },
}; };
let pipeline = match self.pipelines.get(&browsing_context.pipeline_id) { let pipeline = match self.pipelines.get(&browsing_context.pipeline_id) {
Some(pipeline) => pipeline, Some(pipeline) => pipeline,
None => { None => {
warn!("Pipeline {:?} iterated after closure.", browsing_context.pipeline_id); warn!(
"Pipeline {:?} iterated after closure.",
browsing_context.pipeline_id
);
continue; continue;
}, },
}; };
self.stack.extend(pipeline.children.iter()); self.stack.extend(pipeline.children.iter());
return Some(browsing_context) return Some(browsing_context);
} }
} }
} }
@ -126,15 +132,20 @@ impl<'a> Iterator for AllBrowsingContextsIterator<'a> {
let browsing_context = match self.browsing_contexts.get(&browsing_context_id) { let browsing_context = match self.browsing_contexts.get(&browsing_context_id) {
Some(browsing_context) => browsing_context, Some(browsing_context) => browsing_context,
None => { None => {
warn!("BrowsingContext {:?} iterated after closure.", browsing_context_id); warn!(
"BrowsingContext {:?} iterated after closure.",
browsing_context_id
);
continue; continue;
}, },
}; };
let child_browsing_context_ids = browsing_context.pipelines.iter() let child_browsing_context_ids = browsing_context
.pipelines
.iter()
.filter_map(|pipeline_id| pipelines.get(&pipeline_id)) .filter_map(|pipeline_id| pipelines.get(&pipeline_id))
.flat_map(|pipeline| pipeline.children.iter()); .flat_map(|pipeline| pipeline.children.iter());
self.stack.extend(child_browsing_context_ids); self.stack.extend(child_browsing_context_ids);
return Some(browsing_context) return Some(browsing_context);
} }
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -20,7 +20,9 @@ pub struct EventLoop {
impl Drop for EventLoop { impl Drop for EventLoop {
fn drop(&mut self) { fn drop(&mut self) {
let _ = self.script_chan.send(ConstellationControlMsg::ExitScriptThread); let _ = self
.script_chan
.send(ConstellationControlMsg::ExitScriptThread);
} }
} }
@ -43,4 +45,3 @@ impl EventLoop {
self.script_chan.clone() self.script_chan.clone()
} }
} }

View file

@ -32,7 +32,8 @@ extern crate net;
extern crate net_traits; extern crate net_traits;
extern crate profile_traits; extern crate profile_traits;
extern crate script_traits; extern crate script_traits;
#[macro_use] extern crate serde; #[macro_use]
extern crate serde;
extern crate servo_config; extern crate servo_config;
extern crate servo_rand; extern crate servo_rand;
extern crate servo_remutex; extern crate servo_remutex;

View file

@ -27,17 +27,19 @@ pub struct NetworkListener {
} }
impl NetworkListener { impl NetworkListener {
pub fn new(req_init: RequestInit, pub fn new(
req_init: RequestInit,
pipeline_id: PipelineId, pipeline_id: PipelineId,
resource_threads: ResourceThreads, resource_threads: ResourceThreads,
sender: Sender<(PipelineId, FetchResponseMsg)>) -> NetworkListener { sender: Sender<(PipelineId, FetchResponseMsg)>,
) -> NetworkListener {
NetworkListener { NetworkListener {
res_init: None, res_init: None,
req_init, req_init,
pipeline_id, pipeline_id,
resource_threads, resource_threads,
sender, sender,
should_send: false should_send: false,
} }
} }
@ -57,33 +59,38 @@ impl NetworkListener {
Some(ref res_init_) => CoreResourceMsg::FetchRedirect( Some(ref res_init_) => CoreResourceMsg::FetchRedirect(
self.req_init.clone(), self.req_init.clone(),
res_init_.clone(), res_init_.clone(),
ipc_sender, None), ipc_sender,
None,
),
None => { None => {
set_default_accept(Destination::Document, &mut listener.req_init.headers); set_default_accept(Destination::Document, &mut listener.req_init.headers);
set_default_accept_language(&mut listener.req_init.headers); set_default_accept_language(&mut listener.req_init.headers);
CoreResourceMsg::Fetch( CoreResourceMsg::Fetch(
listener.req_init.clone(), listener.req_init.clone(),
FetchChannels::ResponseMsg(ipc_sender, cancel_chan)) FetchChannels::ResponseMsg(ipc_sender, cancel_chan),
} )
},
}; };
ROUTER.add_route(ipc_receiver.to_opaque(), Box::new(move |message| { ROUTER.add_route(
ipc_receiver.to_opaque(),
Box::new(move |message| {
let msg = message.to(); let msg = message.to();
match msg { match msg {
Ok(FetchResponseMsg::ProcessResponse(res)) => listener.check_redirect(res), Ok(FetchResponseMsg::ProcessResponse(res)) => listener.check_redirect(res),
Ok(msg_) => listener.send(msg_), Ok(msg_) => listener.send(msg_),
Err(e) => warn!("Error while receiving network listener message: {}", e), Err(e) => warn!("Error while receiving network listener message: {}", e),
}; };
})); }),
);
if let Err(e) = self.resource_threads.sender().send(msg) { if let Err(e) = self.resource_threads.sender().send(msg) {
warn!("Resource thread unavailable ({})", e); warn!("Resource thread unavailable ({})", e);
} }
} }
fn check_redirect(&mut self, fn check_redirect(&mut self, message: Result<(FetchMetadata), NetworkError>) {
message: Result<(FetchMetadata), NetworkError>) {
match message { match message {
Ok(res_metadata) => { Ok(res_metadata) => {
let metadata = match res_metadata { let metadata = match res_metadata {
@ -118,20 +125,23 @@ impl NetworkListener {
// Response should be processed by script thread. // Response should be processed by script thread.
self.should_send = true; self.should_send = true;
self.send(FetchResponseMsg::ProcessResponse(Ok(res_metadata.clone()))); self.send(FetchResponseMsg::ProcessResponse(Ok(res_metadata.clone())));
} },
}; };
}, },
Err(e) => { Err(e) => {
self.should_send = true; self.should_send = true;
self.send(FetchResponseMsg::ProcessResponse(Err(e))) self.send(FetchResponseMsg::ProcessResponse(Err(e)))
} },
}; };
} }
fn send(&mut self, msg: FetchResponseMsg) { fn send(&mut self, msg: FetchResponseMsg) {
if self.should_send { if self.should_send {
if let Err(e) = self.sender.send((self.pipeline_id, msg)) { if let Err(e) = self.sender.send((self.pipeline_id, msg)) {
warn!("Failed to forward network message to pipeline {}: {:?}", self.pipeline_id, e); warn!(
"Failed to forward network message to pipeline {}: {:?}",
self.pipeline_id, e
);
} }
} }
} }

View file

@ -190,23 +190,21 @@ impl Pipeline {
/// Starts a layout thread, and possibly a script thread, in /// Starts a layout thread, and possibly a script thread, in
/// a new process if requested. /// a new process if requested.
pub fn spawn<Message, LTF, STF>(state: InitialPipelineState) -> Result<Pipeline, Error> pub fn spawn<Message, LTF, STF>(state: InitialPipelineState) -> Result<Pipeline, Error>
where LTF: LayoutThreadFactory<Message=Message>, where
STF: ScriptThreadFactory<Message=Message> LTF: LayoutThreadFactory<Message = Message>,
STF: ScriptThreadFactory<Message = Message>,
{ {
// Note: we allow channel creation to panic, since recovering from this // Note: we allow channel creation to panic, since recovering from this
// probably requires a general low-memory strategy. // probably requires a general low-memory strategy.
let (pipeline_chan, pipeline_port) = ipc::channel() let (pipeline_chan, pipeline_port) = ipc::channel().expect("Pipeline main chan");
.expect("Pipeline main chan");
let (layout_content_process_shutdown_chan, layout_content_process_shutdown_port) = let (layout_content_process_shutdown_chan, layout_content_process_shutdown_port) =
ipc::channel().expect("Pipeline layout content shutdown chan"); ipc::channel().expect("Pipeline layout content shutdown chan");
let device_pixel_ratio = state.device_pixel_ratio; let device_pixel_ratio = state.device_pixel_ratio;
let window_size = state.window_size.map(|size| { let window_size = state.window_size.map(|size| WindowSizeData {
WindowSizeData {
initial_viewport: size, initial_viewport: size,
device_pixel_ratio: device_pixel_ratio, device_pixel_ratio: device_pixel_ratio,
}
}); });
let url = state.load_data.url.clone(); let url = state.load_data.url.clone();
@ -221,31 +219,42 @@ impl Pipeline {
load_data: state.load_data.clone(), load_data: state.load_data.clone(),
window_size: window_size, window_size: window_size,
pipeline_port: pipeline_port, pipeline_port: pipeline_port,
content_process_shutdown_chan: Some(layout_content_process_shutdown_chan.clone()), content_process_shutdown_chan: Some(
layout_content_process_shutdown_chan.clone(),
),
layout_threads: PREFS.get("layout.threads").as_u64().expect("count") as usize, layout_threads: PREFS.get("layout.threads").as_u64().expect("count") as usize,
}; };
if let Err(e) = script_chan.send(ConstellationControlMsg::AttachLayout(new_layout_info)) { if let Err(e) =
script_chan.send(ConstellationControlMsg::AttachLayout(new_layout_info))
{
warn!("Sending to script during pipeline creation failed ({})", e); warn!("Sending to script during pipeline creation failed ({})", e);
} }
script_chan script_chan
} },
None => { None => {
let (script_chan, script_port) = ipc::channel().expect("Pipeline script chan"); let (script_chan, script_port) = ipc::channel().expect("Pipeline script chan");
// Route messages coming from content to devtools as appropriate. // 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 = state.devtools_chan.as_ref().map(|devtools_chan| {
let (script_to_devtools_chan, script_to_devtools_port) = ipc::channel() let (script_to_devtools_chan, script_to_devtools_port) =
.expect("Pipeline script to devtools chan"); ipc::channel().expect("Pipeline script to devtools chan");
let devtools_chan = (*devtools_chan).clone(); let devtools_chan = (*devtools_chan).clone();
ROUTER.add_route(script_to_devtools_port.to_opaque(), Box::new(move |message| { ROUTER.add_route(
match message.to::<ScriptToDevtoolsControlMsg>() { script_to_devtools_port.to_opaque(),
Err(e) => error!("Cast to ScriptToDevtoolsControlMsg failed ({}).", e), Box::new(
Ok(message) => if let Err(e) = devtools_chan.send(DevtoolsControlMsg::FromScript(message)) { 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) warn!("Sending to devtools failed ({})", e)
}, },
} },
})); ),
);
script_to_devtools_chan script_to_devtools_chan
}); });
@ -295,10 +304,11 @@ impl Pipeline {
} }
EventLoop::new(script_chan) EventLoop::new(script_chan)
} },
}; };
Ok(Pipeline::new(state.id, Ok(Pipeline::new(
state.id,
state.browsing_context_id, state.browsing_context_id,
state.top_level_browsing_context_id, state.top_level_browsing_context_id,
state.parent_info, state.parent_info,
@ -308,12 +318,14 @@ impl Pipeline {
state.is_private, state.is_private,
url, url,
state.prev_visibility.unwrap_or(true), state.prev_visibility.unwrap_or(true),
state.load_data)) state.load_data,
))
} }
/// Creates a new `Pipeline`, after the script and layout threads have been /// Creates a new `Pipeline`, after the script and layout threads have been
/// spawned. /// spawned.
pub fn new(id: PipelineId, pub fn new(
id: PipelineId,
browsing_context_id: BrowsingContextId, browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId, top_level_browsing_context_id: TopLevelBrowsingContextId,
parent_info: Option<PipelineId>, parent_info: Option<PipelineId>,
@ -323,8 +335,8 @@ impl Pipeline {
is_private: bool, is_private: bool,
url: ServoUrl, url: ServoUrl,
visible: bool, visible: bool,
load_data: LoadData) load_data: LoadData,
-> Pipeline { ) -> Pipeline {
let pipeline = Pipeline { let pipeline = Pipeline {
id: id, id: id,
browsing_context_id: browsing_context_id, browsing_context_id: browsing_context_id,
@ -334,7 +346,7 @@ impl Pipeline {
layout_chan: layout_chan, layout_chan: layout_chan,
compositor_proxy: compositor_proxy, compositor_proxy: compositor_proxy,
url: url, url: url,
children: vec!(), children: vec![],
running_animations: false, running_animations: false,
visible: visible, visible: visible,
is_private: is_private, is_private: is_private,
@ -359,7 +371,8 @@ impl Pipeline {
// It's OK for the constellation to block on the compositor, // It's OK for the constellation to block on the compositor,
// since the compositor never blocks on the constellation. // since the compositor never blocks on the constellation.
if let Ok((sender, receiver)) = ipc::channel() { if let Ok((sender, receiver)) = ipc::channel() {
self.compositor_proxy.send(CompositorMsg::PipelineExited(self.id, sender)); self.compositor_proxy
.send(CompositorMsg::PipelineExited(self.id, sender));
if let Err(e) = receiver.recv() { if let Err(e) = receiver.recv() {
warn!("Sending exit message failed ({}).", e); warn!("Sending exit message failed ({}).", e);
} }
@ -410,15 +423,25 @@ impl Pipeline {
/// Remove a child browsing context. /// Remove a child browsing context.
pub fn remove_child(&mut self, browsing_context_id: BrowsingContextId) { pub fn remove_child(&mut self, browsing_context_id: BrowsingContextId) {
match self.children.iter().position(|id| *id == browsing_context_id) { match self
None => return warn!("Pipeline remove child already removed ({:?}).", browsing_context_id), .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), Some(index) => self.children.remove(index),
}; };
} }
/// Notify the script thread that this pipeline is visible. /// Notify the script thread that this pipeline is visible.
fn notify_visibility(&self) { fn notify_visibility(&self) {
let script_msg = ConstellationControlMsg::ChangeFrameVisibilityStatus(self.id, self.visible); let script_msg =
ConstellationControlMsg::ChangeFrameVisibilityStatus(self.id, self.visible);
let compositor_msg = CompositorMsg::PipelineVisibilityChanged(self.id, self.visible); let compositor_msg = CompositorMsg::PipelineVisibilityChanged(self.id, self.visible);
let err = self.event_loop.send(script_msg); let err = self.event_loop.send(script_msg);
if let Err(e) = err { if let Err(e) = err {
@ -435,7 +458,6 @@ impl Pipeline {
self.visible = visible; self.visible = visible;
self.notify_visibility(); self.notify_visibility();
} }
} }
/// Creating a new pipeline may require creating a new event loop. /// Creating a new pipeline may require creating a new event loop.
@ -477,16 +499,20 @@ pub struct UnprivilegedPipelineContent {
impl UnprivilegedPipelineContent { impl UnprivilegedPipelineContent {
pub fn start_all<Message, LTF, STF>(self, wait_for_completion: bool) pub fn start_all<Message, LTF, STF>(self, wait_for_completion: bool)
where LTF: LayoutThreadFactory<Message=Message>, where
STF: ScriptThreadFactory<Message=Message> LTF: LayoutThreadFactory<Message = Message>,
STF: ScriptThreadFactory<Message = Message>,
{ {
let image_cache = Arc::new(ImageCacheImpl::new(self.webrender_api_sender.create_api())); let image_cache = Arc::new(ImageCacheImpl::new(self.webrender_api_sender.create_api()));
let paint_time_metrics = PaintTimeMetrics::new(self.id, let paint_time_metrics = PaintTimeMetrics::new(
self.id,
self.time_profiler_chan.clone(), self.time_profiler_chan.clone(),
self.layout_to_constellation_chan.clone(), self.layout_to_constellation_chan.clone(),
self.script_chan.clone(), self.script_chan.clone(),
self.load_data.url.clone()); self.load_data.url.clone(),
let layout_pair = STF::create(InitialScriptState { );
let layout_pair = STF::create(
InitialScriptState {
id: self.id, id: self.id,
browsing_context_id: self.browsing_context_id, browsing_context_id: self.browsing_context_id,
top_level_browsing_context_id: self.top_level_browsing_context_id, top_level_browsing_context_id: self.top_level_browsing_context_id,
@ -508,9 +534,12 @@ impl UnprivilegedPipelineContent {
webgl_chan: self.webgl_chan, webgl_chan: self.webgl_chan,
webvr_chan: self.webvr_chan, webvr_chan: self.webvr_chan,
webrender_document: self.webrender_document, webrender_document: self.webrender_document,
}, self.load_data.clone()); },
self.load_data.clone(),
);
LTF::create(self.id, LTF::create(
self.id,
self.top_level_browsing_context_id, self.top_level_browsing_context_id,
self.load_data.url, self.load_data.url,
self.parent_info.is_some(), self.parent_info.is_some(),
@ -525,9 +554,14 @@ impl UnprivilegedPipelineContent {
Some(self.layout_content_process_shutdown_chan), Some(self.layout_content_process_shutdown_chan),
self.webrender_api_sender, self.webrender_api_sender,
self.webrender_document, self.webrender_document,
self.prefs.get("layout.threads").expect("exists").value() self.prefs
.as_u64().expect("count") as usize, .get("layout.threads")
paint_time_metrics); .expect("exists")
.value()
.as_u64()
.expect("count") as usize,
paint_time_metrics,
);
if wait_for_completion { if wait_for_completion {
let _ = self.script_content_process_shutdown_port.recv(); let _ = self.script_content_process_shutdown_port.recv();
@ -543,12 +577,17 @@ impl UnprivilegedPipelineContent {
impl CommandMethods for sandbox::Command { impl CommandMethods for sandbox::Command {
fn arg<T>(&mut self, arg: T) fn arg<T>(&mut self, arg: T)
where T: AsRef<OsStr> { where
T: AsRef<OsStr>,
{
self.arg(arg); self.arg(arg);
} }
fn env<T, U>(&mut self, key: T, val: U) fn env<T, U>(&mut self, key: T, val: U)
where T: AsRef<OsStr>, U: AsRef<OsStr> { where
T: AsRef<OsStr>,
U: AsRef<OsStr>,
{
self.env(key, val); self.env(key, val);
} }
} }
@ -556,8 +595,7 @@ impl UnprivilegedPipelineContent {
// Note that this function can panic, due to process creation, // Note that this function can panic, due to process creation,
// avoiding this panic would require a mechanism for dealing // avoiding this panic would require a mechanism for dealing
// with low-resource scenarios. // with low-resource scenarios.
let (server, token) = let (server, token) = IpcOneShotServer::<IpcSender<UnprivilegedPipelineContent>>::new()
IpcOneShotServer::<IpcSender<UnprivilegedPipelineContent>>::new()
.expect("Failed to create IPC one-shot server."); .expect("Failed to create IPC one-shot server.");
// If there is a sandbox, use the `gaol` API to create the child process. // If there is a sandbox, use the `gaol` API to create the child process.
@ -570,11 +608,12 @@ impl UnprivilegedPipelineContent {
.start(&mut command) .start(&mut command)
.expect("Failed to start sandboxed child process!"); .expect("Failed to start sandboxed child process!");
} else { } else {
let path_to_self = env::current_exe() let path_to_self = env::current_exe().expect("Failed to get current executor.");
.expect("Failed to get current executor.");
let mut child_process = process::Command::new(path_to_self); let mut child_process = process::Command::new(path_to_self);
self.setup_common(&mut child_process, token); self.setup_common(&mut child_process, token);
let _ = child_process.spawn().expect("Failed to start unsandboxed child process!"); let _ = child_process
.spawn()
.expect("Failed to start unsandboxed child process!");
} }
let (_receiver, sender) = server.accept().expect("Server failed to accept."); let (_receiver, sender) = server.accept().expect("Server failed to accept.");
@ -618,7 +657,7 @@ impl UnprivilegedPipelineContent {
pub fn swmanager_senders(&self) -> SWManagerSenders { pub fn swmanager_senders(&self) -> SWManagerSenders {
SWManagerSenders { SWManagerSenders {
swmanager_sender: self.swmanager_thread.clone(), swmanager_sender: self.swmanager_thread.clone(),
resource_sender: self.resource_threads.sender() resource_sender: self.resource_threads.sender(),
} }
} }
} }
@ -627,21 +666,29 @@ impl UnprivilegedPipelineContent {
trait CommandMethods { trait CommandMethods {
/// A command line argument. /// A command line argument.
fn arg<T>(&mut self, arg: T) fn arg<T>(&mut self, arg: T)
where T: AsRef<OsStr>; where
T: AsRef<OsStr>;
/// An environment variable. /// An environment variable.
fn env<T, U>(&mut self, key: T, val: U) fn env<T, U>(&mut self, key: T, val: U)
where T: AsRef<OsStr>, U: AsRef<OsStr>; where
T: AsRef<OsStr>,
U: AsRef<OsStr>;
} }
impl CommandMethods for process::Command { impl CommandMethods for process::Command {
fn arg<T>(&mut self, arg: T) fn arg<T>(&mut self, arg: T)
where T: AsRef<OsStr> { where
T: AsRef<OsStr>,
{
self.arg(arg); self.arg(arg);
} }
fn env<T, U>(&mut self, key: T, val: U) fn env<T, U>(&mut self, key: T, val: U)
where T: AsRef<OsStr>, U: AsRef<OsStr> { where
T: AsRef<OsStr>,
U: AsRef<OsStr>,
{
self.env(key, val); self.env(key, val);
} }
} }

View file

@ -16,24 +16,31 @@ pub fn content_process_sandbox_profile() -> Profile {
Operation::FileReadAll(PathPattern::Subpath(PathBuf::from("/Library/Fonts"))), Operation::FileReadAll(PathPattern::Subpath(PathBuf::from("/Library/Fonts"))),
Operation::FileReadAll(PathPattern::Subpath(PathBuf::from("/System/Library/Fonts"))), Operation::FileReadAll(PathPattern::Subpath(PathBuf::from("/System/Library/Fonts"))),
Operation::FileReadAll(PathPattern::Subpath(PathBuf::from( Operation::FileReadAll(PathPattern::Subpath(PathBuf::from(
"/System/Library/Frameworks/ApplicationServices.framework"))), "/System/Library/Frameworks/ApplicationServices.framework",
))),
Operation::FileReadAll(PathPattern::Subpath(PathBuf::from( Operation::FileReadAll(PathPattern::Subpath(PathBuf::from(
"/System/Library/Frameworks/CoreGraphics.framework"))), "/System/Library/Frameworks/CoreGraphics.framework",
))),
Operation::FileReadMetadata(PathPattern::Literal(PathBuf::from("/"))), Operation::FileReadMetadata(PathPattern::Literal(PathBuf::from("/"))),
Operation::FileReadMetadata(PathPattern::Literal(PathBuf::from("/Library"))), Operation::FileReadMetadata(PathPattern::Literal(PathBuf::from("/Library"))),
Operation::FileReadMetadata(PathPattern::Literal(PathBuf::from("/System"))), Operation::FileReadMetadata(PathPattern::Literal(PathBuf::from("/System"))),
Operation::FileReadMetadata(PathPattern::Literal(PathBuf::from("/etc"))), Operation::FileReadMetadata(PathPattern::Literal(PathBuf::from("/etc"))),
Operation::SystemInfoRead, Operation::SystemInfoRead,
Operation::PlatformSpecific(platform::macos::Operation::MachLookup( Operation::PlatformSpecific(platform::macos::Operation::MachLookup(
b"com.apple.FontServer".to_vec())), b"com.apple.FontServer".to_vec(),
)),
]; ];
operations.extend(resources::sandbox_access_files().into_iter().map(|p| { operations.extend(
Operation::FileReadAll(PathPattern::Literal(p)) resources::sandbox_access_files()
})); .into_iter()
operations.extend(resources::sandbox_access_files_dirs().into_iter().map(|p| { .map(|p| Operation::FileReadAll(PathPattern::Literal(p))),
Operation::FileReadAll(PathPattern::Subpath(p)) );
})); operations.extend(
resources::sandbox_access_files_dirs()
.into_iter()
.map(|p| Operation::FileReadAll(PathPattern::Subpath(p))),
);
Profile::new(operations).expect("Failed to create sandbox profile!") Profile::new(operations).expect("Failed to create sandbox profile!")
} }
@ -41,17 +48,20 @@ pub fn content_process_sandbox_profile() -> Profile {
/// Our content process sandbox profile on Linux. As restrictive as possible. /// Our content process sandbox profile on Linux. As restrictive as possible.
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
pub fn content_process_sandbox_profile() -> Profile { pub fn content_process_sandbox_profile() -> Profile {
let mut operations = vec![ let mut operations = vec![Operation::FileReadAll(PathPattern::Literal(PathBuf::from(
Operation::FileReadAll(PathPattern::Literal(PathBuf::from("/dev/urandom"))), "/dev/urandom",
]; )))];
operations.extend(resources::sandbox_access_files().into_iter().map(|p| { operations.extend(
Operation::FileReadAll(PathPattern::Literal(p)) resources::sandbox_access_files()
})); .into_iter()
operations.extend(resources::sandbox_access_files_dirs().into_iter().map(|p| { .map(|p| Operation::FileReadAll(PathPattern::Literal(p))),
Operation::FileReadAll(PathPattern::Subpath(p)) );
})); operations.extend(
resources::sandbox_access_files_dirs()
.into_iter()
.map(|p| Operation::FileReadAll(PathPattern::Subpath(p))),
);
Profile::new(operations).expect("Failed to create sandbox profile!") Profile::new(operations).expect("Failed to create sandbox profile!")
} }

View file

@ -44,19 +44,36 @@ impl JointSessionHistory {
} }
} }
pub fn replace_history_state(&mut self, pipeline_id: PipelineId, history_state_id: HistoryStateId, url: ServoUrl) { pub fn replace_history_state(
if let Some(SessionHistoryDiff::PipelineDiff { ref mut new_history_state_id, ref mut new_url, .. }) = &mut self,
self.past.iter_mut().find(|diff| match diff { pipeline_id: PipelineId,
SessionHistoryDiff::PipelineDiff { pipeline_reloader: NeedsToReload::No(id), .. } => pipeline_id == *id, history_state_id: HistoryStateId,
url: ServoUrl,
) {
if let Some(SessionHistoryDiff::PipelineDiff {
ref mut new_history_state_id,
ref mut new_url,
..
}) = self.past.iter_mut().find(|diff| match diff {
SessionHistoryDiff::PipelineDiff {
pipeline_reloader: NeedsToReload::No(id),
..
} => pipeline_id == *id,
_ => false, _ => false,
}) { }) {
*new_history_state_id = history_state_id; *new_history_state_id = history_state_id;
*new_url = url.clone(); *new_url = url.clone();
} }
if let Some(SessionHistoryDiff::PipelineDiff { ref mut old_history_state_id, ref mut old_url, .. }) = if let Some(SessionHistoryDiff::PipelineDiff {
self.future.iter_mut().find(|diff| match diff { ref mut old_history_state_id,
SessionHistoryDiff::PipelineDiff { pipeline_reloader: NeedsToReload::No(id), .. } => pipeline_id == *id, ref mut old_url,
..
}) = self.future.iter_mut().find(|diff| match diff {
SessionHistoryDiff::PipelineDiff {
pipeline_reloader: NeedsToReload::No(id),
..
} => pipeline_id == *id,
_ => false, _ => false,
}) { }) {
*old_history_state_id = Some(history_state_id); *old_history_state_id = Some(history_state_id);
@ -65,21 +82,19 @@ impl JointSessionHistory {
} }
pub fn remove_entries_for_browsing_context(&mut self, context_id: BrowsingContextId) { pub fn remove_entries_for_browsing_context(&mut self, context_id: BrowsingContextId) {
self.past.retain(|diff| { self.past.retain(|diff| match diff {
match diff { SessionHistoryDiff::BrowsingContextDiff {
SessionHistoryDiff::BrowsingContextDiff { browsing_context_id, .. } => { browsing_context_id,
*browsing_context_id != context_id ..
}, } => *browsing_context_id != context_id,
_ => true, _ => true,
}
}); });
self.future.retain(|diff| { self.future.retain(|diff| match diff {
match diff { SessionHistoryDiff::BrowsingContextDiff {
SessionHistoryDiff::BrowsingContextDiff { browsing_context_id, .. } => { browsing_context_id,
*browsing_context_id != context_id ..
}, } => *browsing_context_id != context_id,
_ => true, _ => true,
}
}); });
} }
} }
@ -132,22 +147,17 @@ impl NeedsToReload {
impl PartialEq for NeedsToReload { impl PartialEq for NeedsToReload {
fn eq(&self, other: &NeedsToReload) -> bool { fn eq(&self, other: &NeedsToReload) -> bool {
match *self { match *self {
NeedsToReload::No(pipeline_id) => { NeedsToReload::No(pipeline_id) => match *other {
match *other {
NeedsToReload::No(other_pipeline_id) => pipeline_id == other_pipeline_id, NeedsToReload::No(other_pipeline_id) => pipeline_id == other_pipeline_id,
_ => false, _ => false,
}
}, },
NeedsToReload::Yes(pipeline_id, _) => { NeedsToReload::Yes(pipeline_id, _) => match *other {
match *other {
NeedsToReload::Yes(other_pipeline_id, _) => pipeline_id == other_pipeline_id, NeedsToReload::Yes(other_pipeline_id, _) => pipeline_id == other_pipeline_id,
_ => false, _ => false,
},
} }
} }
} }
}
}
/// Represents a the difference between two adjacent session history entries. /// Represents a the difference between two adjacent session history entries.
#[derive(Debug)] #[derive(Debug)]
@ -185,11 +195,11 @@ impl SessionHistoryDiff {
/// Returns the old pipeline id if that pipeline is still alive, otherwise returns `None` /// Returns the old pipeline id if that pipeline is still alive, otherwise returns `None`
pub fn alive_old_pipeline(&self) -> Option<PipelineId> { pub fn alive_old_pipeline(&self) -> Option<PipelineId> {
match *self { match *self {
SessionHistoryDiff::BrowsingContextDiff { ref old_reloader, .. } => { SessionHistoryDiff::BrowsingContextDiff {
match *old_reloader { ref old_reloader, ..
} => match *old_reloader {
NeedsToReload::No(pipeline_id) => Some(pipeline_id), NeedsToReload::No(pipeline_id) => Some(pipeline_id),
NeedsToReload::Yes(..) => None, NeedsToReload::Yes(..) => None,
}
}, },
_ => None, _ => None,
} }
@ -198,20 +208,28 @@ impl SessionHistoryDiff {
/// Returns the new pipeline id if that pipeline is still alive, otherwise returns `None` /// Returns the new pipeline id if that pipeline is still alive, otherwise returns `None`
pub fn alive_new_pipeline(&self) -> Option<PipelineId> { pub fn alive_new_pipeline(&self) -> Option<PipelineId> {
match *self { match *self {
SessionHistoryDiff::BrowsingContextDiff { ref new_reloader, .. } => { SessionHistoryDiff::BrowsingContextDiff {
match *new_reloader { ref new_reloader, ..
} => match *new_reloader {
NeedsToReload::No(pipeline_id) => Some(pipeline_id), NeedsToReload::No(pipeline_id) => Some(pipeline_id),
NeedsToReload::Yes(..) => None, NeedsToReload::Yes(..) => None,
}
}, },
_ => None, _ => None,
} }
} }
/// Replaces all occurances of the replaced pipeline with a new pipeline /// Replaces all occurances of the replaced pipeline with a new pipeline
pub fn replace_reloader(&mut self, replaced_reloader: &NeedsToReload, reloader: &NeedsToReload) { pub fn replace_reloader(
&mut self,
replaced_reloader: &NeedsToReload,
reloader: &NeedsToReload,
) {
match *self { match *self {
SessionHistoryDiff::BrowsingContextDiff { ref mut old_reloader, ref mut new_reloader, .. } => { SessionHistoryDiff::BrowsingContextDiff {
ref mut old_reloader,
ref mut new_reloader,
..
} => {
if *old_reloader == *replaced_reloader { if *old_reloader == *replaced_reloader {
*old_reloader = reloader.clone(); *old_reloader = reloader.clone();
} }
@ -219,12 +237,18 @@ impl SessionHistoryDiff {
*new_reloader = reloader.clone(); *new_reloader = reloader.clone();
} }
}, },
SessionHistoryDiff::PipelineDiff { ref mut pipeline_reloader, .. } => { SessionHistoryDiff::PipelineDiff {
ref mut pipeline_reloader,
..
} => {
if *pipeline_reloader == *replaced_reloader { if *pipeline_reloader == *replaced_reloader {
*pipeline_reloader = reloader.clone(); *pipeline_reloader = reloader.clone();
} }
}, },
SessionHistoryDiff::HashDiff { ref mut pipeline_reloader, .. } => { SessionHistoryDiff::HashDiff {
ref mut pipeline_reloader,
..
} => {
if *pipeline_reloader == *replaced_reloader { if *pipeline_reloader == *replaced_reloader {
*pipeline_reloader = reloader.clone(); *pipeline_reloader = reloader.clone();
} }

View file

@ -75,7 +75,10 @@ impl TimerScheduler {
Ok(TimerSchedulerMsg::Request(req)) => { Ok(TimerSchedulerMsg::Request(req)) => {
let TimerEventRequest(_, _, _, delay) = req; let TimerEventRequest(_, _, _, delay) = req;
let schedule = Instant::now() + Duration::from_millis(delay.get()); let schedule = Instant::now() + Duration::from_millis(delay.get());
let event = ScheduledEvent { request: req, for_time: schedule }; let event = ScheduledEvent {
request: req,
for_time: schedule,
};
scheduled_events.push(event); scheduled_events.push(event);
}, },
// If there is no incoming event, park the thread, // If there is no incoming event, park the thread,
@ -86,8 +89,7 @@ impl TimerScheduler {
Some(event) => thread::park_timeout(event.for_time - now), Some(event) => thread::park_timeout(event.for_time - now),
}, },
// If the channel is closed or we are shutting down, we are done. // If the channel is closed or we are shutting down, we are done.
Ok(TimerSchedulerMsg::Exit) | Ok(TimerSchedulerMsg::Exit) | Err(Disconnected) => break,
Err(Disconnected) => break,
} }
} }
// This thread can terminate if the req_ipc_sender is dropped. // This thread can terminate if the req_ipc_sender is dropped.
@ -109,7 +111,7 @@ impl TimerScheduler {
let mut shutting_down = false; let mut shutting_down = false;
match req { match req {
TimerSchedulerMsg::Exit => shutting_down = true, TimerSchedulerMsg::Exit => shutting_down = true,
_ => {} _ => {},
} }
let _ = req_sender.send(req); let _ = req_sender.send(req);
timeout_thread.unpark(); timeout_thread.unpark();