Implement PolicyContainer and update the default ReferrerPolicy (#33977)

* Implement PolicyContainer

Signed-off-by: Shane Handley <shanehandley@fastmail.com>

* implement small parts of fetch that interact with policy container

Signed-off-by: Shane Handley <shanehandley@fastmail.com>

* fix: allow policy container's csp list to be unset

Signed-off-by: Shane Handley <shanehandley@fastmail.com>

* fix: use the correct default policy when parsing from a token

Signed-off-by: Shane Handley <shanehandley@fastmail.com>

---------

Signed-off-by: Shane Handley <shanehandley@fastmail.com>
This commit is contained in:
shanehandley 2024-11-08 18:19:23 +11:00 committed by GitHub
parent 4f6283d7fe
commit 6451767428
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
201 changed files with 210 additions and 5178 deletions

View file

@ -45,6 +45,7 @@ use net_traits::filemanager_thread::{
FileManagerResult, FileManagerThreadMsg, ReadFileProgress, RelativePos,
};
use net_traits::image_cache::ImageCache;
use net_traits::policy_container::PolicyContainer;
use net_traits::request::{Referrer, RequestBuilder};
use net_traits::response::HttpsState;
use net_traits::{
@ -2373,6 +2374,17 @@ impl GlobalScope {
unreachable!();
}
/// <https://html.spec.whatwg.org/multipage/#concept-settings-object-policy-container>
pub fn policy_container(&self) -> PolicyContainer {
if let Some(window) = self.downcast::<Window>() {
return window.Document().policy_container().to_owned();
}
if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
return worker.policy_container().to_owned();
}
unreachable!();
}
/// Get the [base url](https://html.spec.whatwg.org/multipage/#api-base-url)
/// for this global scope.
pub fn api_base_url(&self) -> ServoUrl {
@ -3116,8 +3128,8 @@ impl GlobalScope {
/// <https://www.w3.org/TR/CSP/#get-csp-of-object>
pub fn get_csp_list(&self) -> Option<CspList> {
if let Some(window) = self.downcast::<Window>() {
return window.Document().get_csp_list().map(|c| c.clone());
if self.downcast::<Window>().is_some() {
return self.policy_container().csp_list;
}
// TODO: Worker and Worklet global scopes.
None