Skip to content

Commit

Permalink
WebPDFRepresentation no longer supports the "application/postscript" …
Browse files Browse the repository at this point in the history
…MIME type

https://bugs.webkit.org/show_bug.cgi?id=273859
rdar://127706401

Reviewed by Tim Horton.

WebKit no longer has access to the PostScript conversion service. In
fact, the PSNormalizer framework (required for conversion) is not even
available in macOS Sonoma (and onwards). As such, it is safe for us to
remove the PostScript to PDF transcoding logic in -[WebPDFRepresentation
convertPostScriptDataSourceToPDF:].

With that, we can also drop "application/postscript" as a supported MIME
type in WebPDFRepresentation. We take the liberty to do so in this patch.

* Source/WebKitLegacy/mac/WebView/WebPDFRepresentation.mm:
(+[WebPDFRepresentation supportedMIMETypes]):
(-[WebPDFRepresentation finishedLoadingWithDataSource:]):
(+[WebPDFRepresentation postScriptMIMETypes]): Deleted.
(-[WebPDFRepresentation convertPostScriptDataSourceToPDF:]): Deleted.

Canonical link: https://commits.webkit.org/278515@main
  • Loading branch information
aprotyas committed May 8, 2024
1 parent 4375ba9 commit 47f912e
Showing 1 changed file with 2 additions and 48 deletions.
50 changes: 2 additions & 48 deletions Source/WebKitLegacy/mac/WebView/WebPDFRepresentation.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,9 @@

@implementation WebPDFRepresentation

+ (NSArray *)postScriptMIMETypes
{
return @[
@"application/postscript",
];
}

+ (NSArray *)supportedMIMETypes
{
return [[[self class] postScriptMIMETypes] arrayByAddingObjectsFromArray:
@[
@"text/pdf",
@"application/pdf",
]
];
return @[ @"text/pdf", @"application/pdf" ];
}

+ (Class)PDFDocumentClass
Expand All @@ -83,44 +71,10 @@ - (void)receivedError:(NSError *)error withDataSource:(WebDataSource *)dataSourc
{
}

- (NSData *)convertPostScriptDataSourceToPDF:(NSData *)data
{
// Convert PostScript to PDF using Quartz 2D API
// http://developer.apple.com/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_ps_convert/chapter_16_section_1.html

CGPSConverterCallbacks callbacks = { 0, 0, 0, 0, 0, 0, 0, 0 };
RetainPtr<CGPSConverterRef> converter = adoptCF(CGPSConverterCreate(0, &callbacks, 0));
ASSERT(converter.get());

RetainPtr<CGDataProviderRef> provider = adoptCF(CGDataProviderCreateWithCFData((CFDataRef)data));
ASSERT(provider.get());

RetainPtr<CFMutableDataRef> result = adoptCF(CFDataCreateMutable(kCFAllocatorDefault, 0));
ASSERT(result.get());

RetainPtr<CGDataConsumerRef> consumer = adoptCF(CGDataConsumerCreateWithCFData(result.get()));
ASSERT(consumer.get());

// Error handled by detecting zero-length 'result' in caller
CGPSConverterConvert(converter.get(), provider.get(), consumer.get(), 0);

return result.bridgingAutorelease();
}

- (void)finishedLoadingWithDataSource:(WebDataSource *)dataSource
{
NSData *data = [dataSource data];

NSArray *postScriptMIMETypes = [[self class] postScriptMIMETypes];
NSString *mimeType = [dataSource _responseMIMEType];
if ([postScriptMIMETypes containsObject:mimeType]) {
data = [self convertPostScriptDataSourceToPDF:data];
if ([data length] == 0)
return;
}

WebPDFView *view = (WebPDFView *)[[[dataSource webFrame] frameView] documentView];
auto document = adoptNS([[[[self class] PDFDocumentClass] alloc] initWithData:data]);
auto document = adoptNS([[[[self class] PDFDocumentClass] alloc] initWithData:[dataSource data]]);
[view setPDFDocument:document.get()];

NSArray *scripts = allScriptsInPDFDocument(document.get());
Expand Down

0 comments on commit 47f912e

Please sign in to comment.