Skip to content

Commit

Permalink
Implement list of available images matching logic
Browse files Browse the repository at this point in the history
 https://bugs.webkit.org/show_bug.cgi?id=243790

Reviewed by Sihui Liu and Chris Dumez.

Implement list of available images matching logic:
https://html.spec.whatwg.org/multipage/images.html#updating-the-image-data:list-of-available-images

This is restricted to lazy loading for now.

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/image-loading-lazy-available-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/image-loading-lazy-use-list-of-available-images-expected.txt:
* Source/WebCore/loader/ImageLoader.cpp:
(WebCore::canReuseFromListOfAvailableImages):
(WebCore::ImageLoader::updateFromElement):

Canonical link: https://commits.webkit.org/269243@main
  • Loading branch information
pgorszkowski-igalia authored and Ahmad Saleem committed Oct 12, 2023
1 parent 7ca4198 commit 873115a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@



FAIL The list of available images gets checked before deciding to make a load lazy assert_equals: The list of available images should be checked before delaying the image load expected 256 but got 0
PASS The list of available images gets checked before deciding to make a load lazy

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


FAIL Lazyload images can load immediately from the list of available images promise_test: Unhandled rejection with value: object "Error: The `loading=lazy` image should load immediately from the list of available images, beating this timeout promise."
PASS Lazyload images can load immediately from the list of available images

19 changes: 18 additions & 1 deletion Source/WebCore/loader/ImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "LegacyRenderSVGImage.h"
#include "LocalFrame.h"
#include "Logging.h"
#include "MemoryCache.h"
#include "Page.h"
#include "RenderImage.h"
#include "RenderSVGImage.h"
Expand Down Expand Up @@ -110,6 +111,22 @@ static inline bool pageIsBeingDismissed(Document& document)
return frame && frame->loader().pageDismissalEventBeingDispatched() != FrameLoader::PageDismissalType::None;
}

// https://html.spec.whatwg.org/multipage/images.html#updating-the-image-data:list-of-available-images
static bool canReuseFromListOfAvailableImages(const CachedResourceRequest& request, Document& document)
{
CachedResource* resource = MemoryCache::singleton().resourceForRequest(request.resourceRequest(), document.page()->sessionID());
if (!resource || resource->stillNeedsLoad() || resource->isPreloaded())
return false;

if (resource->options().mode == FetchOptions::Mode::Cors && !document.securityOrigin().isSameOriginAs(*resource->origin()))
return false;

if (resource->options().mode != request.options().mode || resource->options().credentials != request.options().credentials)
return false;

return true;
}

ImageLoader::ImageLoader(Element& element)
: m_element(element)
, m_image(nullptr)
Expand Down Expand Up @@ -229,7 +246,7 @@ void ImageLoader::updateFromElement(RelevantMutation relevantMutation)
#endif
if (m_lazyImageLoadState == LazyImageLoadState::None && isImageElement) {
auto& imageElement = downcast<HTMLImageElement>(element());
if (imageElement.isLazyLoadable() && document.settings().lazyImageLoadingEnabled()) {
if (imageElement.isLazyLoadable() && document.settings().lazyImageLoadingEnabled() && !canReuseFromListOfAvailableImages(request, document)) {
m_lazyImageLoadState = LazyImageLoadState::Deferred;
request.setIgnoreForRequestCount(true);
}
Expand Down

0 comments on commit 873115a

Please sign in to comment.