Bug 178502

Summary: [CG] PostScript images should be supported if they are sub-resource images
Product: WebKit Reporter: Said Abou-Hallawa <sabouhallawa>
Component: ImagesAssignee: Said Abou-Hallawa <sabouhallawa>
Status: RESOLVED FIXED    
Severity: Normal CC: buildbot, cdumez, commit-queue, dbates, japhet, sam, simon.fraser, thorton, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=180104
https://bugs.webkit.org/show_bug.cgi?id=184161
Attachments:
Description Flags
green-100x100.eps
none
green-100x100.html
none
Patch
none
Patch
none
Patch
none
Archive of layout-test-results from ews123 for ios-simulator-wk2
none
Patch
none
Archive of layout-test-results from ews123 for ios-simulator-wk2
none
Patch
none
Patch
none
Archive of layout-test-results from ews121 for ios-simulator-wk2
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Said Abou-Hallawa 2017-10-18 19:28:14 PDT
1. Open the attached EPS image green-100x100.esp

Result: A 100x100 green rectangle is displayed.

2. Open the attached HTML page green-100x100.html

Result: A broken image is displayed.

The PostScript images are detected and converted to images PDF when they are the main resources. When they are sub-resources, WebKit tries to decode them as if they were binary images.
Comment 1 Said Abou-Hallawa 2017-10-18 19:29:42 PDT
Created attachment 324198 [details]
green-100x100.eps
Comment 2 Said Abou-Hallawa 2017-10-18 19:32:05 PDT
Created attachment 324199 [details]
green-100x100.html
Comment 3 Said Abou-Hallawa 2017-10-18 19:43:47 PDT
Created attachment 324201 [details]
Patch
Comment 4 Said Abou-Hallawa 2017-10-18 19:44:58 PDT
<rdar://problem/35000589>
Comment 5 Sam Weinig 2017-10-19 05:59:25 PDT
Comment on attachment 324201 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=324201&action=review

> Source/WebCore/ChangeLog:10
> +        Let PDFDocumentImage replaces the PostScript data with the equivalent PDF
> +        data and use it when creating the PDFDocument.

Why are we doing this conversion? Is it because ImageIO doesn't support PostScript directly?

> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:374
> +    CGPSConverterCallbacks callbacks = { 0, 0, 0, 0, 0, 0, 0, 0 };
> +    RetainPtr<CGPSConverterRef> converter = adoptCF(CGPSConverterCreate(0, &callbacks, 0));
> +    RetainPtr<CGDataProviderRef> provider = adoptCF(CGDataProviderCreateWithCFData(postScriptData.get()));
> +    RetainPtr<CFMutableDataRef> pdfData = adoptCF(CFDataCreateMutable(kCFAllocatorDefault, 0));
> +    RetainPtr<CGDataConsumerRef> consumer = adoptCF(CGDataConsumerCreateWithCFData(pdfData.get()));

Thes should use auto.

> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:376
> +    CGPSConverterConvert(converter.get(), provider.get(), consumer.get(), 0);

Is this operation expensive?  Should we be doing it on a background thread, asynchronously?  What happens with a really big PostScript file?

> Source/WebCore/platform/graphics/cg/PDFDocumentImage.h:51
> +    static Ref<PDFDocumentImage> create(ImageObserver* observer, bool isPostScript = false)

I think this would be clearer as an enum:

enum class Type {
    PDF,
    PostScript
};
Comment 6 Tim Horton 2017-10-19 10:37:30 PDT
Comment on attachment 324201 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=324201&action=review

> LayoutTests/fast/images/resources/green-100x100.eps:1
> +%!PS-Adobe-3.0 EPSF-3.0

This is an insanely overcomplicated EPS, I emailed you a better (<200byte) one.
Comment 7 Said Abou-Hallawa 2017-10-19 13:33:14 PDT
Created attachment 324276 [details]
Patch
Comment 8 Build Bot 2017-10-19 13:35:06 PDT
Attachment 324276 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/graphics/cg/PDFDocumentImage.h:52:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 1 in 14 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Said Abou-Hallawa 2017-10-19 13:40:25 PDT
Comment on attachment 324201 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=324201&action=review

