|
42 | 42 | #include "InspectorInstrumentation.h" |
43 | 43 | #include "JSDOMPromiseDeferred.h" |
44 | 44 | #include "LazyLoadImageObserver.h" |
| 45 | +#include "MemoryCache.h" |
45 | 46 | #include "Page.h" |
46 | 47 | #include "RenderImage.h" |
47 | 48 | #include "RenderSVGImage.h" |
@@ -97,6 +98,22 @@ static inline bool pageIsBeingDismissed(Document& document) |
97 | 98 | return frame && frame->loader().pageDismissalEventBeingDispatched() != FrameLoader::PageDismissalType::None; |
98 | 99 | } |
99 | 100 |
|
| 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 | + |
100 | 117 | ImageLoader::ImageLoader(Element& element) |
101 | 118 | : m_element(element) |
102 | 119 | , m_image(nullptr) |
@@ -214,7 +231,7 @@ void ImageLoader::updateFromElement(RelevantMutation relevantMutation) |
214 | 231 | } else { |
215 | 232 | if (m_lazyImageLoadState == LazyImageLoadState::None && isImageElement) { |
216 | 233 | auto& imageElement = downcast<HTMLImageElement>(element()); |
217 | | - if (imageElement.isLazyLoadable() && document.lazyImageLoadingEnabled()) { |
| 234 | + if (imageElement.isLazyLoadable() && document.lazyImageLoadingEnabled() && !canReuseFromListOfAvailableImages(request, document)) { |
218 | 235 | m_lazyImageLoadState = LazyImageLoadState::Deferred; |
219 | 236 | request.setIgnoreForRequestCount(true); |
220 | 237 | } |
|
0 commit comments