diff options
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 94 |
1 files changed, 54 insertions, 40 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 9704b4ba0ab..6f8f2435311 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -24,7 +24,7 @@ use dom::bindings::codegen::Bindings::WindowBinding::{FrameRequestCallback, Scro use dom::bindings::codegen::UnionTypes::NodeOrString; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId}; -use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root}; +use dom::bindings::js::{JS, LayoutJS, MutNullableJS, Root}; use dom::bindings::js::RootedReference; use dom::bindings::num::Finite; use dom::bindings::refcounted::{Trusted, TrustedPromise}; @@ -91,8 +91,9 @@ use encoding::EncodingRef; use encoding::all::UTF_8; use euclid::point::Point2D; use gfx_traits::ScrollRootId; -use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks, QuirksMode}; use html5ever_atoms::{LocalName, QualName}; +use hyper::header::{Header, SetCookie}; +use hyper_serde::Serde; use ipc_channel::ipc::{self, IpcSender}; use js::jsapi::{JSContext, JSObject, JSRuntime}; use js::jsapi::JS_GetRuntime; @@ -113,6 +114,7 @@ use script_traits::{ScriptMsg as ConstellationMsg, TouchpadPressurePhase}; use script_traits::{TouchEventType, TouchId}; use script_traits::UntrustedNodeAddress; use servo_atoms::Atom; +use servo_config::prefs::PREFS; use servo_url::ServoUrl; use std::ascii::AsciiExt; use std::borrow::ToOwned; @@ -126,14 +128,13 @@ use std::rc::Rc; use std::sync::Arc; use std::time::{Duration, Instant}; use style::attr::AttrValue; -use style::context::ReflowGoal; +use style::context::{QuirksMode, ReflowGoal}; use style::restyle_hints::RestyleHint; use style::selector_parser::{RestyleDamage, Snapshot}; use style::str::{split_html_space_chars, str_join}; use style::stylesheets::Stylesheet; use time; use url::percent_encoding::percent_decode; -use util::prefs::PREFS; pub enum TouchEventResult { Processed(bool), @@ -184,8 +185,8 @@ pub struct Document { window: JS<Window>, /// https://html.spec.whatwg.org/multipage/#concept-document-bc browsing_context: Option<JS<BrowsingContext>>, - implementation: MutNullableHeap<JS<DOMImplementation>>, - location: MutNullableHeap<JS<Location>>, + implementation: MutNullableJS<DOMImplementation>, + location: MutNullableJS<Location>, content_type: DOMString, last_modified: Option<String>, encoding: Cell<EncodingRef>, @@ -197,29 +198,29 @@ pub struct Document { tag_map: DOMRefCell<HashMap<LocalName, JS<HTMLCollection>>>, tagns_map: DOMRefCell<HashMap<QualName, JS<HTMLCollection>>>, classes_map: DOMRefCell<HashMap<Vec<Atom>, JS<HTMLCollection>>>, - images: MutNullableHeap<JS<HTMLCollection>>, - embeds: MutNullableHeap<JS<HTMLCollection>>, - links: MutNullableHeap<JS<HTMLCollection>>, - forms: MutNullableHeap<JS<HTMLCollection>>, - scripts: MutNullableHeap<JS<HTMLCollection>>, - anchors: MutNullableHeap<JS<HTMLCollection>>, - applets: MutNullableHeap<JS<HTMLCollection>>, + images: MutNullableJS<HTMLCollection>, + embeds: MutNullableJS<HTMLCollection>, + links: MutNullableJS<HTMLCollection>, + forms: MutNullableJS<HTMLCollection>, + scripts: MutNullableJS<HTMLCollection>, + anchors: MutNullableJS<HTMLCollection>, + applets: MutNullableJS<HTMLCollection>, /// List of stylesheets associated with nodes in this document. |None| if the list needs to be refreshed. stylesheets: DOMRefCell<Option<Vec<StylesheetInDocument>>>, /// Whether the list of stylesheets has changed since the last reflow was triggered. stylesheets_changed_since_reflow: Cell<bool>, - stylesheet_list: MutNullableHeap<JS<StyleSheetList>>, + stylesheet_list: MutNullableJS<StyleSheetList>, ready_state: Cell<DocumentReadyState>, /// Whether the DOMContentLoaded event has already been dispatched. domcontentloaded_dispatched: Cell<bool>, /// The element that has most recently requested focus for itself. - possibly_focused: MutNullableHeap<JS<Element>>, + possibly_focused: MutNullableJS<Element>, /// The element that currently has the document focus context. - focused: MutNullableHeap<JS<Element>>, + focused: MutNullableJS<Element>, /// The script element that is currently executing. - current_script: MutNullableHeap<JS<HTMLScriptElement>>, + current_script: MutNullableJS<HTMLScriptElement>, /// https://html.spec.whatwg.org/multipage/#pending-parsing-blocking-script - pending_parsing_blocking_script: MutNullableHeap<JS<HTMLScriptElement>>, + pending_parsing_blocking_script: MutNullableJS<HTMLScriptElement>, /// Number of stylesheets that block executing the next parser-inserted script script_blocking_stylesheets_count: Cell<u32>, /// https://html.spec.whatwg.org/multipage/#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing @@ -245,14 +246,14 @@ pub struct Document { /// Tracks all outstanding loads related to this document. loader: DOMRefCell<DocumentLoader>, /// The current active HTML parser, to allow resuming after interruptions. - current_parser: MutNullableHeap<JS<ServoParser>>, + current_parser: MutNullableJS<ServoParser>, /// When we should kick off a reflow. This happens during parsing. reflow_timeout: Cell<Option<u64>>, /// The cached first `base` element with an `href` attribute. - base_element: MutNullableHeap<JS<HTMLBaseElement>>, + base_element: MutNullableJS<HTMLBaseElement>, /// This field is set to the document itself for inert documents. /// https://html.spec.whatwg.org/multipage/#appropriate-template-contents-owner-document - appropriate_template_contents_owner_document: MutNullableHeap<JS<Document>>, + appropriate_template_contents_owner_document: MutNullableJS<Document>, /// Information on elements needing restyle to ship over to the layout thread when the /// time comes. pending_restyles: DOMRefCell<HashMap<JS<Element>, PendingRestyle>>, @@ -280,7 +281,7 @@ pub struct Document { /// https://html.spec.whatwg.org/multipage/#dom-document-referrer referrer: Option<String>, /// https://html.spec.whatwg.org/multipage/#target-element - target_element: MutNullableHeap<JS<Element>>, + target_element: MutNullableJS<Element>, /// https://w3c.github.io/uievents/#event-type-dblclick #[ignore_heap_size_of = "Defined in std"] last_click_info: DOMRefCell<Option<(Instant, Point2D<f32>)>>, @@ -293,7 +294,7 @@ pub struct Document { /// See also: https://github.com/servo/servo/issues/10110 dom_count: Cell<u32>, /// Entry node for fullscreen. - fullscreen_element: MutNullableHeap<JS<Element>>, + fullscreen_element: MutNullableJS<Element>, } #[derive(JSTraceable, HeapSizeOf)] @@ -488,7 +489,7 @@ impl Document { pub fn set_quirks_mode(&self, mode: QuirksMode) { self.quirks_mode.set(mode); - if mode == Quirks { + if mode == QuirksMode::Quirks { self.window.layout_chan().send(Msg::SetQuirksMode).unwrap(); } } @@ -1036,7 +1037,7 @@ impl Document { pub fn handle_mouse_move_event(&self, js_runtime: *mut JSRuntime, client_point: Option<Point2D<f32>>, - prev_mouse_over_target: &MutNullableHeap<JS<Element>>) { + prev_mouse_over_target: &MutNullableJS<Element>) { let client_point = match client_point { None => { // If there's no point, there's no target under the mouse @@ -1521,8 +1522,11 @@ impl Document { /// https://html.spec.whatwg.org/multipage/#run-the-animation-frame-callbacks pub fn run_the_animation_frame_callbacks(&self) { - let mut animation_frame_list = - mem::replace(&mut *self.animation_frame_list.borrow_mut(), vec![]); + rooted_vec!(let mut animation_frame_list); + mem::swap( + &mut *animation_frame_list, + &mut *self.animation_frame_list.borrow_mut()); + self.running_animation_callbacks.set(true); let timing = self.window.Performance().Now(); @@ -1538,7 +1542,7 @@ impl Document { // message quickly followed by an AnimationCallbacksPresent message. if self.animation_frame_list.borrow().is_empty() { mem::swap(&mut *self.animation_frame_list.borrow_mut(), - &mut animation_frame_list); + &mut *animation_frame_list); let global_scope = self.window.upcast::<GlobalScope>(); let event = ConstellationMsg::ChangeRunningAnimationsState(global_scope.pipeline_id(), AnimationState::NoAnimationCallbacksPresent); @@ -1772,6 +1776,7 @@ pub trait LayoutDocumentHelpers { unsafe fn drain_pending_restyles(&self) -> Vec<(LayoutJS<Element>, PendingRestyle)>; unsafe fn needs_paint_from_layout(&self); unsafe fn will_paint(&self); + unsafe fn quirks_mode(&self) -> QuirksMode; } #[allow(unsafe_code)] @@ -1798,6 +1803,11 @@ impl LayoutDocumentHelpers for LayoutJS<Document> { unsafe fn will_paint(&self) { (*self.unsafe_get()).needs_paint.set(false) } + + #[inline] + unsafe fn quirks_mode(&self) -> QuirksMode { + (*self.unsafe_get()).quirks_mode() + } } /// https://url.spec.whatwg.org/#network-scheme @@ -1855,7 +1865,7 @@ impl Document { last_modified: last_modified, url: DOMRefCell::new(url), // https://dom.spec.whatwg.org/#concept-document-quirks - quirks_mode: Cell::new(NoQuirks), + quirks_mode: Cell::new(QuirksMode::NoQuirks), // https://dom.spec.whatwg.org/#concept-document-encoding encoding: Cell::new(UTF_8), is_html_document: is_html_document == IsHTMLDocument::HTMLDocument, @@ -1872,7 +1882,7 @@ impl Document { applets: Default::default(), stylesheets: DOMRefCell::new(None), stylesheets_changed_since_reflow: Cell::new(false), - stylesheet_list: MutNullableHeap::new(None), + stylesheet_list: MutNullableJS::new(None), ready_state: Cell::new(ready_state), domcontentloaded_dispatched: Cell::new(domcontentloaded_dispatched), possibly_focused: Default::default(), @@ -1907,11 +1917,11 @@ impl Document { origin: origin, referrer: referrer, referrer_policy: Cell::new(referrer_policy), - target_element: MutNullableHeap::new(None), + target_element: MutNullableJS::new(None), last_click_info: DOMRefCell::new(None), ignore_destructive_writes_counter: Default::default(), dom_count: Cell::new(1), - fullscreen_element: MutNullableHeap::new(None), + fullscreen_element: MutNullableJS::new(None), } } @@ -2298,8 +2308,8 @@ impl DocumentMethods for Document { // https://dom.spec.whatwg.org/#dom-document-compatmode fn CompatMode(&self) -> DOMString { DOMString::from(match self.quirks_mode.get() { - LimitedQuirks | NoQuirks => "CSS1Compat", - Quirks => "BackCompat", + QuirksMode::LimitedQuirks | QuirksMode::NoQuirks => "CSS1Compat", + QuirksMode::Quirks => "BackCompat", }) } @@ -2667,7 +2677,7 @@ impl DocumentMethods for Document { None => DOMString::new(), Some(ref title) => { // Steps 3-4. - let value = Node::collect_text_contents(title.children()); + let value = title.child_text_content(); DOMString::from(str_join(split_html_space_chars(&value), " ")) }, } @@ -2957,11 +2967,15 @@ impl DocumentMethods for Document { return Err(Error::Security); } - let url = self.url(); - let _ = self.window - .upcast::<GlobalScope>() - .resource_threads() - .send(SetCookiesForUrl(url, String::from(cookie), NonHTTP)); + let header = Header::parse_header(&[cookie.into()]); + if let Ok(SetCookie(cookies)) = header { + let cookies = cookies.into_iter().map(Serde).collect(); + let _ = self.window + .upcast::<GlobalScope>() + .resource_threads() + .send(SetCookiesForUrl(self.url(), cookies, NonHTTP)); + } + Ok(()) } |