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>,
source: DocumentSource,
doc_loader: DocumentLoader,
referrer: Option<String>)
referrer: Option<String>,
referrer_policy: Option<ReferrerPolicy>)
-> Document {
let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap());
@ -1652,6 +1653,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),
@ -1718,9 +1730,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),
}
}
@ -1738,6 +1749,7 @@ impl Document {
None,
DocumentSource::NotFromParser,
docloader,
None,
None))
}
@ -1749,7 +1761,8 @@ impl Document {
last_modified: Option<String>,
source: DocumentSource,
doc_loader: DocumentLoader,
referrer: Option<String>)
referrer: Option<String>,
referrer_policy: Option<ReferrerPolicy>)
-> Root<Document> {
let document = reflect_dom_object(box Document::new_inherited(window,
browsing_context,
@ -1759,7 +1772,8 @@ impl Document {
last_modified,
source,
doc_loader,
referrer),
referrer,
referrer_policy),
GlobalRef::Window(window),
DocumentBinding::Wrap);
{
@ -1824,6 +1838,7 @@ impl Document {
None,
DocumentSource::NotFromParser,
DocumentLoader::new(&self.loader()),
None,
None);
new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc));
new_doc

View file

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

View file

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

View file

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

View file

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

View file

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