mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
compositing: Split Servo up into multiple sandboxed processes.
Multiprocess mode is enabled with the `-M` switch, and sandboxing is enabled with the `-S` switch.
This commit is contained in:
parent
ff4171170d
commit
1c130819ca
33 changed files with 688 additions and 265 deletions
|
@ -68,14 +68,20 @@ features = ["texture_surface"]
|
|||
version = "0.2"
|
||||
features = [ "serde_serialization" ]
|
||||
|
||||
[dependencies.gaol]
|
||||
git = "https://github.com/pcwalton/gaol"
|
||||
|
||||
[dependencies]
|
||||
app_units = {version = "0.1", features = ["plugins"]}
|
||||
image = "0.4.0"
|
||||
libc = "0.1"
|
||||
log = "0.3"
|
||||
num = "0.1.24"
|
||||
time = "0.1.17"
|
||||
gleam = "0.1"
|
||||
euclid = {version = "0.3", features = ["plugins"]}
|
||||
serde = "0.6"
|
||||
serde_macros = "0.6"
|
||||
|
||||
[target.x86_64-apple-darwin.dependencies]
|
||||
core-graphics = "0.1"
|
||||
|
|
|
@ -17,7 +17,7 @@ use gfx_traits::color;
|
|||
use gleam::gl;
|
||||
use gleam::gl::types::{GLint, GLsizei};
|
||||
use image::{DynamicImage, ImageFormat, RgbImage};
|
||||
use ipc_channel::ipc::{self, IpcSharedMemory};
|
||||
use ipc_channel::ipc::{self, IpcSender, IpcSharedMemory};
|
||||
use ipc_channel::router::ROUTER;
|
||||
use layers::geometry::{DevicePixel, LayerPixel};
|
||||
use layers::layers::{BufferRequest, Layer, LayerBuffer, LayerBufferSet};
|
||||
|
@ -30,7 +30,7 @@ use msg::compositor_msg::{Epoch, EventResult, FrameTreeId, LayerId, LayerKind};
|
|||
use msg::compositor_msg::{LayerProperties, ScrollPolicy};
|
||||
use msg::constellation_msg::CompositorMsg as ConstellationMsg;
|
||||
use msg::constellation_msg::{AnimationState, Image, PixelFormat};
|
||||
use msg::constellation_msg::{ConstellationChan, Key, KeyModifiers, KeyState, LoadData};
|
||||
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData};
|
||||
use msg::constellation_msg::{NavigationDirection, PipelineId, WindowSizeData};
|
||||
use pipeline::CompositionPipeline;
|
||||
use profile_traits::mem::{self, ReportKind, Reporter, ReporterRequest};
|
||||
|
@ -168,7 +168,7 @@ pub struct IOCompositor<Window: WindowMethods> {
|
|||
frame_tree_id: FrameTreeId,
|
||||
|
||||
/// The channel on which messages can be sent to the constellation.
|
||||
constellation_chan: ConstellationChan<ConstellationMsg>,
|
||||
constellation_chan: Sender<ConstellationMsg>,
|
||||
|
||||
/// The channel on which messages can be sent to the time profiler.
|
||||
time_profiler_chan: time::ProfilerChan,
|
||||
|
@ -385,8 +385,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
|
||||
pub fn start_shutting_down(&mut self) {
|
||||
debug!("Compositor sending Exit message to Constellation");
|
||||
let ConstellationChan(ref constellation_channel) = self.constellation_chan;
|
||||
constellation_channel.send(ConstellationMsg::Exit).unwrap();
|
||||
self.constellation_chan.send(ConstellationMsg::Exit).unwrap();
|
||||
|
||||
self.mem_profiler_chan.send(mem::ProfilerMsg::UnregisterReporter(reporter_name()));
|
||||
|
||||
|
@ -702,8 +701,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
|
||||
fn set_frame_tree(&mut self,
|
||||
frame_tree: &SendableFrameTree,
|
||||
response_chan: Sender<()>,
|
||||
new_constellation_chan: ConstellationChan<ConstellationMsg>) {
|
||||
response_chan: IpcSender<()>,
|
||||
new_constellation_chan: Sender<ConstellationMsg>) {
|
||||
response_chan.send(()).unwrap();
|
||||
|
||||
// There are now no more pending iframes.
|
||||
|
@ -943,8 +942,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
let initial_viewport = self.window_size.as_f32() / dppx;
|
||||
let visible_viewport = initial_viewport / self.viewport_zoom;
|
||||
|
||||
let ConstellationChan(ref chan) = self.constellation_chan;
|
||||
chan.send(ConstellationMsg::ResizedWindow(WindowSizeData {
|
||||
self.constellation_chan.send(ConstellationMsg::ResizedWindow(WindowSizeData {
|
||||
device_pixel_ratio: dppx,
|
||||
initial_viewport: initial_viewport,
|
||||
visible_viewport: visible_viewport,
|
||||
|
@ -959,9 +957,9 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
None => return,
|
||||
};
|
||||
|
||||
let ConstellationChan(ref chan) = self.constellation_chan;
|
||||
chan.send(ConstellationMsg::FrameSize(*subpage_pipeline_id,
|
||||
layer_properties.rect.size)).unwrap();
|
||||
self.constellation_chan.send(ConstellationMsg::FrameSize(
|
||||
*subpage_pipeline_id,
|
||||
layer_properties.rect.size)).unwrap();
|
||||
}
|
||||
|
||||
pub fn move_layer(&self,
|
||||
|
@ -1168,8 +1166,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
None => ConstellationMsg::InitLoadUrl(url)
|
||||
};
|
||||
|
||||
let ConstellationChan(ref chan) = self.constellation_chan;
|
||||
chan.send(msg).unwrap()
|
||||
self.constellation_chan.send(msg).unwrap()
|
||||
}
|
||||
|
||||
fn on_mouse_window_event_class(&mut self, mouse_window_event: MouseWindowEvent) {
|
||||
|
@ -1446,7 +1443,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
}
|
||||
|
||||
fn tick_animations_for_pipeline(&self, pipeline_id: PipelineId) {
|
||||
self.constellation_chan.0.send(ConstellationMsg::TickAnimation(pipeline_id)).unwrap()
|
||||
self.constellation_chan.send(ConstellationMsg::TickAnimation(pipeline_id)).unwrap()
|
||||
}
|
||||
|
||||
fn constrain_viewport(&mut self, pipeline_id: PipelineId, constraints: ViewportConstraints) {
|
||||
|
@ -1538,13 +1535,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
windowing::WindowNavigateMsg::Forward => NavigationDirection::Forward,
|
||||
windowing::WindowNavigateMsg::Back => NavigationDirection::Back,
|
||||
};
|
||||
let ConstellationChan(ref chan) = self.constellation_chan;
|
||||
chan.send(ConstellationMsg::Navigate(None, direction)).unwrap()
|
||||
self.constellation_chan.send(ConstellationMsg::Navigate(None, direction)).unwrap()
|
||||
}
|
||||
|
||||
fn on_key_event(&self, key: Key, state: KeyState, modifiers: KeyModifiers) {
|
||||
let ConstellationChan(ref chan) = self.constellation_chan;
|
||||
chan.send(ConstellationMsg::KeyEvent(key, state, modifiers)).unwrap()
|
||||
self.constellation_chan.send(ConstellationMsg::KeyEvent(key, state, modifiers)).unwrap()
|
||||
}
|
||||
|
||||
fn fill_paint_request_with_cached_layer_buffers(&mut self, paint_request: &mut PaintRequest) {
|
||||
|
@ -1744,8 +1739,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
|
||||
// Pass the pipeline/epoch states to the constellation and check
|
||||
// if it's safe to output the image.
|
||||
let ConstellationChan(ref chan) = self.constellation_chan;
|
||||
chan.send(ConstellationMsg::IsReadyToSaveImage(pipeline_epochs)).unwrap();
|
||||
self.constellation_chan.send(ConstellationMsg::IsReadyToSaveImage(pipeline_epochs)).unwrap();
|
||||
self.ready_to_save_state = ReadyState::WaitingForConstellationReply;
|
||||
Err(NotReadyToPaint::JustNotifiedConstellation)
|
||||
}
|
||||
|
@ -2167,8 +2161,7 @@ impl<Window> CompositorEventListener for IOCompositor<Window> where Window: Wind
|
|||
None => return,
|
||||
Some(ref root_pipeline) => root_pipeline.id,
|
||||
};
|
||||
let ConstellationChan(ref chan) = self.constellation_chan;
|
||||
chan.send(ConstellationMsg::GetPipelineTitle(root_pipeline_id)).unwrap();
|
||||
self.constellation_chan.send(ConstellationMsg::GetPipelineTitle(root_pipeline_id)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,15 +5,16 @@
|
|||
//! Communication with the compositor task.
|
||||
|
||||
use compositor;
|
||||
use euclid::{Point2D, Size2D};
|
||||
use euclid::point::Point2D;
|
||||
use euclid::size::Size2D;
|
||||
use headless;
|
||||
use ipc_channel::ipc::{IpcReceiver, IpcSender};
|
||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||
use layers::layers::{BufferRequest, LayerBufferSet};
|
||||
use layers::platform::surface::{NativeDisplay, NativeSurface};
|
||||
use msg::compositor_msg::{Epoch, EventResult, FrameTreeId, LayerId, LayerProperties};
|
||||
use msg::compositor_msg::{PaintListener, ScriptToCompositorMsg};
|
||||
use msg::constellation_msg::CompositorMsg as ConstellationMsg;
|
||||
use msg::constellation_msg::{AnimationState, ConstellationChan, PipelineId};
|
||||
use msg::constellation_msg::{AnimationState, PipelineId};
|
||||
use msg::constellation_msg::{Image, Key, KeyModifiers, KeyState};
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time;
|
||||
|
@ -60,11 +61,11 @@ pub fn run_script_listener_thread(compositor_proxy: Box<CompositorProxy + 'stati
|
|||
receiver: IpcReceiver<ScriptToCompositorMsg>) {
|
||||
while let Ok(msg) = receiver.recv() {
|
||||
match msg {
|
||||
ScriptToCompositorMsg::ScrollFragmentPoint(pipeline_id, layer_id, point, _smooth) => {
|
||||
ScriptToCompositorMsg::ScrollFragmentPoint(pipeline_id, layer_id, point, smooth) => {
|
||||
compositor_proxy.send(Msg::ScrollFragmentPoint(pipeline_id,
|
||||
layer_id,
|
||||
point,
|
||||
_smooth));
|
||||
smooth));
|
||||
}
|
||||
|
||||
ScriptToCompositorMsg::GetClientWindow(send) => {
|
||||
|
@ -80,7 +81,7 @@ pub fn run_script_listener_thread(compositor_proxy: Box<CompositorProxy + 'stati
|
|||
}
|
||||
|
||||
ScriptToCompositorMsg::Exit => {
|
||||
let (chan, port) = channel();
|
||||
let (chan, port) = ipc::channel().unwrap();
|
||||
compositor_proxy.send(Msg::Exit(chan));
|
||||
port.recv().unwrap();
|
||||
}
|
||||
|
@ -152,7 +153,7 @@ impl PaintListener for Box<CompositorProxy + 'static + Send> {
|
|||
/// Messages from the painting task and the constellation task to the compositor task.
|
||||
pub enum Msg {
|
||||
/// Requests that the compositor shut down.
|
||||
Exit(Sender<()>),
|
||||
Exit(IpcSender<()>),
|
||||
|
||||
/// Informs the compositor that the constellation has completed shutdown.
|
||||
/// Required because the constellation can have pending calls to make
|
||||
|
@ -180,7 +181,7 @@ pub enum Msg {
|
|||
/// Alerts the compositor that the given pipeline has changed whether it is running animations.
|
||||
ChangeRunningAnimationsState(PipelineId, AnimationState),
|
||||
/// Replaces the current frame tree, typically called during main frame navigation.
|
||||
SetFrameTree(SendableFrameTree, Sender<()>, ConstellationChan<ConstellationMsg>),
|
||||
SetFrameTree(SendableFrameTree, IpcSender<()>, Sender<ConstellationMsg>),
|
||||
/// The load of a page has begun: (can go back, can go forward).
|
||||
LoadStart(bool, bool),
|
||||
/// The load of a page has completed: (can go back, can go forward).
|
||||
|
@ -296,7 +297,7 @@ pub struct InitialCompositorState {
|
|||
/// A port on which messages inbound to the compositor can be received.
|
||||
pub receiver: Box<CompositorReceiver>,
|
||||
/// A channel to the constellation.
|
||||
pub constellation_chan: ConstellationChan<ConstellationMsg>,
|
||||
pub constellation_chan: Sender<ConstellationMsg>,
|
||||
/// A channel to the time profiler thread.
|
||||
pub time_profiler_chan: time::ProfilerChan,
|
||||
/// A channel to the memory profiler thread.
|
||||
|
|
|
@ -18,8 +18,11 @@ use compositor_task::Msg as ToCompositorMsg;
|
|||
use devtools_traits::{ChromeToDevtoolsControlMsg, DevtoolsControlMsg};
|
||||
use euclid::scale_factor::ScaleFactor;
|
||||
use euclid::size::{Size2D, TypedSize2D};
|
||||
use gaol;
|
||||
use gaol::sandbox::{self, Sandbox, SandboxMethods};
|
||||
use gfx::font_cache_task::FontCacheTask;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use ipc_channel::ipc::{self, IpcOneShotServer, IpcSender};
|
||||
use ipc_channel::router::ROUTER;
|
||||
use layout_traits::{LayoutControlChan, LayoutTaskFactory};
|
||||
use msg::compositor_msg::Epoch;
|
||||
use msg::constellation_msg::AnimationState;
|
||||
|
@ -37,19 +40,21 @@ use net_traits::image_cache_task::ImageCacheTask;
|
|||
use net_traits::storage_task::{StorageTask, StorageTaskMsg};
|
||||
use net_traits::{self, ResourceTask};
|
||||
use offscreen_gl_context::GLContextAttributes;
|
||||
use pipeline::{CompositionPipeline, InitialPipelineState, Pipeline};
|
||||
use pipeline::{CompositionPipeline, InitialPipelineState, Pipeline, UnprivilegedPipelineContent};
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time;
|
||||
use sandboxing;
|
||||
use script_traits::{CompositorEvent, ConstellationControlMsg, LayoutControlMsg};
|
||||
use script_traits::{ScriptState, ScriptTaskFactory};
|
||||
use script_traits::{TimerEventRequest};
|
||||
use std::borrow::ToOwned;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::io::{self, Write};
|
||||
use std::marker::PhantomData;
|
||||
use std::mem::replace;
|
||||
use std::process;
|
||||
use std::sync::mpsc::{Receiver, Sender, channel};
|
||||
use std::sync::mpsc::{Sender, channel, Receiver};
|
||||
use style_traits::viewport::ViewportConstraints;
|
||||
use timer_scheduler::TimerScheduler;
|
||||
use url::Url;
|
||||
|
@ -79,7 +84,7 @@ pub struct Constellation<LTF, STF> {
|
|||
pub script_sender: ConstellationChan<FromScriptMsg>,
|
||||
|
||||
/// A channel through which compositor messages can be sent to this object.
|
||||
pub compositor_sender: ConstellationChan<FromCompositorMsg>,
|
||||
pub compositor_sender: Sender<FromCompositorMsg>,
|
||||
|
||||
/// Receives messages from scripts.
|
||||
pub script_receiver: Receiver<FromScriptMsg>,
|
||||
|
@ -156,6 +161,9 @@ pub struct Constellation<LTF, STF> {
|
|||
webgl_paint_tasks: Vec<Sender<CanvasMsg>>,
|
||||
|
||||
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||
|
||||
/// A list of child content processes.
|
||||
child_processes: Vec<ChildProcess>,
|
||||
}
|
||||
|
||||
/// State needed to construct a constellation.
|
||||
|
@ -259,14 +267,21 @@ enum ExitPipelineMode {
|
|||
Force,
|
||||
}
|
||||
|
||||
enum ChildProcess {
|
||||
Sandboxed(gaol::platform::process::Process),
|
||||
Unsandboxed(process::Child),
|
||||
}
|
||||
|
||||
impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
|
||||
pub fn start(state: InitialConstellationState) -> ConstellationChan<FromCompositorMsg> {
|
||||
let (script_receiver, script_sender) = ConstellationChan::<FromScriptMsg>::new();
|
||||
let (compositor_receiver, compositor_sender) = ConstellationChan::<FromCompositorMsg>::new();
|
||||
pub fn start(state: InitialConstellationState) -> Sender<FromCompositorMsg> {
|
||||
let (ipc_script_receiver, ipc_script_sender) = ConstellationChan::<FromScriptMsg>::new();
|
||||
//let (script_receiver, script_sender) = channel();
|
||||
let script_receiver = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_script_receiver);
|
||||
let (compositor_sender, compositor_receiver) = channel();
|
||||
let compositor_sender_clone = compositor_sender.clone();
|
||||
spawn_named("Constellation".to_owned(), move || {
|
||||
let mut constellation: Constellation<LTF, STF> = Constellation {
|
||||
script_sender: script_sender,
|
||||
script_sender: ipc_script_sender,
|
||||
compositor_sender: compositor_sender_clone,
|
||||
script_receiver: script_receiver,
|
||||
compositor_receiver: compositor_receiver,
|
||||
|
@ -305,6 +320,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
|
|||
canvas_paint_tasks: Vec::new(),
|
||||
webgl_paint_tasks: Vec::new(),
|
||||
scheduler_chan: TimerScheduler::start(),
|
||||
child_processes: Vec::new(),
|
||||
};
|
||||
let namespace_id = constellation.next_pipeline_namespace_id();
|
||||
PipelineNamespace::install(namespace_id);
|
||||
|
@ -333,10 +349,10 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
|
|||
pipeline_id: PipelineId,
|
||||
parent_info: Option<(PipelineId, SubpageId)>,
|
||||
initial_window_size: Option<TypedSize2D<PagePx, f32>>,
|
||||
script_channel: Option<Sender<ConstellationControlMsg>>,
|
||||
script_channel: Option<IpcSender<ConstellationControlMsg>>,
|
||||
load_data: LoadData) {
|
||||
let spawning_paint_only = script_channel.is_some();
|
||||
let (pipeline, mut pipeline_content) =
|
||||
let (pipeline, unprivileged_pipeline_content, mut privileged_pipeline_content) =
|
||||
Pipeline::create::<LTF, STF>(InitialPipelineState {
|
||||
id: pipeline_id,
|
||||
parent_info: parent_info,
|
||||
|
@ -357,12 +373,39 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
|
|||
pipeline_namespace_id: self.next_pipeline_namespace_id(),
|
||||
});
|
||||
|
||||
// TODO(pcwalton): In multiprocess mode, send that `PipelineContent` instance over to
|
||||
// the content process and call this over there.
|
||||
if spawning_paint_only {
|
||||
pipeline_content.start_paint_task();
|
||||
privileged_pipeline_content.start_paint_task();
|
||||
} else {
|
||||
pipeline_content.start_all::<LTF, STF>();
|
||||
privileged_pipeline_content.start_all();
|
||||
|
||||
// Spawn the child process.
|
||||
//
|
||||
// Yes, that's all there is to it!
|
||||
if opts::multiprocess() {
|
||||
let (server, token) =
|
||||
IpcOneShotServer::<IpcSender<UnprivilegedPipelineContent>>::new().unwrap();
|
||||
|
||||
// If there is a sandbox, use the `gaol` API to create the child process.
|
||||
let child_process = if opts::get().sandbox {
|
||||
let mut command = sandbox::Command::me().unwrap();
|
||||
command.arg("--content-process").arg(token);
|
||||
let profile = sandboxing::content_process_sandbox_profile();
|
||||
ChildProcess::Sandboxed(Sandbox::new(profile).start(&mut command).expect(
|
||||
"Failed to start sandboxed child process!"))
|
||||
} else {
|
||||
let path_to_self = env::current_exe().unwrap();
|
||||
let mut child_process = process::Command::new(path_to_self);
|
||||
child_process.arg("--content-process");
|
||||
child_process.arg(token);
|
||||
ChildProcess::Unsandboxed(child_process.spawn().unwrap())
|
||||
};
|
||||
self.child_processes.push(child_process);
|
||||
|
||||
let (_receiver, sender) = server.accept().unwrap();
|
||||
sender.send(unprivileged_pipeline_content).unwrap();
|
||||
} else {
|
||||
unprivileged_pipeline_content.start_all::<LTF, STF>(false);
|
||||
}
|
||||
}
|
||||
|
||||
assert!(!self.pipelines.contains_key(&pipeline_id));
|
||||
|
@ -1290,7 +1333,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
|
|||
|
||||
// Synchronously query the script task for this pipeline
|
||||
// to see if it is idle.
|
||||
let (sender, receiver) = channel();
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
let msg = ConstellationControlMsg::GetCurrentState(sender, frame.current);
|
||||
pipeline.script_chan.send(msg).unwrap();
|
||||
let result = receiver.recv().unwrap();
|
||||
|
@ -1445,7 +1488,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
|
|||
if let Some(root_frame_id) = self.root_frame_id {
|
||||
let frame_tree = self.frame_to_sendable(root_frame_id);
|
||||
|
||||
let (chan, port) = channel();
|
||||
let (chan, port) = ipc::channel().unwrap();
|
||||
self.compositor_proxy.send(ToCompositorMsg::SetFrameTree(frame_tree,
|
||||
chan,
|
||||
self.compositor_sender.clone()));
|
||||
|
|
|
@ -8,9 +8,10 @@ use euclid::scale_factor::ScaleFactor;
|
|||
use euclid::{Point2D, Size2D};
|
||||
use msg::constellation_msg::AnimationState;
|
||||
use msg::constellation_msg::CompositorMsg as ConstellationMsg;
|
||||
use msg::constellation_msg::{ConstellationChan, WindowSizeData};
|
||||
use msg::constellation_msg::WindowSizeData;
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time;
|
||||
use std::sync::mpsc::Sender;
|
||||
use util::opts;
|
||||
use windowing::WindowEvent;
|
||||
|
||||
|
@ -22,7 +23,7 @@ pub struct NullCompositor {
|
|||
/// The port on which we receive messages.
|
||||
pub port: Box<CompositorReceiver>,
|
||||
/// A channel to the constellation.
|
||||
constellation_chan: ConstellationChan<ConstellationMsg>,
|
||||
constellation_chan: Sender<ConstellationMsg>,
|
||||
/// A channel to the time profiler.
|
||||
time_profiler_chan: time::ProfilerChan,
|
||||
/// A channel to the memory profiler.
|
||||
|
@ -44,8 +45,7 @@ impl NullCompositor {
|
|||
|
||||
// Tell the constellation about the initial fake size.
|
||||
{
|
||||
let ConstellationChan(ref chan) = compositor.constellation_chan;
|
||||
chan.send(ConstellationMsg::ResizedWindow(WindowSizeData {
|
||||
compositor.constellation_chan.send(ConstellationMsg::ResizedWindow(WindowSizeData {
|
||||
initial_viewport: Size2D::typed(800_f32, 600_f32),
|
||||
visible_viewport: Size2D::typed(800_f32, 600_f32),
|
||||
device_pixel_ratio:
|
||||
|
@ -62,8 +62,7 @@ impl CompositorEventListener for NullCompositor {
|
|||
match self.port.recv_compositor_msg() {
|
||||
Msg::Exit(chan) => {
|
||||
debug!("shutting down the constellation");
|
||||
let ConstellationChan(ref con_chan) = self.constellation_chan;
|
||||
con_chan.send(ConstellationMsg::Exit).unwrap();
|
||||
self.constellation_chan.send(ConstellationMsg::Exit).unwrap();
|
||||
chan.send(()).unwrap();
|
||||
}
|
||||
|
||||
|
@ -100,7 +99,7 @@ impl CompositorEventListener for NullCompositor {
|
|||
AnimationState::NoAnimationCallbacksPresent => {}
|
||||
AnimationState::AnimationCallbacksPresent => {
|
||||
let msg = ConstellationMsg::TickAnimation(pipeline_id);
|
||||
self.constellation_chan.0.send(msg).unwrap()
|
||||
self.constellation_chan.send(msg).unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#![feature(box_syntax)]
|
||||
#![feature(custom_derive)]
|
||||
#![feature(iter_cmp)]
|
||||
#![feature(plugin)]
|
||||
#![feature(slice_bytes)]
|
||||
#![feature(vec_push_all)]
|
||||
#![feature(mpsc_select)]
|
||||
|
@ -11,6 +13,7 @@
|
|||
#![plugin(plugins)]
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![plugin(serde_macros)]
|
||||
|
||||
extern crate app_units;
|
||||
#[macro_use]
|
||||
|
@ -31,6 +34,7 @@ extern crate core_text;
|
|||
|
||||
extern crate devtools_traits;
|
||||
extern crate euclid;
|
||||
extern crate gaol;
|
||||
extern crate gfx;
|
||||
extern crate gfx_traits;
|
||||
extern crate gleam;
|
||||
|
@ -43,7 +47,10 @@ extern crate net_traits;
|
|||
extern crate num;
|
||||
extern crate offscreen_gl_context;
|
||||
extern crate script_traits;
|
||||
extern crate serde;
|
||||
extern crate style_traits;
|
||||
|
||||
extern crate libc;
|
||||
extern crate time;
|
||||
extern crate url;
|
||||
|
||||
|
@ -59,4 +66,5 @@ mod timer_scheduler;
|
|||
pub mod compositor_task;
|
||||
pub mod constellation;
|
||||
pub mod pipeline;
|
||||
pub mod sandboxing;
|
||||
pub mod windowing;
|
||||
|
|
|
@ -14,6 +14,7 @@ use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
|||
use ipc_channel::router::ROUTER;
|
||||
use layers::geometry::DevicePixel;
|
||||
use layout_traits::{LayoutControlChan, LayoutTaskFactory};
|
||||
use msg::compositor_msg::ScriptToCompositorMsg;
|
||||
use msg::constellation_msg::ScriptMsg as ConstellationMsg;
|
||||
use msg::constellation_msg::{ConstellationChan, Failure, FrameId, PipelineId, SubpageId};
|
||||
use msg::constellation_msg::{LoadData, MozBrowserEvent, WindowSizeData};
|
||||
|
@ -26,7 +27,6 @@ use profile_traits::time;
|
|||
use script_traits::{ConstellationControlMsg, InitialScriptState};
|
||||
use script_traits::{LayoutControlMsg, NewLayoutInfo, ScriptTaskFactory};
|
||||
use script_traits::{TimerEventRequest};
|
||||
use std::any::Any;
|
||||
use std::mem;
|
||||
use std::sync::mpsc::{Receiver, Sender, channel};
|
||||
use std::thread;
|
||||
|
@ -34,20 +34,21 @@ use url::Url;
|
|||
use util;
|
||||
use util::geometry::{PagePx, ViewportPx};
|
||||
use util::ipc::OptionalIpcSender;
|
||||
use util::opts::{self, Opts};
|
||||
use util::prefs;
|
||||
|
||||
/// A uniquely-identifiable pipeline of script task, layout task, and paint task.
|
||||
pub struct Pipeline {
|
||||
pub id: PipelineId,
|
||||
pub parent_info: Option<(PipelineId, SubpageId)>,
|
||||
pub script_chan: Sender<ConstellationControlMsg>,
|
||||
pub script_chan: IpcSender<ConstellationControlMsg>,
|
||||
/// A channel to layout, for performing reflows and shutdown.
|
||||
pub layout_chan: LayoutControlChan,
|
||||
/// A channel to the compositor.
|
||||
pub compositor_proxy: Box<CompositorProxy + 'static + Send>,
|
||||
pub chrome_to_paint_chan: Sender<ChromeToPaintMsg>,
|
||||
pub layout_shutdown_port: Receiver<()>,
|
||||
pub paint_shutdown_port: Receiver<()>,
|
||||
pub layout_shutdown_port: IpcReceiver<()>,
|
||||
pub paint_shutdown_port: IpcReceiver<()>,
|
||||
/// URL corresponding to the most recently-loaded page.
|
||||
pub url: Url,
|
||||
/// The title of the most recently-loaded page.
|
||||
|
@ -63,7 +64,7 @@ pub struct Pipeline {
|
|||
#[derive(Clone)]
|
||||
pub struct CompositionPipeline {
|
||||
pub id: PipelineId,
|
||||
pub script_chan: Sender<ConstellationControlMsg>,
|
||||
pub script_chan: IpcSender<ConstellationControlMsg>,
|
||||
pub layout_chan: LayoutControlChan,
|
||||
pub chrome_to_paint_chan: Sender<ChromeToPaintMsg>,
|
||||
}
|
||||
|
@ -104,7 +105,7 @@ pub struct InitialPipelineState {
|
|||
pub device_pixel_ratio: ScaleFactor<ViewportPx, DevicePixel, f32>,
|
||||
/// A channel to the script thread, if applicable. If this is `Some`,
|
||||
/// then `parent_info` must also be `Some`.
|
||||
pub script_chan: Option<Sender<ConstellationControlMsg>>,
|
||||
pub script_chan: Option<IpcSender<ConstellationControlMsg>>,
|
||||
/// Information about the page to load.
|
||||
pub load_data: LoadData,
|
||||
/// The ID of the pipeline namespace for this script thread.
|
||||
|
@ -115,13 +116,14 @@ impl Pipeline {
|
|||
/// Starts a paint task, layout task, and possibly a script task.
|
||||
/// Returns the channels wrapped in a struct.
|
||||
pub fn create<LTF, STF>(state: InitialPipelineState)
|
||||
-> (Pipeline, PipelineContent)
|
||||
-> (Pipeline, UnprivilegedPipelineContent, PrivilegedPipelineContent)
|
||||
where LTF: LayoutTaskFactory, STF: ScriptTaskFactory {
|
||||
let (layout_to_paint_chan, layout_to_paint_port) = util::ipc::optional_ipc_channel();
|
||||
let (chrome_to_paint_chan, chrome_to_paint_port) = channel();
|
||||
let (paint_shutdown_chan, paint_shutdown_port) = channel();
|
||||
let (layout_shutdown_chan, layout_shutdown_port) = channel();
|
||||
let (paint_shutdown_chan, paint_shutdown_port) = ipc::channel().unwrap();
|
||||
let (layout_shutdown_chan, layout_shutdown_port) = ipc::channel().unwrap();
|
||||
let (pipeline_chan, pipeline_port) = ipc::channel().unwrap();
|
||||
let (script_to_compositor_chan, script_to_compositor_port) = ipc::channel().unwrap();
|
||||
let mut pipeline_port = Some(pipeline_port);
|
||||
|
||||
let failure = Failure {
|
||||
|
@ -148,6 +150,9 @@ impl Pipeline {
|
|||
script_to_devtools_chan
|
||||
});
|
||||
|
||||
let (layout_content_process_shutdown_chan, layout_content_process_shutdown_port) =
|
||||
ipc::channel().unwrap();
|
||||
|
||||
let (script_chan, script_port) = match state.script_chan {
|
||||
Some(script_chan) => {
|
||||
let (containing_pipeline_id, subpage_id) =
|
||||
|
@ -157,10 +162,11 @@ impl Pipeline {
|
|||
new_pipeline_id: state.id,
|
||||
subpage_id: subpage_id,
|
||||
load_data: state.load_data.clone(),
|
||||
paint_chan: box layout_to_paint_chan.clone() as Box<Any + Send>,
|
||||
paint_chan: layout_to_paint_chan.clone().to_opaque(),
|
||||
failure: failure,
|
||||
pipeline_port: mem::replace(&mut pipeline_port, None).unwrap(),
|
||||
layout_shutdown_chan: layout_shutdown_chan.clone(),
|
||||
content_process_shutdown_chan: layout_content_process_shutdown_chan.clone(),
|
||||
};
|
||||
|
||||
script_chan.send(ConstellationControlMsg::AttachLayout(new_layout_info))
|
||||
|
@ -168,11 +174,14 @@ impl Pipeline {
|
|||
(script_chan, None)
|
||||
}
|
||||
None => {
|
||||
let (script_chan, script_port) = channel();
|
||||
let (script_chan, script_port) = ipc::channel().unwrap();
|
||||
(script_chan, Some(script_port))
|
||||
}
|
||||
};
|
||||
|
||||
let (script_content_process_shutdown_chan, script_content_process_shutdown_port) =
|
||||
ipc::channel().unwrap();
|
||||
|
||||
let pipeline = Pipeline::new(state.id,
|
||||
state.parent_info,
|
||||
script_chan.clone(),
|
||||
|
@ -184,45 +193,63 @@ impl Pipeline {
|
|||
state.load_data.url.clone(),
|
||||
state.window_size);
|
||||
|
||||
let pipeline_content = PipelineContent {
|
||||
let unprivileged_pipeline_content = UnprivilegedPipelineContent {
|
||||
id: state.id,
|
||||
parent_info: state.parent_info,
|
||||
constellation_chan: state.constellation_chan,
|
||||
constellation_chan: state.constellation_chan.clone(),
|
||||
scheduler_chan: state.scheduler_chan,
|
||||
compositor_proxy: state.compositor_proxy,
|
||||
devtools_chan: script_to_devtools_chan,
|
||||
image_cache_task: state.image_cache_task,
|
||||
font_cache_task: state.font_cache_task,
|
||||
font_cache_task: state.font_cache_task.clone(),
|
||||
resource_task: state.resource_task,
|
||||
storage_task: state.storage_task,
|
||||
time_profiler_chan: state.time_profiler_chan,
|
||||
mem_profiler_chan: state.mem_profiler_chan,
|
||||
time_profiler_chan: state.time_profiler_chan.clone(),
|
||||
mem_profiler_chan: state.mem_profiler_chan.clone(),
|
||||
window_size: window_size,
|
||||
script_chan: script_chan,
|
||||
load_data: state.load_data,
|
||||
load_data: state.load_data.clone(),
|
||||
failure: failure,
|
||||
script_port: script_port,
|
||||
opts: (*opts::get()).clone(),
|
||||
layout_to_paint_chan: layout_to_paint_chan,
|
||||
chrome_to_paint_chan: chrome_to_paint_chan,
|
||||
layout_to_paint_port: Some(layout_to_paint_port),
|
||||
chrome_to_paint_port: Some(chrome_to_paint_port),
|
||||
pipeline_port: pipeline_port,
|
||||
paint_shutdown_chan: paint_shutdown_chan,
|
||||
layout_shutdown_chan: layout_shutdown_chan,
|
||||
paint_shutdown_chan: paint_shutdown_chan.clone(),
|
||||
script_to_compositor_chan: script_to_compositor_chan,
|
||||
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,
|
||||
};
|
||||
|
||||
(pipeline, pipeline_content)
|
||||
let privileged_pipeline_content = PrivilegedPipelineContent {
|
||||
id: state.id,
|
||||
constellation_chan: state.constellation_chan,
|
||||
compositor_proxy: state.compositor_proxy,
|
||||
font_cache_task: state.font_cache_task,
|
||||
time_profiler_chan: state.time_profiler_chan,
|
||||
mem_profiler_chan: state.mem_profiler_chan,
|
||||
load_data: state.load_data,
|
||||
failure: failure,
|
||||
layout_to_paint_port: Some(layout_to_paint_port),
|
||||
chrome_to_paint_chan: chrome_to_paint_chan,
|
||||
chrome_to_paint_port: Some(chrome_to_paint_port),
|
||||
paint_shutdown_chan: paint_shutdown_chan,
|
||||
script_to_compositor_port: Some(script_to_compositor_port),
|
||||
};
|
||||
|
||||
(pipeline, unprivileged_pipeline_content, privileged_pipeline_content)
|
||||
}
|
||||
|
||||
pub fn new(id: PipelineId,
|
||||
parent_info: Option<(PipelineId, SubpageId)>,
|
||||
script_chan: Sender<ConstellationControlMsg>,
|
||||
script_chan: IpcSender<ConstellationControlMsg>,
|
||||
layout_chan: LayoutControlChan,
|
||||
compositor_proxy: Box<CompositorProxy + 'static + Send>,
|
||||
chrome_to_paint_chan: Sender<ChromeToPaintMsg>,
|
||||
layout_shutdown_port: Receiver<()>,
|
||||
paint_shutdown_port: Receiver<()>,
|
||||
layout_shutdown_port: IpcReceiver<()>,
|
||||
paint_shutdown_port: IpcReceiver<()>,
|
||||
url: Url,
|
||||
size: Option<TypedSize2D<PagePx, f32>>)
|
||||
-> Pipeline {
|
||||
|
@ -315,13 +342,14 @@ impl Pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct PipelineContent {
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct UnprivilegedPipelineContent {
|
||||
id: PipelineId,
|
||||
parent_info: Option<(PipelineId, SubpageId)>,
|
||||
constellation_chan: ConstellationChan<ConstellationMsg>,
|
||||
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||
compositor_proxy: Box<CompositorProxy + Send + 'static>,
|
||||
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
||||
script_to_compositor_chan: IpcSender<ScriptToCompositorMsg>,
|
||||
image_cache_task: ImageCacheTask,
|
||||
font_cache_task: FontCacheTask,
|
||||
resource_task: ResourceTask,
|
||||
|
@ -329,39 +357,31 @@ pub struct PipelineContent {
|
|||
time_profiler_chan: time::ProfilerChan,
|
||||
mem_profiler_chan: profile_mem::ProfilerChan,
|
||||
window_size: Option<WindowSizeData>,
|
||||
script_chan: Sender<ConstellationControlMsg>,
|
||||
script_chan: IpcSender<ConstellationControlMsg>,
|
||||
load_data: LoadData,
|
||||
failure: Failure,
|
||||
script_port: Option<Receiver<ConstellationControlMsg>>,
|
||||
script_port: Option<IpcReceiver<ConstellationControlMsg>>,
|
||||
layout_to_paint_chan: OptionalIpcSender<LayoutToPaintMsg>,
|
||||
chrome_to_paint_chan: Sender<ChromeToPaintMsg>,
|
||||
layout_to_paint_port: Option<Receiver<LayoutToPaintMsg>>,
|
||||
chrome_to_paint_port: Option<Receiver<ChromeToPaintMsg>>,
|
||||
paint_shutdown_chan: Sender<()>,
|
||||
opts: Opts,
|
||||
paint_shutdown_chan: IpcSender<()>,
|
||||
pipeline_port: Option<IpcReceiver<LayoutControlMsg>>,
|
||||
layout_shutdown_chan: Sender<()>,
|
||||
pipeline_namespace_id: PipelineNamespaceId,
|
||||
layout_shutdown_chan: IpcSender<()>,
|
||||
layout_content_process_shutdown_chan: IpcSender<()>,
|
||||
layout_content_process_shutdown_port: IpcReceiver<()>,
|
||||
script_content_process_shutdown_chan: IpcSender<()>,
|
||||
script_content_process_shutdown_port: IpcReceiver<()>,
|
||||
}
|
||||
|
||||
impl PipelineContent {
|
||||
pub fn start_all<LTF, STF>(mut self) where LTF: LayoutTaskFactory, STF: ScriptTaskFactory {
|
||||
impl UnprivilegedPipelineContent {
|
||||
pub fn start_all<LTF, STF>(mut self, wait_for_completion: bool)
|
||||
where LTF: LayoutTaskFactory, STF: ScriptTaskFactory {
|
||||
let layout_pair = ScriptTaskFactory::create_layout_channel(None::<&mut STF>);
|
||||
let (script_to_compositor_chan, script_to_compositor_port) = ipc::channel().unwrap();
|
||||
|
||||
self.start_paint_task();
|
||||
|
||||
let compositor_proxy_for_script_listener_thread =
|
||||
self.compositor_proxy.clone_compositor_proxy();
|
||||
thread::spawn(move || {
|
||||
compositor_task::run_script_listener_thread(
|
||||
compositor_proxy_for_script_listener_thread,
|
||||
script_to_compositor_port)
|
||||
});
|
||||
|
||||
ScriptTaskFactory::create(None::<&mut STF>, InitialScriptState {
|
||||
id: self.id,
|
||||
parent_info: self.parent_info,
|
||||
compositor: script_to_compositor_chan,
|
||||
compositor: self.script_to_compositor_chan.clone(),
|
||||
control_chan: self.script_chan.clone(),
|
||||
control_port: mem::replace(&mut self.script_port, None).unwrap(),
|
||||
constellation_chan: self.constellation_chan.clone(),
|
||||
|
@ -375,6 +395,7 @@ impl PipelineContent {
|
|||
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.clone(),
|
||||
}, &layout_pair, self.load_data.clone());
|
||||
|
||||
LayoutTaskFactory::create(None::<&mut LTF>,
|
||||
|
@ -391,7 +412,49 @@ impl PipelineContent {
|
|||
self.font_cache_task,
|
||||
self.time_profiler_chan,
|
||||
self.mem_profiler_chan,
|
||||
self.layout_shutdown_chan);
|
||||
self.layout_shutdown_chan,
|
||||
self.layout_content_process_shutdown_chan.clone());
|
||||
|
||||
if wait_for_completion {
|
||||
self.script_content_process_shutdown_port.recv().unwrap();
|
||||
self.layout_content_process_shutdown_port.recv().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opts(&self) -> Opts {
|
||||
self.opts.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PrivilegedPipelineContent {
|
||||
id: PipelineId,
|
||||
constellation_chan: ConstellationChan<ConstellationMsg>,
|
||||
compositor_proxy: Box<CompositorProxy + Send + 'static>,
|
||||
script_to_compositor_port: Option<IpcReceiver<ScriptToCompositorMsg>>,
|
||||
font_cache_task: FontCacheTask,
|
||||
time_profiler_chan: time::ProfilerChan,
|
||||
mem_profiler_chan: profile_mem::ProfilerChan,
|
||||
load_data: LoadData,
|
||||
failure: Failure,
|
||||
layout_to_paint_port: Option<Receiver<LayoutToPaintMsg>>,
|
||||
chrome_to_paint_chan: Sender<ChromeToPaintMsg>,
|
||||
chrome_to_paint_port: Option<Receiver<ChromeToPaintMsg>>,
|
||||
paint_shutdown_chan: IpcSender<()>,
|
||||
}
|
||||
|
||||
impl PrivilegedPipelineContent {
|
||||
pub fn start_all(&mut self) {
|
||||
self.start_paint_task();
|
||||
|
||||
let compositor_proxy_for_script_listener_thread =
|
||||
self.compositor_proxy.clone_compositor_proxy();
|
||||
let script_to_compositor_port =
|
||||
mem::replace(&mut self.script_to_compositor_port, None).unwrap();
|
||||
thread::spawn(move || {
|
||||
compositor_task::run_script_listener_thread(
|
||||
compositor_proxy_for_script_listener_thread,
|
||||
script_to_compositor_port)
|
||||
});
|
||||
}
|
||||
|
||||
pub fn start_paint_task(&mut self) {
|
||||
|
|
38
components/compositing/sandboxing.rs
Normal file
38
components/compositing/sandboxing.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use gaol::platform;
|
||||
use gaol::profile::{Operation, PathPattern, Profile};
|
||||
use std::path::PathBuf;
|
||||
use util::resource_files;
|
||||
|
||||
/// Our content process sandbox profile on Mac. As restrictive as possible.
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn content_process_sandbox_profile() -> Profile {
|
||||
Profile::new(vec![
|
||||
Operation::FileReadAll(PathPattern::Literal(PathBuf::from("/dev/urandom"))),
|
||||
Operation::FileReadAll(PathPattern::Subpath(resource_files::resources_dir_path())),
|
||||
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/"))),
|
||||
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())),
|
||||
]).expect("Failed to create sandbox profile!")
|
||||
}
|
||||
|
||||
/// Our content process sandbox profile on Linux. As restrictive as possible.
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub fn content_process_sandbox_profile() -> Profile {
|
||||
Profile::new(vec![
|
||||
Operation::FileReadAll(PathPattern::Literal(PathBuf::from("/dev/urandom"))),
|
||||
Operation::FileReadAll(PathPattern::Subpath(resource_files::resources_dir_path())),
|
||||
]).expect("Failed to create sandbox profile!")
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue