script: Obtain referrer policy from header

This commit is contained in:
Aravind Gollakota 2016-07-12 23:50:00 -07:00
parent 920a43df95
commit 1a242d8a50
8 changed files with 52 additions and 11 deletions

View file

@ -1633,7 +1633,8 @@ impl Document {
last_modified: Option<String>, last_modified: Option<String>,
source: DocumentSource, source: DocumentSource,
doc_loader: DocumentLoader, doc_loader: DocumentLoader,
referrer: Option<String>) referrer: Option<String>,
referrer_policy: Option<ReferrerPolicy>)
-> Document { -> Document {
let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap()); let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap());
@ -1652,6 +1653,17 @@ impl Document {
Origin::opaque_identifier() 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 { Document {
node: Node::new_document_node(), node: Node::new_document_node(),
window: JS::from_ref(window), window: JS::from_ref(window),
@ -1718,9 +1730,8 @@ impl Document {
https_state: Cell::new(HttpsState::None), https_state: Cell::new(HttpsState::None),
touchpad_pressure_phase: Cell::new(TouchpadPressurePhase::BeforeClick), touchpad_pressure_phase: Cell::new(TouchpadPressurePhase::BeforeClick),
origin: origin, origin: origin,
//TODO - setting this for now so no Referer header set
referrer_policy: Cell::new(Some(ReferrerPolicy::NoReferrer)),
referrer: referrer, referrer: referrer,
referrer_policy: Cell::new(referrer_policy),
} }
} }
@ -1738,6 +1749,7 @@ impl Document {
None, None,
DocumentSource::NotFromParser, DocumentSource::NotFromParser,
docloader, docloader,
None,
None)) None))
} }
@ -1749,7 +1761,8 @@ impl Document {
last_modified: Option<String>, last_modified: Option<String>,
source: DocumentSource, source: DocumentSource,
doc_loader: DocumentLoader, doc_loader: DocumentLoader,
referrer: Option<String>) referrer: Option<String>,
referrer_policy: Option<ReferrerPolicy>)
-> Root<Document> { -> Root<Document> {
let document = reflect_dom_object(box Document::new_inherited(window, let document = reflect_dom_object(box Document::new_inherited(window,
browsing_context, browsing_context,
@ -1759,7 +1772,8 @@ impl Document {
last_modified, last_modified,
source, source,
doc_loader, doc_loader,
referrer), referrer,
referrer_policy),
GlobalRef::Window(window), GlobalRef::Window(window),
DocumentBinding::Wrap); DocumentBinding::Wrap);
{ {
@ -1824,6 +1838,7 @@ impl Document {
None, None,
DocumentSource::NotFromParser, DocumentSource::NotFromParser,
DocumentLoader::new(&self.loader()), DocumentLoader::new(&self.loader()),
None,
None); None);
new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc)); new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc));
new_doc new_doc

View file

@ -130,6 +130,7 @@ impl DOMImplementationMethods for DOMImplementation {
None, None,
DocumentSource::NotFromParser, DocumentSource::NotFromParser,
loader, loader,
None,
None); None);
{ {

View file

@ -69,6 +69,7 @@ impl DOMParserMethods for DOMParser {
None, None,
DocumentSource::FromParser, DocumentSource::FromParser,
loader, loader,
None,
None); None);
parse_html(document.r(), s, url, ParseContext::Owner(None)); parse_html(document.r(), s, url, ParseContext::Owner(None));
document.set_ready_state(DocumentReadyState::Complete); document.set_ready_state(DocumentReadyState::Complete);
@ -84,6 +85,7 @@ impl DOMParserMethods for DOMParser {
None, None,
DocumentSource::NotFromParser, DocumentSource::NotFromParser,
loader, loader,
None,
None); None);
parse_xml(document.r(), s, url, xml::ParseContext::Owner(None)); parse_xml(document.r(), s, url, xml::ParseContext::Owner(None));
Ok(document) Ok(document)

View file

@ -1721,7 +1721,8 @@ impl Node {
let document = Document::new(window, None, let document = Document::new(window, None,
Some((*document.url()).clone()), Some((*document.url()).clone()),
is_html_doc, None, is_html_doc, None,
None, DocumentSource::NotFromParser, loader, None); None, DocumentSource::NotFromParser, loader,
None, None);
Root::upcast::<Node>(document) Root::upcast::<Node>(document)
}, },
NodeTypeId::Element(..) => { NodeTypeId::Element(..) => {

View file

@ -42,6 +42,7 @@ impl XMLDocument {
last_modified, last_modified,
source, source,
doc_loader, doc_loader,
None,
None), None),
} }
} }

View file

@ -1242,6 +1242,7 @@ impl XMLHttpRequest {
None, None,
DocumentSource::FromParser, DocumentSource::FromParser,
docloader, docloader,
None,
None) None)
} }

View file

@ -280,7 +280,7 @@ pub fn parse_html_fragment(context_node: &Node,
None, None, None, None,
DocumentSource::FromParser, DocumentSource::FromParser,
loader, loader,
None); None, None);
// Step 2. // Step 2.
document.set_quirks_mode(context_document.quirks_mode()); document.set_quirks_mode(context_document.quirks_mode());

View file

@ -51,8 +51,8 @@ use dom::worker::TrustedWorkerAddress;
use euclid::Rect; use euclid::Rect;
use euclid::point::Point2D; use euclid::point::Point2D;
use gfx_traits::LayerId; use gfx_traits::LayerId;
use hyper::header::{ContentType, HttpDate}; use hyper::header::{ContentType, Headers, HttpDate, LastModified};
use hyper::header::{Headers, LastModified}; use hyper::header::{ReferrerPolicy as ReferrerPolicyHeader};
use hyper::method::Method; use hyper::method::Method;
use hyper::mime::{Mime, SubLevel, TopLevel}; use hyper::mime::{Mime, SubLevel, TopLevel};
use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::ipc::{self, IpcSender};
@ -65,7 +65,7 @@ use js::jsval::UndefinedValue;
use js::rust::Runtime; use js::rust::Runtime;
use mem::heap_size_of_self_and_children; use mem::heap_size_of_self_and_children;
use msg::constellation_msg::{FrameType, LoadData, PanicMsg, PipelineId, PipelineNamespace}; use msg::constellation_msg::{FrameType, LoadData, PanicMsg, PipelineId, PipelineNamespace};
use msg::constellation_msg::{SubpageId, WindowSizeType}; use msg::constellation_msg::{ReferrerPolicy, SubpageId, WindowSizeType};
use net_traits::LoadData as NetLoadData; use net_traits::LoadData as NetLoadData;
use net_traits::bluetooth_thread::BluetoothMethodMsg; use net_traits::bluetooth_thread::BluetoothMethodMsg;
use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheResult, ImageCacheThread}; use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheResult, ImageCacheThread};
@ -1716,6 +1716,25 @@ impl ScriptThread {
None => None, None => None,
}; };
let referrer_policy = if let Some(headers) = metadata.headers {
headers.get::<ReferrerPolicyHeader>().map(|h| match *h {
ReferrerPolicyHeader::NoReferrer =>
ReferrerPolicy::NoReferrer,
ReferrerPolicyHeader::NoReferrerWhenDowngrade =>
ReferrerPolicy::NoRefWhenDowngrade,
ReferrerPolicyHeader::SameOrigin =>
ReferrerPolicy::SameOrigin,
ReferrerPolicyHeader::Origin =>
ReferrerPolicy::Origin,
ReferrerPolicyHeader::OriginWhenCrossOrigin =>
ReferrerPolicy::OriginWhenCrossOrigin,
ReferrerPolicyHeader::UnsafeUrl =>
ReferrerPolicy::UnsafeUrl,
})
} else {
None
};
let document = Document::new(window.r(), let document = Document::new(window.r(),
Some(&browsing_context), Some(&browsing_context),
Some(final_url.clone()), Some(final_url.clone()),
@ -1724,7 +1743,8 @@ impl ScriptThread {
last_modified, last_modified,
DocumentSource::FromParser, DocumentSource::FromParser,
loader, loader,
referrer); referrer,
referrer_policy);
if using_new_context { if using_new_context {
browsing_context.init(&document); browsing_context.init(&document);
} else { } else {