Skip to content

Commit 9ca878f

Browse files
authored
Merge pull request #1209 from WebPlatformForEmbedded/pgorszkowski/2.38/Implement-list-of-available-images-matching-logic
Implement list of available images matching logic
2 parents c613c9a + 7162fb4 commit 9ca878f

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22

33

4-
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
4+
PASS The list of available images gets checked before deciding to make a load lazy
55

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22

3-
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."
3+
PASS Lazyload images can load immediately from the list of available images
44

Source/WebCore/loader/ImageLoader.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "InspectorInstrumentation.h"
4343
#include "JSDOMPromiseDeferred.h"
4444
#include "LazyLoadImageObserver.h"
45+
#include "MemoryCache.h"
4546
#include "Page.h"
4647
#include "RenderImage.h"
4748
#include "RenderSVGImage.h"
@@ -97,6 +98,22 @@ static inline bool pageIsBeingDismissed(Document& document)
9798
return frame && frame->loader().pageDismissalEventBeingDispatched() != FrameLoader::PageDismissalType::None;
9899
}
99100

101+
// https://html.spec.whatwg.org/multipage/images.html#updating-the-image-data:list-of-available-images
102+
static bool canReuseFromListOfAvailableImages(const CachedResourceRequest& request, Document& document)
103+
{
104+
CachedResource* resource = MemoryCache::singleton().resourceForRequest(request.resourceRequest(), document.page()->sessionID());
105+
if (!resource || resource->stillNeedsLoad() || resource->isPreloaded())
106+
return false;
107+
108+
if (resource->options().mode == FetchOptions::Mode::Cors && !document.securityOrigin().isSameOriginAs(*resource->origin()))
109+
return false;
110+
111+
if (resource->options().mode != request.options().mode || resource->options().credentials != request.options().credentials)
112+
return false;
113+
114+
return true;
115+
}
116+
100117
ImageLoader::ImageLoader(Element& element)
101118
: m_element(element)
102119
, m_image(nullptr)
@@ -214,7 +231,7 @@ void ImageLoader::updateFromElement(RelevantMutation relevantMutation)
214231
} else {
215232
if (m_lazyImageLoadState == LazyImageLoadState::None && isImageElement) {
216233
auto& imageElement = downcast<HTMLImageElement>(element());
217-
if (imageElement.isLazyLoadable() && document.lazyImageLoadingEnabled()) {
234+
if (imageElement.isLazyLoadable() && document.lazyImageLoadingEnabled() && !canReuseFromListOfAvailableImages(request, document)) {
218235
m_lazyImageLoadState = LazyImageLoadState::Deferred;
219236
request.setIgnoreForRequestCount(true);
220237
}

0 commit comments

Comments
 (0)