[CG] PostScript images should be supported if they are sub-resource images
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Nov 2017 23:09:42 +0000 (23:09 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Nov 2017 23:09:42 +0000 (23:09 +0000)
commitdc779672dadfcdc36acc57f3df4f939db18e0374
tree9d46a5d9c5be414c69b06c284a7658b3eb105f5d
parent28c65c5ba430803da975e88fa3b0427bf348e203
[CG] PostScript images should be supported if they are sub-resource images
https://bugs.webkit.org/show_bug.cgi?id=178502
Source/WebCore:

<rdar://problem/35102988>

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2017-11-28
Reviewed by Simon Fraser.

Make CachedImage detect the PostScript mime type and the file extension.
Let PDFDocumentImage replaces the PostScript data with the equivalent PDF
data and use it when creating the PDFDocument.

Test: fast/images/eps-as-image.html

* WebCore.xcodeproj/project.pbxproj:
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::isPDFRequest const):
(WebCore::CachedImage::isPostScriptRequest const):
These functions return whether the request is for a PDF or a PostScript
image. They check for the same conditions we do in WebPage::createPlugin().

(WebCore::CachedImage::createImage): Create a PDFDocumentImage for either
a PDF or a PostScript image. For PostScript, the data will be converted
to PDF when all the data is received.

(WebCore::CachedImage::updateBufferInternal): Use the size() of m_data
instead of using the m_image->data() to setEncodedSize(). Image::m_data
and CachedImage::m_data point to the same SharedBuffer.

(WebCore::CachedImage::convertedDataIfNeeded const): Convert the PostScript
data to PDF if the system can convert it. If the same can't convert it,
return null so loading the image will be canceled.

(WebCore::CachedImage::updateImageData): Get rid of the data argument since
we always send the member m_data to this function.

(WebCore::CachedImage::finishLoading): Convert the PostScript data to PDF
data since all the data is received. Use m_data to set setEncodedSize().

* loader/cache/CachedImage.h:
* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::isPostScriptMIMEType):
(WebCore::MIMETypeRegistry::isPDFOrPostScriptMIMEType):
* platform/MIMETypeRegistry.h:
* platform/graphics/cg/PDFDocumentImage.cpp:
(WebCore::PDFDocumentImage::PDFDocumentImage):
(WebCore::PDFDocumentImage::convertPostScriptDataToPDF):
* platform/graphics/cg/PDFDocumentImage.h:

Source/WebKit:

<rdar://problem/35102988>

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2017-11-28
Reviewed by Simon Fraser.

Make convertPostScriptDataToPDF() be as static function of PDFDocumentImage
in WebCore.

* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::convertPostScriptDataIfNeeded):
(WebKit::convertPostScriptDataToPDF): Deleted.

LayoutTests:

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2017-11-28
Reviewed by Simon Fraser.

* TestExpectations:
* fast/images/eps-as-image-expected.html: Added.
* fast/images/eps-as-image.html: Added.
* fast/images/resources/green-100x100.eps: Added.
* platform/mac/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225241 268f45cc-cd09-0410-ab3c-d52691b4dbfc
16 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/images/eps-as-image-expected.html [new file with mode: 0644]
LayoutTests/fast/images/eps-as-image.html [new file with mode: 0644]
LayoutTests/fast/images/resources/green-100x100.eps [new file with mode: 0644]
LayoutTests/platform/mac/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/loader/cache/CachedImage.cpp
Source/WebCore/loader/cache/CachedImage.h
Source/WebCore/platform/MIMETypeRegistry.cpp
Source/WebCore/platform/MIMETypeRegistry.h
Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp
Source/WebCore/platform/graphics/cg/PDFDocumentImage.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm