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 | |
parent | 310821d3b0c88a5f7ef15c228d2a2b514ebcc477 (diff) | |
download | servo-dd57641987996abcf3886b436231aa07bb00fea7.tar.gz servo-dd57641987996abcf3886b436231aa07bb00fea7.zip |
Propagate referrer policy during about:srcdoc page load
Diffstat (limited to 'components')
-rw-r--r-- | components/net_traits/lib.rs | 34 | ||||
-rw-r--r-- | components/script/script_thread.rs | 7 |
2 files changed, 38 insertions, 3 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 diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 0ef48e78b17..6caba693309 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -2502,7 +2502,7 @@ impl ScriptThread { if load_data.url.as_str() == "about:blank" { self.start_page_load_about_blank(new_load, load_data.js_eval_result); } else if load_data.url.as_str() == "about:srcdoc" { - self.page_load_about_srcdoc(new_load, load_data.srcdoc); + self.page_load_about_srcdoc(new_load, load_data); } else { self.pre_page_load(new_load, load_data); } @@ -3865,7 +3865,7 @@ impl ScriptThread { } /// Synchronously parse a srcdoc document from a giving HTML string. - fn page_load_about_srcdoc(&self, incomplete: InProgressLoad, src_doc: String) { + fn page_load_about_srcdoc(&self, incomplete: InProgressLoad, load_data: LoadData) { let id = incomplete.pipeline_id; self.incomplete_loads.borrow_mut().push(incomplete); @@ -3875,8 +3875,9 @@ impl ScriptThread { let mut meta = Metadata::default(url); meta.set_content_type(Some(&mime::TEXT_HTML)); + meta.set_referrer_policy(load_data.referrer_policy); - let chunk = src_doc.into_bytes(); + let chunk = load_data.srcdoc.into_bytes(); context.process_response(Ok(FetchMetadata::Unfiltered(meta))); context.process_response_chunk(chunk); |