From 41f27ae80b9519bde413b095a0131a76ae51319d Mon Sep 17 00:00:00 2001 From: shanehandley <1322294+shanehandley@users.noreply.github.com> Date: Sun, 22 Dec 2024 21:31:27 +1100 Subject: [PATCH] Implement referrerpolicy attribute on remaining elements (#34736) Fixes #11861 Signed-off-by: Shane Handley --- components/script/dom/htmlanchorelement.rs | 10 +- components/script/dom/htmlareaelement.rs | 10 +- components/script/dom/htmlimageelement.rs | 10 +- .../dom/webidls/HTMLAnchorElement.webidl | 2 + .../script/dom/webidls/HTMLAreaElement.webidl | 1 + .../HTMLAreaElement.html.ini | 6 - .../meta/html/dom/idlharness.https.html.ini | 12 - .../meta/html/dom/reflection-text.html.ini | 384 ------------------ .../attr-referrer-invalid-value.html.ini | 3 - 9 files changed, 25 insertions(+), 413 deletions(-) delete mode 100644 tests/wpt/meta/referrer-policy/generic/subresource-test/attr-referrer-invalid-value.html.ini diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs index afdfa7bb68d..4e6df0f5212 100644 --- a/components/script/dom/htmlanchorelement.rs +++ b/components/script/dom/htmlanchorelement.rs @@ -24,7 +24,7 @@ use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::bindings::str::{DOMString, USVString}; use crate::dom::document::Document; use crate::dom::domtokenlist::DOMTokenList; -use crate::dom::element::{AttributeMutation, Element}; +use crate::dom::element::{reflect_referrer_policy_attribute, AttributeMutation, Element}; use crate::dom::event::Event; use crate::dom::eventtarget::EventTarget; use crate::dom::htmlelement::HTMLElement; @@ -582,6 +582,14 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement { // Step 5. self.update_href(url, can_gc); } + + // https://html.spec.whatwg.org/multipage/#dom-a-referrerpolicy + fn ReferrerPolicy(&self) -> DOMString { + reflect_referrer_policy_attribute(self.upcast::()) + } + + // https://html.spec.whatwg.org/multipage/#dom-script-referrerpolicy + make_setter!(SetReferrerPolicy, "referrerpolicy"); } impl Activatable for HTMLAnchorElement { diff --git a/components/script/dom/htmlareaelement.rs b/components/script/dom/htmlareaelement.rs index 0586b0875d7..1523ae285d8 100644 --- a/components/script/dom/htmlareaelement.rs +++ b/components/script/dom/htmlareaelement.rs @@ -22,7 +22,7 @@ use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::bindings::str::DOMString; use crate::dom::document::Document; use crate::dom::domtokenlist::DOMTokenList; -use crate::dom::element::{AttributeMutation, Element}; +use crate::dom::element::{reflect_referrer_policy_attribute, AttributeMutation, Element}; use crate::dom::event::Event; use crate::dom::eventtarget::EventTarget; use crate::dom::htmlelement::HTMLElement; @@ -362,6 +362,14 @@ impl HTMLAreaElementMethods for HTMLAreaElement { ) }) } + + /// + fn ReferrerPolicy(&self) -> DOMString { + reflect_referrer_policy_attribute(self.upcast::()) + } + + // https://html.spec.whatwg.org/multipage/#attr-iframe-referrerpolicy + make_setter!(SetReferrerPolicy, "referrerpolicy"); } impl Activatable for HTMLAreaElement { diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index c23e02d5672..fe32f388e1d 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -69,8 +69,8 @@ use crate::dom::bindings::str::{DOMString, USVString}; use crate::dom::document::{determine_policy_for_token, Document}; use crate::dom::element::{ cors_setting_for_element, referrer_policy_for_element, reflect_cross_origin_attribute, - set_cross_origin_attribute, AttributeMutation, CustomElementCreationMode, Element, - ElementCreator, LayoutElementHelpers, + reflect_referrer_policy_attribute, set_cross_origin_attribute, AttributeMutation, + CustomElementCreationMode, Element, ElementCreator, LayoutElementHelpers, }; use crate::dom::event::Event; use crate::dom::eventtarget::EventTarget; @@ -1691,11 +1691,9 @@ impl HTMLImageElementMethods for HTMLImageElement { } } - // https://html.spec.whatwg.org/multipage/#dom-img-referrerpolicy + /// fn ReferrerPolicy(&self) -> DOMString { - let element = self.upcast::(); - let current_policy_value = element.get_string_attribute(&local_name!("referrerpolicy")); - get_correct_referrerpolicy_from_raw_token(¤t_policy_value) + reflect_referrer_policy_attribute(self.upcast::()) } // https://html.spec.whatwg.org/multipage/#dom-img-referrerpolicy diff --git a/components/script/dom/webidls/HTMLAnchorElement.webidl b/components/script/dom/webidls/HTMLAnchorElement.webidl index f6e48281102..ed867a6a9a2 100644 --- a/components/script/dom/webidls/HTMLAnchorElement.webidl +++ b/components/script/dom/webidls/HTMLAnchorElement.webidl @@ -32,6 +32,8 @@ interface HTMLAnchorElement : HTMLElement { [CEReactions, Pure] attribute DOMString text; + [CEReactions] attribute DOMString referrerPolicy; + // also has obsolete members }; HTMLAnchorElement includes HTMLHyperlinkElementUtils; diff --git a/components/script/dom/webidls/HTMLAreaElement.webidl b/components/script/dom/webidls/HTMLAreaElement.webidl index 74c281e93c5..222eef4962c 100644 --- a/components/script/dom/webidls/HTMLAreaElement.webidl +++ b/components/script/dom/webidls/HTMLAreaElement.webidl @@ -22,6 +22,7 @@ interface HTMLAreaElement : HTMLElement { [CEReactions] attribute DOMString rel; [SameObject, PutForwards=value] readonly attribute DOMTokenList relList; + [CEReactions] attribute DOMString referrerPolicy; // hreflang and type are not reflected }; //HTMLAreaElement includes HTMLHyperlinkElementUtils; diff --git a/tests/wpt/meta/custom-elements/reactions/customized-builtins/HTMLAreaElement.html.ini b/tests/wpt/meta/custom-elements/reactions/customized-builtins/HTMLAreaElement.html.ini index 3701b29cccc..979f0892854 100644 --- a/tests/wpt/meta/custom-elements/reactions/customized-builtins/HTMLAreaElement.html.ini +++ b/tests/wpt/meta/custom-elements/reactions/customized-builtins/HTMLAreaElement.html.ini @@ -28,9 +28,3 @@ [ping on HTMLAreaElement must enqueue an attributeChanged reaction when replacing an existing attribute] expected: FAIL - - [referrerPolicy on HTMLAreaElement must enqueue an attributeChanged reaction when adding a new attribute] - expected: FAIL - - [referrerPolicy on HTMLAreaElement must enqueue an attributeChanged reaction when replacing an existing attribute] - expected: FAIL diff --git a/tests/wpt/meta/html/dom/idlharness.https.html.ini b/tests/wpt/meta/html/dom/idlharness.https.html.ini index 84e63d5ebe3..38825e47432 100644 --- a/tests/wpt/meta/html/dom/idlharness.https.html.ini +++ b/tests/wpt/meta/html/dom/idlharness.https.html.ini @@ -6307,9 +6307,6 @@ [HTMLAnchorElement interface: attribute type] expected: FAIL - [HTMLAnchorElement interface: attribute referrerPolicy] - expected: FAIL - [HTMLAnchorElement interface: attribute charset] expected: FAIL @@ -6325,9 +6322,6 @@ [HTMLAnchorElement interface: document.createElement("a") must inherit property "type" with the proper type] expected: FAIL - [HTMLAnchorElement interface: document.createElement("a") must inherit property "referrerPolicy" with the proper type] - expected: FAIL - [HTMLAnchorElement interface: document.createElement("a") must inherit property "charset" with the proper type] expected: FAIL @@ -6694,9 +6688,6 @@ [HTMLAreaElement interface: attribute ping] expected: FAIL - [HTMLAreaElement interface: attribute referrerPolicy] - expected: FAIL - [HTMLAreaElement interface: attribute noHref] expected: FAIL @@ -6751,9 +6742,6 @@ [HTMLAreaElement interface: document.createElement("area") must inherit property "ping" with the proper type] expected: FAIL - [HTMLAreaElement interface: document.createElement("area") must inherit property "referrerPolicy" with the proper type] - expected: FAIL - [HTMLAreaElement interface: document.createElement("area") must inherit property "noHref" with the proper type] expected: FAIL diff --git a/tests/wpt/meta/html/dom/reflection-text.html.ini b/tests/wpt/meta/html/dom/reflection-text.html.ini index 6277b7b3aa6..b3e7fe17594 100644 --- a/tests/wpt/meta/html/dom/reflection-text.html.ini +++ b/tests/wpt/meta/html/dom/reflection-text.html.ini @@ -647,390 +647,6 @@ [a.type: IDL set to object "test-valueOf"] expected: FAIL - [a.referrerPolicy: typeof IDL attribute] - expected: FAIL - - [a.referrerPolicy: IDL get with DOM attribute unset] - expected: FAIL - - [a.referrerPolicy: setAttribute() to ""] - expected: FAIL - - [a.referrerPolicy: setAttribute() to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo "] - expected: FAIL - - [a.referrerPolicy: setAttribute() to undefined] - expected: FAIL - - [a.referrerPolicy: setAttribute() to 7] - expected: FAIL - - [a.referrerPolicy: setAttribute() to 1.5] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "5%"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "+100"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to ".5"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to true] - expected: FAIL - - [a.referrerPolicy: setAttribute() to false] - expected: FAIL - - [a.referrerPolicy: setAttribute() to object "[object Object\]"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to NaN] - expected: FAIL - - [a.referrerPolicy: setAttribute() to Infinity] - expected: FAIL - - [a.referrerPolicy: setAttribute() to -Infinity] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "\\0"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to null] - expected: FAIL - - [a.referrerPolicy: setAttribute() to object "test-toString"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to object "test-valueOf"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "no-referrer"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "xno-referrer"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "no-referrer\\0"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "o-referrer"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "NO-REFERRER"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "no-referrer-when-downgrade"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "xno-referrer-when-downgrade"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "no-referrer-when-downgrade\\0"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "o-referrer-when-downgrade"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "NO-REFERRER-WHEN-DOWNGRADE"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "same-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "xsame-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "same-origin\\0"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "ame-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "SAME-ORIGIN"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "ſame-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "xorigin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "origin\\0"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "rigin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "ORIGIN"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "strict-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "xstrict-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "strict-origin\\0"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "trict-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "STRICT-ORIGIN"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "ſtrict-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "origin-when-cross-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "xorigin-when-cross-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "origin-when-cross-origin\\0"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "rigin-when-cross-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "ORIGIN-WHEN-CROSS-ORIGIN"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "origin-when-croſſ-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "strict-origin-when-cross-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "xstrict-origin-when-cross-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "strict-origin-when-cross-origin\\0"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "trict-origin-when-cross-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "STRICT-ORIGIN-WHEN-CROSS-ORIGIN"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "ſtrict-origin-when-croſſ-origin"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "unsafe-url"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "xunsafe-url"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "unsafe-url\\0"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "nsafe-url"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "UNSAFE-URL"] - expected: FAIL - - [a.referrerPolicy: setAttribute() to "unſafe-url"] - expected: FAIL - - [a.referrerPolicy: IDL set to ""] - expected: FAIL - - [a.referrerPolicy: IDL set to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo "] - expected: FAIL - - [a.referrerPolicy: IDL set to undefined] - expected: FAIL - - [a.referrerPolicy: IDL set to 7] - expected: FAIL - - [a.referrerPolicy: IDL set to 1.5] - expected: FAIL - - [a.referrerPolicy: IDL set to "5%"] - expected: FAIL - - [a.referrerPolicy: IDL set to "+100"] - expected: FAIL - - [a.referrerPolicy: IDL set to ".5"] - expected: FAIL - - [a.referrerPolicy: IDL set to true] - expected: FAIL - - [a.referrerPolicy: IDL set to false] - expected: FAIL - - [a.referrerPolicy: IDL set to object "[object Object\]"] - expected: FAIL - - [a.referrerPolicy: IDL set to NaN] - expected: FAIL - - [a.referrerPolicy: IDL set to Infinity] - expected: FAIL - - [a.referrerPolicy: IDL set to -Infinity] - expected: FAIL - - [a.referrerPolicy: IDL set to "\\0"] - expected: FAIL - - [a.referrerPolicy: IDL set to null] - expected: FAIL - - [a.referrerPolicy: IDL set to object "test-toString"] - expected: FAIL - - [a.referrerPolicy: IDL set to object "test-valueOf"] - expected: FAIL - - [a.referrerPolicy: IDL set to "no-referrer"] - expected: FAIL - - [a.referrerPolicy: IDL set to "xno-referrer"] - expected: FAIL - - [a.referrerPolicy: IDL set to "no-referrer\\0"] - expected: FAIL - - [a.referrerPolicy: IDL set to "o-referrer"] - expected: FAIL - - [a.referrerPolicy: IDL set to "NO-REFERRER"] - expected: FAIL - - [a.referrerPolicy: IDL set to "no-referrer-when-downgrade"] - expected: FAIL - - [a.referrerPolicy: IDL set to "xno-referrer-when-downgrade"] - expected: FAIL - - [a.referrerPolicy: IDL set to "no-referrer-when-downgrade\\0"] - expected: FAIL - - [a.referrerPolicy: IDL set to "o-referrer-when-downgrade"] - expected: FAIL - - [a.referrerPolicy: IDL set to "NO-REFERRER-WHEN-DOWNGRADE"] - expected: FAIL - - [a.referrerPolicy: IDL set to "same-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "xsame-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "same-origin\\0"] - expected: FAIL - - [a.referrerPolicy: IDL set to "ame-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "SAME-ORIGIN"] - expected: FAIL - - [a.referrerPolicy: IDL set to "ſame-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "xorigin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "origin\\0"] - expected: FAIL - - [a.referrerPolicy: IDL set to "rigin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "ORIGIN"] - expected: FAIL - - [a.referrerPolicy: IDL set to "strict-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "xstrict-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "strict-origin\\0"] - expected: FAIL - - [a.referrerPolicy: IDL set to "trict-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "STRICT-ORIGIN"] - expected: FAIL - - [a.referrerPolicy: IDL set to "ſtrict-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "origin-when-cross-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "xorigin-when-cross-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "origin-when-cross-origin\\0"] - expected: FAIL - - [a.referrerPolicy: IDL set to "rigin-when-cross-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "ORIGIN-WHEN-CROSS-ORIGIN"] - expected: FAIL - - [a.referrerPolicy: IDL set to "origin-when-croſſ-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "strict-origin-when-cross-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "xstrict-origin-when-cross-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "strict-origin-when-cross-origin\\0"] - expected: FAIL - - [a.referrerPolicy: IDL set to "trict-origin-when-cross-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "STRICT-ORIGIN-WHEN-CROSS-ORIGIN"] - expected: FAIL - - [a.referrerPolicy: IDL set to "ſtrict-origin-when-croſſ-origin"] - expected: FAIL - - [a.referrerPolicy: IDL set to "unsafe-url"] - expected: FAIL - - [a.referrerPolicy: IDL set to "xunsafe-url"] - expected: FAIL - - [a.referrerPolicy: IDL set to "unsafe-url\\0"] - expected: FAIL - - [a.referrerPolicy: IDL set to "nsafe-url"] - expected: FAIL - - [a.referrerPolicy: IDL set to "UNSAFE-URL"] - expected: FAIL - - [a.referrerPolicy: IDL set to "unſafe-url"] - expected: FAIL - [a.charset: typeof IDL attribute] expected: FAIL diff --git a/tests/wpt/meta/referrer-policy/generic/subresource-test/attr-referrer-invalid-value.html.ini b/tests/wpt/meta/referrer-policy/generic/subresource-test/attr-referrer-invalid-value.html.ini deleted file mode 100644 index fa53551a988..00000000000 --- a/tests/wpt/meta/referrer-policy/generic/subresource-test/attr-referrer-invalid-value.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[attr-referrer-invalid-value.html] - [Invalid referrerpolicy values not reflected] - expected: FAIL