Skip to content

Commit

Permalink
Cherry-pick 272448.740@safari-7618-branch (c369f50). https://bugs.web…
Browse files Browse the repository at this point in the history
…kit.org/show_bug.cgi?id=271003

    PDFs should be downloaded in lockdown mode
    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

Canonical link: https://commits.webkit.org/274313.251@webkitglib/2.44
  • Loading branch information
Pascoe authored and aperezdc committed May 13, 2024
1 parent 5a9234b commit 8f9e949
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7111,10 +7111,22 @@ void WebPageProxy::decidePolicyForResponseShared(Ref<WebProcessProxy>&& process,
RELEASE_ASSERT(processSwapRequestedByClient == ProcessSwapRequestedByClient::No);
ASSERT_UNUSED(safeBrowsingWarning, !safeBrowsingWarning);

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;

receivedNavigationResponsePolicyDecision(policyAction, navigation.get(), request, WTFMove(navigationResponse), WTFMove(completionHandler));
}, 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 8f9e949

Please sign in to comment.