Skip to content

Commit

Permalink
opts.rs: don't accept multiple URLs. Fixes #5520.
Browse files Browse the repository at this point in the history
Switched from opts.urls from being of type Vec to type String and changing the name to `url` as well. Changed the other files that are using opts.urls accordingly.

servo/lib.rs + gonk/src/lib.rs: no need for a block scope.

cef: fix compiler errors.

- remove the use of `mut` since it's not needed.
- use `to_owned` instead of `to_string` because it's more efficient.
  • Loading branch information
Jag Talon committed Apr 7, 2015
1 parent c070ad6 commit 74cd4cd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 40 deletions.
24 changes: 10 additions & 14 deletions components/servo/lib.rs
Expand Up @@ -114,23 +114,20 @@ impl Browser {

// Send the URL command to the constellation.
let cwd = env::current_dir().unwrap();
for url in opts.urls.iter() {
let url = match url::Url::parse(&*url) {
Ok(url) => url,
Err(url::ParseError::RelativeUrlWithoutBase)
=> url::Url::from_file_path(&*cwd.join(&*url)).unwrap(),
Err(_) => panic!("URL parsing failed"),
};

let ConstellationChan(ref chan) = constellation_chan;
chan.send(ConstellationMsg::InitLoadUrl(url)).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();

debug!("preparing to enter main loop");
let compositor = CompositorTask::create(window,
compositor_proxy,
compositor_receiver,
constellation_chan,
constellation_chan.clone(),
time_profiler_chan,
mem_profiler_chan);

Expand Down Expand Up @@ -159,4 +156,3 @@ impl Browser {
self.compositor.shutdown();
}
}

14 changes: 7 additions & 7 deletions components/util/opts.rs
Expand Up @@ -22,8 +22,8 @@ use std::rt;
/// Global flags for Servo, currently set on the command line.
#[derive(Clone)]
pub struct Opts {
/// The initial URLs to load.
pub urls: Vec<String>,
/// The initial URL to load.
pub url: String,

/// How many threads to use for CPU painting (`-t`).
///
Expand Down Expand Up @@ -176,7 +176,7 @@ static FORCE_CPU_PAINTING: bool = false;

pub fn default_opts() -> Opts {
Opts {
urls: vec!(),
url: String::new(),
paint_threads: 1,
gpu_painting: false,
tile_size: 512,
Expand Down Expand Up @@ -266,12 +266,12 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
return false;
}

let urls = if opt_match.free.is_empty() {
let url = if opt_match.free.is_empty() {
print_usage(app_name.as_slice(), opts.as_slice());
args_fail("servo asks that you provide 1 or more URLs");
args_fail("servo asks that you provide a URL");
return false;
} else {
opt_match.free.clone()
opt_match.free[0].clone()
};

let tile_size: usize = match opt_match.opt_str("s") {
Expand Down Expand Up @@ -329,7 +329,7 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
};

let opts = Opts {
urls: urls,
url: url,
paint_threads: paint_threads,
gpu_painting: gpu_painting,
tile_size: tile_size,
Expand Down
6 changes: 2 additions & 4 deletions ports/cef/browser.rs
Expand Up @@ -204,10 +204,9 @@ fn browser_host_create(window_info: &cef_window_info_t,
client: CefClient,
callback_executed: bool)
-> CefBrowser {
let mut urls = Vec::new();
urls.push("http://s27.postimg.org/vqbtrolyr/servo.jpg".to_owned());
let url = "http://s27.postimg.org/vqbtrolyr/servo.jpg".to_owned();
let mut opts = opts::default_opts();
opts.urls = urls;
opts.url = url;
let browser = ServoCefBrowser::new(window_info, client).as_cef_interface();
browser.init(window_info);
if callback_executed {
Expand Down Expand Up @@ -246,4 +245,3 @@ cef_static_method_impls! {
browser_host_create(window_info, client, true)
}}
}

3 changes: 1 addition & 2 deletions ports/cef/core.rs
Expand Up @@ -70,7 +70,7 @@ pub extern "C" fn cef_initialize(args: *const cef_main_args_t,
};

let mut temp_opts = opts::default_opts();
temp_opts.urls = vec![HOME_URL.to_owned()];
temp_opts.url = HOME_URL.to_owned();
temp_opts.paint_threads = rendering_threads;
temp_opts.layout_threads = rendering_threads;
temp_opts.headless = false;
Expand Down Expand Up @@ -137,4 +137,3 @@ pub extern "C" fn cef_log(_file: *const c_char,
pub extern "C" fn cef_get_min_log_level() -> c_int {
0
}

23 changes: 10 additions & 13 deletions ports/gonk/src/lib.rs
Expand Up @@ -113,23 +113,20 @@ impl Browser {

// Send the URL command to the constellation.
let cwd = env::current_dir().unwrap();
for url in opts.urls.iter() {
let url = match url::Url::parse(&*url) {
Ok(url) => url,
Err(url::ParseError::RelativeUrlWithoutBase)
=> url::Url::from_file_path(&*cwd.join(&*url)).unwrap(),
Err(_) => panic!("URL parsing failed"),
};

let ConstellationChan(ref chan) = constellation_chan;
chan.send(ConstellationMsg::InitLoadUrl(url)).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();

debug!("preparing to enter main loop");
let compositor = CompositorTask::create(window,
compositor_proxy,
compositor_receiver,
constellation_chan,
constellation_chan.clone(),
time_profiler_chan,
mem_profiler_chan);

Expand Down

0 comments on commit 74cd4cd

Please sign in to comment.