>> Source/WebCore/ChangeLog:10
>> +        data and use it when creating the PDFDocument.
> 
> Why are we doing this conversion? Is it because ImageIO doesn't support PostScript directly?

Yes ImageIO handles only the bitmap images. SVG is handled completely by WebKit. PDF is handled by the PDFKit. So the easiest way to have PostScript handled was to convert it to PDF and let PDFKit render it.

>> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:374
>> +    RetainPtr<CGDataConsumerRef> consumer = adoptCF(CGDataConsumerCreateWithCFData(pdfData.get()));
> 
> Thes should use auto.

Done.

>> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:376
>> +    CGPSConverterConvert(converter.get(), provider.get(), consumer.get(), 0);
> 
> Is this operation expensive?  Should we be doing it on a background thread, asynchronously?  What happens with a really big PostScript file?

Yes I think so. At least it will as slow as decoding the data uri images which is decoded asynchronously. So I will log a separate bug to convert the sub-resource PostScript to a PDF asynchronously.

>> Source/WebCore/platform/graphics/cg/PDFDocumentImage.h:51
>> +    static Ref<PDFDocumentImage> create(ImageObserver* observer, bool isPostScript = false)
> 
> I think this would be clearer as an enum:
> 
> enum class Type {
>     PDF,
>     PostScript
> };

Done.

>> LayoutTests/fast/images/resources/green-100x100.eps:1
>> +%!PS-Adobe-3.0 EPSF-3.0
> 
> This is an insanely overcomplicated EPS, I emailed you a better (<200byte) one.

Thanks. This was very helpful. But I had to tweak it a little to get the green rectangle without anti-aliasing at the borders.
Comment 10 Said Abou-Hallawa 2017-10-19 17:55:41 PDT
Created attachment 324325 [details]
Patch
Comment 11 Build Bot 2017-10-19 17:57:45 PDT
Attachment 324325 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/graphics/cg/PDFDocumentImage.h:52:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 1 in 15 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 12 Build Bot 2017-10-19 19:36:14 PDT
Comment on attachment 324325 [details]
Patch

Attachment 324325 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/4926892

New failing tests:
fast/images/eps-support-sub-resource.html
Comment 13 Build Bot 2017-10-19 19:36:15 PDT
Created attachment 324335 [details]
Archive of layout-test-results from ews123 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews123  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 14 Said Abou-Hallawa 2017-10-20 12:44:18 PDT
Created attachment 324431 [details]
Patch
Comment 15 Build Bot 2017-10-20 12:45:31 PDT
Attachment 324431 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/graphics/cg/PDFDocumentImage.h:52:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 1 in 17 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 16 Build Bot 2017-10-20 14:34:00 PDT
Comment on attachment 324431 [details]
Patch

Attachment 324431 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/4936524

New failing tests:
webrtc/video-replace-muted-track.html
Comment 17 Build Bot 2017-10-20 14:34:02 PDT
Created attachment 324447 [details]
Archive of layout-test-results from ews123 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews123  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 18 Said Abou-Hallawa 2017-10-20 14:58:11 PDT
<rdar://problem/35102988>
Comment 19 Said Abou-Hallawa 2017-10-20 15:04:18 PDT
Created attachment 324449 [details]
Patch
Comment 20 Build Bot 2017-10-20 15:05:49 PDT
Attachment 324449 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/graphics/cg/PDFDocumentImage.h:52:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 1 in 17 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 21 Tim Horton 2017-10-20 16:38:11 PDT
Comment on attachment 324449 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=324449&action=review

> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:92
> +#if ENABLE(PDFKIT_PLUGIN)

Why is this in ENABLE(PDFKIT_PLUGIN)?

> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:366
> +#if ENABLE(PDFKIT_PLUGIN)

