Make 'Document.url' field mutable

Use DOMRefCell as the type of the url field.
This commit is contained in:
Pu Xingyu 2016-11-18 12:29:02 +08:00
parent 22aebdf5d4
commit eca8f1d0b4

View file

@ -192,7 +192,7 @@ pub struct Document {
last_modified: Option<String>, last_modified: Option<String>,
encoding: Cell<EncodingRef>, encoding: Cell<EncodingRef>,
is_html_document: bool, is_html_document: bool,
url: ServoUrl, url: DOMRefCell<ServoUrl>,
quirks_mode: Cell<QuirksMode>, quirks_mode: Cell<QuirksMode>,
/// Caches for the getElement methods /// Caches for the getElement methods
id_map: DOMRefCell<HashMap<Atom, Vec<JS<Element>>>>, id_map: DOMRefCell<HashMap<Atom, Vec<JS<Element>>>>,
@ -398,8 +398,12 @@ impl Document {
} }
// https://dom.spec.whatwg.org/#concept-document-url // https://dom.spec.whatwg.org/#concept-document-url
pub fn url(&self) -> &ServoUrl { pub fn url(&self) -> ServoUrl {
&self.url 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 // https://html.spec.whatwg.org/multipage/#fallback-base-url
@ -407,7 +411,7 @@ impl Document {
// Step 1: iframe srcdoc (#4767). // Step 1: iframe srcdoc (#4767).
// Step 2: about:blank with a creator browsing context. // Step 2: about:blank with a creator browsing context.
// Step 3. // Step 3.
self.url().clone() self.url()
} }
// https://html.spec.whatwg.org/multipage/#document-base-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 /// https://html.spec.whatwg.org/multipage/#cookie-averse-document-object
pub fn is_cookie_averse(&self) -> bool { 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> { pub fn nodes_from_point(&self, client_point: &Point2D<f32>) -> Vec<UntrustedNodeAddress> {
@ -1814,7 +1818,7 @@ impl Document {
}), }),
}, },
last_modified: last_modified, last_modified: last_modified,
url: url, url: DOMRefCell::new(url),
// https://dom.spec.whatwg.org/#concept-document-quirks // https://dom.spec.whatwg.org/#concept-document-quirks
quirks_mode: Cell::new(NoQuirks), quirks_mode: Cell::new(NoQuirks),
// https://dom.spec.whatwg.org/#concept-document-encoding // https://dom.spec.whatwg.org/#concept-document-encoding
@ -2787,7 +2791,7 @@ impl DocumentMethods for Document {
let _ = self.window let _ = self.window
.upcast::<GlobalScope>() .upcast::<GlobalScope>()
.resource_threads() .resource_threads()
.send(GetCookiesForUrl((*url).clone(), tx, NonHTTP)); .send(GetCookiesForUrl(url, tx, NonHTTP));
let cookies = rx.recv().unwrap(); let cookies = rx.recv().unwrap();
Ok(cookies.map_or(DOMString::new(), DOMString::from)) Ok(cookies.map_or(DOMString::new(), DOMString::from))
} }
@ -2806,7 +2810,7 @@ impl DocumentMethods for Document {
let _ = self.window let _ = self.window
.upcast::<GlobalScope>() .upcast::<GlobalScope>()
.resource_threads() .resource_threads()
.send(SetCookiesForUrl((*url).clone(), String::from(cookie), NonHTTP)); .send(SetCookiesForUrl(url, String::from(cookie), NonHTTP));
Ok(()) Ok(())
} }