diff --git a/components/net/about_loader.rs b/components/net/about_loader.rs index 30f34a100ae..55d4bf384ef 100644 --- a/components/net/about_loader.rs +++ b/components/net/about_loader.rs @@ -5,10 +5,10 @@ use resource_task::{LoadResponse, Metadata, Done, LoadData, start_sending}; use file_loader; -use std::os; use std::io::fs::PathExtensions; use url::Url; use http::status::Ok as StatusOk; +use servo_util::resource_files::resources_dir_path; pub fn factory(mut load_data: LoadData, start_chan: Sender) { @@ -26,13 +26,8 @@ pub fn factory(mut load_data: LoadData, start_chan: Sender) { } "crash" => fail!("Loading the about:crash URL."), "failure" => { - // FIXME: Find a way to load this without relying on the `../src` directory. - let mut path = os::self_exe_path().expect("can't get exe path"); - path.pop(); - if !path.join(Path::new("./tests/")).is_dir() { - path.pop(); - } - path.push_many(["tests", "html", "failure.html"]); + let mut path = resources_dir_path(); + path.push("failure.html"); assert!(path.exists()); load_data.url = Url::from_file_path(&path).unwrap(); } diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index 5b64840d491..fc37688cea0 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -10,6 +10,7 @@ use sync::Arc; use url::Url; use servo_util::bloom::BloomFilter; +use servo_util::resource_files::read_resource_file; use servo_util::smallvec::VecLike; use servo_util::sort; use string_cache::Atom; @@ -279,7 +280,7 @@ impl Stylist { rules_source_order: 0u, }; let ua_stylesheet = Stylesheet::from_bytes( - include_bin!("user-agent.css"), + read_resource_file(["user-agent.css"]).unwrap().as_slice(), Url::parse("chrome:///user-agent.css").unwrap(), None, None); diff --git a/components/util/lib.rs b/components/util/lib.rs index 4de1cff459c..58289bfa581 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -42,6 +42,7 @@ pub mod memory; pub mod namespace; pub mod opts; pub mod range; +pub mod resource_files; pub mod smallvec; pub mod sort; pub mod str; diff --git a/components/util/resource_files.rs b/components/util/resource_files.rs new file mode 100644 index 00000000000..7f01c3e84e4 --- /dev/null +++ b/components/util/resource_files.rs @@ -0,0 +1,30 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use std::io::{File, IoResult}; +use std::io::fs::PathExtensions; +use std::os; +use std::path::Path; + + +pub fn resources_dir_path() -> Path { + // FIXME: Find a way to not rely on the executable being under `/target`. + let mut path = os::self_exe_path().expect("can't get exe path"); + path.pop(); + path.push("resources"); + if !path.is_dir() { + path.pop(); + path.pop(); + path.push("resources"); + } + path +} + + +pub fn read_resource_file(relative_path_components: &[&str]) -> IoResult> { + let mut path = resources_dir_path(); + path.push_many(relative_path_components); + let mut file = try!(File::open(&path)); + file.read_to_end() +} diff --git a/tests/html/failure.html b/resources/failure.html similarity index 100% rename from tests/html/failure.html rename to resources/failure.html diff --git a/components/style/user-agent.css b/resources/user-agent.css similarity index 98% rename from components/style/user-agent.css rename to resources/user-agent.css index 076d82ccd3d..209bafa4c2e 100644 --- a/components/style/user-agent.css +++ b/resources/user-agent.css @@ -4,8 +4,8 @@ body, div, dt, fieldset, form, frame, frameset, h1, h2, h3, h4, -h5, h6, noframes, -center, dir, +h5, h6, noframes, +center, dir, hr, menu, pre { display: block; unicode-bidi: embed } head, noscript { display: none } table { display: table } @@ -54,7 +54,7 @@ thead, tbody, /* lists */ dd { display: block; margin-left: 40px } p, dl, multicol { display: block; margin: 1em 0 } -ul { display: block; list-style-type: disc; +ul { display: block; list-style-type: disc; margin: 1em 0; padding-left: 40px } ol { display: block; list-style-type: decimal;