Why is this in ENABLE(PDFKIT_PLUGIN)?
Comment 22 Said Abou-Hallawa 2017-10-20 17:19:13 PDT
Created attachment 324476 [details]
Patch
Comment 23 Build Bot 2017-10-20 17:20:21 PDT
Attachment 324476 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/graphics/cg/PDFDocumentImage.h:52:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 1 in 17 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 24 Said Abou-Hallawa 2017-10-20 18:00:08 PDT
Comment on attachment 324449 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=324449&action=review

>> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:92
>> +#if ENABLE(PDFKIT_PLUGIN)
> 
> Why is this in ENABLE(PDFKIT_PLUGIN)?

I replaced it by #if PLATFORM(MAC). And I made sure that we do not create a PDFDocumentImage unless the data is for a PDF image or the data is for an EPS image and the platform is Mac.
Comment 25 Build Bot 2017-10-20 18:50:52 PDT
Comment on attachment 324476 [details]
Patch

Attachment 324476 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/4938954

New failing tests:
webrtc/video-replace-muted-track.html
Comment 26 Build Bot 2017-10-20 18:50:54 PDT
Created attachment 324479 [details]
Archive of layout-test-results from ews121 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews121  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 27 Tim Horton 2017-10-20 19:12:10 PDT
(In reply to Said Abou-Hallawa from comment #24)
> Comment on attachment 324449 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=324449&action=review
> 
> >> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:92
> >> +#if ENABLE(PDFKIT_PLUGIN)
> > 
> > Why is this in ENABLE(PDFKIT_PLUGIN)?
> 
> I replaced it by #if PLATFORM(MAC). And I made sure that we do not create a
> PDFDocumentImage unless the data is for a PDF image or the data is for an
> EPS image and the platform is Mac.

I don't understand why we wouldn't want this on iOS as well.
Comment 28 Said Abou-Hallawa 2017-10-25 15:43:30 PDT
Created attachment 324909 [details]
Patch
Comment 29 Build Bot 2017-10-25 15:45:39 PDT
Attachment 324909 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/graphics/cg/PDFDocumentImage.h:52:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 1 in 17 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 30 Said Abou-Hallawa 2017-10-25 15:48:24 PDT
(In reply to Tim Horton from comment #27)
> (In reply to Said Abou-Hallawa from comment #24)
> > Comment on attachment 324449 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=324449&action=review
> > 
> > >> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:92
> > >> +#if ENABLE(PDFKIT_PLUGIN)
> > > 
> > > Why is this in ENABLE(PDFKIT_PLUGIN)?
> > 
> > I replaced it by #if PLATFORM(MAC). And I made sure that we do not create a
> > PDFDocumentImage unless the data is for a PDF image or the data is for an
> > EPS image and the platform is Mac.
> 
> I don't understand why we wouldn't want this on iOS as well.

Because the header file CGPSConverter.h exists only in the Mac CoreGraphics framework. This header file contains all the definitions of the structures and APIs we use in PDFDocumentImage::convertPostScriptDataToPDF().
Comment 31 Said Abou-Hallawa 2017-10-27 11:59:34 PDT
Created attachment 325182 [details]
Patch
Comment 32 Said Abou-Hallawa 2017-10-27 12:10:49 PDT
Created attachment 325183 [details]
Patch
Comment 33 Said Abou-Hallawa 2017-10-27 12:55:19 PDT
Created attachment 325185 [details]
Patch
Comment 34 Said Abou-Hallawa 2017-10-31 15:21:07 PDT
Created attachment 325506 [details]
Patch
Comment 35 Tim Horton 2017-11-01 10:54:24 PDT
Comment on attachment 325506 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=325506&action=review

> Source/WebCore/loader/cache/CachedImage.cpp:315
> +        return url().path().endsWith(".pdf", false);

This random extension checking seems weird, do we have any prior examples?
Comment 36 Said Abou-Hallawa 2017-11-28 11:54:06 PST
Created attachment 327768 [details]
Patch
Comment 37 Said Abou-Hallawa 2017-11-28 11:55:32 PST
Comment on attachment 325506 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=325506&action=review

>> Source/WebCore/loader/cache/CachedImage.cpp:315
>> +        return url().path().endsWith(".pdf", false);
> 
> This random extension checking seems weird, do we have any prior examples?

In WebPage::createPlugin() we have the following if-statment:

if (shouldUsePDFPlugin() && (MIMETypeRegistry::isPDFOrPostScriptMIMEType(parameters.mimeType) || (parameters.mimeType.isEmpty() && (path.endsWithIgnoringASCIICase(".pdf") || path.endsWithIgnoringASCIICase(".ps")))))
Comment 38 Simon Fraser (smfr) 2017-11-28 12:01:52 PST
Comment on attachment 327768 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=327768&action=review

> Source/WebCore/loader/cache/CachedImage.h:98
> +    bool isPDFRequest() const;
> +    bool isPostScriptRequest() const;

It's odd to ask whether an image is a "request". Maybe isPDFResource()/isPostScriptResource()?

> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:363
> +    CGPSConverterCallbacks callbacks = { 0, 0, 0, 0, 0, 0, 0, 0 };

Could be CGPSConverterCallbacks callbacks = { };

> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:369
> +    CGPSConverterConvert(converter.get(), provider.get(), consumer.get(), 0);

How expensive is this? Can it happen off the main thread?

> Source/WebCore/platform/graphics/cg/PDFDocumentImage.h:58
> +    WEBCORE_EXPORT static RetainPtr<CFMutableDataRef> convertPostScriptDataToPDF(RetainPtr<CFDataRef> postScriptData);

This should return a CFDataRef, right? The caller doesn't need mutability.

Can the argument be a  RetainPtr<CFDataRef>&& ?
Comment 39 Said Abou-Hallawa 2017-11-28 12:46:58 PST
Created attachment 327778 [details]
Patch
Comment 40 Said Abou-Hallawa 2017-11-28 13:32:05 PST
Comment on attachment 327768 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=327768&action=review

>> Source/WebCore/loader/cache/CachedImage.h:98
>> +    bool isPostScriptRequest() const;
> 
> It's odd to ask whether an image is a "request". Maybe isPDFResource()/isPostScriptResource()?

Functions were renamed.

>> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:363
>> +    CGPSConverterCallbacks callbacks = { 0, 0, 0, 0, 0, 0, 0, 0 };
> 
> Could be CGPSConverterCallbacks callbacks = { };

Done.

>> Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp:369
>> +    CGPSConverterConvert(converter.get(), provider.get(), consumer.get(), 0);
> 
> How expensive is this? Can it happen off the main thread?

It is expensive operation for sure. I logged https://bugs.webkit.org/show_bug.cgi?id=180104 to track this issue.

>> Source/WebCore/platform/graphics/cg/PDFDocumentImage.h:58
>> +    WEBCORE_EXPORT static RetainPtr<CFMutableDataRef> convertPostScriptDataToPDF(RetainPtr<CFDataRef> postScriptData);
> 
> This should return a CFDataRef, right? The caller doesn't need mutability.
> 
> Can the argument be a  RetainPtr<CFDataRef>&& ?

Yes the argument can be RetainPtr<CFDataRef>&&. But I could not change the return value because we assign the value of convertPostScriptDataToPDF() to PDFPlugin::m_data which is of type RetainPtr<CFMutableDataRef>. I can't change its type because PDFPlugin CFDataAppendBytes to the m_data at some point.
Comment 41 WebKit Commit Bot 2017-11-28 15:09:46 PST
Comment on attachment 327778 [details]
Patch

Clearing flags on attachment: 327778

Committed r225241: <https://trac.webkit.org/changeset/225241>
Comment 42 WebKit Commit Bot 2017-11-28 15:09:48 PST
All reviewed patches have been landed.  Closing bug.