mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add meta-referrer support for documents
This commit is contained in:
parent
d0f5a5fd74
commit
687d0cd7c3
56 changed files with 136 additions and 263 deletions
|
@ -238,7 +238,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)]
|
||||
|
@ -1700,7 +1700,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)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1830,9 +1830,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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2803,6 +2807,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>
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue