Skip to content

Commit

Permalink
Implement referrer policy for dom worker construction
Browse files Browse the repository at this point in the history
  • Loading branch information
shanehandley committed Nov 8, 2024
1 parent eabfd16 commit cfbff2b
Show file tree
Hide file tree
Showing 60 changed files with 25 additions and 381 deletions.
17 changes: 16 additions & 1 deletion components/script/dom/globalscope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/serviceworkerregistration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl ServiceWorkerRegistration {
Referrer::ReferrerUrl(url) => Some(url),
_ => None,
},
referrer_policy: Some(global.policy_container().referrer_policy),
referrer_policy: global.get_referrer_policy(),
pipeline_id: global.pipeline_id(),
};

Expand Down
9 changes: 7 additions & 2 deletions components/script/dom/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use ipc_channel::ipc;
use js::jsapi::{Heap, JSObject};
use js::jsval::UndefinedValue;
use js::rust::{CustomAutoRooter, CustomAutoRooterGuard, HandleObject, HandleValue};
use net_traits::request::Referrer;
use script_traits::{StructuredSerializedData, WorkerScriptLoadOrigin};
use uuid::Uuid;

Expand Down Expand Up @@ -178,8 +179,12 @@ impl WorkerMethods for Worker {
let worker_ref = Trusted::new(&*worker);

let worker_load_origin = WorkerScriptLoadOrigin {
referrer_url: None,
referrer_policy: None,
referrer_url: match global.get_referrer() {
Referrer::Client(url) => Some(url),
Referrer::ReferrerUrl(url) => Some(url),
_ => None,
},
referrer_policy: global.get_referrer_policy(),
pipeline_id: global.pipeline_id(),
};

Expand Down
10 changes: 1 addition & 9 deletions components/script/dom/xmlhttprequest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,6 @@ pub struct XMLHttpRequest {

impl XMLHttpRequest {
fn new_inherited(global: &GlobalScope) -> XMLHttpRequest {
//TODO - update this when referrer policy implemented for workers
let referrer_policy = if let Some(window) = global.downcast::<Window>() {
let document = window.Document();
document.get_referrer_policy()
} else {
None
};

XMLHttpRequest {
eventtarget: XMLHttpRequestEventTarget::new_inherited(),
ready_state: Cell::new(XMLHttpRequestState::Unsent),
Expand Down Expand Up @@ -213,7 +205,7 @@ impl XMLHttpRequest {
generation_id: Cell::new(GenerationId(0)),
response_status: Cell::new(Ok(())),
referrer: global.get_referrer(),
referrer_policy,
referrer_policy: global.get_referrer_policy(),
canceller: DomRefCell::new(Default::default()),
}
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit cfbff2b

Please sign in to comment.