Branch: refs/heads/main Home: https://github.com/WebKit/WebKit Commit: 408858f600d2b7aafb86848018a1b8858f8dfd17 https://github.com/WebKit/WebKit/commit/408858f600d2b7aafb86848018a1b8858f8dfd17 Author: Wenson Hsieh <wenson_hs...@apple.com> Date: 2024-04-02 (Tue, 02 Apr 2024)
Changed paths: M Source/WebCore/html/HTMLImageElement.cpp M Source/WebCore/html/parser/HTMLSrcsetParser.cpp M Source/WebCore/html/parser/HTMLSrcsetParser.h M Source/WebCore/loader/DocumentLoader.h M Source/WebCore/loader/ImageLoader.cpp M Source/WebCore/loader/ImageLoader.h M Tools/TestWebKitAPI/Tests/mac/LoadWebArchive.mm M Tools/TestWebKitAPI/cocoa/TestWKWebView.h M Tools/TestWebKitAPI/cocoa/TestWKWebView.mm Log Message: ----------- QuickLook sometimes shows broken images for image sources when loading web archives https://bugs.webkit.org/show_bug.cgi?id=272005 rdar://123918480 Reviewed by Sihui Liu. When previewing web archives, QuickLook (more precisely, `QLPreviewController`) loads the archive data in a `WKWebView` that is configured to have an empty set of `_allowedNetworkHosts` (thereby preventing network access when loading the archive). While this is a perfectly reasonable behavior for the purposes of loading web archives, it exposes an issue when rendering images with sources specified via the `srcset` attribute — if the "best fit" chosen for the image in QuickLook's web view isn't the same source as the one that was chosen when creating the web archive, we end up with a broken image since the selected source isn't present in the web archive, and we also can't download it over the network. Since everything from viewport/screen dimensions to the device scale factor can influence this, we can end up with broken images when copying images with `srcset`s in many cases. To mitigate this, we add some logic to detect when image sources are unavailable when loading web archives (*and* we're additionally not allowed to fetch them from over the internet), and avoid surfacing these image sources as potential candidates when selecting the best fit. See below for more details. Test: LoadWebArchive.PreferCachedImageSourceOverBrokenImage * Source/WebCore/html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::bestFitSourceFromPictureElement): (WebCore::HTMLImageElement::selectImageSource): Pass the new filtering function (using `ImageLoader::shouldIgnoreCandidateWhenLoadingFromArchive` below) into `bestFitSourceForImageAttributes`. * Source/WebCore/html/parser/HTMLSrcsetParser.cpp: (WebCore::bestFitSourceForImageAttributes): Add a new optional filtering function that takes an `ImageCandidate` and returns whether or not we can even attempt to load the candidate; for now, this is `false` only in the case where we're loading archived resources, and we're not allowed to load the URL over the network. * Source/WebCore/html/parser/HTMLSrcsetParser.h: (WebCore::bestFitSourceForImageAttributes): * Source/WebCore/loader/DocumentLoader.h: (WebCore::DocumentLoader::hasArchiveResourceCollection const): Add a new helper function, which we can use to bail early in `ImageLoader::shouldIgnoreCandidateWhenLoadingFromArchive`, to avoid eagerly parsing all URLs in the `srcset`. * Source/WebCore/loader/ImageLoader.cpp: (WebCore::ImageLoader::shouldIgnoreCandidateWhenLoadingFromArchive const): * Source/WebCore/loader/ImageLoader.h: * Tools/TestWebKitAPI/Tests/mac/LoadWebArchive.mm: (TestWebKitAPI::TEST(LoadWebArchive, PreferCachedImageSourceOverBrokenImage)): Add a new API test to exercise the change, by loading a web archive from a web view at 1x device pixel scale that contains an image with a `srcset`, and loading the archive in another web view at 2x scale. Before the changes in this patch, this results in a broken image. * Tools/TestWebKitAPI/cocoa/TestWKWebView.h: * Tools/TestWebKitAPI/cocoa/TestWKWebView.mm: (-[WKWebView contentsAsWebArchive]): Canonical link: https://commits.webkit.org/276952@main To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications _______________________________________________ webkit-changes mailing list webkit-changes@lists.webkit.org https://lists.webkit.org/mailman/listinfo/webkit-changes