diff options
author | Josh Matthews <josh@joshmatthews.net> | 2015-02-02 20:16:42 +0000 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2015-02-04 13:37:01 +0000 |
commit | 542e8d52d586590872b4bf0148d3d25fbfa67555 (patch) | |
tree | e0cc93d0b478ee18dff7947503dfce0a1dc23031 | |
parent | 94de93b3a32940167b5798c150753e4181e9c70b (diff) | |
download | servo-542e8d52d586590872b4bf0148d3d25fbfa67555.tar.gz servo-542e8d52d586590872b4bf0148d3d25fbfa67555.zip |
Reorganize document creation so it occurs after we have a final URL.
-rw-r--r-- | components/script/dom/document.rs | 3 | ||||
-rw-r--r-- | components/script/script_task.rs | 88 |
2 files changed, 45 insertions, 46 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 0b136459cd8..fa8637b374d 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -210,8 +210,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { } fn url(self) -> Url { - let window = self.window().root(); - window.page().get_url() + self.url.clone() } fn quirks_mode(self) -> QuirksMode { diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 35f85f593c9..d374cfcf9ba 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -787,6 +787,43 @@ impl ScriptTask { let is_javascript = url.scheme.as_slice() == "javascript"; + self.compositor.borrow_mut().set_ready_state(pipeline_id, Loading); + + let (mut parser_input, final_url, last_modified) = if !is_javascript { + // Wait for the LoadResponse so that the parser knows the final URL. + let (input_chan, input_port) = channel(); + self.resource_task.send(ControlMsg::Load(NetLoadData { + url: url, + method: load_data.method, + headers: load_data.headers, + data: load_data.data, + cors: None, + consumer: input_chan, + })).unwrap(); + + let load_response = input_port.recv().unwrap(); + + let last_modified = load_response.metadata.headers.as_ref().and_then(|headers| { + headers.get().map(|&LastModified(ref tm)| tm.clone()) + }); + + let final_url = load_response.metadata.final_url.clone(); + + (HTMLInput::InputUrl(load_response), final_url, last_modified) + } else { + let doc_url = last_url.unwrap_or_else(|| { + Url::parse("about:blank").unwrap() + }); + (HTMLInput::InputString("".to_owned()), doc_url, None) + }; + + // Store the final URL before we start parsing, so that DOM routines + // (e.g. HTMLImageElement::update_image) can resolve relative URLs + // correctly. + { + *page.mut_url() = Some((final_url.clone(), true)); + } + let cx = self.js_context.borrow(); let cx = cx.as_ref().unwrap(); // Create the window and document objects. @@ -796,22 +833,15 @@ impl ScriptTask { self.control_chan.clone(), self.compositor.borrow_mut().dup(), self.image_cache_task.clone()).root(); - let doc_url = if is_javascript { - let doc_url = last_url.unwrap_or_else(|| { - Url::parse("about:blank").unwrap() - }); - *page.mut_url() = Some((doc_url.clone(), true)); - doc_url - } else { - url.clone() - }; - let document = Document::new(window.r(), Some(doc_url.clone()), + + let document = Document::new(window.r(), Some(final_url.clone()), IsHTMLDocument::HTMLDocument, None, DocumentSource::FromParser).root(); - + if let Some(tm) = last_modified { + document.set_last_modified(dom_last_modified(&tm)); + } window.r().init_browser_context(document.r()); - self.compositor.borrow_mut().set_ready_state(pipeline_id, Loading); { // Create the root frame. @@ -822,42 +852,12 @@ impl ScriptTask { }); } - let (parser_input, final_url) = if !is_javascript { - // Wait for the LoadResponse so that the parser knows the final URL. - let (input_chan, input_port) = channel(); - self.resource_task.send(ControlMsg::Load(NetLoadData { - url: url, - method: load_data.method, - headers: load_data.headers, - data: load_data.data, - cors: None, - consumer: input_chan, - })).unwrap(); - - let load_response = input_port.recv().unwrap(); - - load_response.metadata.headers.as_ref().map(|headers| { - headers.get().map(|&LastModified(ref tm)| { - document.r().set_last_modified(dom_last_modified(tm)); - }); - }); - - let final_url = load_response.metadata.final_url.clone(); - - { - // Store the final URL before we start parsing, so that DOM routines - // (e.g. HTMLImageElement::update_image) can resolve relative URLs - // correctly. - *page.mut_url() = Some((final_url.clone(), true)); - } - - (HTMLInput::InputUrl(load_response), final_url) - } else { + if is_javascript { let evalstr = load_data.url.non_relative_scheme_data().unwrap(); let jsval = window.r().evaluate_js_on_global_with_result(evalstr); let strval = FromJSValConvertible::from_jsval(self.get_cx(), jsval, StringificationBehavior::Empty); - (HTMLInput::InputString(strval.unwrap_or("".to_owned())), doc_url) + parser_input = HTMLInput::InputString(strval.unwrap_or("".to_owned())); }; parse_html(document.r(), parser_input, &final_url); |