diff options
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 93 |
1 files changed, 68 insertions, 25 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 669c4d9a31a..78ccbbdf1f5 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -122,9 +122,9 @@ use std::sync::Arc; use string_cache::{Atom, QualName}; use style::attr::AttrValue; use style::context::ReflowGoal; -use style::restyle_hints::ElementSnapshot; -use style::servo::Stylesheet; +use style::selector_impl::ElementSnapshot; use style::str::{split_html_space_chars, str_join}; +use style::stylesheets::Stylesheet; use time; use url::Url; use url::percent_encoding::percent_decode; @@ -239,6 +239,8 @@ pub struct Document { origin: Origin, /// https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-states referrer_policy: Cell<Option<ReferrerPolicy>>, + /// https://html.spec.whatwg.org/multipage/#dom-document-referrer + referrer: Option<String>, } #[derive(JSTraceable, HeapSizeOf)] @@ -374,6 +376,7 @@ impl Document { // that workable. match self.GetDocumentElement() { Some(root) => { + root.upcast::<Node>().is_dirty() || root.upcast::<Node>().has_dirty_descendants() || !self.modified_elements.borrow().is_empty() } @@ -1279,7 +1282,7 @@ impl Document { if PREFS.is_mozbrowser_enabled() { if let Some((containing_pipeline_id, subpage_id, _)) = self.window.parent_info() { let event = ConstellationMsg::MozBrowserEvent(containing_pipeline_id, - subpage_id, + Some(subpage_id), event); self.window.constellation_chan().send(event).unwrap(); } @@ -1369,6 +1372,7 @@ impl Document { } pub fn finish_load(&self, load: LoadType) { + debug!("Document got finish_load: {:?}", load); // The parser might need the loader, so restrict the lifetime of the borrow. { let mut loader = self.loader.borrow_mut(); @@ -1394,9 +1398,9 @@ impl Document { // If we don't have a parser, and the reflow timer has been reset, explicitly // trigger a reflow. if let LoadType::Stylesheet(_) = load { - self.window().reflow(ReflowGoal::ForDisplay, - ReflowQueryType::NoQuery, - ReflowReason::StylesheetLoaded); + self.window.reflow(ReflowGoal::ForDisplay, + ReflowQueryType::NoQuery, + ReflowReason::StylesheetLoaded); } } @@ -1485,23 +1489,25 @@ impl Document { return; } self.domcontentloaded_dispatched.set(true); + assert!(self.ReadyState() != DocumentReadyState::Complete, + "Complete before DOMContentLoaded?"); update_with_current_time_ms(&self.dom_content_loaded_event_start); - self.window().dom_manipulation_task_source().queue_event(self.upcast(), atom!("DOMContentLoaded"), - EventBubbles::Bubbles, EventCancelable::NotCancelable); - self.window().reflow(ReflowGoal::ForDisplay, - ReflowQueryType::NoQuery, - ReflowReason::DOMContentLoaded); + let window = self.window(); + window.dom_manipulation_task_source().queue_event(self.upcast(), atom!("DOMContentLoaded"), + EventBubbles::Bubbles, EventCancelable::NotCancelable, window); + window.reflow(ReflowGoal::ForDisplay, + ReflowQueryType::NoQuery, + ReflowReason::DOMContentLoaded); update_with_current_time_ms(&self.dom_content_loaded_event_end); } pub fn notify_constellation_load(&self) { let pipeline_id = self.window.pipeline(); - let event = ConstellationMsg::DOMLoad(pipeline_id); - self.window.constellation_chan().send(event).unwrap(); - + let load_event = ConstellationMsg::LoadComplete(pipeline_id); + self.window.constellation_chan().send(load_event).unwrap(); } pub fn set_current_parser(&self, script: Option<ParserRef>) { @@ -1629,7 +1635,9 @@ impl Document { content_type: Option<DOMString>, last_modified: Option<String>, source: DocumentSource, - doc_loader: DocumentLoader) + doc_loader: DocumentLoader, + referrer: Option<String>, + referrer_policy: Option<ReferrerPolicy>) -> Document { let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap()); @@ -1648,6 +1656,17 @@ impl Document { Origin::opaque_identifier() }; + // TODO: we currently default to Some(NoReferrer) instead of None (i.e. unset) + // for an important reason. Many of the methods by which a referrer policy is communicated + // are currently unimplemented, and so in such cases we may be ignoring the desired policy. + // If the default were left unset, then in Step 7 of the Fetch algorithm we adopt + // no-referrer-when-downgrade. However, since we are potentially ignoring a stricter + // referrer policy, this might be passing too much info. Hence, we default to the + // strictest policy, which is no-referrer. + // Once other delivery methods are implemented, make the unset case really + // unset (i.e. None). + let referrer_policy = referrer_policy.or(Some(ReferrerPolicy::NoReferrer)); + Document { node: Node::new_document_node(), window: JS::from_ref(window), @@ -1714,8 +1733,8 @@ impl Document { https_state: Cell::new(HttpsState::None), touchpad_pressure_phase: Cell::new(TouchpadPressurePhase::BeforeClick), origin: origin, - //TODO - setting this for now so no Referer header set - referrer_policy: Cell::new(Some(ReferrerPolicy::NoReferrer)), + referrer: referrer, + referrer_policy: Cell::new(referrer_policy), } } @@ -1732,7 +1751,9 @@ impl Document { None, None, DocumentSource::NotFromParser, - docloader)) + docloader, + None, + None)) } pub fn new(window: &Window, @@ -1742,7 +1763,9 @@ impl Document { content_type: Option<DOMString>, last_modified: Option<String>, source: DocumentSource, - doc_loader: DocumentLoader) + doc_loader: DocumentLoader, + referrer: Option<String>, + referrer_policy: Option<ReferrerPolicy>) -> Root<Document> { let document = reflect_dom_object(box Document::new_inherited(window, browsing_context, @@ -1751,7 +1774,9 @@ impl Document { content_type, last_modified, source, - doc_loader), + doc_loader, + referrer, + referrer_policy), GlobalRef::Window(window), DocumentBinding::Wrap); { @@ -1815,7 +1840,9 @@ impl Document { None, None, DocumentSource::NotFromParser, - DocumentLoader::new(&self.loader())); + DocumentLoader::new(&self.loader()), + None, + None); new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc)); new_doc }) @@ -1827,7 +1854,10 @@ impl Document { pub fn element_state_will_change(&self, el: &Element) { let mut map = self.modified_elements.borrow_mut(); - let snapshot = map.entry(JS::from_ref(el)).or_insert(ElementSnapshot::new()); + let snapshot = map.entry(JS::from_ref(el)) + .or_insert_with(|| { + ElementSnapshot::new(el.html_element_in_html_document()) + }); if snapshot.state.is_none() { snapshot.state = Some(el.state()); } @@ -1835,7 +1865,10 @@ impl Document { pub fn element_attr_will_change(&self, el: &Element) { let mut map = self.modified_elements.borrow_mut(); - let mut snapshot = map.entry(JS::from_ref(el)).or_insert(ElementSnapshot::new()); + let mut snapshot = map.entry(JS::from_ref(el)) + .or_insert_with(|| { + ElementSnapshot::new(el.html_element_in_html_document()) + }); if snapshot.attrs.is_none() { let attrs = el.attrs() .iter() @@ -1934,6 +1967,14 @@ impl DocumentMethods for Document { } } + // https://html.spec.whatwg.org/multipage/#dom-document-referrer + fn Referrer(&self) -> DOMString { + match self.referrer { + Some(ref referrer) => DOMString::from(referrer.to_string()), + None => DOMString::new() + } + } + // https://dom.spec.whatwg.org/#dom-document-documenturi fn DocumentURI(&self) -> USVString { self.URL() @@ -2831,7 +2872,7 @@ pub fn determine_policy_for_token(token: &str) -> Option<ReferrerPolicy> { let lower = token.to_lowercase(); return match lower.as_ref() { "never" | "no-referrer" => Some(ReferrerPolicy::NoReferrer), - "default" | "no-referrer-when-downgrade" => Some(ReferrerPolicy::NoRefWhenDowngrade), + "default" | "no-referrer-when-downgrade" => Some(ReferrerPolicy::NoReferrerWhenDowngrade), "origin" => Some(ReferrerPolicy::Origin), "same-origin" => Some(ReferrerPolicy::SameOrigin), "origin-when-cross-origin" => Some(ReferrerPolicy::OriginWhenCrossOrigin), @@ -2870,16 +2911,18 @@ impl DocumentProgressHandler { // http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventStart update_with_current_time_ms(&document.load_event_start); + debug!("About to dispatch load for {:?}", document.url()); let _ = wintarget.dispatch_event_with_target(document.upcast(), &event); // http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventEnd update_with_current_time_ms(&document.load_event_end); - document.notify_constellation_load(); window.reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::DocumentLoaded); + + document.notify_constellation_load(); } } |