Skip to content

Commit

Permalink
PDFs should be downloaded in lockdown mode
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271003
rdar://124636755

Reviewed by Chris Dumez.

This functionality was first introduced in https://bugs.webkit.org/show_bug.cgi?id=237245, but
was disabled for macOS in https://bugs.webkit.org/show_bug.cgi?id=241741. This patch is to re-enable it.

This functionality should be covered by WKDownload.LockdownModePDF. Which is also fixed in this change
such that it fails whenever the conditional doesn't exist.

* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::decidePolicyForResponseShared):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm:

Canonical link: https://commits.webkit.org/272448.740@safari-7618-branch
  • Loading branch information
Pascoe committed Mar 15, 2024
1 parent f84cad4 commit c369f50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7038,11 +7038,23 @@ void WebPageProxy::decidePolicyForResponseShared(Ref<WebProcessProxy>&& process,
RELEASE_ASSERT(processSwapRequestedByClient == ProcessSwapRequestedByClient::No);
ASSERT_UNUSED(safeBrowsingWarning, !safeBrowsingWarning);

Ref sender = PolicyDecisionSender::create(WTFMove(completionHandler));
bool shouldForceDownload = [&] {
if (policyAction != PolicyAction::Use || process->lockdownMode() != WebProcessProxy::LockdownMode::Enabled)
return false;
if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(navigationResponse->response().mimeType()))
return true;
if (MIMETypeRegistry::isSupportedModelMIMEType(navigationResponse->response().mimeType()))
return true;
#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())))
policyAction = PolicyAction::Download;
if (PreviewConverter::supportsMIMEType(navigationResponse->response().mimeType()))
return true;
#endif
return false;
}();
if (shouldForceDownload)
policyAction = PolicyAction::Download;

Ref sender = PolicyDecisionSender::create(WTFMove(completionHandler));
receivedPolicyDecision(policyAction, navigation.get(), nullptr, WTFMove(navigationResponse), WTFMove(sender), WillContinueLoadInNewProcess::No, std::nullopt);
}, ShouldExpectSafeBrowsingResult::No, ShouldExpectAppBoundDomainResult::No, ShouldWaitForInitialLinkDecorationFilteringData::No);

Expand Down
4 changes: 4 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,10 @@ HTTPServer childFrameServer({
auto server = simplePDFTestServer();
NSURL *expectedDownloadFile = tempPDFThatDoesNotExist();

delegate.get().decidePolicyForNavigationResponse = ^(WKNavigationResponse *, void (^completionHandler)(WKNavigationResponsePolicy)) {
completionHandler(WKNavigationResponsePolicyAllow);
};

delegate.get().navigationResponseDidBecomeDownload = ^(WKWebView *, WKNavigationResponse *, WKDownload *download) {
download.delegate = delegate.get();
delegate.get().decideDestinationUsingResponse = ^(WKDownload *download, NSURLResponse *, NSString *, void (^completionHandler)(NSURL *)) {
Expand Down

0 comments on commit c369f50

Please sign in to comment.