Skip to content

Commit

Permalink
Stop asking isPDFOrPostScriptMIMEType() since PDFPlugin does not tran…
Browse files Browse the repository at this point in the history
…scode PostScript to PDF anymore

https://bugs.webkit.org/show_bug.cgi?id=273807
rdar://127647542

Reviewed by Tim Horton.

In 246657@main, we removed PostScript conversion code. Since the
transcoding to PDF is not supported anymore, we can replace all calls to
`isPDFOrPostScriptMIMEType()` with `isPDFMIMEType()`. The former rests
on a false premise now.

This patch introduces one subtle behavior change, which is that we no
longer present a HUD on <object type="application/postscript">.

* Source/WebCore/dom/DOMImplementation.cpp:
(WebCore::DOMImplementation::createDocument):
* Source/WebCore/html/HTMLImageLoader.cpp:
(WebCore::HTMLImageLoader::dispatchLoadEvent):
* Source/WebCore/platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::isPDFOrPostScriptMIMEType): Deleted.
* Source/WebCore/platform/MIMETypeRegistry.h:
* Source/WebCore/platform/cocoa/MIMETypeRegistryCocoa.mm:
(WebCore::MIMETypeRegistry::isApplicationPluginMIMEType):
* Source/WebKit/UIProcess/WebFrameProxy.cpp:
(WebKit::WebFrameProxy::isDisplayingPDFDocument const):
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::canShowMIMEType):
(WebKit::WebPageProxy::decidePolicyForResponseShared):
* Source/WebKit/WebProcess/WebCoreSupport/WebLocalFrameLoaderClient.cpp:
(WebKit::WebLocalFrameLoaderClient::objectContentType):
* Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::shouldUsePDFPlugin const):
* Source/WebKitLegacy/mac/Misc/WebNSPasteboardExtras.mm:
(-[NSPasteboard _web_writePromisedRTFDFromArchive:containsImage:]):

Canonical link: https://commits.webkit.org/278471@main
  • Loading branch information
aprotyas committed May 7, 2024
1 parent 27853e7 commit 86f6d64
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/dom/DOMImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Ref<Document> DOMImplementation::createDocument(const String& contentType, Local
#endif

bool isImage = MIMETypeRegistry::isSupportedImageMIMEType(contentType);
if (frame && isImage && !MIMETypeRegistry::isPDFOrPostScriptMIMEType(contentType))
if (frame && isImage && !MIMETypeRegistry::isPDFMIMEType(contentType))
return ImageDocument::create(*frame, url);

// The "image documents for subframe PDFs" mode will override a PDF plug-in.
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/HTMLImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void HTMLImageLoader::dispatchLoadEvent()
// firing such events for PDF loads on iOS can cause confusion on some sites.
// See rdar://107795151.
if (auto* objectElement = dynamicDowncast<HTMLObjectElement>(element())) {
if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(objectElement->serviceType()))
if (MIMETypeRegistry::isPDFMIMEType(objectElement->serviceType()))
return;
}
#endif
Expand Down
5 changes: 0 additions & 5 deletions Source/WebCore/platform/MIMETypeRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,6 @@ bool MIMETypeRegistry::isPostScriptMIMEType(const String& mimeType)
return equalLettersIgnoringASCIICase(mimeType, "application/postscript"_s);
}

bool MIMETypeRegistry::isPDFOrPostScriptMIMEType(const String& mimeType)
{
return isPDFMIMEType(mimeType) || isPostScriptMIMEType(mimeType);
}

