Remove referrer policy from document (#34263)

* Remove the referrer policy from document and rely on its policy container

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

* Make ReferrerPolicy non-optional, instead using a new enum value to represent the empty string case

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

* Fix clippy issue

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

* Fix usage of Option<ReferrerPolicy> in unit test

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

---------

Signed-off-by: Shane Handley <shanehandley@fastmail.com>
This commit is contained in:
shanehandley 2024-11-19 23:45:10 +11:00 committed by GitHub
parent 83f8e88818
commit 975e2ae859
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
108 changed files with 171 additions and 1509 deletions

View file

@ -371,9 +371,6 @@ pub struct Document {
/// The document's origin.
#[no_trace]
origin: MutableOrigin,
/// <https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-states>
#[no_trace]
referrer_policy: Cell<Option<ReferrerPolicy>>,
/// <https://html.spec.whatwg.org/multipage/#dom-document-referrer>
referrer: Option<String>,
/// <https://html.spec.whatwg.org/multipage/#target-element>
@ -3295,7 +3292,6 @@ impl Document {
source: DocumentSource,
doc_loader: DocumentLoader,
referrer: Option<String>,
referrer_policy: Option<ReferrerPolicy>,
status_code: Option<u16>,
canceller: FetchCanceller,
) -> Document {
@ -3401,7 +3397,6 @@ impl Document {
https_state: Cell::new(HttpsState::None),
origin,
referrer,
referrer_policy: Cell::new(referrer_policy),
target_element: MutNullableDom::new(None),
policy_container: DomRefCell::new(PolicyContainer::default()),
last_click_info: DomRefCell::new(None),
@ -3580,7 +3575,6 @@ impl Document {
source: DocumentSource,
doc_loader: DocumentLoader,
referrer: Option<String>,
referrer_policy: Option<ReferrerPolicy>,
status_code: Option<u16>,
canceller: FetchCanceller,
can_gc: CanGc,
@ -3598,7 +3592,6 @@ impl Document {
source,
doc_loader,
referrer,
referrer_policy,
status_code,
canceller,
can_gc,
@ -3619,7 +3612,6 @@ impl Document {
source: DocumentSource,
doc_loader: DocumentLoader,
referrer: Option<String>,
referrer_policy: Option<ReferrerPolicy>,
status_code: Option<u16>,
canceller: FetchCanceller,
can_gc: CanGc,
@ -3637,7 +3629,6 @@ impl Document {
source,
doc_loader,
referrer,
referrer_policy,
status_code,
canceller,
)),
@ -3762,7 +3753,6 @@ impl Document {
DocumentLoader::new(&self.loader()),
None,
None,
None,
Default::default(),
can_gc,
);
@ -3847,13 +3837,14 @@ impl Document {
}
}
pub fn set_referrer_policy(&self, policy: Option<ReferrerPolicy>) {
self.referrer_policy.set(policy);
pub fn set_referrer_policy(&self, policy: ReferrerPolicy) {
self.policy_container
.borrow_mut()
.set_referrer_policy(policy);
}
//TODO - default still at no-referrer
pub fn get_referrer_policy(&self) -> Option<ReferrerPolicy> {
self.referrer_policy.get()
pub fn get_referrer_policy(&self) -> ReferrerPolicy {
self.policy_container.borrow().get_referrer_policy()
}
pub fn set_target_element(&self, node: Option<&Element>, can_gc: CanGc) {
@ -4301,7 +4292,6 @@ impl DocumentMethods for Document {
docloader,
None,
None,
None,
Default::default(),
can_gc,
))
@ -5621,18 +5611,17 @@ fn update_with_current_instant(marker: &Cell<Option<CrossProcessInstant>>) {
}
/// <https://w3c.github.io/webappsec-referrer-policy/#determine-policy-for-token>
pub fn determine_policy_for_token(token: &str) -> Option<ReferrerPolicy> {
pub fn determine_policy_for_token(token: &str) -> ReferrerPolicy {
match_ignore_ascii_case! { token,
"never" | "no-referrer" => Some(ReferrerPolicy::NoReferrer),
"no-referrer-when-downgrade" => Some(ReferrerPolicy::NoReferrerWhenDowngrade),
"origin" => Some(ReferrerPolicy::Origin),
"same-origin" => Some(ReferrerPolicy::SameOrigin),
"strict-origin" => Some(ReferrerPolicy::StrictOrigin),
"default" | "strict-origin-when-cross-origin" => Some(ReferrerPolicy::StrictOriginWhenCrossOrigin),
"origin-when-cross-origin" => Some(ReferrerPolicy::OriginWhenCrossOrigin),
"always" | "unsafe-url" => Some(ReferrerPolicy::UnsafeUrl),
"" => Some(ReferrerPolicy::default()),
_ => None,
"never" | "no-referrer" => ReferrerPolicy::NoReferrer,
"no-referrer-when-downgrade" => ReferrerPolicy::NoReferrerWhenDowngrade,
"origin" => ReferrerPolicy::Origin,
"same-origin" => ReferrerPolicy::SameOrigin,
"strict-origin" => ReferrerPolicy::StrictOrigin,
"default" | "strict-origin-when-cross-origin" => ReferrerPolicy::StrictOriginWhenCrossOrigin,
"origin-when-cross-origin" => ReferrerPolicy::OriginWhenCrossOrigin,
"always" | "unsafe-url" => ReferrerPolicy::UnsafeUrl,
_ => ReferrerPolicy::EmptyString,
}
}