When using SVG as an image, we should load datauri images when these images are not...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Feb 2015 20:55:21 +0000 (20:55 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Feb 2015 20:55:21 +0000 (20:55 +0000)
commit1893676ebe3b8134ecf992a59ed172fec3a3fe1f
treedad358558c9389628e366e8f9ddd31059bb88be9
parent8867d8fa45c0e8a605bd3720d2507481f317a4e0
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179626 268f45cc-cd09-0410-ab3c-d52691b4dbfc
27 files changed:
LayoutTests/ChangeLog
LayoutTests/svg/as-image/resources/image-with-nested-data-uri-images.svg [new file with mode: 0644]
LayoutTests/svg/as-image/resources/image-with-nested-rects.svg [new file with mode: 0644]
LayoutTests/svg/as-image/svg-image-with-data-uri-background-expected.html [new file with mode: 0644]
LayoutTests/svg/as-image/svg-image-with-data-uri-background.html [new file with mode: 0644]
LayoutTests/svg/as-image/svg-image-with-data-uri-from-canvas-expected.html [new file with mode: 0644]
LayoutTests/svg/as-image/svg-image-with-data-uri-from-canvas.html [new file with mode: 0644]
LayoutTests/svg/as-image/svg-image-with-data-uri-images-disabled-expected.html [new file with mode: 0644]
LayoutTests/svg/as-image/svg-image-with-data-uri-images-disabled.html [new file with mode: 0644]
LayoutTests/svg/as-image/svg-image-with-data-uri-reloading-expected.html [new file with mode: 0644]
LayoutTests/svg/as-image/svg-image-with-data-uri-reloading.html [new file with mode: 0644]
LayoutTests/svg/as-image/svg-image-with-data-uri-use-data-uri-expected.svg [new file with mode: 0644]
LayoutTests/svg/as-image/svg-image-with-data-uri-use-data-uri.svg [new file with mode: 0644]
LayoutTests/svg/as-image/svg-image-with-svg-data-uri-expected.html [new file with mode: 0644]
LayoutTests/svg/as-image/svg-image-with-svg-data-uri.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/loader/FrameLoaderClient.h
Source/WebCore/loader/ResourceLoader.cpp
Source/WebCore/loader/ResourceLoader.h
Source/WebCore/loader/cache/CachedImage.cpp
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/CachedResourceLoader.h
Source/WebCore/svg/graphics/SVGImage.cpp
Source/WebCore/svg/graphics/SVGImage.h
Source/WebCore/svg/graphics/SVGImageClients.h [moved from Source/WebCore/svg/graphics/SVGImageChromeClient.h with 80% similarity]