Auto merge of #5992 - zmike:random-fixups, r=larsbergstrom

Attempt to not panic as much if the resources/ dir is not where it's expected to be.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5992)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-05-12 13:26:22 -05:00
commit 76225bdccb
3 changed files with 44 additions and 27 deletions

View file

@ -9,6 +9,7 @@ use selectors::matching::{SelectorMap, Rule};
use selectors::matching::DeclarationBlock as GenericDeclarationBlock;
use selectors::parser::PseudoElement;
use selectors::tree::TNode;
use std::process;
use util::resource_files::read_resource_file;
use util::smallvec::VecLike;
@ -59,13 +60,21 @@ impl Stylist {
// FIXME: presentational-hints.css should be at author origin with zero specificity.
// (Does it make a difference?)
for &filename in ["user-agent.css", "servo.css", "presentational-hints.css"].iter() {
let ua_stylesheet = Stylesheet::from_bytes(
&read_resource_file(&[filename]).unwrap(),
Url::parse(&format!("chrome:///{:?}", filename)).unwrap(),
None,
None,
Origin::UserAgent);
stylist.add_stylesheet(ua_stylesheet);
match read_resource_file(&[filename]) {
Ok(res) => {
let ua_stylesheet = Stylesheet::from_bytes(
&res,
Url::parse(&format!("chrome:///{:?}", filename)).unwrap(),
None,
None,
Origin::UserAgent);
stylist.add_stylesheet(ua_stylesheet);
}
Err(..) => {
error!("Stylist::new() failed at loading {}!", filename);
process::exit(1);
}
}
}
stylist
}
@ -154,12 +163,20 @@ impl Stylist {
}
pub fn add_quirks_mode_stylesheet(&mut self) {
self.add_stylesheet(Stylesheet::from_bytes(
&read_resource_file(&["quirks-mode.css"]).unwrap(),
Url::parse("chrome:///quirks-mode.css").unwrap(),
None,
None,
Origin::UserAgent))
match read_resource_file(&["quirks-mode.css"]) {
Ok(res) => {
self.add_stylesheet(Stylesheet::from_bytes(
&res,
Url::parse("chrome:///quirks-mode.css").unwrap(),
None,
None,
Origin::UserAgent));
}
Err(..) => {
error!("Stylist::add_quirks_mode_stylesheet() failed at loading 'quirks-mode.css'!");
process::exit(1);
}
}
}
pub fn add_stylesheet(&mut self, stylesheet: Stylesheet) {

View file

@ -25,14 +25,23 @@ pub fn resources_dir_path() -> PathBuf {
// or `<servo source>/components/servo/target/release`.
let mut path = env::current_exe().ok().expect("can't get exe path");
path.pop();
path.pop();
path.pop();
path.pop();
path.push("resources");
if !path.is_dir() { // self_exe_path() is probably in .../target/release
if !path.is_dir() { // resources dir not in same dir as exe?
path.pop();
path.pop();
path.pop();
path.pop();
path.push("resources");
if !path.is_dir() { // self_exe_path() is probably in .../target/release
path.pop();
path.pop();
path.push("resources");
if !path.is_dir() { // self_exe_path() is probably in .../target/release
path.pop();
path.pop();
path.push("resources");
}
}
}
path
}

View file

@ -27,15 +27,6 @@ static CEF_API_HASH_PLATFORM: &'static [u8] = b"6813214accbf2ebfb6bdcf8d00654650
#[cfg(target_os="linux")]
static CEF_API_HASH_PLATFORM: &'static [u8] = b"2bc564c3871965ef3a2531b528bda3e17fa17a6d\0";
#[cfg(target_os="linux")]
fn resources_path() -> Option<String> {
Some("../../servo/resources".to_owned())
}
#[cfg(not(target_os="linux"))]
fn resources_path() -> Option<String> {
None
}
#[no_mangle]
pub extern "C" fn cef_initialize(args: *const cef_main_args_t,
@ -77,7 +68,7 @@ pub extern "C" fn cef_initialize(args: *const cef_main_args_t,
temp_opts.headless = false;
temp_opts.hard_fail = false;
temp_opts.enable_text_antialiasing = true;
temp_opts.resources_path = resources_path();
temp_opts.resources_path = None;
opts::set(temp_opts);
return 1