aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/document.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r--components/script/dom/document.rs52
1 files changed, 36 insertions, 16 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index ddaebcd35bf..eb7e0da8a1b 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -69,6 +69,7 @@ use dom::nodelist::NodeList;
use dom::processinginstruction::ProcessingInstruction;
use dom::range::Range;
use dom::servohtmlparser::{ParserRoot, ParserRef, MutNullableParserField};
+use dom::stylesheetlist::StyleSheetList;
use dom::text::Text;
use dom::touch::Touch;
use dom::touchevent::TouchEvent;
@@ -157,7 +158,7 @@ pub struct Document {
anchors: MutNullableHeap<JS<HTMLCollection>>,
applets: MutNullableHeap<JS<HTMLCollection>>,
/// List of stylesheets associated with nodes in this document. |None| if the list needs to be refreshed.
- stylesheets: DOMRefCell<Option<Vec<Arc<Stylesheet>>>>,
+ stylesheets: DOMRefCell<Option<Vec<(JS<Node>, Arc<Stylesheet>)>>>,
/// Whether the list of stylesheets has changed since the last reflow was triggered.
stylesheets_changed_since_reflow: Cell<bool>,
ready_state: Cell<DocumentReadyState>,
@@ -355,7 +356,7 @@ impl Document {
// that workable.
match self.GetDocumentElement() {
Some(root) => {
- root.upcast::<Node>().get_has_dirty_descendants() ||
+ root.upcast::<Node>().has_dirty_descendants() ||
!self.modified_elements.borrow().is_empty()
}
None => false,
@@ -1466,6 +1467,19 @@ impl Document {
let target = node.upcast();
event.fire(target);
}
+
+ /// https://html.spec.whatwg.org/multipage/#cookie-averse-document-object
+ fn is_cookie_averse(&self) -> bool {
+ /// https://url.spec.whatwg.org/#network-scheme
+ fn url_has_network_scheme(url: &Url) -> bool {
+ match &*url.scheme {
+ "ftp" | "http" | "https" => true,
+ _ => false,
+ }
+ }
+
+ self.browsing_context.is_none() || !url_has_network_scheme(&self.url)
+ }
}
#[derive(PartialEq, HeapSizeOf)]
@@ -1635,11 +1649,11 @@ impl Document {
}
/// Returns the list of stylesheets associated with nodes in the document.
- pub fn stylesheets(&self) -> Ref<Vec<Arc<Stylesheet>>> {
+ pub fn stylesheets(&self) -> Vec<Arc<Stylesheet>> {
{
let mut stylesheets = self.stylesheets.borrow_mut();
if stylesheets.is_none() {
- let new_stylesheets: Vec<Arc<Stylesheet>> = self.upcast::<Node>()
+ *stylesheets = Some(self.upcast::<Node>()
.traverse_preorder()
.filter_map(|node| {
if let Some(node) = node.downcast::<HTMLStyleElement>() {
@@ -1650,13 +1664,14 @@ impl Document {
node.get_stylesheet()
} else {
None
- }
+ }.map(|stylesheet| (JS::from_rooted(&node), stylesheet))
})
- .collect();
- *stylesheets = Some(new_stylesheets);
+ .collect());
};
}
- Ref::map(self.stylesheets.borrow(), |t| t.as_ref().unwrap())
+ self.stylesheets.borrow().as_ref().unwrap().iter()
+ .map(|&(_, ref stylesheet)| stylesheet.clone())
+ .collect()
}
/// https://html.spec.whatwg.org/multipage/#appropriate-template-contents-owner-document
@@ -1723,6 +1738,11 @@ impl Element {
}
impl DocumentMethods for Document {
+ // https://drafts.csswg.org/cssom/#dom-document-stylesheets
+ fn StyleSheets(&self) -> Root<StyleSheetList> {
+ StyleSheetList::new(&self.window, JS::from_ref(&self))
+ }
+
// https://dom.spec.whatwg.org/#dom-document-implementation
fn Implementation(&self) -> Root<DOMImplementation> {
self.implementation.or_init(|| DOMImplementation::new(self))
@@ -1767,12 +1787,6 @@ impl DocumentMethods for Document {
fn Domain(&self) -> DOMString {
// TODO: This should use the effective script origin when it exists
let origin = self.window.get_url();
-
- if let Some(&Host::Ipv6(ipv6)) = origin.host() {
- // Omit square brackets for IPv6 addresses.
- return DOMString::from(ipv6.to_string());
- }
-
DOMString::from(origin.serialize_host().unwrap_or_else(|| "".to_owned()))
}
@@ -2396,7 +2410,10 @@ impl DocumentMethods for Document {
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
fn GetCookie(&self) -> Fallible<DOMString> {
- // TODO: return empty string for cookie-averse Document
+ if self.is_cookie_averse() {
+ return Ok(DOMString::new());
+ }
+
let url = self.url();
if !is_scheme_host_port_tuple(&url) {
return Err(Error::Security);
@@ -2409,7 +2426,10 @@ impl DocumentMethods for Document {
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
fn SetCookie(&self, cookie: DOMString) -> ErrorResult {
- // TODO: ignore for cookie-averse Document
+ if self.is_cookie_averse() {
+ return Ok(());
+ }
+
let url = self.url();
if !is_scheme_host_port_tuple(url) {
return Err(Error::Security);