"javascript:" urls: run in correct global

Make some changes to javascript scheme url evaluation to bring it
closer to
https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigating-across-documents

- Evaluate the js before the page load so that it happens in the
  correct `window` global.
- If the result is not a string, the response should be a 204.

This required saving some data in load_data, since it's not
possible to modify the response at the point where we're evaluating
the js.
This commit is contained in:
Daniel Johnson 2017-08-20 14:50:02 -07:00
parent 20c73e7f7d
commit fa3e9ab244
2 changed files with 93 additions and 44 deletions

View file

@ -146,12 +146,24 @@ pub struct LoadData {
pub headers: Headers,
/// The data.
pub data: Option<Vec<u8>>,
/// The result of evaluating a javascript scheme url.
pub js_eval_result: Option<JsEvalResult>,
/// The referrer policy.
pub referrer_policy: Option<ReferrerPolicy>,
/// The referrer URL.
pub referrer_url: Option<ServoUrl>,
}
/// The result of evaluating a javascript scheme url.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum JsEvalResult {
/// The js evaluation had a non-string result, 204 status code.
/// https://html.spec.whatwg.org/multipage/#navigate 12.11
NoContent,
/// The js evaluation had a string result.
Ok(Vec<u8>)
}
impl LoadData {
/// Create a new `LoadData` object.
pub fn new(url: ServoUrl,
@ -165,6 +177,7 @@ impl LoadData {
method: Method::Get,
headers: Headers::new(),
data: None,
js_eval_result: None,
referrer_policy: referrer_policy,
referrer_url: referrer_url,
}