mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
Auto merge of #12441 - aravind-pg:referrer-pol-header, r=jdm
Implement referrer policy delivery by header Adds a new `Option<ReferrerPolicy>` field to Document and sets it appropriately in `ScriptThread::load` if a Referrer-Policy header is present. r? @jdm <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #11860 - [X] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12441) <!-- Reviewable:end -->
This commit is contained in:
commit
b382cc2103
40 changed files with 83 additions and 171 deletions
|
@ -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
|
||||
|
@ -2848,7 +2863,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),
|
||||
|
|
|
@ -130,6 +130,7 @@ impl DOMImplementationMethods for DOMImplementation {
|
|||
None,
|
||||
DocumentSource::NotFromParser,
|
||||
loader,
|
||||
None,
|
||||
None);
|
||||
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(..) => {
|
||||
|
|
|
@ -42,6 +42,7 @@ impl XMLDocument {
|
|||
last_modified,
|
||||
source,
|
||||
doc_loader,
|
||||
None,
|
||||
None),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1242,6 +1242,7 @@ impl XMLHttpRequest {
|
|||
None,
|
||||
DocumentSource::FromParser,
|
||||
docloader,
|
||||
None,
|
||||
None)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue