Skip to content

Commit

Permalink
The download client should be able to determine if a placeholder shou…
Browse files Browse the repository at this point in the history
…ld be used

https://bugs.webkit.org/show_bug.cgi?id=278737
rdar://134794671

Reviewed by Alex Christensen.

The download client should be able to determine if a placeholder should be used for the final location of the
download. This patch prepares for this by passing the value from the UI process to the Networking process.

This was previously landed in <https://commits.webkit.org/283043@main>. This version addresses a build error.

* Source/WebKit/NetworkProcess/Downloads/Download.h:
* Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp:
(WebKit::DownloadManager::publishDownloadProgress):
* Source/WebKit/NetworkProcess/Downloads/DownloadManager.h:
* Source/WebKit/NetworkProcess/Downloads/PendingDownload.cpp:
(WebKit::PendingDownload::publishProgress):
(WebKit::PendingDownload::didBecomeDownload):
* Source/WebKit/NetworkProcess/Downloads/PendingDownload.h:
* Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm:
(WebKit::Download::publishProgress):
* Source/WebKit/NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::publishDownloadProgress):
* Source/WebKit/NetworkProcess/NetworkProcess.h:
* Source/WebKit/NetworkProcess/NetworkProcess.messages.in:
* Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKDownload.mm:
(-[_WKDownload publishProgressAtURL:]):
* Source/WebKit/UIProcess/API/Cocoa/WKDownload.mm:
(-[WKDownload setDelegate:]):
* Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegate.h:
* Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegatePrivate.h: Added.
* Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp:
(WebKit::DownloadProxy::decideDestinationWithSuggestedFilename):
* Source/WebKit/UIProcess/Downloads/DownloadProxy.h:
(WebKit::DownloadProxy::setUseDownloadPlaceholder):
* Source/WebKit/UIProcess/Downloads/DownloadProxyCocoa.mm:
(WebKit::DownloadProxy::publishProgress):
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm:
(TestWebKitAPI::DecidePlaceholderPolicy)):
* Tools/TestWebKitAPI/cocoa/TestDownloadDelegate.h:
* Tools/TestWebKitAPI/cocoa/TestDownloadDelegate.mm:
(-[TestDownloadDelegate _download:decidePlaceholderPolicy:]):

Canonical link: https://commits.webkit.org/283071@main
  • Loading branch information
pvollan committed Sep 2, 2024
1 parent 6fb6b90 commit 3c3c719
Show file tree
Hide file tree
Showing 23 changed files with 235 additions and 37 deletions.
3 changes: 2 additions & 1 deletion Source/WebKit/NetworkProcess/Downloads/Download.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "MessageSender.h"
#include "NetworkDataTask.h"
#include "SandboxExtension.h"
#include "UseDownloadPlaceholder.h"
#include <WebCore/AuthenticationChallenge.h>
#include <WebCore/ResourceRequest.h>
#include <memory>
Expand Down Expand Up @@ -90,7 +91,7 @@ class Download : public IPC::MessageSender, public CanMakeWeakPtr<Download>, pub
#endif

#if HAVE(MODERN_DOWNLOADPROGRESS)
void publishProgress(const URL&, std::span<const uint8_t>);
void publishProgress(const URL&, std::span<const uint8_t>, WebKit::UseDownloadPlaceholder);
#endif

DownloadID downloadID() const { return m_downloadID; }
Expand Down
6 changes: 3 additions & 3 deletions Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ void DownloadManager::cancelDownload(DownloadID downloadID, CompletionHandler<vo

#if PLATFORM(COCOA)
#if HAVE(MODERN_DOWNLOADPROGRESS)
void DownloadManager::publishDownloadProgress(DownloadID downloadID, const URL& url, std::span<const uint8_t> bookmarkData)
void DownloadManager::publishDownloadProgress(DownloadID downloadID, const URL& url, std::span<const uint8_t> bookmarkData, WebKit::UseDownloadPlaceholder useDownloadPlaceholder)
{
if (auto* download = m_downloads.get(downloadID))
download->publishProgress(url, bookmarkData);
download->publishProgress(url, bookmarkData, useDownloadPlaceholder);
else if (auto* pendingDownload = m_pendingDownloads.get(downloadID))
pendingDownload->publishProgress(url, bookmarkData);
pendingDownload->publishProgress(url, bookmarkData, useDownloadPlaceholder);
}
#else
void DownloadManager::publishDownloadProgress(DownloadID downloadID, const URL& url, SandboxExtension::Handle&& sandboxExtensionHandle)
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/NetworkProcess/Downloads/DownloadManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "PendingDownload.h"
#include "PolicyDecision.h"
#include "SandboxExtension.h"
#include "UseDownloadPlaceholder.h"
#include <WebCore/NotImplemented.h>
#include <wtf/CheckedRef.h>
#include <wtf/Forward.h>
Expand Down Expand Up @@ -101,7 +102,7 @@ class DownloadManager : public CanMakeCheckedPtr<DownloadManager> {
void cancelDownload(DownloadID, CompletionHandler<void(std::span<const uint8_t>)>&&);
#if PLATFORM(COCOA)
#if HAVE(MODERN_DOWNLOADPROGRESS)
void publishDownloadProgress(DownloadID, const URL&, std::span<const uint8_t> bookmarkData);
void publishDownloadProgress(DownloadID, const URL&, std::span<const uint8_t> bookmarkData, WebKit::UseDownloadPlaceholder);
#else
void publishDownloadProgress(DownloadID, const URL&, SandboxExtension::Handle&&);
#endif
Expand Down
5 changes: 3 additions & 2 deletions Source/WebKit/NetworkProcess/Downloads/PendingDownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ void PendingDownload::cancel(CompletionHandler<void(std::span<const uint8_t>)>&&

#if PLATFORM(COCOA)
#if HAVE(MODERN_DOWNLOADPROGRESS)
void PendingDownload::publishProgress(const URL& url, std::span<const uint8_t> bookmarkData)
void PendingDownload::publishProgress(const URL& url, std::span<const uint8_t> bookmarkData, UseDownloadPlaceholder useDownloadPlaceholder)
{
ASSERT(!m_progressURL.isValid());
m_progressURL = url;
m_bookmarkData = bookmarkData;
m_useDownloadPlaceholder = useDownloadPlaceholder;
}
#else
void PendingDownload::publishProgress(const URL& url, SandboxExtension::Handle&& sandboxExtension)
Expand All @@ -101,7 +102,7 @@ void PendingDownload::didBecomeDownload(const std::unique_ptr<Download>& downloa
if (!m_progressURL.isValid())
return;
#if HAVE(MODERN_DOWNLOADPROGRESS)
download->publishProgress(m_progressURL, m_bookmarkData);
download->publishProgress(m_progressURL, m_bookmarkData, m_useDownloadPlaceholder);
#else
download->publishProgress(m_progressURL, WTFMove(m_progressSandboxExtension));
#endif
Expand Down
4 changes: 3 additions & 1 deletion Source/WebKit/NetworkProcess/Downloads/PendingDownload.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "MessageSender.h"
#include "NetworkLoadClient.h"
#include "SandboxExtension.h"
#include "UseDownloadPlaceholder.h"
#include <wtf/TZoneMalloc.h>

namespace WebKit {
Expand Down Expand Up @@ -66,7 +67,7 @@ class PendingDownload : public NetworkLoadClient, public IPC::MessageSender, pub

#if PLATFORM(COCOA)
#if HAVE(MODERN_DOWNLOADPROGRESS)
void publishProgress(const URL&, std::span<const uint8_t>);
void publishProgress(const URL&, std::span<const uint8_t>, UseDownloadPlaceholder);
#else
void publishProgress(const URL&, SandboxExtension::Handle&&);
#endif
Expand Down Expand Up @@ -97,6 +98,7 @@ class PendingDownload : public NetworkLoadClient, public IPC::MessageSender, pub
URL m_progressURL;
#if HAVE(MODERN_DOWNLOADPROGRESS)
Vector<uint8_t> m_bookmarkData;
UseDownloadPlaceholder m_useDownloadPlaceholder { UseDownloadPlaceholder::No };
#else
SandboxExtension::Handle m_progressSandboxExtension;
#endif
Expand Down
5 changes: 3 additions & 2 deletions Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
}

#if HAVE(MODERN_DOWNLOADPROGRESS)
void Download::publishProgress(const URL& url, std::span<const uint8_t> bookmarkData)
void Download::publishProgress(const URL& url, std::span<const uint8_t> bookmarkData, UseDownloadPlaceholder useDownloadPlaceholder)
{
if (m_progress) {
RELEASE_LOG(Network, "Progress is already being published for download.");
Expand All @@ -110,7 +110,8 @@
bool shouldEnableModernDownloadProgress = CFPreferencesGetAppBooleanValue(CFSTR("EnableModernDownloadProgress"), CFSTR("com.apple.WebKit"), NULL);

if (shouldEnableModernDownloadProgress) {
m_progress = adoptNS([[WKModernDownloadProgress alloc] initWithDownloadTask:m_downloadTask.get() download:*this URL:(NSURL *)url]);
NSData *accessToken = [NSData data]; // FIXME: replace with actual access token
m_progress = adoptNS([[WKModernDownloadProgress alloc] initWithDownloadTask:m_downloadTask.get() download:*this URL:(NSURL *)url useDownloadPlaceholder:useDownloadPlaceholder == WebKit::UseDownloadPlaceholder::Yes liveActivityAccessToken:accessToken]);
[m_progress publish];
} else {
m_progress = adoptNS([[WKDownloadProgress alloc] initWithDownloadTask:m_downloadTask.get() download:*this URL:(NSURL *)url sandboxExtension:nullptr]);
Expand Down
14 changes: 11 additions & 3 deletions Source/WebKit/NetworkProcess/NetworkProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2141,9 +2141,9 @@ void NetworkProcess::cancelDownload(DownloadID downloadID, CompletionHandler<voi

#if PLATFORM(COCOA)
#if HAVE(MODERN_DOWNLOADPROGRESS)
void NetworkProcess::publishDownloadProgress(DownloadID downloadID, const URL& url, std::span<const uint8_t> bookmarkData)
void NetworkProcess::publishDownloadProgress(DownloadID downloadID, const URL& url, std::span<const uint8_t> bookmarkData, WebKit::UseDownloadPlaceholder useDownloadPlaceholder)
{
downloadManager().publishDownloadProgress(downloadID, url, bookmarkData);
downloadManager().publishDownloadProgress(downloadID, url, bookmarkData, useDownloadPlaceholder);
}
#else
void NetworkProcess::publishDownloadProgress(DownloadID downloadID, const URL& url, SandboxExtension::Handle&& sandboxExtensionHandle)
Expand All @@ -2157,7 +2157,7 @@ void NetworkProcess::findPendingDownloadLocation(NetworkDataTask& networkDataTas
{
String suggestedFilename = networkDataTask.suggestedFilename();

downloadProxyConnection()->sendWithAsyncReply(Messages::DownloadProxy::DecideDestinationWithSuggestedFilename(response, suggestedFilename), [this, protectedThis = Ref { *this }, completionHandler = WTFMove(completionHandler), networkDataTask = Ref { networkDataTask }] (String&& destination, SandboxExtension::Handle&& sandboxExtensionHandle, AllowOverwrite allowOverwrite) mutable {
downloadProxyConnection()->sendWithAsyncReply(Messages::DownloadProxy::DecideDestinationWithSuggestedFilename(response, suggestedFilename), [this, protectedThis = Ref { *this }, completionHandler = WTFMove(completionHandler), networkDataTask = Ref { networkDataTask }] (String&& destination, SandboxExtension::Handle&& sandboxExtensionHandle, AllowOverwrite allowOverwrite, WebKit::UseDownloadPlaceholder usePlaceholder) mutable {
auto downloadID = *networkDataTask->pendingDownloadID();
if (destination.isEmpty())
return completionHandler(PolicyAction::Ignore);
Expand All @@ -2166,6 +2166,14 @@ void NetworkProcess::findPendingDownloadLocation(NetworkDataTask& networkDataTas
if (networkDataTask->state() == NetworkDataTask::State::Canceling || networkDataTask->state() == NetworkDataTask::State::Completed)
return;

#if HAVE(MODERN_DOWNLOADPROGRESS)
bool shouldEnableModernDownloadProgress = CFPreferencesGetAppBooleanValue(CFSTR("EnableModernDownloadProgress"), CFSTR("com.apple.WebKit"), nullptr);
if (shouldEnableModernDownloadProgress)
publishDownloadProgress(downloadID, URL::fileURLWithFileSystemPath(destination), std::span<const uint8_t>(), usePlaceholder);
#else
UNUSED_PARAM(usePlaceholder);
#endif

if (downloadManager().download(downloadID)) {
// The completion handler already called dataTaskBecameDownloadTask().
return;
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/NetworkProcess/NetworkProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "DownloadManager.h"
#include "NetworkContentRuleListManager.h"
#include "QuotaIncreaseRequestIdentifier.h"
#include "UseDownloadPlaceholder.h"
#include "WebPageProxyIdentifier.h"
#include "WebResourceLoadStatisticsStore.h"
#include "WebsiteData.h"
Expand Down Expand Up @@ -483,7 +484,7 @@ class NetworkProcess final : public AuxiliaryProcess, private DownloadManager::C
void cancelDownload(DownloadID, CompletionHandler<void(std::span<const uint8_t>)>&&);
#if PLATFORM(COCOA)
#if HAVE(MODERN_DOWNLOADPROGRESS)
void publishDownloadProgress(DownloadID, const URL&, std::span<const uint8_t> bookmarkData);
void publishDownloadProgress(DownloadID, const URL&, std::span<const uint8_t> bookmarkData, WebKit::UseDownloadPlaceholder);
#else
void publishDownloadProgress(DownloadID, const URL&, SandboxExtensionHandle&&);
#endif
Expand Down
3 changes: 0 additions & 3 deletions Source/WebKit/NetworkProcess/NetworkProcess.messages.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ messages -> NetworkProcess LegacyReceiver {
DownloadRequest(PAL::SessionID sessionID, WebKit::DownloadID downloadID, WebCore::ResourceRequest request, std::optional<WebCore::SecurityOriginData> topOrigin, std::optional<WebKit::NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain, String suggestedFilename)
ResumeDownload(PAL::SessionID sessionID, WebKit::DownloadID downloadID, std::span<const uint8_t> resumeData, String path, WebKit::SandboxExtensionHandle sandboxExtensionHandle, enum:bool WebKit::CallDownloadDidStart callDownloadDidStart)
CancelDownload(WebKit::DownloadID downloadID) -> (std::span<const uint8_t> resumeData)
#if HAVE(MODERN_DOWNLOADPROGRESS)
PublishDownloadProgress(WebKit::DownloadID downloadID, URL url, std::span<const uint8_t> bookmarkData)
#endif
#if PLATFORM(COCOA) && !HAVE(MODERN_DOWNLOADPROGRESS)
PublishDownloadProgress(WebKit::DownloadID downloadID, URL url, WebKit::SandboxExtensionHandle sandboxExtensionHandle)
#endif
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#import <WebKit/WKDownloadDelegatePrivate.h>
#import <WebKit/WKHistoryDelegatePrivate.h>
#import <WebKit/WKNavigationPrivate.h>
#import <WebKit/WKProcessPoolPrivate.h>
Expand Down
5 changes: 4 additions & 1 deletion Source/WebKit/UIProcess/API/APIDownloadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "AuthenticationChallengeProxy.h"
#include "AuthenticationDecisionListener.h"
#include "DownloadID.h"
#include "DownloadProxy.h"
#include <wtf/CompletionHandler.h>
#include <wtf/TZoneMallocInlines.h>
#include <wtf/text/WTFString.h>
Expand All @@ -41,7 +42,6 @@ class ResourceResponse;

namespace WebKit {
class AuthenticationChallengeProxy;
class DownloadProxy;
class WebsiteDataStore;
class WebProtectionSpace;

Expand All @@ -60,6 +60,9 @@ class DownloadClient : public RefCounted<DownloadClient> {
virtual void legacyDidStart(WebKit::DownloadProxy&) { }
virtual void didReceiveAuthenticationChallenge(WebKit::DownloadProxy&, WebKit::AuthenticationChallengeProxy& challenge) { challenge.listener().completeChallenge(WebKit::AuthenticationChallengeDisposition::Cancel); }
virtual void didReceiveData(WebKit::DownloadProxy&, uint64_t, uint64_t, uint64_t) { }
#if HAVE(MODERN_DOWNLOADPROGRESS)
virtual void decidePlaceholderPolicy(WebKit::DownloadProxy&, CompletionHandler<void(WebKit::UseDownloadPlaceholder)>&& completionHandler) { completionHandler(WebKit::UseDownloadPlaceholder::No); }
#endif
virtual void decideDestinationWithSuggestedFilename(WebKit::DownloadProxy&, const WebCore::ResourceResponse&, const WTF::String&, CompletionHandler<void(WebKit::AllowOverwrite, WTF::String)>&& completionHandler) { completionHandler(WebKit::AllowOverwrite::No, { }); }
virtual void didCreateDestination(WebKit::DownloadProxy&, const WTF::String&) { }
virtual void didFinish(WebKit::DownloadProxy&) { }
Expand Down
38 changes: 35 additions & 3 deletions Source/WebKit/UIProcess/API/Cocoa/WKDownload.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#import "CompletionHandlerCallChecker.h"
#import "DownloadProxy.h"
#import "WKDownloadDelegate.h"
#import "WKDownloadDelegatePrivate.h"
#import "WKFrameInfoInternal.h"
#import "WKNSData.h"
#import "WKNSURLAuthenticationChallenge.h"
Expand All @@ -41,12 +42,16 @@

class DownloadClient final : public API::DownloadClient {
public:
explicit DownloadClient(id <WKDownloadDelegate> delegate)
explicit DownloadClient(id<WKDownloadDelegatePrivate> delegate)
: m_delegate(delegate)
, m_respondsToWillPerformHTTPRedirection([delegate respondsToSelector:@selector(download:willPerformHTTPRedirection:newRequest:decisionHandler:)])
, m_respondsToDidReceiveAuthenticationChallenge([delegate respondsToSelector:@selector(download:didReceiveAuthenticationChallenge:completionHandler:)])
, m_respondsToDidFinish([m_delegate respondsToSelector:@selector(downloadDidFinish:)])
, m_respondsToDidFailWithError([delegate respondsToSelector:@selector(download:didFailWithError:resumeData:)])
#if HAVE(MODERN_DOWNLOADPROGRESS)
, m_respondsToDecidePlaceholderPolicy([delegate respondsToSelector:@selector(_download:decidePlaceholderPolicy:)])
#endif

{
ASSERT([delegate respondsToSelector:@selector(download:decideDestinationUsingResponse:suggestedFilename:completionHandler:)]);
}
Expand Down Expand Up @@ -142,6 +147,30 @@ void decideDestinationWithSuggestedFilename(WebKit::DownloadProxy& download, con
}).get()];
}

#if HAVE(MODERN_DOWNLOADPROGRESS)
void decidePlaceholderPolicy(WebKit::DownloadProxy& download, CompletionHandler<void(WebKit::UseDownloadPlaceholder)>&& completionHandler)
{
if (!m_respondsToDecidePlaceholderPolicy) {
completionHandler(WebKit::UseDownloadPlaceholder::No);
return;
}
[m_delegate _download:wrapper(download) decidePlaceholderPolicy:makeBlockPtr([completionHandler = WTFMove(completionHandler)] (_WKPlaceholderPolicy policy) mutable {
switch (policy) {
case _WKPlaceholderPolicyDisable: {
completionHandler(WebKit::UseDownloadPlaceholder::No);
break;
}
case _WKPlaceholderPolicyEnable: {
completionHandler(WebKit::UseDownloadPlaceholder::Yes);
break;
}
default:
[NSException raise:NSInvalidArgumentException format:@"Invalid WKPlaceholderPolicy (%ld)", (long)policy];
}
}).get()];
}
#endif

void didReceiveData(WebKit::DownloadProxy& download, uint64_t, uint64_t totalBytesWritten, uint64_t totalBytesExpectedToWrite) final
{
NSProgress *progress = wrapper(download).progress;
Expand Down Expand Up @@ -173,12 +202,15 @@ void processDidCrash(WebKit::DownloadProxy& download) final
[m_delegate download:wrapper(download) didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorNetworkConnectionLost userInfo:nil] resumeData:nil];
}

WeakObjCPtr<id <WKDownloadDelegate> > m_delegate;
WeakObjCPtr<id<WKDownloadDelegatePrivate>> m_delegate;

bool m_respondsToWillPerformHTTPRedirection : 1;
bool m_respondsToDidReceiveAuthenticationChallenge : 1;
bool m_respondsToDidFinish : 1;
bool m_respondsToDidFailWithError : 1;
#if HAVE(MODERN_DOWNLOADPROGRESS)
bool m_respondsToDecidePlaceholderPolicy : 1;
#endif
};

@implementation WKDownload
Expand Down Expand Up @@ -219,7 +251,7 @@ - (WKFrameInfo *)originatingFrame
return _delegate.get().get();
}

- (void)setDelegate:(id <WKDownloadDelegate>)delegate
- (void)setDelegate:(id<WKDownloadDelegatePrivate>)delegate
{
_delegate = delegate;
_download->setClient(adoptRef(*new DownloadClient(delegate)));
Expand Down
59 changes: 59 additions & 0 deletions Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegatePrivate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#import <Foundation/Foundation.h>
#import <WebKit/WKDownloadDelegate.h>
#import <WebKit/WKFoundation.h>

@class WKDownload;

/* @enum _WKPlaceholderPolicy
@abstract The policy for creating a placeholder file in the Downloads directory during downloads.
@constant _WKPlaceholderPolicyDisable Do not create a placeholder file.
@constant _WKPlaceholderPolicyEnable Create a placeholder file.
*/
typedef NS_ENUM(NSInteger, _WKPlaceholderPolicy) {
_WKPlaceholderPolicyDisable,
_WKPlaceholderPolicyEnable,
} NS_SWIFT_NAME(WKDownload.PlaceholderPolicy) WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));

NS_ASSUME_NONNULL_BEGIN

WK_SWIFT_UI_ACTOR
@protocol WKDownloadDelegatePrivate <WKDownloadDelegate>

@optional

/* @abstract Invoked when the download needs a placeholder policy from the client.
@param download The download for which we need a placeholder policy
@param completionHandler The completion handler that should be invoked with the chosen policy
@discussion The placeholder policy specifies whether a placeholder file should be created in
the Downloads directory when the download is in progress.
*/
- (void)_download:(WKDownload *)download decidePlaceholderPolicy:(void (^)(_WKPlaceholderPolicy))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));

@end

NS_ASSUME_NONNULL_END
2 changes: 2 additions & 0 deletions Source/WebKit/UIProcess/API/Cocoa/_WKDownload.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ - (void)cancel

- (void)publishProgressAtURL:(NSURL *)URL
{
#if !HAVE(MODERN_DOWNLOADPROGRESS)
_download->_download->publishProgress(URL);
#endif
}

- (NSURLRequest *)request
Expand Down
Loading

0 comments on commit 3c3c719

Please sign in to comment.