mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Rustfmt the constellation
This commit is contained in:
parent
a97d8b99ef
commit
a2064cef28
9 changed files with 1605 additions and 878 deletions
|
@ -34,11 +34,11 @@ pub struct BrowsingContext {
|
|||
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,
|
||||
top_level_id: TopLevelBrowsingContextId,
|
||||
pipeline_id: PipelineId)
|
||||
-> BrowsingContext
|
||||
{
|
||||
pub fn new(
|
||||
id: BrowsingContextId,
|
||||
top_level_id: TopLevelBrowsingContextId,
|
||||
pipeline_id: PipelineId,
|
||||
) -> BrowsingContext {
|
||||
let mut pipelines = HashSet::new();
|
||||
pipelines.insert(pipeline_id);
|
||||
BrowsingContext {
|
||||
|
@ -84,19 +84,25 @@ impl<'a> Iterator for FullyActiveBrowsingContextsIterator<'a> {
|
|||
let browsing_context = match self.browsing_contexts.get(&browsing_context_id) {
|
||||
Some(browsing_context) => browsing_context,
|
||||
None => {
|
||||
warn!("BrowsingContext {:?} iterated after closure.", browsing_context_id);
|
||||
warn!(
|
||||
"BrowsingContext {:?} iterated after closure.",
|
||||
browsing_context_id
|
||||
);
|
||||
continue;
|
||||
},
|
||||
};
|
||||
let pipeline = match self.pipelines.get(&browsing_context.pipeline_id) {
|
||||
Some(pipeline) => pipeline,
|
||||
None => {
|
||||
warn!("Pipeline {:?} iterated after closure.", browsing_context.pipeline_id);
|
||||
warn!(
|
||||
"Pipeline {:?} iterated after closure.",
|
||||
browsing_context.pipeline_id
|
||||
);
|
||||
continue;
|
||||
},
|
||||
};
|
||||
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) {
|
||||
Some(browsing_context) => browsing_context,
|
||||
None => {
|
||||
warn!("BrowsingContext {:?} iterated after closure.", browsing_context_id);
|
||||
warn!(
|
||||
"BrowsingContext {:?} iterated after closure.",
|
||||
browsing_context_id
|
||||
);
|
||||
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))
|
||||
.flat_map(|pipeline| pipeline.children.iter());
|
||||
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
|
@ -20,7 +20,9 @@ pub struct EventLoop {
|
|||
|
||||
impl Drop for EventLoop {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@ extern crate net;
|
|||
extern crate net_traits;
|
||||
extern crate profile_traits;
|
||||
extern crate script_traits;
|
||||
#[macro_use] extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde;
|
||||
extern crate servo_config;
|
||||
extern crate servo_rand;
|
||||
extern crate servo_remutex;
|
||||
|
|
|
@ -27,17 +27,19 @@ pub struct NetworkListener {
|
|||
}
|
||||
|
||||
impl NetworkListener {
|
||||
pub fn new(req_init: RequestInit,
|
||||
pipeline_id: PipelineId,
|
||||
resource_threads: ResourceThreads,
|
||||
sender: Sender<(PipelineId, FetchResponseMsg)>) -> NetworkListener {
|
||||
pub fn new(
|
||||
req_init: RequestInit,
|
||||
pipeline_id: PipelineId,
|
||||
resource_threads: ResourceThreads,
|
||||
sender: Sender<(PipelineId, FetchResponseMsg)>,
|
||||
) -> NetworkListener {
|
||||
NetworkListener {
|
||||
res_init: None,
|
||||
req_init,
|
||||
pipeline_id,
|
||||
resource_threads,
|
||||
sender,
|
||||
should_send: false
|
||||
should_send: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,35 +57,40 @@ impl NetworkListener {
|
|||
|
||||
let msg = match self.res_init {
|
||||
Some(ref res_init_) => CoreResourceMsg::FetchRedirect(
|
||||
self.req_init.clone(),
|
||||
res_init_.clone(),
|
||||
ipc_sender, None),
|
||||
self.req_init.clone(),
|
||||
res_init_.clone(),
|
||||
ipc_sender,
|
||||
None,
|
||||
),
|
||||
None => {
|
||||
set_default_accept(Destination::Document, &mut listener.req_init.headers);
|
||||
set_default_accept_language(&mut listener.req_init.headers);
|
||||
|
||||
CoreResourceMsg::Fetch(
|
||||
listener.req_init.clone(),
|
||||
FetchChannels::ResponseMsg(ipc_sender, cancel_chan))
|
||||
}
|
||||
listener.req_init.clone(),
|
||||
FetchChannels::ResponseMsg(ipc_sender, cancel_chan),
|
||||
)
|
||||
},
|
||||
};
|
||||
|
||||
ROUTER.add_route(ipc_receiver.to_opaque(), Box::new(move |message| {
|
||||
let msg = message.to();
|
||||
match msg {
|
||||
Ok(FetchResponseMsg::ProcessResponse(res)) => listener.check_redirect(res),
|
||||
Ok(msg_) => listener.send(msg_),
|
||||
Err(e) => warn!("Error while receiving network listener message: {}", e),
|
||||
};
|
||||
}));
|
||||
ROUTER.add_route(
|
||||
ipc_receiver.to_opaque(),
|
||||
Box::new(move |message| {
|
||||
let msg = message.to();
|
||||
match msg {
|
||||
Ok(FetchResponseMsg::ProcessResponse(res)) => listener.check_redirect(res),
|
||||
Ok(msg_) => listener.send(msg_),
|
||||
Err(e) => warn!("Error while receiving network listener message: {}", e),
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
if let Err(e) = self.resource_threads.sender().send(msg) {
|
||||
warn!("Resource thread unavailable ({})", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_redirect(&mut self,
|
||||
message: Result<(FetchMetadata), NetworkError>) {
|
||||
fn check_redirect(&mut self, message: Result<(FetchMetadata), NetworkError>) {
|
||||
match message {
|
||||
Ok(res_metadata) => {
|
||||
let metadata = match res_metadata {
|
||||
|
@ -118,20 +125,23 @@ impl NetworkListener {
|
|||
// Response should be processed by script thread.
|
||||
self.should_send = true;
|
||||
self.send(FetchResponseMsg::ProcessResponse(Ok(res_metadata.clone())));
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
Err(e) => {
|
||||
self.should_send = true;
|
||||
self.send(FetchResponseMsg::ProcessResponse(Err(e)))
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
fn send(&mut self, msg: FetchResponseMsg) {
|
||||
if self.should_send {
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -190,23 +190,21 @@ impl Pipeline {
|
|||
/// Starts a layout thread, and possibly a script thread, in
|
||||
/// a new process if requested.
|
||||
pub fn spawn<Message, LTF, STF>(state: InitialPipelineState) -> Result<Pipeline, Error>
|
||||
where LTF: LayoutThreadFactory<Message=Message>,
|
||||
STF: ScriptThreadFactory<Message=Message>
|
||||
where
|
||||
LTF: LayoutThreadFactory<Message = Message>,
|
||||
STF: ScriptThreadFactory<Message = Message>,
|
||||
{
|
||||
// Note: we allow channel creation to panic, since recovering from this
|
||||
// probably requires a general low-memory strategy.
|
||||
let (pipeline_chan, pipeline_port) = ipc::channel()
|
||||
.expect("Pipeline main chan");
|
||||
let (pipeline_chan, pipeline_port) = ipc::channel().expect("Pipeline main chan");
|
||||
|
||||
let (layout_content_process_shutdown_chan, layout_content_process_shutdown_port) =
|
||||
ipc::channel().expect("Pipeline layout content shutdown chan");
|
||||
|
||||
let device_pixel_ratio = state.device_pixel_ratio;
|
||||
let window_size = state.window_size.map(|size| {
|
||||
WindowSizeData {
|
||||
initial_viewport: size,
|
||||
device_pixel_ratio: device_pixel_ratio,
|
||||
}
|
||||
let window_size = state.window_size.map(|size| WindowSizeData {
|
||||
initial_viewport: size,
|
||||
device_pixel_ratio: device_pixel_ratio,
|
||||
});
|
||||
|
||||
let url = state.load_data.url.clone();
|
||||
|
@ -221,31 +219,42 @@ impl Pipeline {
|
|||
load_data: state.load_data.clone(),
|
||||
window_size: window_size,
|
||||
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,
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
script_chan
|
||||
}
|
||||
},
|
||||
None => {
|
||||
let (script_chan, script_port) = ipc::channel().expect("Pipeline script chan");
|
||||
|
||||
// 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 (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::new(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)
|
||||
ROUTER.add_route(
|
||||
script_to_devtools_port.to_opaque(),
|
||||
Box::new(
|
||||
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
|
||||
});
|
||||
|
||||
|
@ -295,36 +304,39 @@ impl Pipeline {
|
|||
}
|
||||
|
||||
EventLoop::new(script_chan)
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Pipeline::new(state.id,
|
||||
state.browsing_context_id,
|
||||
state.top_level_browsing_context_id,
|
||||
state.parent_info,
|
||||
script_chan,
|
||||
pipeline_chan,
|
||||
state.compositor_proxy,
|
||||
state.is_private,
|
||||
url,
|
||||
state.prev_visibility.unwrap_or(true),
|
||||
state.load_data))
|
||||
Ok(Pipeline::new(
|
||||
state.id,
|
||||
state.browsing_context_id,
|
||||
state.top_level_browsing_context_id,
|
||||
state.parent_info,
|
||||
script_chan,
|
||||
pipeline_chan,
|
||||
state.compositor_proxy,
|
||||
state.is_private,
|
||||
url,
|
||||
state.prev_visibility.unwrap_or(true),
|
||||
state.load_data,
|
||||
))
|
||||
}
|
||||
|
||||
/// Creates a new `Pipeline`, after the script and layout threads have been
|
||||
/// spawned.
|
||||
pub fn new(id: PipelineId,
|
||||
browsing_context_id: BrowsingContextId,
|
||||
top_level_browsing_context_id: TopLevelBrowsingContextId,
|
||||
parent_info: Option<PipelineId>,
|
||||
event_loop: Rc<EventLoop>,
|
||||
layout_chan: IpcSender<LayoutControlMsg>,
|
||||
compositor_proxy: CompositorProxy,
|
||||
is_private: bool,
|
||||
url: ServoUrl,
|
||||
visible: bool,
|
||||
load_data: LoadData)
|
||||
-> Pipeline {
|
||||
pub fn new(
|
||||
id: PipelineId,
|
||||
browsing_context_id: BrowsingContextId,
|
||||
top_level_browsing_context_id: TopLevelBrowsingContextId,
|
||||
parent_info: Option<PipelineId>,
|
||||
event_loop: Rc<EventLoop>,
|
||||
layout_chan: IpcSender<LayoutControlMsg>,
|
||||
compositor_proxy: CompositorProxy,
|
||||
is_private: bool,
|
||||
url: ServoUrl,
|
||||
visible: bool,
|
||||
load_data: LoadData,
|
||||
) -> Pipeline {
|
||||
let pipeline = Pipeline {
|
||||
id: id,
|
||||
browsing_context_id: browsing_context_id,
|
||||
|
@ -334,7 +346,7 @@ impl Pipeline {
|
|||
layout_chan: layout_chan,
|
||||
compositor_proxy: compositor_proxy,
|
||||
url: url,
|
||||
children: vec!(),
|
||||
children: vec![],
|
||||
running_animations: false,
|
||||
visible: visible,
|
||||
is_private: is_private,
|
||||
|
@ -359,7 +371,8 @@ impl Pipeline {
|
|||
// It's OK for the constellation to block on the compositor,
|
||||
// since the compositor never blocks on the constellation.
|
||||
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() {
|
||||
warn!("Sending exit message failed ({}).", e);
|
||||
}
|
||||
|
@ -410,15 +423,25 @@ impl Pipeline {
|
|||
|
||||
/// 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),
|
||||
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),
|
||||
};
|
||||
}
|
||||
|
||||
/// Notify the script thread that this pipeline is visible.
|
||||
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 err = self.event_loop.send(script_msg);
|
||||
if let Err(e) = err {
|
||||
|
@ -435,7 +458,6 @@ impl Pipeline {
|
|||
self.visible = visible;
|
||||
self.notify_visibility();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Creating a new pipeline may require creating a new event loop.
|
||||
|
@ -477,57 +499,69 @@ pub struct UnprivilegedPipelineContent {
|
|||
|
||||
impl UnprivilegedPipelineContent {
|
||||
pub fn start_all<Message, LTF, STF>(self, wait_for_completion: bool)
|
||||
where LTF: LayoutThreadFactory<Message=Message>,
|
||||
STF: ScriptThreadFactory<Message=Message>
|
||||
where
|
||||
LTF: LayoutThreadFactory<Message = Message>,
|
||||
STF: ScriptThreadFactory<Message = Message>,
|
||||
{
|
||||
let image_cache = Arc::new(ImageCacheImpl::new(self.webrender_api_sender.create_api()));
|
||||
let paint_time_metrics = PaintTimeMetrics::new(self.id,
|
||||
self.time_profiler_chan.clone(),
|
||||
self.layout_to_constellation_chan.clone(),
|
||||
self.script_chan.clone(),
|
||||
self.load_data.url.clone());
|
||||
let layout_pair = STF::create(InitialScriptState {
|
||||
id: self.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,
|
||||
script_to_constellation_chan: self.script_to_constellation_chan.clone(),
|
||||
layout_to_constellation_chan: self.layout_to_constellation_chan.clone(),
|
||||
scheduler_chan: self.scheduler_chan,
|
||||
bluetooth_thread: self.bluetooth_thread,
|
||||
resource_threads: self.resource_threads,
|
||||
image_cache: image_cache.clone(),
|
||||
time_profiler_chan: self.time_profiler_chan.clone(),
|
||||
mem_profiler_chan: self.mem_profiler_chan.clone(),
|
||||
devtools_chan: self.devtools_chan,
|
||||
window_size: self.window_size,
|
||||
pipeline_namespace_id: self.pipeline_namespace_id,
|
||||
content_process_shutdown_chan: self.script_content_process_shutdown_chan,
|
||||
webgl_chan: self.webgl_chan,
|
||||
webvr_chan: self.webvr_chan,
|
||||
webrender_document: self.webrender_document,
|
||||
}, self.load_data.clone());
|
||||
let paint_time_metrics = PaintTimeMetrics::new(
|
||||
self.id,
|
||||
self.time_profiler_chan.clone(),
|
||||
self.layout_to_constellation_chan.clone(),
|
||||
self.script_chan.clone(),
|
||||
self.load_data.url.clone(),
|
||||
);
|
||||
let layout_pair = STF::create(
|
||||
InitialScriptState {
|
||||
id: self.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,
|
||||
script_to_constellation_chan: self.script_to_constellation_chan.clone(),
|
||||
layout_to_constellation_chan: self.layout_to_constellation_chan.clone(),
|
||||
scheduler_chan: self.scheduler_chan,
|
||||
bluetooth_thread: self.bluetooth_thread,
|
||||
resource_threads: self.resource_threads,
|
||||
image_cache: image_cache.clone(),
|
||||
time_profiler_chan: self.time_profiler_chan.clone(),
|
||||
mem_profiler_chan: self.mem_profiler_chan.clone(),
|
||||
devtools_chan: self.devtools_chan,
|
||||
window_size: self.window_size,
|
||||
pipeline_namespace_id: self.pipeline_namespace_id,
|
||||
content_process_shutdown_chan: self.script_content_process_shutdown_chan,
|
||||
webgl_chan: self.webgl_chan,
|
||||
webvr_chan: self.webvr_chan,
|
||||
webrender_document: self.webrender_document,
|
||||
},
|
||||
self.load_data.clone(),
|
||||
);
|
||||
|
||||
LTF::create(self.id,
|
||||
self.top_level_browsing_context_id,
|
||||
self.load_data.url,
|
||||
self.parent_info.is_some(),
|
||||
layout_pair,
|
||||
self.pipeline_port,
|
||||
self.layout_to_constellation_chan,
|
||||
self.script_chan,
|
||||
image_cache.clone(),
|
||||
self.font_cache_thread,
|
||||
self.time_profiler_chan,
|
||||
self.mem_profiler_chan,
|
||||
Some(self.layout_content_process_shutdown_chan),
|
||||
self.webrender_api_sender,
|
||||
self.webrender_document,
|
||||
self.prefs.get("layout.threads").expect("exists").value()
|
||||
.as_u64().expect("count") as usize,
|
||||
paint_time_metrics);
|
||||
LTF::create(
|
||||
self.id,
|
||||
self.top_level_browsing_context_id,
|
||||
self.load_data.url,
|
||||
self.parent_info.is_some(),
|
||||
layout_pair,
|
||||
self.pipeline_port,
|
||||
self.layout_to_constellation_chan,
|
||||
self.script_chan,
|
||||
image_cache.clone(),
|
||||
self.font_cache_thread,
|
||||
self.time_profiler_chan,
|
||||
self.mem_profiler_chan,
|
||||
Some(self.layout_content_process_shutdown_chan),
|
||||
self.webrender_api_sender,
|
||||
self.webrender_document,
|
||||
self.prefs
|
||||
.get("layout.threads")
|
||||
.expect("exists")
|
||||
.value()
|
||||
.as_u64()
|
||||
.expect("count") as usize,
|
||||
paint_time_metrics,
|
||||
);
|
||||
|
||||
if wait_for_completion {
|
||||
let _ = self.script_content_process_shutdown_port.recv();
|
||||
|
@ -543,12 +577,17 @@ impl UnprivilegedPipelineContent {
|
|||
|
||||
impl CommandMethods for sandbox::Command {
|
||||
fn arg<T>(&mut self, arg: T)
|
||||
where T: AsRef<OsStr> {
|
||||
where
|
||||
T: AsRef<OsStr>,
|
||||
{
|
||||
self.arg(arg);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -556,8 +595,7 @@ impl UnprivilegedPipelineContent {
|
|||
// Note that this function can panic, due to process creation,
|
||||
// avoiding this panic would require a mechanism for dealing
|
||||
// with low-resource scenarios.
|
||||
let (server, token) =
|
||||
IpcOneShotServer::<IpcSender<UnprivilegedPipelineContent>>::new()
|
||||
let (server, token) = IpcOneShotServer::<IpcSender<UnprivilegedPipelineContent>>::new()
|
||||
.expect("Failed to create IPC one-shot server.");
|
||||
|
||||
// If there is a sandbox, use the `gaol` API to create the child process.
|
||||
|
@ -570,11 +608,12 @@ impl UnprivilegedPipelineContent {
|
|||
.start(&mut command)
|
||||
.expect("Failed to start sandboxed child process!");
|
||||
} else {
|
||||
let path_to_self = env::current_exe()
|
||||
.expect("Failed to get current executor.");
|
||||
let path_to_self = env::current_exe().expect("Failed to get current executor.");
|
||||
let mut child_process = process::Command::new(path_to_self);
|
||||
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.");
|
||||
|
@ -618,7 +657,7 @@ impl UnprivilegedPipelineContent {
|
|||
pub fn swmanager_senders(&self) -> SWManagerSenders {
|
||||
SWManagerSenders {
|
||||
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 {
|
||||
/// A command line argument.
|
||||
fn arg<T>(&mut self, arg: T)
|
||||
where T: AsRef<OsStr>;
|
||||
where
|
||||
T: AsRef<OsStr>;
|
||||
|
||||
/// An environment variable.
|
||||
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 {
|
||||
fn arg<T>(&mut self, arg: T)
|
||||
where T: AsRef<OsStr> {
|
||||
where
|
||||
T: AsRef<OsStr>,
|
||||
{
|
||||
self.arg(arg);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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("/System/Library/Fonts"))),
|
||||
Operation::FileReadAll(PathPattern::Subpath(PathBuf::from(
|
||||
"/System/Library/Frameworks/ApplicationServices.framework"))),
|
||||
"/System/Library/Frameworks/ApplicationServices.framework",
|
||||
))),
|
||||
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("/Library"))),
|
||||
Operation::FileReadMetadata(PathPattern::Literal(PathBuf::from("/System"))),
|
||||
Operation::FileReadMetadata(PathPattern::Literal(PathBuf::from("/etc"))),
|
||||
Operation::SystemInfoRead,
|
||||
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| {
|
||||
Operation::FileReadAll(PathPattern::Literal(p))
|
||||
}));
|
||||
operations.extend(resources::sandbox_access_files_dirs().into_iter().map(|p| {
|
||||
Operation::FileReadAll(PathPattern::Subpath(p))
|
||||
}));
|
||||
operations.extend(
|
||||
resources::sandbox_access_files()
|
||||
.into_iter()
|
||||
.map(|p| Operation::FileReadAll(PathPattern::Literal(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!")
|
||||
}
|
||||
|
@ -41,17 +48,20 @@ pub fn content_process_sandbox_profile() -> Profile {
|
|||
/// Our content process sandbox profile on Linux. As restrictive as possible.
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub fn content_process_sandbox_profile() -> Profile {
|
||||
let mut operations = vec![
|
||||
Operation::FileReadAll(PathPattern::Literal(PathBuf::from("/dev/urandom"))),
|
||||
];
|
||||
let mut operations = vec![Operation::FileReadAll(PathPattern::Literal(PathBuf::from(
|
||||
"/dev/urandom",
|
||||
)))];
|
||||
|
||||
operations.extend(resources::sandbox_access_files().into_iter().map(|p| {
|
||||
Operation::FileReadAll(PathPattern::Literal(p))
|
||||
}));
|
||||
operations.extend(resources::sandbox_access_files_dirs().into_iter().map(|p| {
|
||||
Operation::FileReadAll(PathPattern::Subpath(p))
|
||||
}));
|
||||
operations.extend(
|
||||
resources::sandbox_access_files()
|
||||
.into_iter()
|
||||
.map(|p| Operation::FileReadAll(PathPattern::Literal(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!")
|
||||
}
|
||||
|
||||
|
|
|
@ -44,20 +44,37 @@ impl JointSessionHistory {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn replace_history_state(&mut self, pipeline_id: PipelineId, 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,
|
||||
pub fn replace_history_state(
|
||||
&mut self,
|
||||
pipeline_id: PipelineId,
|
||||
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,
|
||||
}) {
|
||||
*new_history_state_id = history_state_id;
|
||||
*new_url = url.clone();
|
||||
}
|
||||
|
||||
if let Some(SessionHistoryDiff::PipelineDiff { ref mut old_history_state_id, ref mut old_url, .. }) =
|
||||
self.future.iter_mut().find(|diff| match diff {
|
||||
SessionHistoryDiff::PipelineDiff { pipeline_reloader: NeedsToReload::No(id), .. } => pipeline_id == *id,
|
||||
_ => false,
|
||||
if let Some(SessionHistoryDiff::PipelineDiff {
|
||||
ref mut old_history_state_id,
|
||||
ref mut old_url,
|
||||
..
|
||||
}) = self.future.iter_mut().find(|diff| match diff {
|
||||
SessionHistoryDiff::PipelineDiff {
|
||||
pipeline_reloader: NeedsToReload::No(id),
|
||||
..
|
||||
} => pipeline_id == *id,
|
||||
_ => false,
|
||||
}) {
|
||||
*old_history_state_id = Some(history_state_id);
|
||||
*old_url = url;
|
||||
|
@ -65,21 +82,19 @@ impl JointSessionHistory {
|
|||
}
|
||||
|
||||
pub fn remove_entries_for_browsing_context(&mut self, context_id: BrowsingContextId) {
|
||||
self.past.retain(|diff| {
|
||||
match diff {
|
||||
SessionHistoryDiff::BrowsingContextDiff { browsing_context_id, .. } => {
|
||||
*browsing_context_id != context_id
|
||||
},
|
||||
_ => true,
|
||||
}
|
||||
self.past.retain(|diff| match diff {
|
||||
SessionHistoryDiff::BrowsingContextDiff {
|
||||
browsing_context_id,
|
||||
..
|
||||
} => *browsing_context_id != context_id,
|
||||
_ => true,
|
||||
});
|
||||
self.future.retain(|diff| {
|
||||
match diff {
|
||||
SessionHistoryDiff::BrowsingContextDiff { browsing_context_id, .. } => {
|
||||
*browsing_context_id != context_id
|
||||
},
|
||||
_ => true,
|
||||
}
|
||||
self.future.retain(|diff| match diff {
|
||||
SessionHistoryDiff::BrowsingContextDiff {
|
||||
browsing_context_id,
|
||||
..
|
||||
} => *browsing_context_id != context_id,
|
||||
_ => true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -132,23 +147,18 @@ impl NeedsToReload {
|
|||
impl PartialEq for NeedsToReload {
|
||||
fn eq(&self, other: &NeedsToReload) -> bool {
|
||||
match *self {
|
||||
NeedsToReload::No(pipeline_id) => {
|
||||
match *other {
|
||||
NeedsToReload::No(other_pipeline_id) => pipeline_id == other_pipeline_id,
|
||||
_ => false,
|
||||
}
|
||||
NeedsToReload::No(pipeline_id) => match *other {
|
||||
NeedsToReload::No(other_pipeline_id) => pipeline_id == other_pipeline_id,
|
||||
_ => false,
|
||||
},
|
||||
NeedsToReload::Yes(pipeline_id, _) => match *other {
|
||||
NeedsToReload::Yes(other_pipeline_id, _) => pipeline_id == other_pipeline_id,
|
||||
_ => false,
|
||||
},
|
||||
NeedsToReload::Yes(pipeline_id, _) => {
|
||||
match *other {
|
||||
NeedsToReload::Yes(other_pipeline_id, _) => pipeline_id == other_pipeline_id,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Represents a the difference between two adjacent session history entries.
|
||||
#[derive(Debug)]
|
||||
pub enum SessionHistoryDiff {
|
||||
|
@ -185,11 +195,11 @@ impl SessionHistoryDiff {
|
|||
/// Returns the old pipeline id if that pipeline is still alive, otherwise returns `None`
|
||||
pub fn alive_old_pipeline(&self) -> Option<PipelineId> {
|
||||
match *self {
|
||||
SessionHistoryDiff::BrowsingContextDiff { ref old_reloader, .. } => {
|
||||
match *old_reloader {
|
||||
NeedsToReload::No(pipeline_id) => Some(pipeline_id),
|
||||
NeedsToReload::Yes(..) => None,
|
||||
}
|
||||
SessionHistoryDiff::BrowsingContextDiff {
|
||||
ref old_reloader, ..
|
||||
} => match *old_reloader {
|
||||
NeedsToReload::No(pipeline_id) => Some(pipeline_id),
|
||||
NeedsToReload::Yes(..) => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
|
@ -198,20 +208,28 @@ impl SessionHistoryDiff {
|
|||
/// Returns the new pipeline id if that pipeline is still alive, otherwise returns `None`
|
||||
pub fn alive_new_pipeline(&self) -> Option<PipelineId> {
|
||||
match *self {
|
||||
SessionHistoryDiff::BrowsingContextDiff { ref new_reloader, .. } => {
|
||||
match *new_reloader {
|
||||
NeedsToReload::No(pipeline_id) => Some(pipeline_id),
|
||||
NeedsToReload::Yes(..) => None,
|
||||
}
|
||||
SessionHistoryDiff::BrowsingContextDiff {
|
||||
ref new_reloader, ..
|
||||
} => match *new_reloader {
|
||||
NeedsToReload::No(pipeline_id) => Some(pipeline_id),
|
||||
NeedsToReload::Yes(..) => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
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 {
|
||||
*old_reloader = reloader.clone();
|
||||
}
|
||||
|
@ -219,12 +237,18 @@ impl SessionHistoryDiff {
|
|||
*new_reloader = reloader.clone();
|
||||
}
|
||||
},
|
||||
SessionHistoryDiff::PipelineDiff { ref mut pipeline_reloader, .. } => {
|
||||
SessionHistoryDiff::PipelineDiff {
|
||||
ref mut pipeline_reloader,
|
||||
..
|
||||
} => {
|
||||
if *pipeline_reloader == *replaced_reloader {
|
||||
*pipeline_reloader = reloader.clone();
|
||||
}
|
||||
},
|
||||
SessionHistoryDiff::HashDiff { ref mut pipeline_reloader, .. } => {
|
||||
SessionHistoryDiff::HashDiff {
|
||||
ref mut pipeline_reloader,
|
||||
..
|
||||
} => {
|
||||
if *pipeline_reloader == *replaced_reloader {
|
||||
*pipeline_reloader = reloader.clone();
|
||||
}
|
||||
|
|
|
@ -75,7 +75,10 @@ impl TimerScheduler {
|
|||
Ok(TimerSchedulerMsg::Request(req)) => {
|
||||
let TimerEventRequest(_, _, _, delay) = req;
|
||||
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);
|
||||
},
|
||||
// If there is no incoming event, park the thread,
|
||||
|
@ -86,8 +89,7 @@ impl TimerScheduler {
|
|||
Some(event) => thread::park_timeout(event.for_time - now),
|
||||
},
|
||||
// If the channel is closed or we are shutting down, we are done.
|
||||
Ok(TimerSchedulerMsg::Exit) |
|
||||
Err(Disconnected) => break,
|
||||
Ok(TimerSchedulerMsg::Exit) | Err(Disconnected) => break,
|
||||
}
|
||||
}
|
||||
// This thread can terminate if the req_ipc_sender is dropped.
|
||||
|
@ -109,7 +111,7 @@ impl TimerScheduler {
|
|||
let mut shutting_down = false;
|
||||
match req {
|
||||
TimerSchedulerMsg::Exit => shutting_down = true,
|
||||
_ => {}
|
||||
_ => {},
|
||||
}
|
||||
let _ = req_sender.send(req);
|
||||
timeout_thread.unpark();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue