diff options
author | Utsav Oza <utsavoza96@gmail.com> | 2020-07-01 16:43:32 +0530 |
---|---|---|
committer | Utsav Oza <utsavoza96@gmail.com> | 2020-07-02 14:29:27 +0530 |
commit | dd57641987996abcf3886b436231aa07bb00fea7 (patch) | |
tree | 7753a7c6b3eef4186f1e28dcbe4488b32724b595 /components/net_traits/lib.rs | |
parent | 310821d3b0c88a5f7ef15c228d2a2b514ebcc477 (diff) | |
download | servo-dd57641987996abcf3886b436231aa07bb00fea7.tar.gz servo-dd57641987996abcf3886b436231aa07bb00fea7.zip |
Propagate referrer policy during about:srcdoc page load
Diffstat (limited to 'components/net_traits/lib.rs')
-rw-r--r-- | components/net_traits/lib.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/components/net_traits/lib.rs b/components/net_traits/lib.rs index 6dea965d7f8..83d9513d987 100644 --- a/components/net_traits/lib.rs +++ b/components/net_traits/lib.rs @@ -162,6 +162,25 @@ impl From<ReferrerPolicyHeader> for ReferrerPolicy { } } +impl From<ReferrerPolicy> for ReferrerPolicyHeader { + fn from(referrer_policy: ReferrerPolicy) -> Self { + match referrer_policy { + ReferrerPolicy::NoReferrer => ReferrerPolicyHeader::NO_REFERRER, + ReferrerPolicy::NoReferrerWhenDowngrade => { + ReferrerPolicyHeader::NO_REFERRER_WHEN_DOWNGRADE + }, + ReferrerPolicy::SameOrigin => ReferrerPolicyHeader::SAME_ORIGIN, + ReferrerPolicy::Origin => ReferrerPolicyHeader::ORIGIN, + ReferrerPolicy::OriginWhenCrossOrigin => ReferrerPolicyHeader::ORIGIN_WHEN_CROSS_ORIGIN, + ReferrerPolicy::UnsafeUrl => ReferrerPolicyHeader::UNSAFE_URL, + ReferrerPolicy::StrictOrigin => ReferrerPolicyHeader::STRICT_ORIGIN, + ReferrerPolicy::StrictOriginWhenCrossOrigin => { + ReferrerPolicyHeader::STRICT_ORIGIN_WHEN_CROSS_ORIGIN + }, + } + } +} + #[derive(Debug, Deserialize, Serialize)] pub enum FetchResponseMsg { // todo: should have fields for transmitted/total bytes @@ -695,6 +714,21 @@ impl Metadata { self.content_type = Some(Serde(ContentType::from(mime.clone()))); } } + + /// Set the referrer policy associated with the loaded resource. + pub fn set_referrer_policy(&mut self, referrer_policy: Option<ReferrerPolicy>) { + if self.headers.is_none() { + self.headers = Some(Serde(HeaderMap::new())); + } + + self.referrer_policy = referrer_policy; + if let Some(referrer_policy) = referrer_policy { + self.headers + .as_mut() + .unwrap() + .typed_insert::<ReferrerPolicyHeader>(referrer_policy.into()); + } + } } /// The creator of a given cookie |