diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 2f95be12aa2..1ff007e12f9 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -1231,6 +1231,7 @@ dependencies = [ "string_cache 0.1.0 (git+https://github.com/servo/string-cache)", "string_cache_plugin 0.1.1 (git+https://github.com/servo/string-cache)", "time 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "url 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 2cc681b038e..1682f0e8c2b 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -32,7 +32,6 @@ extern crate script; extern crate layout; extern crate gfx; extern crate libc; -extern crate url; extern crate webdriver_server; use compositing::CompositorEventListener; @@ -153,8 +152,6 @@ fn create_constellation(opts: opts::Opts, time_profiler_chan: time::ProfilerChan, devtools_chan: Option>, mem_profiler_chan: mem::ProfilerChan) -> ConstellationChan { - use std::env; - let resource_task = new_resource_task(opts.user_agent.clone(), devtools_chan.clone()); let image_cache_task = new_image_cache_task(resource_task.clone()); @@ -173,17 +170,9 @@ fn create_constellation(opts: opts::Opts, storage_task); // Send the URL command to the constellation. - let cwd = env::current_dir().unwrap(); - let url = match url::Url::parse(&opts.url) { - Ok(url) => url, - Err(url::ParseError::RelativeUrlWithoutBase) - => url::Url::from_file_path(&*cwd.join(&opts.url)).unwrap(), - Err(_) => panic!("URL parsing failed"), - }; - { let ConstellationChan(ref chan) = constellation_chan; - chan.send(ConstellationMsg::InitLoadUrl(url)).unwrap(); + chan.send(ConstellationMsg::InitLoadUrl(opts.url.clone())).unwrap(); } constellation_chan diff --git a/components/util/Cargo.toml b/components/util/Cargo.toml index dadc3872d8e..1ac5eff1354 100644 --- a/components/util/Cargo.toml +++ b/components/util/Cargo.toml @@ -48,3 +48,4 @@ fnv = "1.0" cssparser = "0.3.1" num = "0.1.24" lazy_static = "0.1.10" +url = "*" diff --git a/components/util/lib.rs b/components/util/lib.rs index 021499c3adc..61c6de2475c 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -36,6 +36,7 @@ extern crate rustc_serialize; extern crate selectors; extern crate smallvec as smallvec_; extern crate string_cache; +extern crate url; use std::sync::Arc; diff --git a/components/util/opts.rs b/components/util/opts.rs index 70ca9d4b92b..5816ec313aa 100644 --- a/components/util/opts.rs +++ b/components/util/opts.rs @@ -18,12 +18,13 @@ use std::env; use std::io::{self, Write}; use std::mem; use std::ptr; +use url::{self, Url}; /// Global flags for Servo, currently set on the command line. #[derive(Clone)] pub struct Opts { /// The initial URL to load. - pub url: String, + pub url: Url, /// How many threads to use for CPU painting (`-t`). /// @@ -192,7 +193,7 @@ static FORCE_CPU_PAINTING: bool = false; pub fn default_opts() -> Opts { Opts { - url: String::new(), + url: Url::parse("about:blank").unwrap(), paint_threads: 1, gpu_painting: false, tile_size: 512, @@ -293,7 +294,14 @@ pub fn from_cmdline_args(args: &[String]) -> bool { args_fail("servo asks that you provide a URL"); return false; } else { - opt_match.free[0].clone() + let ref url = opt_match.free[0]; + let cwd = env::current_dir().unwrap(); + match Url::parse(url) { + Ok(url) => url, + Err(url::ParseError::RelativeUrlWithoutBase) + => Url::from_file_path(&*cwd.join(url)).unwrap(), + Err(_) => panic!("URL parsing failed"), + } }; let tile_size: usize = match opt_match.opt_str("s") { diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 6d3248bbc62..838428b130d 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -1068,7 +1068,6 @@ dependencies = [ "profile_traits 0.0.1", "script 0.0.1", "time 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "url 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", "util 0.0.1", "webdriver_server 0.0.1", ] @@ -1224,6 +1223,7 @@ dependencies = [ "string_cache 0.1.0 (git+https://github.com/servo/string-cache)", "string_cache_plugin 0.1.1 (git+https://github.com/servo/string-cache)", "time 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "url 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/ports/cef/browser.rs b/ports/cef/browser.rs index 6f773fa335a..90e13801bec 100644 --- a/ports/cef/browser.rs +++ b/ports/cef/browser.rs @@ -15,7 +15,6 @@ use window; use compositing::windowing::{WindowNavigateMsg, WindowEvent}; use glutin_app; use libc::c_int; -use util::opts; use std::borrow::ToOwned; use std::cell::{Cell, RefCell, BorrowState}; use std::sync::atomic::{AtomicIsize, Ordering}; @@ -204,9 +203,6 @@ fn browser_host_create(window_info: &cef_window_info_t, client: CefClient, callback_executed: bool) -> CefBrowser { - let url = "http://s27.postimg.org/vqbtrolyr/servo.jpg".to_owned(); - let mut opts = opts::default_opts(); - opts.url = url; let browser = ServoCefBrowser::new(window_info, client).as_cef_interface(); browser.init(window_info); if callback_executed { diff --git a/ports/cef/core.rs b/ports/cef/core.rs index 7a27f37618f..da964455ddc 100644 --- a/ports/cef/core.rs +++ b/ports/cef/core.rs @@ -12,6 +12,7 @@ use std::borrow::ToOwned; use std::ffi; use std::str; use browser; +use std_url::Url; const MAX_RENDERING_THREADS: usize = 128; @@ -70,7 +71,7 @@ pub extern "C" fn cef_initialize(args: *const cef_main_args_t, }; let mut temp_opts = opts::default_opts(); - temp_opts.url = HOME_URL.to_owned(); + temp_opts.url = Url::parse(HOME_URL).unwrap(); temp_opts.paint_threads = rendering_threads; temp_opts.layout_threads = rendering_threads; temp_opts.headless = false;