Implement referrer policy for dom worker construction (#34192)

Signed-off-by: Shane Handley <shanehandley@fastmail.com>
This commit is contained in:
shanehandley 2024-11-09 12:16:35 +11:00 committed by GitHub
parent 6c1cd56e52
commit da462d0fcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
60 changed files with 25 additions and 381 deletions

View file

@ -50,7 +50,7 @@ use net_traits::request::{Referrer, RequestBuilder};
use net_traits::response::HttpsState;
use net_traits::{
fetch_async, CoreResourceMsg, CoreResourceThread, FetchResponseListener, IpcSend,
ResourceThreads,
ReferrerPolicy, ResourceThreads,
};
use profile_traits::{ipc as profile_ipc, mem as profile_mem, time as profile_time};
use script_traits::serializable::{BlobData, BlobImpl, FileBlob};
@ -2418,6 +2418,21 @@ impl GlobalScope {
unreachable!();
}
/// Get the Referrer Policy for this global scope.
pub fn get_referrer_policy(&self) -> Option<ReferrerPolicy> {
if let Some(window) = self.downcast::<Window>() {
let document = window.Document();
return document.get_referrer_policy();
}
if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
let policy_container = worker.policy_container().to_owned();
return Some(policy_container.referrer_policy);
}
unreachable!();
}
/// Determine the Referrer for a request whose Referrer is "client"
pub fn get_referrer(&self) -> Referrer {
// Step 3 of https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer