Commit c69a0d7c authored by Dominic Farolino's avatar Dominic Farolino Committed by Commit Bot

Image Loading: `crossorigin` mutations should queue a microtask

This CL makes HTMLImageElement aware of `crossorigin` attribute value
mutations, and respond by invoking ImageLoader::UpdateFromElement if
the attribute's state changes. This queues a microtask to finish the
image loading steps.

This change does not influence the crossorigin attribute state used to
influence any image request, because the crossorigin attribute state
used to configure image requests (in blink::ConfigureRequest) is already
referring to the element's latest. Instead, this change simply invokes
ImageLoader::UpdateFromElement (enqueueing an ImageLoader::Task
microtask) when an image's crossorigin attribute state changes, even
after an image has been fetched.

This makes our implementation of the HTML Standard's image element's
relevant mutations [1] more compliant, passing more relevant mutations
web-platform-tests. See also [2].

[1]: https://html.spec.whatwg.org/multipage/images.html#relevant-mutations
[2]: https://docs.google.com/document/d/1Xp34FIbbZnJILl0PNd1sfs_3z1HSriUVyRUgnAesGZk/

Bug: 384251,774706,1061685
Change-Id: I11e66800309df96aea61226932b9aa40c3cc5d27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2102992
Commit-Queue: Dominic Farolino <dom@chromium.org>
Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750885}
parent d24a1835
......@@ -39,6 +39,7 @@
#include "third_party/blink/renderer/core/frame/deprecation.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h"
#include "third_party/blink/renderer/core/html/cross_origin_attribute.h"
#include "third_party/blink/renderer/core/html/forms/form_associated.h"
#include "third_party/blink/renderer/core/html/forms/html_form_element.h"
#include "third_party/blink/renderer/core/html/html_dimension.h"
......@@ -288,6 +289,24 @@ void HTMLImageElement::ParseAttribute(
// |importance| attribute to the loading pipeline takes place in
// ImageLoader.
UseCounter::Count(GetDocument(), WebFeature::kPriorityHints);
} else if (name == html_names::kCrossoriginAttr) {
// As per an image's relevant mutations [1], we must queue a new loading
// microtask when the `crossorigin` attribute state has changed. Note that
// the attribute value can change without the attribute state changing [2].
//
// [1]:
// https://html.spec.whatwg.org/multipage/images.html#relevant-mutations
// [2]: https://github.com/whatwg/html/issues/4533#issuecomment-483417499
CrossOriginAttributeValue new_crossorigin_state =
GetCrossOriginAttributeValue(params.new_value);
CrossOriginAttributeValue old_crossorigin_state =
GetCrossOriginAttributeValue(params.old_value);
if (new_crossorigin_state != old_crossorigin_state) {
// Update the current state so we can detect future state changes.
GetImageLoader().UpdateFromElement(
ImageLoader::kUpdateIgnorePreviousError, referrer_policy_);
}
} else {
HTMLElement::ParseAttribute(params);
}
......
This is a testharness.js-based test.
Found 81 tests; 64 PASS, 17 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 81 tests; 74 PASS, 7 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS src set
PASS src changed
PASS src removed
......@@ -20,16 +20,16 @@ PASS crossorigin anonymous to use-credentials, src absent
PASS crossorigin use-credentials to absent, src absent
PASS crossorigin use-credentials to empty, src absent
PASS crossorigin use-credentials to anonymous, src absent
FAIL crossorigin absent to empty, src already set assert_unreached: update the image data didn't run Reached unreachable code
FAIL crossorigin absent to anonymous, src already set assert_unreached: update the image data didn't run Reached unreachable code
FAIL crossorigin absent to use-credentials, src already set assert_unreached: update the image data didn't run Reached unreachable code
FAIL crossorigin empty to absent, src already set assert_unreached: update the image data didn't run Reached unreachable code
FAIL crossorigin empty to use-credentials, src already set assert_unreached: update the image data didn't run Reached unreachable code
FAIL crossorigin anonymous to absent, src already set assert_unreached: update the image data didn't run Reached unreachable code
FAIL crossorigin anonymous to use-credentials, src already set assert_unreached: update the image data didn't run Reached unreachable code
FAIL crossorigin use-credentials to absent, src already set assert_unreached: update the image data didn't run Reached unreachable code
FAIL crossorigin use-credentials to empty, src already set assert_unreached: update the image data didn't run Reached unreachable code
FAIL crossorigin use-credentials to anonymous, src already set assert_unreached: update the image data didn't run Reached unreachable code
PASS crossorigin absent to empty, src already set
PASS crossorigin absent to anonymous, src already set
PASS crossorigin absent to use-credentials, src already set
PASS crossorigin empty to absent, src already set
PASS crossorigin empty to use-credentials, src already set
PASS crossorigin anonymous to absent, src already set
PASS crossorigin anonymous to use-credentials, src already set
PASS crossorigin use-credentials to absent, src already set
PASS crossorigin use-credentials to empty, src already set
PASS crossorigin use-credentials to anonymous, src already set
FAIL inserted into picture assert_unreached: update the image data didn't run Reached unreachable code
FAIL removed from picture assert_unreached: update the image data didn't run Reached unreachable code
PASS parent is picture, previous source inserted
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment