mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Make new test use local resources only.
This commit is contained in:
parent
16096f1a9c
commit
d888ed368d
12 changed files with 121 additions and 15 deletions
47
components/net/chrome_loader.rs
Normal file
47
components/net/chrome_loader.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* 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 file_loader;
|
||||
use mime_classifier::MIMEClassifier;
|
||||
use net_traits::{LoadConsumer, LoadData, NetworkError};
|
||||
use resource_thread::{CancellationListener, send_error};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use url::Url;
|
||||
use util::resource_files::resources_dir_path;
|
||||
|
||||
pub fn resolve_chrome_url(url: &Url) -> Result<Url, ()> {
|
||||
assert_eq!(url.scheme, "chrome");
|
||||
// Skip the initial //
|
||||
let non_relative_scheme_data = &url.non_relative_scheme_data().unwrap()[2..];
|
||||
let relative_path = Path::new(non_relative_scheme_data);
|
||||
// Don't allow chrome URLs access to files outside of the resources directory.
|
||||
if non_relative_scheme_data.find("..").is_some() ||
|
||||
relative_path.is_absolute() ||
|
||||
relative_path.has_root() {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
let mut path = resources_dir_path();
|
||||
path.push(non_relative_scheme_data);
|
||||
assert!(path.exists());
|
||||
return Ok(Url::from_file_path(&*path).unwrap());
|
||||
}
|
||||
|
||||
pub fn factory(mut load_data: LoadData,
|
||||
start_chan: LoadConsumer,
|
||||
classifier: Arc<MIMEClassifier>,
|
||||
cancel_listener: CancellationListener) {
|
||||
let file_url = match resolve_chrome_url(&load_data.url) {
|
||||
Ok(url) => url,
|
||||
Err(_) => {
|
||||
send_error(load_data.url,
|
||||
NetworkError::Internal("Invalid chrome URL.".to_owned()),
|
||||
start_chan);
|
||||
return;
|
||||
}
|
||||
};
|
||||
load_data.url = file_url;
|
||||
file_loader::factory(load_data, start_chan, classifier, cancel_listener)
|
||||
}
|
|
@ -39,6 +39,7 @@ extern crate webrender_traits;
|
|||
extern crate websocket;
|
||||
|
||||
pub mod about_loader;
|
||||
pub mod chrome_loader;
|
||||
pub mod cookie;
|
||||
pub mod cookie_storage;
|
||||
pub mod data_loader;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
//! A thread that takes a URL and streams back the binary data.
|
||||
|
||||
use about_loader;
|
||||
use chrome_loader;
|
||||
use cookie;
|
||||
use cookie_storage::CookieStorage;
|
||||
use data_loader;
|
||||
|
@ -332,6 +333,7 @@ impl ResourceManager {
|
|||
|
||||
let cancel_listener = CancellationListener::new(cancel_resource);
|
||||
let loader = match &*load_data.url.scheme {
|
||||
"chrome" => from_factory(chrome_loader::factory),
|
||||
"file" => from_factory(file_loader::factory),
|
||||
"http" | "https" | "view-source" => {
|
||||
let http_state = HttpState {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue