Sync gonk lib.rs & main.rs with components/servo

This commit is contained in:
Michael Wu 2015-03-24 06:48:34 -04:00 committed by Ms2ger
parent 1ffa40ab55
commit 88b31933c4
2 changed files with 41 additions and 55 deletions

View file

@ -5,7 +5,7 @@
#![feature(thread_local)] #![feature(thread_local)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(int_uint)] #![feature(int_uint)]
#![feature(core, path, rustc_private)] #![feature(path, rustc_private)]
// For FFI // For FFI
#![allow(non_snake_case, dead_code)] #![allow(non_snake_case, dead_code)]
@ -58,10 +58,6 @@ use util::taskpool::TaskPool;
use std::env; use std::env;
#[cfg(not(test))] #[cfg(not(test))]
use std::rc::Rc; use std::rc::Rc;
#[cfg(not(test))]
use std::thread::Builder;
#[cfg(not(test))]
use std::sync::mpsc::channel;
pub struct Browser { pub struct Browser {
compositor: Box<CompositorEventListener + 'static>, compositor: Box<CompositorEventListener + 'static>,
@ -85,60 +81,46 @@ impl Browser {
devtools::start_server(port) devtools::start_server(port)
}); });
let opts_clone = opts.clone();
let time_profiler_chan_clone = time_profiler_chan.clone();
let mem_profiler_chan_clone = mem_profiler_chan.clone();
let (result_chan, result_port) = channel();
let compositor_proxy_for_constellation = compositor_proxy.clone_compositor_proxy();
Builder::new()
.spawn(move || {
let opts = &opts_clone;
// Create a Servo instance. // Create a Servo instance.
let resource_task = new_resource_task(opts.user_agent.clone()); let resource_task = new_resource_task(opts.user_agent.clone());
// If we are emitting an output file, then we need to block on // If we are emitting an output file, then we need to block on
// image load or we risk emitting an output file missing the // image load or we risk emitting an output file missing the
// image. // image.
let image_cache_task = if opts.output_file.is_some() { let image_cache_task = if opts.output_file.is_some() {
ImageCacheTask::new_sync(resource_task.clone(), shared_task_pool, ImageCacheTask::new_sync(resource_task.clone(), shared_task_pool,
time_profiler_chan_clone.clone()) time_profiler_chan.clone())
} else { } else {
ImageCacheTask::new(resource_task.clone(), shared_task_pool, ImageCacheTask::new(resource_task.clone(), shared_task_pool,
time_profiler_chan_clone.clone()) time_profiler_chan.clone())
}; };
let font_cache_task = FontCacheTask::new(resource_task.clone()); let font_cache_task = FontCacheTask::new(resource_task.clone());
let storage_task = StorageTaskFactory::new(); let storage_task = StorageTaskFactory::new();
let constellation_chan = Constellation::<layout::layout_task::LayoutTask, let constellation_chan = Constellation::<layout::layout_task::LayoutTask,
script::script_task::ScriptTask>::start( script::script_task::ScriptTask>::start(
compositor_proxy_for_constellation, compositor_proxy.clone_compositor_proxy(),
resource_task, resource_task,
image_cache_task, image_cache_task,
font_cache_task, font_cache_task,
time_profiler_chan_clone, time_profiler_chan.clone(),
mem_profiler_chan_clone, mem_profiler_chan.clone(),
devtools_chan, devtools_chan,
storage_task); storage_task);
// Send the URL command to the constellation. // Send the URL command to the constellation.
let cwd = env::current_dir().unwrap(); let cwd = env::current_dir().unwrap();
for url in opts.urls.iter() { for url in opts.urls.iter() {
let url = match url::Url::parse(url.as_slice()) { let url = match url::Url::parse(&*url) {
Ok(url) => url, Ok(url) => url,
Err(url::ParseError::RelativeUrlWithoutBase) Err(url::ParseError::RelativeUrlWithoutBase)
=> url::Url::from_file_path(&*cwd.join(url.as_slice())).unwrap(), => url::Url::from_file_path(&*cwd.join(&*url)).unwrap(),
Err(_) => panic!("URL parsing failed"), Err(_) => panic!("URL parsing failed"),
}; };
let ConstellationChan(ref chan) = constellation_chan; let ConstellationChan(ref chan) = constellation_chan;
chan.send(ConstellationMsg::InitLoadUrl(url)).ok().unwrap(); chan.send(ConstellationMsg::InitLoadUrl(url)).unwrap();
} }
// Send the constallation Chan as the result
result_chan.send(constellation_chan).ok().unwrap();
});
let constellation_chan = result_port.recv().unwrap();
debug!("preparing to enter main loop"); debug!("preparing to enter main loop");
let compositor = CompositorTask::create(window, let compositor = CompositorTask::create(window,
compositor_proxy, compositor_proxy,

View file

@ -23,8 +23,10 @@ extern crate gleam;
extern crate layers; extern crate layers;
extern crate egl; extern crate egl;
extern crate url; extern crate url;
extern crate net;
use util::opts; use util::opts;
use net::resource_task;
use servo::Browser; use servo::Browser;
use compositing::windowing::WindowEvent; use compositing::windowing::WindowEvent;
@ -39,6 +41,8 @@ struct BrowserWrapper {
fn main() { fn main() {
if opts::from_cmdline_args(env::args().collect::<Vec<_>>().as_slice()) { if opts::from_cmdline_args(env::args().collect::<Vec<_>>().as_slice()) {
resource_task::global_init();
let window = if opts::get().headless { let window = if opts::get().headless {
None None
} else { } else {