script: Stop copying the document URL.

This commit is contained in:
Patrick Walton 2015-07-28 19:08:35 -07:00
parent 4d1be2f56c
commit 5dce5f0c97
8 changed files with 19 additions and 16 deletions

View file

@ -226,7 +226,6 @@ impl CollectionFilter for AppletsFilter {
}
}
impl Document {
#[inline]
pub fn loader(&self) -> Ref<DocumentLoader> {
@ -269,16 +268,16 @@ impl Document {
}
// https://dom.spec.whatwg.org/#concept-document-url
pub fn url(&self) -> Url {
self.url.clone()
pub fn url<'a>(&'a self) -> &'a Url {
&self.url
}
// https://html.spec.whatwg.org/multipage/#fallback-base-url
pub fn fallback_base_url(&self) -> Url {
pub fn fallback_base_url<'a>(&'a self) -> Url {
// Step 1: iframe srcdoc (#4767).
// Step 2: about:blank with a creator browsing context.
// Step 3.
self.url()
self.url().clone()
}
// https://html.spec.whatwg.org/multipage/#document-base-url
@ -1735,7 +1734,7 @@ impl DocumentMethods for Document {
}
let window = self.window.root();
let (tx, rx) = ipc::channel().unwrap();
let _ = window.r().resource_task().send(GetCookiesForUrl(url, tx, NonHTTP));
let _ = window.r().resource_task().send(GetCookiesForUrl((*url).clone(), tx, NonHTTP));
let cookies = rx.recv().unwrap();
Ok(cookies.unwrap_or("".to_owned()))
}
@ -1744,11 +1743,11 @@ impl DocumentMethods for Document {
fn SetCookie(&self, cookie: DOMString) -> ErrorResult {
//TODO: ignore for cookie-averse Document
let url = self.url();
if !is_scheme_host_port_tuple(&url) {
if !is_scheme_host_port_tuple(url) {
return Err(Security);
}
let window = self.window.root();
let _ = window.r().resource_task().send(SetCookiesForUrl(url, cookie, NonHTTP));
let _ = window.r().resource_task().send(SetCookiesForUrl((*url).clone(), cookie, NonHTTP));
Ok(())
}

View file

@ -50,7 +50,8 @@ impl HTMLBaseElement {
let href = ElementCast::from_ref(self).get_attribute(&ns!(""), &atom!("href"))
.expect("The frozen base url is only defined for base elements \
that have a base url.");
let base = document_from_node(self).fallback_base_url();
let document = document_from_node(self);
let base = document.fallback_base_url();
let parsed = UrlParser::new().base_url(&base).parse(&href.value());
parsed.unwrap_or(base)
}

View file

@ -133,7 +133,8 @@ impl VirtualMethods for HTMLBodyElement {
},
(&atom!(background), _) => {
*self.background.borrow_mut() = mutation.new_value(attr).and_then(|value| {
let base = document_from_node(self).url();
let document = document_from_node(self);
let base = document.url();
UrlParser::new().base_url(&base).parse(&value).ok()
});
},

View file

@ -187,7 +187,8 @@ impl HTMLFormElement {
}
// TODO: Resolve the url relative to the submitter element
// Step 10-15
let action_components = UrlParser::new().base_url(&base).parse(&action).unwrap_or(base);
let action_components =
UrlParser::new().base_url(base).parse(&action).unwrap_or((*base).clone());
let _action = action_components.serialize();
let scheme = action_components.scheme.clone();
let enctype = submitter.enctype();

View file

@ -1715,7 +1715,7 @@ impl Node {
};
let window = document.window();
let loader = DocumentLoader::new(&*document.loader());
let document = Document::new(window.r(), Some(document.url()),
let document = Document::new(window.r(), Some((*document.url()).clone()),
is_html_doc, None,
None, DocumentSource::NotFromParser, loader);
NodeCast::from_root(document)

View file

@ -1098,7 +1098,7 @@ impl Window {
pub fn get_url(&self) -> Url {
let doc = self.Document();
doc.r().url()
(*doc.r().url()).clone()
}
pub fn resource_task(&self) -> ResourceTask {