Merge pull request #3216 from seanmonstar/about-blank

Implements about:blank in an about_loader
This commit is contained in:
Josh Matthews 2014-09-11 16:45:06 -04:00
commit 4e35b82770
10 changed files with 95 additions and 75 deletions

View file

@ -0,0 +1,41 @@
/* 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 resource_task::{LoadResponse, Metadata, Done, LoadData, start_sending};
use file_loader;
use std::os;
use url::Url;
use StatusOk = http::status::Ok;
pub fn factory(mut load_data: LoadData, start_chan: Sender<LoadResponse>) {
match load_data.url.non_relative_scheme_data().unwrap() {
"blank" => {
let chan = start_sending(start_chan, Metadata {
final_url: load_data.url,
content_type: Some(("text".to_string(), "html".to_string())),
charset: Some("utf-8".to_string()),
headers: None,
status: StatusOk,
});
chan.send(Done(Ok(())));
return
}
"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();
}
_ => {
start_sending(start_chan, Metadata::default(load_data.url))
.send(Done(Err("Unknown about: URL.".to_string())));
return
}
};
file_loader::factory(load_data, start_chan)
}

View file

@ -4,7 +4,7 @@
use std::str; use std::str;
use resource_task::{Done, Payload, Metadata, LoadData, LoadResponse, LoaderTask, start_sending}; use resource_task::{Done, Payload, Metadata, LoadData, LoadResponse, start_sending};
use serialize::base64::FromBase64; use serialize::base64::FromBase64;
@ -13,13 +13,12 @@ use http::headers::content_type::MediaType;
use url::{percent_decode, NonRelativeSchemeData}; use url::{percent_decode, NonRelativeSchemeData};
pub fn factory() -> LoaderTask { pub fn factory(load_data: LoadData, start_chan: Sender<LoadResponse>) {
proc(url, start_chan) { // NB: we don't spawn a new task.
// NB: we don't spawn a new task. // Hypothesis: data URLs are too small for parallel base64 etc. to be worth it.
// Hypothesis: data URLs are too small for parallel base64 etc. to be worth it. // Should be tested at some point.
// Should be tested at some point. // Left in separate function to allow easy moving to a task, if desired.
load(url, start_chan) load(load_data, start_chan)
}
} }
fn load(load_data: LoadData, start_chan: Sender<LoadResponse>) { fn load(load_data: LoadData, start_chan: Sender<LoadResponse>) {

View file

@ -2,7 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use resource_task::{ProgressMsg, Metadata, Payload, Done, LoaderTask, start_sending}; use resource_task::{ProgressMsg, Metadata, Payload, Done, LoadData, start_sending};
use resource_task::{LoadResponse};
use std::io; use std::io;
use std::io::File; use std::io::File;
@ -29,30 +30,27 @@ fn read_all(reader: &mut io::Stream, progress_chan: &Sender<ProgressMsg>)
} }
} }
pub fn factory() -> LoaderTask { pub fn factory(load_data: LoadData, start_chan: Sender<LoadResponse>) {
let f: LoaderTask = proc(load_data, start_chan) { let url = load_data.url;
let url = load_data.url; assert!("file" == url.scheme.as_slice());
assert!("file" == url.scheme.as_slice()); let progress_chan = start_sending(start_chan, Metadata::default(url.clone()));
let progress_chan = start_sending(start_chan, Metadata::default(url.clone())); spawn_named("file_loader", proc() {
spawn_named("file_loader", proc() { let file_path: Result<Path, ()> = url.to_file_path();
let file_path: Result<Path, ()> = url.to_file_path(); match file_path {
match file_path { Ok(file_path) => {
Ok(file_path) => { match File::open_mode(&Path::new(file_path), io::Open, io::Read) {
match File::open_mode(&Path::new(file_path), io::Open, io::Read) { Ok(ref mut reader) => {
Ok(ref mut reader) => { let res = read_all(reader as &mut io::Stream, &progress_chan);
let res = read_all(reader as &mut io::Stream, &progress_chan); progress_chan.send(Done(res));
progress_chan.send(Done(res)); }
} Err(e) => {
Err(e) => { progress_chan.send(Done(Err(e.desc.to_string())));
progress_chan.send(Done(Err(e.desc.to_string())));
}
} }
} }
Err(_) => {
progress_chan.send(Done(Err(url.to_string())));
}
} }
}); Err(_) => {
}; progress_chan.send(Done(Err(url.to_string())));
f }
}
});
} }

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use resource_task::{Metadata, Payload, Done, LoadResponse, LoadData, LoaderTask, start_sending_opt}; use resource_task::{Metadata, Payload, Done, LoadResponse, LoadData, start_sending_opt};
use std::collections::hashmap::HashSet; use std::collections::hashmap::HashSet;
use http::client::{RequestWriter, NetworkStream}; use http::client::{RequestWriter, NetworkStream};
@ -11,11 +11,8 @@ use std::io::Reader;
use servo_util::task::spawn_named; use servo_util::task::spawn_named;
use url::Url; use url::Url;
pub fn factory() -> LoaderTask { pub fn factory(load_data: LoadData, start_chan: Sender<LoadResponse>) {
let f: LoaderTask = proc(url, start_chan) { spawn_named("http_loader", proc() load(load_data, start_chan))
spawn_named("http_loader", proc() load(url, start_chan))
};
f
} }
fn send_error(url: Url, err: String, start_chan: Sender<LoadResponse>) { fn send_error(url: Url, err: String, start_chan: Sender<LoadResponse>) {

View file

@ -28,6 +28,7 @@ pub mod image {
pub mod holder; pub mod holder;
} }
pub mod about_loader;
pub mod file_loader; pub mod file_loader;
pub mod http_loader; pub mod http_loader;
pub mod data_loader; pub mod data_loader;

View file

@ -4,13 +4,13 @@
//! A task that takes a URL and streams back the binary data. //! A task that takes a URL and streams back the binary data.
use about_loader;
use data_loader;
use file_loader; use file_loader;
use http_loader; use http_loader;
use data_loader;
use std::comm::{channel, Receiver, Sender}; use std::comm::{channel, Receiver, Sender};
use std::task::TaskBuilder; use std::task::TaskBuilder;
use std::os;
use http::headers::content_type::MediaType; use http::headers::content_type::MediaType;
use ResponseHeaderCollection = http::headers::response::HeaderCollection; use ResponseHeaderCollection = http::headers::response::HeaderCollection;
use RequestHeaderCollection = http::headers::request::HeaderCollection; use RequestHeaderCollection = http::headers::request::HeaderCollection;
@ -163,16 +163,6 @@ pub fn load_whole_resource(resource_task: &ResourceTask, url: Url)
/// Handle to a resource task /// Handle to a resource task
pub type ResourceTask = Sender<ControlMsg>; pub type ResourceTask = Sender<ControlMsg>;
pub type LoaderTask = proc(load_data: LoadData, Sender<LoadResponse>);
/**
Creates a task to load a specific resource
The ResourceManager delegates loading to a different type of loader task for
each URL scheme
*/
type LoaderTaskFactory = extern "Rust" fn() -> LoaderTask;
/// Create a ResourceTask /// Create a ResourceTask
pub fn new_resource_task() -> ResourceTask { pub fn new_resource_task() -> ResourceTask {
let (setup_chan, setup_port) = channel(); let (setup_chan, setup_port) = channel();
@ -211,29 +201,12 @@ impl ResourceManager {
} }
} }
fn load(&self, mut load_data: LoadData, start_chan: Sender<LoadResponse>) { fn load(&self, load_data: LoadData, start_chan: Sender<LoadResponse>) {
let loader = match load_data.url.scheme.as_slice() { let loader = match load_data.url.scheme.as_slice() {
"file" => file_loader::factory(), "file" => file_loader::factory,
"http" | "https" => http_loader::factory(), "http" | "https" => http_loader::factory,
"data" => data_loader::factory(), "data" => data_loader::factory,
"about" => { "about" => about_loader::factory,
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); debug!("resource_task: no loader for scheme {:s}", load_data.url.scheme);
start_sending(start_chan, Metadata::default(load_data.url)) start_sending(start_chan, Metadata::default(load_data.url))

View file

@ -1,3 +1,4 @@
[open-url-about-blank-window.htm] [open-url-about-blank-window.htm]
type: testharness type: testharness
expected: TIMEOUT [XMLHttpRequest: open() resolving URLs (about:blank iframe)]
expected: FAIL

View file

@ -1,3 +1,7 @@
[exceptions.html] [exceptions.html]
type: testharness type: testharness
expected: TIMEOUT expected: TIMEOUT
[exception.hasOwnProperty("message")]
expected: FAIL
[Object.getOwnPropertyDescriptor(exception, "message")]
expected: FAIL

View file

@ -1,3 +1,8 @@
[Node-appendChild.html] [Node-appendChild.html]
type: testharness type: testharness
expected: TIMEOUT [Appending a document]
expected: FAIL
[Adopting an orphan]
expected: FAIL
[Adopting a non-orphan]
expected: FAIL

View file

@ -1,3 +1,4 @@
[indexed-browsing-contexts-03.html] [indexed-browsing-contexts-03.html]
type: testharness type: testharness
expected: TIMEOUT [Indexed child browsing contexts]
expected: FAIL