From 609762ac638475b22ebe25151272edcc6928a447 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sat, 19 Jul 2014 16:26:11 +0100 Subject: [PATCH] Move about: URL handling from parsing to loading. Fix #1094 --- src/components/net/resource_task.rs | 23 +++++++++++++++++++++-- src/components/util/url.rs | 15 --------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/components/net/resource_task.rs b/src/components/net/resource_task.rs index 12472fead1e..15ede7b28e3 100644 --- a/src/components/net/resource_task.rs +++ b/src/components/net/resource_task.rs @@ -10,6 +10,7 @@ use data_loader; use std::comm::{channel, Receiver, Sender}; use std::task::TaskBuilder; +use std::os; use http::headers::content_type::MediaType; use ResponseHeaderCollection = http::headers::response::HeaderCollection; use RequestHeaderCollection = http::headers::request::HeaderCollection; @@ -202,15 +203,33 @@ impl ResourceManager { } } - fn load(&self, load_data: LoadData, start_chan: Sender) { + fn load(&self, mut load_data: LoadData, start_chan: Sender) { let loader = match load_data.url.scheme.as_slice() { "file" => file_loader::factory(), "http" => http_loader::factory(), "data" => data_loader::factory(), + "about" => { + match load_data.url.non_relative_scheme_data().unwrap() { + "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(); + path.push_many(["src", "test", "html", "failure.html"]); + load_data.url = Url::from_file_path(&path).unwrap(); + file_loader::factory() + } + _ => { + start_sending(start_chan, Metadata::default(load_data.url)) + .send(Done(Err("Unknown about: URL.".to_string()))); + return + } + } + }, _ => { debug!("resource_task: no loader for scheme {:s}", load_data.url.scheme); start_sending(start_chan, Metadata::default(load_data.url)) - .send(Done(Err("no loader for scheme".to_string()))); + .send(Done(Err("no loader for scheme".to_string()))); return } }; diff --git a/src/components/util/url.rs b/src/components/util/url.rs index e4160e6d7e6..db052c82a8a 100644 --- a/src/components/util/url.rs +++ b/src/components/util/url.rs @@ -42,21 +42,6 @@ pub fn try_parse_url(str_url: &str, base_url: Option) -> Result { match (url.scheme.as_slice(), url.scheme_data.clone()) { - ("about", rust_url::OtherSchemeData(scheme_data)) => { - match scheme_data.as_slice() { - "crash" => { - fail!("about:crash"); - } - "failure" => { - let mut path = os::self_exe_path().expect("can't get exe path"); - path.push("../src/test/html/failure.html"); - // FIXME (#1094): not the right way to transform a path - format!("file://{}", path.display().to_str()) - } - // TODO: handle the rest of the about: pages - _ => str_url.to_string() - } - }, ("data", _) => { // Drop whitespace within data: URLs, e.g. newlines within a base64 // src="..." block. Whitespace intended as content should be