Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

view-source protocol and text/plain handling #5219

Closed
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Implement displaying of text/plain documents

This is done by detecting the content type as text/plain
and following the requirements from:
https://html.spec.whatwg.org/multipage/browsers.html#read-text
  • Loading branch information
doublec committed Mar 17, 2015
commit 618142fac7a580071f758333f91afc683e70f6d7
@@ -55,23 +55,31 @@ fn load(mut load_data: LoadData, start_chan: Sender<TargetedLoadResponse>, cooki
let mut url = load_data.url.clone();
let mut redirected_to = HashSet::new();

let senders = ResponseSenders {
immediate_consumer: start_chan,
eventual_consumer: load_data.consumer
};

// If the URL is a view-source scheme then the scheme data contains the
// real URL that should be used for which the source is to be viewed.
// Change our existing URL to that and keep note that we are viewing
// the source rather than rendering the contents of the URL.
let viewing_source = if url.scheme == "view-source" {
let inner_url = load_data.url.non_relative_scheme_data().unwrap();
url = Url::parse(inner_url).unwrap();
match url.scheme.as_slice() {
"http" | "https" => {}
_ => {
let s = format!("The {} scheme with view-source is not supported", url.scheme);
send_error(url, s, senders);
return;
}
};
true
} else {
false
};

let senders = ResponseSenders {
immediate_consumer: start_chan,
eventual_consumer: load_data.consumer
};

// Loop to handle redirects.
loop {
iters = iters + 1;
@@ -180,6 +180,22 @@ pub fn parse_html(document: JSRef<Document>,
task_state::enter(IN_HTML_PARSER);
}

fn parse_progress(parser: &JSRef<ServoHTMLParser>, url: &Url, load_response: &LoadResponse) {
for msg in load_response.progress_port.iter() {
match msg {
ProgressMsg::Payload(data) => {
// FIXME: use Vec<u8> (html5ever #34)
let data = UTF_8.decode(data.as_slice(), DecoderTrap::Replace).unwrap();
parser.parse_chunk(data);
}
ProgressMsg::Done(Err(err)) => {
panic!("Failed to load page URL {}, error: {}", url.serialize(), err);
}
ProgressMsg::Done(Ok(())) => break,
}
}
};

match input {
HTMLInput::InputString(s) => {
parser.parse_chunk(s);
@@ -205,19 +221,7 @@ pub fn parse_html(document: JSRef<Document>,
parse_progress(&parser, url, &load_response);
},
_ => {
for msg in load_response.progress_port.iter() {
match msg {
ProgressMsg::Payload(data) => {
// FIXME: use Vec<u8> (html5ever #34)
let data = UTF_8.decode(data.as_slice(), DecoderTrap::Replace).unwrap();
parser.parse_chunk(data);
}
ProgressMsg::Done(Err(err)) => {
panic!("Failed to load page URL {}, error: {}", url.serialize(), err);
}
ProgressMsg::Done(Ok(())) => break,
}
}
parse_progress(&parser, url, &load_response);
}
}
}
@@ -82,6 +82,7 @@ use js;
use url::Url;

use libc;
use std::ascii::AsciiExt;
use std::any::Any;
use std::borrow::ToOwned;
use std::cell::{Cell, RefCell};
@@ -984,10 +985,18 @@ impl ScriptTask {
headers.get().map(|&LastModified(ref tm)| dom_last_modified(tm))
});

let content_type = match response.metadata.content_type {
Some((ref t, ref st)) if t.as_slice().eq_ignore_ascii_case("text") &&
st.as_slice().eq_ignore_ascii_case("plain") => {
Some("text/plain".to_owned())
}
_ => None
};

let document = Document::new(window.r(),
Some(final_url.clone()),
IsHTMLDocument::HTMLDocument,
None,
content_type,
last_modified,
DocumentSource::FromParser).root();

@@ -1,11 +1,5 @@
[load-text-plain.html]
type: testharness
[Checking document metadata for text file]
expected: FAIL

[Checking DOM for text file]
expected: FAIL

[Checking contents for text file]
expected: FAIL

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.