aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorJames Graham <james@hoppipolla.co.uk>2015-09-17 00:50:50 +0100
committerJames Graham <james@hoppipolla.co.uk>2015-09-25 00:58:51 +0100
commit8d9ab50a96aea40f08c9d42d344fa749896b8b47 (patch)
tree95e8d9ba3141981edc9ec752d686b24f0c36c4b3 /components
parent79e548905e3c5c9891eef2fcbf20203c56f952ee (diff)
downloadservo-8d9ab50a96aea40f08c9d42d344fa749896b8b47.tar.gz
servo-8d9ab50a96aea40f08c9d42d344fa749896b8b47.zip
Add a pref for a default homepage.
Diffstat (limited to 'components')
-rw-r--r--components/util/opts.rs27
-rw-r--r--components/util/resource_files.rs15
2 files changed, 30 insertions, 12 deletions
diff --git a/components/util/opts.rs b/components/util/opts.rs
index bdf8277adce..42dc8ec3ae6 100644
--- a/components/util/opts.rs
+++ b/components/util/opts.rs
@@ -10,6 +10,7 @@ use geometry::ScreenPx;
use getopts::Options;
use num_cpus;
use prefs::{self, PrefValue};
+use resource_files::set_resources_path;
use std::cmp;
use std::default::Default;
use std::env;
@@ -155,9 +156,6 @@ pub struct Opts {
/// Whether to show an error when display list geometry escapes flow overflow regions.
pub validate_display_list_geometry: bool,
- /// A specific path to find required resources (such as user-agent.css).
- pub resources_path: Option<String>,
-
/// Whether MIME sniffing should be used
pub sniff_mime_types: bool,
@@ -409,7 +407,6 @@ pub fn default_opts() -> Opts {
validate_display_list_geometry: false,
profile_tasks: false,
profile_script_events: false,
- resources_path: None,
sniff_mime_types: false,
disable_share_style_cache: false,
parallel_display_list_building: false,
@@ -460,6 +457,8 @@ pub fn from_cmdline_args(args: &[String]) {
Err(f) => args_fail(&f.to_string()),
};
+ set_resources_path(opt_match.opt_str("resources-path"));
+
if opt_match.opt_present("h") || opt_match.opt_present("help") {
print_usage(app_name, &opts);
process::exit(0);
@@ -480,12 +479,21 @@ pub fn from_cmdline_args(args: &[String]) {
}
let cwd = env::current_dir().unwrap();
- let url = if opt_match.free.is_empty() {
- print_usage(app_name, &opts);
- args_fail("servo asks that you provide a URL")
+ let homepage_pref = prefs::get_pref("shell.homepage");
+ let url_opt = if !opt_match.free.is_empty() {
+ Some(&opt_match.free[0][..])
} else {
- parse_url_or_filename(&cwd, &opt_match.free[0])
- .unwrap_or_else(|()| args_fail("URL parsing failed"))
+ homepage_pref.as_string()
+ };
+ let url = match url_opt {
+ Some(url_string) => {
+ parse_url_or_filename(&cwd, url_string)
+ .unwrap_or_else(|()| args_fail("URL parsing failed"))
+ },
+ None => {
+ print_usage(app_name, &opts);
+ args_fail("servo asks that you provide a URL")
+ }
};
let tile_size: usize = match opt_match.opt_str("s") {
@@ -602,7 +610,6 @@ pub fn from_cmdline_args(args: &[String]) {
dump_display_list_optimized: debug_options.dump_display_list_optimized,
relayout_event: debug_options.relayout_event,
validate_display_list_geometry: debug_options.validate_display_list_geometry,
- resources_path: opt_match.opt_str("resources-path"),
sniff_mime_types: opt_match.opt_present("sniff-mime-types"),
disable_share_style_cache: debug_options.disable_share_style_cache,
parallel_display_list_building: debug_options.parallel_display_list_building,
diff --git a/components/util/resource_files.rs b/components/util/resource_files.rs
index 41a09511078..68d735697c7 100644
--- a/components/util/resource_files.rs
+++ b/components/util/resource_files.rs
@@ -5,6 +5,18 @@
use std::fs::File;
use std::io::{self, Read};
use std::path::PathBuf;
+use std::sync::{Arc, Mutex};
+
+lazy_static! {
+ static ref CMD_RESOURCE_DIR: Arc<Mutex<Option<String>>> = {
+ Arc::new(Mutex::new(None))
+ };
+}
+
+pub fn set_resources_path(path: Option<String>) {
+ let mut dir = CMD_RESOURCE_DIR.lock().unwrap();
+ *dir = path;
+}
#[cfg(target_os = "android")]
pub fn resources_dir_path() -> PathBuf {
@@ -13,11 +25,10 @@ pub fn resources_dir_path() -> PathBuf {
#[cfg(not(target_os = "android"))]
pub fn resources_dir_path() -> PathBuf {
- use opts;
use std::env;
use std::fs::PathExt;
- match opts::get().resources_path {
+ match *CMD_RESOURCE_DIR.lock().unwrap() {
Some(ref path) => PathBuf::from(path),
None => {
// FIXME: Find a way to not rely on the executable being