Store the Page's final URL before parsing

We were parsing URLs like

    //bits.wikimedia.org/static-1.22wmf22/skins/vector/images/search-ltr.png?303-4

as local filenames because HTMLImageElement::update_image didn't have a
current_url to pass to make_url().
This commit is contained in:
Keegan McAllister 2013-10-29 18:22:42 -07:00 committed by Jack Moffitt
parent da6c27c421
commit cbcd04ffa8
2 changed files with 12 additions and 4 deletions

View file

@ -129,7 +129,6 @@ pub enum HtmlDiscoveryMessage {
pub struct HtmlParserResult { pub struct HtmlParserResult {
root: AbstractNode<ScriptView>, root: AbstractNode<ScriptView>,
discovery_port: Port<HtmlDiscoveryMessage>, discovery_port: Port<HtmlDiscoveryMessage>,
url: Url,
} }
trait NodeWrapping { trait NodeWrapping {
@ -350,6 +349,17 @@ pub fn parse_html(cx: *JSContext,
let url2 = load_response.metadata.final_url.clone(); let url2 = load_response.metadata.final_url.clone();
let url3 = url2.clone(); let url3 = url2.clone();
// Store the final URL before we start parsing, so that DOM routines
// (e.g. HTMLImageElement::update_image) can resolve relative URLs
// correctly.
//
// FIXME: is this safe? When we instead pass an &mut Page to parse_html,
// we crash with a dynamic borrow failure.
let page = page_from_context(cx);
unsafe {
(*page).url = Some((url2.clone(), true));
}
// Build the root node. // Build the root node.
let root = @HTMLHtmlElement { htmlelement: HTMLElement::new(HTMLHtmlElementTypeId, ~"html", document) }; let root = @HTMLHtmlElement { htmlelement: HTMLElement::new(HTMLHtmlElementTypeId, ~"html", document) };
let root = unsafe { Node::as_abstract_node(cx, root) }; let root = unsafe { Node::as_abstract_node(cx, root) };
@ -595,7 +605,6 @@ pub fn parse_html(cx: *JSContext,
HtmlParserResult { HtmlParserResult {
root: root, root: root,
discovery_port: discovery_port, discovery_port: discovery_port,
url: load_response.metadata.final_url,
} }
} }

View file

@ -699,14 +699,13 @@ impl ScriptTask {
self.constellation_chan.clone()); self.constellation_chan.clone());
let HtmlParserResult {root, discovery_port, url: final_url} = html_parsing_result; let HtmlParserResult {root, discovery_port} = html_parsing_result;
// Create the root frame. // Create the root frame.
page.frame = Some(Frame { page.frame = Some(Frame {
document: document, document: document,
window: window, window: window,
}); });
page.url = Some((final_url, true));
// Send style sheets over to layout. // Send style sheets over to layout.
// //