Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make document url mutable and implement location.replace() #13418

Merged
merged 5 commits into from Nov 20, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Make 'Document.url' field mutable

Use DOMRefCell as the type of the url field.
  • Loading branch information
stshine committed Nov 18, 2016
commit eca8f1d0b44993e8abe514612148c20b3452c6ff
@@ -192,7 +192,7 @@ pub struct Document {
last_modified: Option<String>,
encoding: Cell<EncodingRef>,
is_html_document: bool,
url: ServoUrl,
url: DOMRefCell<ServoUrl>,
quirks_mode: Cell<QuirksMode>,
/// Caches for the getElement methods
id_map: DOMRefCell<HashMap<Atom, Vec<JS<Element>>>>,
@@ -398,16 +398,20 @@ impl Document {
}

// https://dom.spec.whatwg.org/#concept-document-url
pub fn url(&self) -> &ServoUrl {
&self.url
pub fn url(&self) -> ServoUrl {
self.url.borrow().clone()
}

pub fn set_url(&self, url: ServoUrl) {
*self.url.borrow_mut() = url;
}

// https://html.spec.whatwg.org/multipage/#fallback-base-url
pub fn fallback_base_url(&self) -> ServoUrl {
// Step 1: iframe srcdoc (#4767).
// Step 2: about:blank with a creator browsing context.
// Step 3.
self.url().clone()
self.url()
}

// https://html.spec.whatwg.org/multipage/#document-base-url
@@ -1709,7 +1713,7 @@ impl Document {

/// https://html.spec.whatwg.org/multipage/#cookie-averse-document-object
pub fn is_cookie_averse(&self) -> bool {
self.browsing_context.is_none() || !url_has_network_scheme(&self.url)
self.browsing_context.is_none() || !url_has_network_scheme(&self.url())
}

pub fn nodes_from_point(&self, client_point: &Point2D<f32>) -> Vec<UntrustedNodeAddress> {
@@ -1814,7 +1818,7 @@ impl Document {
}),
},
last_modified: last_modified,
url: url,
url: DOMRefCell::new(url),
// https://dom.spec.whatwg.org/#concept-document-quirks
quirks_mode: Cell::new(NoQuirks),
// https://dom.spec.whatwg.org/#concept-document-encoding
@@ -2787,7 +2791,7 @@ impl DocumentMethods for Document {
let _ = self.window
.upcast::<GlobalScope>()
.resource_threads()
.send(GetCookiesForUrl((*url).clone(), tx, NonHTTP));
.send(GetCookiesForUrl(url, tx, NonHTTP));
let cookies = rx.recv().unwrap();
Ok(cookies.map_or(DOMString::new(), DOMString::from))
}
@@ -2806,7 +2810,7 @@ impl DocumentMethods for Document {
let _ = self.window
.upcast::<GlobalScope>()
.resource_threads()
.send(SetCookiesForUrl((*url).clone(), String::from(cookie), NonHTTP));
.send(SetCookiesForUrl(url, String::from(cookie), NonHTTP));
Ok(())
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.