haikuwebkit/LayoutTests/svg/as-image/svg-image-with-data-uri-bac...

17 lines
250 B
HTML
Raw Permalink Normal View History

When using SVG as an image, we should load datauri images when these images are not in the image cache. https://bugs.webkit.org/show_bug.cgi?id=99677. Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2015-02-04 Reviewed by Darin Adler. Source/WebCore: Data URI sub-resources are not loaded because the networking context of FrameLoader attached to the SubResourceLoader is set to null. This is done intentionally to disallow any resource from loading external sub-resources. For example if an <img> tag has its 'src' attribute points to an svg file, this svg is not allowed to load an external image through the 'xlink' attribute of an <image> element. This restriction is not valid if the value of the 'xlink' attribute is a data URI. In this case the image should be loaded into memory since there is no network traffic involved. All we need to do is to decode the data part of the URI. The fix is to pass the root FrameLoader, which has a valid NetworkingContext, through the FrameLoaderClient, to the ResourceHandle::create() which uses the NetworkingContext to decode the data and fire the load events of the data URI resources. Tests: svg/as-image/svg-image-with-data-uri-background.html svg/as-image/svg-image-with-data-uri-from-canvas.html svg/as-image/svg-image-with-data-uri-images-disabled.html svg/as-image/svg-image-with-data-uri-reloading.html svg/as-image/svg-image-with-data-uri-use-data-uri.svg svg/as-image/svg-image-with-svg-data-uri.html * accessibility/AccessibilityRenderObject.cpp: Remove unreferenced header file. * loader/FrameLoaderClient.h: Define the null virtual function dataProtocolLoader() which should return the FrameLoader for loading data URI resources. * loader/ResourceLoader.cpp: (WebCore::ResourceLoader::start): (WebCore::ResourceLoader::dataProtocolFrameLoader): * loader/ResourceLoader.h: Add ResourceLoader::dataProtocolFrameLoader() which returns the root FrameLoader. The root FrameLoader is used to get a valid NetworkingContext which can be passed to ResourceHandle::create() when url().protocolIsData(). * loader/cache/CachedImage.cpp: (WebCore::CachedImage::load): (WebCore::CachedImage::finishLoading): * loader/cache/CachedResourceLoader.cpp: (WebCore::CachedResourceLoader::shouldPerformImageLoad): (WebCore::CachedResourceLoader::shouldDeferImageLoad): * loader/cache/CachedResourceLoader.h: Allow loading data URI sub-resources as long as loading images is not disabled. Also we need to call setDataProtocolLoader() before calling setData() for the isSVGImage case, setData() will create a page by calling Page::createPageFromBuffer() via SVGImage::dataChanged(), and we need to pass the correct FrameLoaderClient to the created FrameLoader of the main frame of this page. * svg/graphics/SVGImage.cpp: (WebCore::SVGImage::SVGImage): (WebCore::SVGImage::dataChanged): * svg/graphics/SVGImage.h: Create a new FrameLoaderClient of type SVGFrameLoaderClient and set it in pageConfiguration which is used when creating the page from the SVG data URI. * WebCore.xcodeproj/project.pbxproj: * svg/graphics/SVGImageChromeClient.h: Removed. * svg/graphics/SVGImageClients.h: Added. Add a new class SVGImageChromeClient which overrides the function dataProtocolLoader(). Rename the header file SVGImageChromeClient.h to be SVGImageClients.h since it now includes the classes SVGImageChromeClient and SVGFrameLoaderClient. LayoutTests: * svg/as-image/resources/image-with-nested-data-uri-images.svg: Added. This SVG has a tree of depth = 5 of nested data URI images. All the data URI images are SVG images expect the innermost one which is a png data URI image. * svg/as-image/resources/image-with-nested-rects.svg: Added. This SVG produces the same drawing as image-with-nested-data-uri-images.svg does but it uses <rect> SVG elements instead. * svg/as-image/svg-image-with-data-uri-background-expected.html: Added. * svg/as-image/svg-image-with-data-uri-background.html: Added. Test the data URI SVG as a css background image. * svg/as-image/svg-image-with-data-uri-from-canvas-expected.html: Added. * svg/as-image/svg-image-with-data-uri-from-canvas.html: Added. Test the data URI image when it is the result of drawing an SVG image on a canvas object. * svg/as-image/svg-image-with-data-uri-images-disabled-expected.html: Added. * svg/as-image/svg-image-with-data-uri-images-disabled.html: Added. Ensure the data uri images are not loaded if imagesEnabled is turned off. * svg/as-image/svg-image-with-data-uri-reloading-expected.html: Added. * svg/as-image/svg-image-with-data-uri-reloading.html: Added. Test the data URI SVG when reloading the page. * svg/as-image/svg-image-with-data-uri-use-data-uri-expected.svg: Added. * svg/as-image/svg-image-with-data-uri-use-data-uri.svg: Added. Test the data URI image when it is referenced from an SVG <use> tag. * svg/as-image/svg-image-with-svg-data-uri-expected.html: Added. * svg/as-image/svg-image-with-svg-data-uri.html: Added. Test the data URI image when it is referenced from an HTML <img> tag. Canonical link: https://commits.webkit.org/159272@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179626 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-04 20:55:21 +00:00
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 200px;
height: 200px;
background-color:red;
background-image:url("resources/image-with-nested-rects.svg");
}
</style>
</head>
<body>
<div></div>
</body>
</html>