diff options
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 76 |
1 files changed, 45 insertions, 31 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index d65efd7acd8..9272c7f6da1 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -27,7 +27,7 @@ use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root}; use dom::bindings::num::Finite; use dom::bindings::refcounted::Trusted; use dom::bindings::reflector::{Reflectable, reflect_dom_object}; -use dom::bindings::str::DOMString; +use dom::bindings::str::{DOMString, USVString}; use dom::bindings::trace::RootedVec; use dom::bindings::xmlname::XMLName::InvalidXMLName; use dom::bindings::xmlname::{validate_and_extract, namespace_from_domstring, xml_name_type}; @@ -92,7 +92,7 @@ use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks, QuirksMode}; use ipc_channel::ipc::{self, IpcSender}; use js::jsapi::JS_GetRuntime; use js::jsapi::{JSContext, JSObject, JSRuntime}; -use layout_interface::{LayoutChan, Msg, ReflowQueryType}; +use layout_interface::{Msg, ReflowQueryType}; use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER}; use msg::constellation_msg::{Key, KeyModifiers, KeyState}; use msg::constellation_msg::{PipelineId, ReferrerPolicy, SubpageId}; @@ -100,7 +100,7 @@ use net_traits::CookieSource::NonHTTP; use net_traits::CoreResourceMsg::{GetCookiesForUrl, SetCookiesForUrl}; use net_traits::response::HttpsState; use net_traits::{AsyncResponseTarget, PendingAsyncLoad, IpcSend}; -use num_traits::{ToPrimitive}; +use num_traits::ToPrimitive; use origin::Origin; use parse::{ParserRoot, ParserRef, MutNullableParserField}; use script_thread::{MainThreadScriptMsg, Runnable}; @@ -123,7 +123,6 @@ use string_cache::{Atom, QualName}; use style::context::ReflowGoal; use style::restyle_hints::ElementSnapshot; use style::servo::Stylesheet; -use task_source::dom_manipulation::DOMManipulationTask; use time; use url::Url; use url::percent_encoding::percent_decode; @@ -238,7 +237,7 @@ pub struct Document { /// The document's origin. origin: Origin, /// https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-states - referrer_policy: Option<ReferrerPolicy>, + referrer_policy: Cell<Option<ReferrerPolicy>>, } #[derive(JSTraceable, HeapSizeOf)] @@ -404,8 +403,7 @@ impl Document { self.quirks_mode.set(mode); if mode == Quirks { - let LayoutChan(ref layout_chan) = *self.window.layout_chan(); - layout_chan.send(Msg::SetQuirksMode).unwrap(); + self.window.layout_chan().send(Msg::SetQuirksMode).unwrap(); } } @@ -600,7 +598,6 @@ impl Document { /// Reassign the focus context to the element that last requested focus during this /// transaction, or none if no elements requested it. pub fn commit_focus_transaction(&self, focus_type: FocusType) { - if let Some(ref elem) = self.focused.get() { let node = elem.upcast::<Node>(); elem.set_focus_state(false); @@ -755,7 +752,6 @@ impl Document { client_point: Point2D<f32>, pressure: f32, phase_now: TouchpadPressurePhase) { - let phase_before = self.touchpad_pressure_phase.get(); self.touchpad_pressure_phase.set(phase_now); @@ -986,13 +982,13 @@ impl Document { match event_type { TouchEventType::Down => { // Add a new touch point - self.active_touch_points.borrow_mut().push(JS::from_rooted(&touch)); + self.active_touch_points.borrow_mut().push(JS::from_ref(&*touch)); } TouchEventType::Move => { // Replace an existing touch point let mut active_touch_points = self.active_touch_points.borrow_mut(); match active_touch_points.iter_mut().find(|t| t.Identifier() == identifier) { - Some(t) => *t = JS::from_rooted(&touch), + Some(t) => *t = JS::from_ref(&*touch), None => warn!("Got a touchmove event for a non-active touch point"), } } @@ -1013,7 +1009,7 @@ impl Document { touches.extend(self.active_touch_points.borrow().iter().cloned()); let mut changed_touches = RootedVec::new(); - changed_touches.push(JS::from_rooted(&touch)); + changed_touches.push(JS::from_ref(&*touch)); let mut target_touches = RootedVec::new(); target_touches.extend(self.active_touch_points @@ -1229,9 +1225,9 @@ impl Document { self.stylesheets_changed_since_reflow.set(true); *self.stylesheets.borrow_mut() = None; // Mark the document element dirty so a reflow will be performed. - self.get_html_element().map(|root| { - root.upcast::<Node>().dirty(NodeDamage::NodeStyleDamaged); - }); + if let Some(element) = self.GetDocumentElement() { + element.upcast::<Node>().dirty(NodeDamage::NodeStyleDamaged); + } } pub fn get_and_reset_stylesheets_changed_since_reflow(&self) -> bool { @@ -1474,10 +1470,8 @@ impl Document { update_with_current_time_ms(&self.dom_content_loaded_event_start); - let doctarget = Trusted::new(self.upcast::<EventTarget>()); - let task_source = self.window().dom_manipulation_task_source(); - let _ = task_source.queue(DOMManipulationTask::FireEvent( - atom!("DOMContentLoaded"), doctarget, EventBubbles::Bubbles, EventCancelable::NotCancelable)); + 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); @@ -1703,7 +1697,7 @@ impl Document { touchpad_pressure_phase: Cell::new(TouchpadPressurePhase::BeforeClick), origin: origin, //TODO - setting this for now so no Referer header set - referrer_policy: Some(ReferrerPolicy::NoReferrer), + referrer_policy: Cell::new(Some(ReferrerPolicy::NoReferrer)), } } @@ -1778,7 +1772,7 @@ impl Document { node.get_stylesheet() } else { None - }.map(|stylesheet| (JS::from_rooted(&node), stylesheet)) + }.map(|stylesheet| (JS::from_ref(&*node), stylesheet)) }) .collect()); }; @@ -1833,9 +1827,13 @@ impl Document { } } - //TODO - for now, returns no-referrer for all until reading in the value + pub fn set_referrer_policy(&self, policy: Option<ReferrerPolicy>) { + self.referrer_policy.set(policy); + } + + //TODO - default still at no-referrer pub fn get_referrer_policy(&self) -> Option<ReferrerPolicy> { - return self.referrer_policy.clone(); + return self.referrer_policy.get(); } } @@ -1868,8 +1866,8 @@ impl DocumentMethods for Document { } // https://dom.spec.whatwg.org/#dom-document-url - fn URL(&self) -> DOMString { - DOMString::from(self.url().as_str()) + fn URL(&self) -> USVString { + USVString(String::from(self.url().as_str())) } // https://html.spec.whatwg.org/multipage/#dom-document-activeelement @@ -1919,7 +1917,7 @@ impl DocumentMethods for Document { } // https://dom.spec.whatwg.org/#dom-document-documenturi - fn DocumentURI(&self) -> DOMString { + fn DocumentURI(&self) -> USVString { self.URL() } @@ -2001,7 +1999,7 @@ impl DocumentMethods for Document { self.upcast(), tag_atom, ascii_lower_tag); - entry.insert(JS::from_rooted(&result)); + entry.insert(JS::from_ref(&*result)); result } } @@ -2019,7 +2017,7 @@ impl DocumentMethods for Document { Occupied(entry) => Root::from_ref(entry.get()), Vacant(entry) => { let result = HTMLCollection::by_qual_tag_name(&self.window, self.upcast(), qname); - entry.insert(JS::from_rooted(&result)); + entry.insert(JS::from_ref(&*result)); result } } @@ -2036,7 +2034,7 @@ impl DocumentMethods for Document { let result = HTMLCollection::by_atomic_class_name(&self.window, self.upcast(), class_atoms); - entry.insert(JS::from_rooted(&result)); + entry.insert(JS::from_ref(&*result)); result } } @@ -2195,8 +2193,10 @@ impl DocumentMethods for Document { )), "webglcontextevent" => Ok(Root::upcast(WebGLContextEvent::new_uninitialized(GlobalRef::Window(&self.window)))), - "storageevent" => - Ok(Root::upcast(StorageEvent::new_uninitialized(&self.window, self.URL()))), + "storageevent" => { + let USVString(url) = self.URL(); + Ok(Root::upcast(StorageEvent::new_uninitialized(&self.window, DOMString::from(url)))) + }, "progressevent" => Ok(Root::upcast(ProgressEvent::new_uninitialized(&self.window))), "focusevent" => @@ -2804,6 +2804,20 @@ fn update_with_current_time_ms(marker: &Cell<u64>) { } } +/// https://w3c.github.io/webappsec-referrer-policy/#determine-policy-for-token +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), + "origin" => Some(ReferrerPolicy::OriginOnly), + "origin-when-cross-origin" => Some(ReferrerPolicy::OriginWhenCrossOrigin), + "always" | "unsafe-url" => Some(ReferrerPolicy::UnsafeUrl), + "" => Some(ReferrerPolicy::NoReferrer), + _ => None, + } +} + pub struct DocumentProgressHandler { addr: Trusted<Document> } |