bool MIMETypeRegistry::canShowMIMEType(const String& mimeType)
{
if (isSupportedImageMIMEType(mimeType) || isSupportedNonImageMIMEType(mimeType) || isSupportedMediaMIMEType(mimeType))
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/platform/MIMETypeRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class MIMETypeRegistry {
// Check to see if a MIME type is one of the common PDF/PS types.
WEBCORE_EXPORT static bool isPDFMIMEType(const String& mimeType);
static bool isPostScriptMIMEType(const String& mimeType);
WEBCORE_EXPORT static bool isPDFOrPostScriptMIMEType(const String& mimeType);

WEBCORE_EXPORT static bool isUSDMIMEType(const String& mimeType);

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/cocoa/MIMETypeRegistryCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
// but we only know that in WebKit2 at the moment. This is not a problem
// in practice because if we don't have PDFPlugin and we go to instantiate the
// plugin, there won't exist an application plugin supporting these MIME types.
if (isPDFOrPostScriptMIMEType(MIMEType))
if (isPDFMIMEType(MIMEType))
return true;
#else
UNUSED_PARAM(MIMEType);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/UIProcess/WebFrameProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ bool WebFrameProxy::isDisplayingMarkupDocument() const

bool WebFrameProxy::isDisplayingPDFDocument() const
{
return MIMETypeRegistry::isPDFOrPostScriptMIMEType(m_MIMEType);
return MIMETypeRegistry::isPDFMIMEType(m_MIMEType);
}

void WebFrameProxy::didStartProvisionalLoad(const URL& url)
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2315,7 +2315,7 @@ bool WebPageProxy::canShowMIMEType(const String& mimeType)

#if PLATFORM(COCOA)
// On Mac, we can show PDFs.
if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(mimeType) && !WebProcessPool::omitPDFSupport())
if (MIMETypeRegistry::isPDFMIMEType(mimeType) && !WebProcessPool::omitPDFSupport())
return true;
#endif // PLATFORM(COCOA)

Expand Down Expand Up @@ -7318,7 +7318,7 @@ void WebPageProxy::decidePolicyForResponseShared(Ref<WebProcessProxy>&& process,
ASSERT_UNUSED(safeBrowsingWarning, !safeBrowsingWarning);

#if USE(QUICK_LOOK)
if (policyAction == PolicyAction::Use && process->lockdownMode() == WebProcessProxy::LockdownMode::Enabled && (MIMETypeRegistry::isPDFOrPostScriptMIMEType(navigationResponse->response().mimeType()) || MIMETypeRegistry::isSupportedModelMIMEType(navigationResponse->response().mimeType()) || PreviewConverter::supportsMIMEType(navigationResponse->response().mimeType())))
if (policyAction == PolicyAction::Use && process->lockdownMode() == WebProcessProxy::LockdownMode::Enabled && (MIMETypeRegistry::isPDFMIMEType(navigationResponse->response().mimeType()) || MIMETypeRegistry::isSupportedModelMIMEType(navigationResponse->response().mimeType()) || PreviewConverter::supportsMIMEType(navigationResponse->response().mimeType())))
policyAction = PolicyAction::Download;
#if ENABLE(QUICKLOOK_SANDBOX_RESTRICTIONS)
if (policyAction == PolicyAction::Use && PreviewConverter::supportsMIMEType(navigationResponse->response().mimeType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ ObjectContentType WebLocalFrameLoaderClient::objectContentType(const URL& url, c

#if PLATFORM(IOS_FAMILY)
// iOS can render PDF in <object>/<embed> via PDFDocumentImage.
if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(mimeType))
if (MIMETypeRegistry::isPDFMIMEType(mimeType))
return ObjectContentType::Image;
#endif

Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
if (!pluginEnabled)
return false;

return MIMETypeRegistry::isPDFOrPostScriptMIMEType(contentType) || (contentType.isEmpty() && (path.endsWithIgnoringASCIICase(".pdf"_s) || path.endsWithIgnoringASCIICase(".ps"_s)));
return MIMETypeRegistry::isPDFMIMEType(contentType) || (contentType.isEmpty() && path.endsWithIgnoringASCIICase(".pdf"_s));
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions Source/WebKitLegacy/mac/Misc/WebNSPasteboardExtras.mm
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ - (void)_web_writePromisedRTFDFromArchive:(WebArchive*)archive containsImage:(BO
if (containsImage && [subresources count] > 0) {
WebResource *subresource = [subresources objectAtIndex:0];
NSString *subresourceMIMEType = [subresource MIMEType];
if (MIMETypeRegistry::isSupportedImageMIMEType(subresourceMIMEType) || MIMETypeRegistry::isPDFOrPostScriptMIMEType(subresourceMIMEType))
if (MIMETypeRegistry::isSupportedImageMIMEType(subresourceMIMEType) || MIMETypeRegistry::isPDFMIMEType(subresourceMIMEType))
resource = subresource;
}
ASSERT(resource != nil);

ASSERT(!containsImage || MIMETypeRegistry::isSupportedImageMIMEType([resource MIMEType]) || MIMETypeRegistry::isPDFOrPostScriptMIMEType([resource MIMEType]));
if (!containsImage || MIMETypeRegistry::isSupportedImageMIMEType([resource MIMEType]) || MIMETypeRegistry::isPDFOrPostScriptMIMEType([resource MIMEType]))
ASSERT(!containsImage || MIMETypeRegistry::isSupportedImageMIMEType([resource MIMEType]) || MIMETypeRegistry::isPDFMIMEType([resource MIMEType]));
if (!containsImage || MIMETypeRegistry::isSupportedImageMIMEType([resource MIMEType]) || MIMETypeRegistry::isPDFMIMEType([resource MIMEType]))
[self _web_writeFileWrapperAsRTFDAttachment:[resource _fileWrapperRepresentation]];

}
Expand Down

0 comments on commit 86f6d64

Please sign in to comment.