Make Document::url return the page's URL to avoid stale URLs after redirects.

This commit is contained in:
Josh Matthews 2014-12-30 16:52:13 -05:00
parent 19fbb9e568
commit ae2b74c783
4 changed files with 8 additions and 7 deletions

View file

@ -170,7 +170,7 @@ pub trait DocumentHelpers<'a> {
fn window(self) -> Temporary<Window>;
fn encoding_name(self) -> Ref<'a, DOMString>;
fn is_html_document(self) -> bool;
fn url(self) -> &'a Url;
fn url(self) -> Url;
fn quirks_mode(self) -> QuirksMode;
fn set_quirks_mode(self, mode: QuirksMode);
fn set_last_modified(self, value: DOMString);
@ -206,8 +206,9 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
self.is_html_document
}
fn url(self) -> &'a Url {
&self.extended_deref().url
fn url(self) -> Url {
let window = self.window().root();
window.page().get_url()
}
fn quirks_mode(self) -> QuirksMode {

View file

@ -777,7 +777,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
let base = doc.r().url();
// https://html.spec.whatwg.org/multipage/infrastructure.html#reflect
// XXXManishearth this doesn't handle `javascript:` urls properly
match UrlParser::new().base_url(base).parse(url.as_slice()) {
match UrlParser::new().base_url(&base).parse(url.as_slice()) {
Ok(parsed) => parsed.serialize(),
Err(_) => "".to_owned()
}
@ -1174,7 +1174,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
// Modifying the `style` attribute might change style.
let node: JSRef<Node> = NodeCast::from_ref(*self);
let doc = document_from_node(*self).root();
let base_url = doc.r().url().clone();
let base_url = doc.r().url();
let value = attr.value();
let style = Some(parse_style_attribute(value.as_slice(), &base_url));
*self.style_attribute.borrow_mut() = style;

View file

@ -180,7 +180,7 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> {
}
// TODO: Resolve the url relative to the submitter element
// Step 10-15
let action_components = UrlParser::new().base_url(base).parse(action.as_slice()).unwrap_or(base.clone());
let action_components = UrlParser::new().base_url(&base).parse(action.as_slice()).unwrap_or(base);
let _action = action_components.serialize();
let scheme = action_components.scheme.clone();
let enctype = submitter.enctype();

View file

@ -1574,7 +1574,7 @@ impl Node {
false => IsHTMLDocument::NonHTMLDocument,
};
let window = document.window().root();
let document = Document::new(window.r(), Some(document.url().clone()),
let document = Document::new(window.r(), Some(document.url()),
is_html_doc, None,
DocumentSource::NotFromParser);
NodeCast::from_temporary(document)