Make chrome: URLs have a "host".

This commit is contained in:
Simon Sapin 2016-04-23 01:16:29 +02:00
parent 7375e2cedd
commit 374679852c
4 changed files with 20 additions and 10 deletions

View file

@ -8,14 +8,18 @@ use net_traits::{LoadConsumer, LoadData, NetworkError};
use resource_thread::{CancellationListener, send_error};
use std::sync::Arc;
use url::Url;
use url::percent_encoding::percent_decode;
use util::resource_files::resources_dir_path;
pub fn resolve_chrome_url(url: &Url) -> Result<Url, ()> {
assert_eq!(url.scheme(), "chrome");
if url.host_str() != Some("resources") {
return Err(())
}
let resources = resources_dir_path();
let mut path = resources.clone();
for segment in url.path_segments().unwrap() {
path.push(segment)
path.push(&*try!(percent_decode(segment.as_bytes()).decode_utf8().map_err(|_| ())))
}
// Don't allow chrome URLs access to files outside of the resources directory.
if !(path.starts_with(resources) && path.exists()) {

View file

@ -42,7 +42,7 @@ lazy_static! {
Ok(res) => {
let ua_stylesheet = Stylesheet::from_bytes(
&res,
Url::parse(&format!("chrome:///{:?}", filename)).unwrap(),
Url::parse(&format!("chrome://resources/{:?}", filename)).unwrap(),
None,
None,
Origin::UserAgent,
@ -69,7 +69,7 @@ lazy_static! {
Ok(res) => {
Stylesheet::from_bytes(
&res,
Url::parse("chrome:///quirks-mode.css").unwrap(),
Url::parse("chrome://resources/quirks-mode.css").unwrap(),
None,
None,
Origin::UserAgent,