mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Added referrerpolicy as relevant mutation for img
This fixes #26388. referrerPolicy is now calls onload for image mutations. Not all referrerPolicy attribute changes result in an image update event. Only valid changes are reflected. Referrerpolicy tests now pass.
This commit is contained in:
parent
0b05b5ed87
commit
f44c2c9bc5
6 changed files with 58 additions and 54 deletions
|
@ -126,6 +126,22 @@ pub enum ReferrerPolicy {
|
|||
StrictOriginWhenCrossOrigin,
|
||||
}
|
||||
|
||||
impl ToString for ReferrerPolicy {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
ReferrerPolicy::NoReferrer => "no-referrer",
|
||||
ReferrerPolicy::NoReferrerWhenDowngrade => "no-referrer-when-downgrade",
|
||||
ReferrerPolicy::Origin => "origin",
|
||||
ReferrerPolicy::SameOrigin => "same-origin",
|
||||
ReferrerPolicy::OriginWhenCrossOrigin => "origin-when-cross-origin",
|
||||
ReferrerPolicy::UnsafeUrl => "unsafe-url",
|
||||
ReferrerPolicy::StrictOrigin => "strict-origin",
|
||||
ReferrerPolicy::StrictOriginWhenCrossOrigin => "strict-origin-when-cross-origin",
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ReferrerPolicyHeader> for ReferrerPolicy {
|
||||
fn from(policy: ReferrerPolicyHeader) -> Self {
|
||||
match policy {
|
||||
|
|
|
@ -18,7 +18,7 @@ use crate::dom::bindings::refcounted::Trusted;
|
|||
use crate::dom::bindings::reflector::DomObject;
|
||||
use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
|
||||
use crate::dom::bindings::str::{DOMString, USVString};
|
||||
use crate::dom::document::Document;
|
||||
use crate::dom::document::{determine_policy_for_token, Document};
|
||||
use crate::dom::element::{cors_setting_for_element, referrer_policy_for_element};
|
||||
use crate::dom::element::{reflect_cross_origin_attribute, set_cross_origin_attribute};
|
||||
use crate::dom::element::{
|
||||
|
@ -1420,6 +1420,21 @@ pub fn parse_a_sizes_attribute(value: DOMString) -> SourceSizeList {
|
|||
SourceSizeList::parse(&context, &mut parser)
|
||||
}
|
||||
|
||||
fn get_correct_referrerpolicy_from_raw_token(token: &DOMString) -> DOMString {
|
||||
if token == "" {
|
||||
// Empty token is treated as no-referrer inside determine_policy_for_token,
|
||||
// while here it should be treated as the default value, so it should remain unchanged.
|
||||
DOMString::new()
|
||||
} else {
|
||||
match determine_policy_for_token(token) {
|
||||
Some(policy) => DOMString::from_string(policy.to_string()),
|
||||
// If the policy is set to an incorrect value, then it should be
|
||||
// treated as an invalid value default (empty string).
|
||||
None => DOMString::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLImageElementMethods for HTMLImageElement {
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-alt
|
||||
make_getter!(Alt, "alt");
|
||||
|
@ -1542,6 +1557,28 @@ impl HTMLImageElementMethods for HTMLImageElement {
|
|||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-referrerpolicy
|
||||
fn ReferrerPolicy(&self) -> DOMString {
|
||||
let element = self.upcast::<Element>();
|
||||
let current_policy_value = element.get_string_attribute(&local_name!("referrerpolicy"));
|
||||
get_correct_referrerpolicy_from_raw_token(¤t_policy_value)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-referrerpolicy
|
||||
fn SetReferrerPolicy(&self, value: DOMString) {
|
||||
let referrerpolicy_attr_name = local_name!("referrerpolicy");
|
||||
let element = self.upcast::<Element>();
|
||||
let previous_correct_attribute_value = get_correct_referrerpolicy_from_raw_token(
|
||||
&element.get_string_attribute(&referrerpolicy_attr_name),
|
||||
);
|
||||
let correct_value_or_empty_string = get_correct_referrerpolicy_from_raw_token(&value);
|
||||
if previous_correct_attribute_value != correct_value_or_empty_string {
|
||||
// Setting the attribute to the same value will update the image.
|
||||
// We don't want to start an update if referrerpolicy is set to the same value.
|
||||
element.set_string_attribute(&referrerpolicy_attr_name, correct_value_or_empty_string);
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-name
|
||||
make_getter!(Name, "name");
|
||||
|
||||
|
@ -1596,7 +1633,8 @@ impl VirtualMethods for HTMLImageElement {
|
|||
&local_name!("srcset") |
|
||||
&local_name!("width") |
|
||||
&local_name!("crossorigin") |
|
||||
&local_name!("sizes") => self.update_the_image_data(),
|
||||
&local_name!("sizes") |
|
||||
&local_name!("referrerpolicy") => self.update_the_image_data(),
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ interface HTMLImageElement : HTMLElement {
|
|||
readonly attribute unsigned long naturalHeight;
|
||||
readonly attribute boolean complete;
|
||||
readonly attribute USVString currentSrc;
|
||||
[CEReactions]
|
||||
attribute DOMString referrerPolicy;
|
||||
// also has obsolete members
|
||||
};
|
||||
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
[HTMLImageElement.html]
|
||||
[referrerPolicy on HTMLImageElement must enqueue an attributeChanged reaction when replacing an existing attribute]
|
||||
expected: FAIL
|
||||
|
||||
[referrerPolicy on HTMLImageElement must enqueue an attributeChanged reaction when adding a new attribute]
|
||||
expected: FAIL
|
||||
|
||||
[decoding on HTMLImageElement must enqueue an attributeChanged reaction when replacing an existing attribute]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -2700,9 +2700,6 @@
|
|||
[HTMLInputElement interface: createInput("radio") must inherit property "height" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLImageElement interface: document.createElement("img") must inherit property "referrerPolicy" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLDialogElement interface: operation showModal()]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -3042,9 +3039,6 @@
|
|||
[HTMLLinkElement interface: document.createElement("link") must inherit property "imageSizes" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLImageElement interface: attribute referrerPolicy]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("time") must inherit property "align" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -3273,9 +3267,6 @@
|
|||
[HTMLObjectElement interface: attribute width]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLImageElement interface: new Image() must inherit property "referrerPolicy" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLObjectElement interface: operation getSVGDocument()]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -29,40 +29,3 @@
|
|||
|
||||
[picture is inserted; img has src]
|
||||
expected: FAIL
|
||||
|
||||
[referrerpolicy no-referrer-when-downgrade to empty, src already set]
|
||||
expected: FAIL
|
||||
|
||||
[referrerpolicy no-referrer-when-downgrade to no-referrer, src already set]
|
||||
expected: FAIL
|
||||
|
||||
[referrerpolicy absent to no-referrer-when-downgrade, src already set]
|
||||
expected: FAIL
|
||||
|
||||
[referrerpolicy no-referrer-when-downgrade to absent, src already set]
|
||||
expected: FAIL
|
||||
|
||||
[referrerpolicy no-referrer to invalid, src already set]
|
||||
expected: FAIL
|
||||
|
||||
[referrerpolicy no-referrer to no-referrer-when-downgrade, src already set]
|
||||
expected: FAIL
|
||||
|
||||
[referrerpolicy empty to no-referrer-when-downgrade, src already set]
|
||||
expected: FAIL
|
||||
|
||||
[referrerpolicy no-referrer to empty, src already set]
|
||||
expected: FAIL
|
||||
|
||||
[referrerpolicy absent to no-referrer, src already set]
|
||||
expected: FAIL
|
||||
|
||||
[referrerpolicy no-referrer-when-downgrade to invalid, src already set]
|
||||
expected: FAIL
|
||||
|
||||
[referrerpolicy no-referrer to absent, src already set]
|
||||
expected: FAIL
|
||||
|
||||
[referrerpolicy empty to no-referrer, src already set]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue