diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index aafe234896d..8266fe0fe40 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -406,45 +406,36 @@ impl Constellation initial_window_size: Option>, script_channel: Option>, load_data: LoadData) { - let spawning_content = script_channel.is_none(); - let (pipeline, unprivileged_pipeline_content, privileged_pipeline_content) = - Pipeline::create::(InitialPipelineState { - id: pipeline_id, - parent_info: parent_info, - constellation_chan: self.script_sender.clone(), - layout_to_constellation_chan: self.layout_sender.clone(), - panic_chan: self.panic_sender.clone(), - scheduler_chan: self.scheduler_chan.clone(), - compositor_proxy: self.compositor_proxy.clone_compositor_proxy(), - devtools_chan: self.devtools_chan.clone(), - bluetooth_thread: self.bluetooth_thread.clone(), - image_cache_thread: self.image_cache_thread.clone(), - font_cache_thread: self.font_cache_thread.clone(), - resource_threads: self.resource_threads.clone(), - time_profiler_chan: self.time_profiler_chan.clone(), - mem_profiler_chan: self.mem_profiler_chan.clone(), - window_size: initial_window_size, - script_chan: script_channel, - load_data: load_data, - device_pixel_ratio: self.window_size.device_pixel_ratio, - pipeline_namespace_id: self.next_pipeline_namespace_id(), - webrender_api_sender: self.webrender_api_sender.clone(), - }); + let result = Pipeline::spawn::(InitialPipelineState { + id: pipeline_id, + parent_info: parent_info, + constellation_chan: self.script_sender.clone(), + layout_to_constellation_chan: self.layout_sender.clone(), + panic_chan: self.panic_sender.clone(), + scheduler_chan: self.scheduler_chan.clone(), + compositor_proxy: self.compositor_proxy.clone_compositor_proxy(), + devtools_chan: self.devtools_chan.clone(), + bluetooth_thread: self.bluetooth_thread.clone(), + image_cache_thread: self.image_cache_thread.clone(), + font_cache_thread: self.font_cache_thread.clone(), + resource_threads: self.resource_threads.clone(), + time_profiler_chan: self.time_profiler_chan.clone(), + mem_profiler_chan: self.mem_profiler_chan.clone(), + window_size: initial_window_size, + script_chan: script_channel, + load_data: load_data, + device_pixel_ratio: self.window_size.device_pixel_ratio, + pipeline_namespace_id: self.next_pipeline_namespace_id(), + webrender_api_sender: self.webrender_api_sender.clone(), + }); - privileged_pipeline_content.start(); + let (pipeline, child_process) = match result { + Ok(result) => result, + Err(e) => return self.handle_send_error(pipeline_id, e), + }; - if spawning_content { - // Spawn the child process. - // - // Yes, that's all there is to it! - if opts::multiprocess() { - match unprivileged_pipeline_content.spawn_multiprocess() { - Ok(child_process) => self.child_processes.push(child_process), - Err(e) => self.handle_send_error(pipeline_id, e), - } - } else { - unprivileged_pipeline_content.start_all::(false); - } + if let Some(child_process) = child_process { + self.child_processes.push(child_process); } assert!(!self.pipelines.contains_key(&pipeline_id)); diff --git a/components/constellation/pipeline.rs b/components/constellation/pipeline.rs index 0e6acf571d4..d11129794d1 100644 --- a/components/constellation/pipeline.rs +++ b/components/constellation/pipeline.rs @@ -120,10 +120,8 @@ pub struct InitialPipelineState { } impl Pipeline { - /// Starts a paint thread, layout thread, and possibly a script thread. - /// Returns the channels wrapped in a struct. - pub fn create(state: InitialPipelineState) - -> (Pipeline, UnprivilegedPipelineContent, PrivilegedPipelineContent) + fn create(state: InitialPipelineState) + -> (Pipeline, UnprivilegedPipelineContent, PrivilegedPipelineContent) where LTF: LayoutThreadFactory, STF: ScriptThreadFactory { @@ -256,6 +254,34 @@ impl Pipeline { (pipeline, unprivileged_pipeline_content, privileged_pipeline_content) } + /// Starts a paint thread, layout thread, and possibly a script thread, in + /// a new process if requested. + pub fn spawn(state: InitialPipelineState) + -> Result<(Pipeline, Option), IOError> + where LTF: LayoutThreadFactory, + STF: ScriptThreadFactory + { + let spawning_content = state.script_chan.is_none(); + let (pipeline, unprivileged_pipeline_content, privileged_pipeline_content) = + Pipeline::create::(state); + + privileged_pipeline_content.start(); + + let mut child_process = None; + if spawning_content { + // Spawn the child process. + // + // Yes, that's all there is to it! + if opts::multiprocess() { + child_process = Some(try!(unprivileged_pipeline_content.spawn_multiprocess())); + } else { + unprivileged_pipeline_content.start_all::(false); + } + } + + Ok((pipeline, child_process)) + } + fn new(id: PipelineId, parent_info: Option<(PipelineId, SubpageId, FrameType)>, script_chan: IpcSender, @@ -520,7 +546,7 @@ impl UnprivilegedPipelineContent { } } -pub struct PrivilegedPipelineContent { +struct PrivilegedPipelineContent { id: PipelineId, compositor_proxy: Box, font_cache_thread: FontCacheThread,