Skip to content

Commit

Permalink
Allow _WKDataTask to load blob URLs
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=258994
rdar://111173888

Reviewed by Tim Horton and Matthew Finkel.

When System Preview of AR models moved from the download code to using _WKDataTask,
it lost the ability to load blobs.  This fixes that.

Additionally, some blob URLs are immediately revoked using URL.revokeObjectURL.
This uses URLKeepingBlobAlive to make the blob URL available to load from
until the _WKDataTask has started loading.  I renamed handleSystemPreview to
beginSystemPreview and gave it a completion handler to indicate when it has
successfully begun.

I also removed a few unused parameters to get and use the BlobRegistry in the network process.

* Source/WebCore/html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::handleClick):
* Source/WebCore/page/ChromeClient.h:
(WebCore::ChromeClient::beginSystemPreview):
(WebCore::ChromeClient::handleSystemPreview): Deleted.
* Source/WebCore/page/Page.cpp:
(WebCore::Page::beginSystemPreview):
(WebCore::Page::handleSystemPreview): Deleted.
* Source/WebCore/page/Page.h:
* Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp:
(WebKit::DownloadManager::startDownload):
* Source/WebKit/NetworkProcess/Downloads/PendingDownload.cpp:
(WebKit::PendingDownload::PendingDownload):
* Source/WebKit/NetworkProcess/Downloads/PendingDownload.h:
* Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp:
(WebKit::NetworkDataTaskBlob::NetworkDataTaskBlob):
* Source/WebKit/NetworkProcess/NetworkDataTaskBlob.h:
* Source/WebKit/NetworkProcess/NetworkLoad.cpp:
(WebKit::NetworkLoad::NetworkLoad):
* Source/WebKit/NetworkProcess/NetworkLoad.h:
* Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::startNetworkLoad):
* Source/WebKit/NetworkProcess/PreconnectTask.cpp:
* Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerNavigationPreloader.cpp:
(WebKit::ServiceWorkerNavigationPreloader::loadFromNetwork):
* Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.cpp:
(WebKit::ServiceWorkerSoftUpdateLoader::loadFromNetwork):
* Source/WebKit/NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp:
(WebKit::NetworkCache::SpeculativeLoad::SpeculativeLoad):
* Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h:
* Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(WebKit::NetworkSessionCocoa::dataTaskWithRequest):
(WebKit::NetworkSessionCocoa::cancelDataTask):
(WebKit::NetworkSessionCocoa::removeBlobDataTask):
* Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm:
* Source/WebKit/UIProcess/SystemPreviewController.h:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::beginSystemPreview):
(WebKit::WebPageProxy::handleSystemPreview): Deleted.
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/WebPageProxy.messages.in:
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::beginSystemPreview):
(WebKit::WebChromeClient::handleSystemPreview): Deleted.
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/NetworkProcess.mm:
(TEST):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemPreview.mm:
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/265917@main
  • Loading branch information
achristensen07 committed Jul 10, 2023
1 parent 153d88f commit 9bf05cc
Show file tree
Hide file tree
Showing 27 changed files with 193 additions and 41 deletions.
3 changes: 2 additions & 1 deletion Source/WebCore/html/HTMLAnchorElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "SecurityOrigin.h"
#include "SecurityPolicy.h"
#include "Settings.h"
#include "URLKeepingBlobAlive.h"
#include "UserGestureIndicator.h"
#include <wtf/IsoMallocInlines.h>
#include <wtf/WeakHashMap.h>
Expand Down Expand Up @@ -614,7 +615,7 @@ void HTMLAnchorElement::handleClick(Event& event)
systemPreviewInfo.previewRect = child->boundsInRootViewSpace();

if (auto* page = document().page())
page->handleSystemPreview(WTFMove(completedURL), WTFMove(systemPreviewInfo));
page->beginSystemPreview(completedURL, WTFMove(systemPreviewInfo), [keepBlobAlive = URLKeepingBlobAlive(completedURL, document().topOrigin().data())] { });
return;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/ChromeClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ class ChromeClient {
#endif

#if USE(SYSTEM_PREVIEW)
virtual void handleSystemPreview(const URL&, const SystemPreviewInfo&) { }
virtual void beginSystemPreview(const URL&, const SystemPreviewInfo&, CompletionHandler<void()>&&) { }
#endif

virtual void requestCookieConsent(CompletionHandler<void(CookieConsentDecisionResult)>&&) = 0;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/page/Page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3984,9 +3984,9 @@ void Page::abortApplePayAMSUISession(ApplePayAMSUIPaymentHandler& paymentHandler
#endif // ENABLE(APPLE_PAY_AMS_UI)

#if USE(SYSTEM_PREVIEW)
void Page::handleSystemPreview(const URL& url, const SystemPreviewInfo& systemPreviewInfo)
void Page::beginSystemPreview(const URL& url, const SystemPreviewInfo& systemPreviewInfo, CompletionHandler<void()>&& completionHandler)
{
chrome().client().handleSystemPreview(url, systemPreviewInfo);
chrome().client().beginSystemPreview(url, systemPreviewInfo, WTFMove(completionHandler));
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/Page.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ class Page : public Supplementable<Page>, public CanMakeWeakPtr<Page> {
#endif

#if USE(SYSTEM_PREVIEW)
void handleSystemPreview(const URL&, const SystemPreviewInfo&);
void beginSystemPreview(const URL&, const SystemPreviewInfo&, CompletionHandler<void()>&&);
#endif

#if ENABLE(WEB_AUTHN)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void DownloadManager::startDownload(PAL::SessionID sessionID, DownloadID downloa
parameters.blobFileReferences = client().networkSession(sessionID)->blobRegistry().filesInBlob(request.url());
parameters.storedCredentialsPolicy = sessionID.isEphemeral() ? StoredCredentialsPolicy::DoNotUse : StoredCredentialsPolicy::Use;

m_pendingDownloads.add(downloadID, makeUnique<PendingDownload>(m_client.parentProcessConnectionForDownloads(), WTFMove(parameters), downloadID, *networkSession, &client().networkSession(sessionID)->blobRegistry(), suggestedName));
m_pendingDownloads.add(downloadID, makeUnique<PendingDownload>(m_client.parentProcessConnectionForDownloads(), WTFMove(parameters), downloadID, *networkSession, suggestedName));
}

void DownloadManager::dataTaskBecameDownloadTask(DownloadID downloadID, std::unique_ptr<Download>&& download)
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/NetworkProcess/Downloads/PendingDownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
namespace WebKit {
using namespace WebCore;

PendingDownload::PendingDownload(IPC::Connection* parentProcessConnection, NetworkLoadParameters&& parameters, DownloadID downloadID, NetworkSession& networkSession, WebCore::BlobRegistryImpl* blobRegistry, const String& suggestedName)
: m_networkLoad(makeUnique<NetworkLoad>(*this, blobRegistry, WTFMove(parameters), networkSession))
PendingDownload::PendingDownload(IPC::Connection* parentProcessConnection, NetworkLoadParameters&& parameters, DownloadID downloadID, NetworkSession& networkSession, const String& suggestedName)
: m_networkLoad(makeUnique<NetworkLoad>(*this, WTFMove(parameters), networkSession))
, m_parentProcessConnection(parentProcessConnection)
{
m_networkLoad->start();
Expand Down
3 changes: 1 addition & 2 deletions Source/WebKit/NetworkProcess/Downloads/PendingDownload.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Connection;
}

namespace WebCore {
class BlobRegistryImpl;
class ResourceResponse;
}

Expand All @@ -50,7 +49,7 @@ class NetworkSession;
class PendingDownload : public NetworkLoadClient, public IPC::MessageSender {
WTF_MAKE_FAST_ALLOCATED;
public:
PendingDownload(IPC::Connection*, NetworkLoadParameters&&, DownloadID, NetworkSession&, WebCore::BlobRegistryImpl*, const String& suggestedName);
PendingDownload(IPC::Connection*, NetworkLoadParameters&&, DownloadID, NetworkSession&, const String& suggestedName);
PendingDownload(IPC::Connection*, std::unique_ptr<NetworkLoad>&&, ResponseCompletionHandler&&, DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);

void continueWillSendRequest(WebCore::ResourceRequest&&);
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static constexpr auto httpPartialContentText = "Partial Content"_s;

static constexpr auto webKitBlobResourceDomain = "WebKitBlobResource"_s;

NetworkDataTaskBlob::NetworkDataTaskBlob(NetworkSession& session, BlobRegistryImpl& blobRegistry, NetworkDataTaskClient& client, const ResourceRequest& request, ContentSniffingPolicy shouldContentSniff, const Vector<RefPtr<WebCore::BlobDataFileReference>>& fileReferences)
NetworkDataTaskBlob::NetworkDataTaskBlob(NetworkSession& session, NetworkDataTaskClient& client, const ResourceRequest& request, const Vector<RefPtr<WebCore::BlobDataFileReference>>& fileReferences)
: NetworkDataTask(session, client, request, StoredCredentialsPolicy::DoNotUse, false, false)
, m_stream(makeUnique<AsyncFileStream>(*this))
, m_fileReferences(fileReferences)
Expand All @@ -71,7 +71,7 @@ NetworkDataTaskBlob::NetworkDataTaskBlob(NetworkSession& session, BlobRegistryIm
for (auto& fileReference : m_fileReferences)
fileReference->prepareForFileAccess();

m_blobData = blobRegistry.getBlobDataFromURL(request.url());
m_blobData = session.blobRegistry().getBlobDataFromURL(request.url());

m_session->registerNetworkDataTask(*this);
LOG(NetworkSession, "%p - Created NetworkDataTaskBlob for %s", this, request.url().string().utf8().data());
Expand Down
7 changes: 3 additions & 4 deletions Source/WebKit/NetworkProcess/NetworkDataTaskBlob.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class AsyncFileStream;
class BlobDataFileReference;
class BlobData;
class BlobDataItem;
class BlobRegistryImpl;
}

namespace WebKit {
Expand All @@ -49,15 +48,15 @@ class NetworkProcess;

class NetworkDataTaskBlob final : public NetworkDataTask, public WebCore::FileStreamClient {
public:
static Ref<NetworkDataTask> create(NetworkSession& session, WebCore::BlobRegistryImpl& blobRegistry, NetworkDataTaskClient& client, const WebCore::ResourceRequest& request, WebCore::ContentSniffingPolicy shouldContentSniff, const Vector<RefPtr<WebCore::BlobDataFileReference>>& fileReferences)
static Ref<NetworkDataTask> create(NetworkSession& session, NetworkDataTaskClient& client, const WebCore::ResourceRequest& request, const Vector<RefPtr<WebCore::BlobDataFileReference>>& fileReferences)
{
return adoptRef(*new NetworkDataTaskBlob(session, blobRegistry, client, request, shouldContentSniff, fileReferences));
return adoptRef(*new NetworkDataTaskBlob(session, client, request, fileReferences));
}

~NetworkDataTaskBlob();

private:
NetworkDataTaskBlob(NetworkSession&, WebCore::BlobRegistryImpl&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, WebCore::ContentSniffingPolicy, const Vector<RefPtr<WebCore::BlobDataFileReference>>&);
NetworkDataTaskBlob(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, const Vector<RefPtr<WebCore::BlobDataFileReference>>&);

void cancel() override;
void resume() override;
Expand Down
6 changes: 3 additions & 3 deletions Source/WebKit/NetworkProcess/NetworkLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ namespace WebKit {

using namespace WebCore;

NetworkLoad::NetworkLoad(NetworkLoadClient& client, BlobRegistryImpl* blobRegistry, NetworkLoadParameters&& parameters, NetworkSession& networkSession)
NetworkLoad::NetworkLoad(NetworkLoadClient& client, NetworkLoadParameters&& parameters, NetworkSession& networkSession)
: m_client(client)
, m_networkProcess(networkSession.networkProcess())
, m_parameters(WTFMove(parameters))
, m_currentRequest(m_parameters.request)
{
if (blobRegistry && m_parameters.request.url().protocolIsBlob())
m_task = NetworkDataTaskBlob::create(networkSession, *blobRegistry, *this, m_parameters.request, m_parameters.contentSniffingPolicy, m_parameters.blobFileReferences);
if (m_parameters.request.url().protocolIsBlob())
m_task = NetworkDataTaskBlob::create(networkSession, *this, m_parameters.request, m_parameters.blobFileReferences);
else
m_task = NetworkDataTask::create(networkSession, *this, m_parameters);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/NetworkProcess/NetworkLoad.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class NetworkProcess;
class NetworkLoad final : private NetworkDataTaskClient {
WTF_MAKE_FAST_ALLOCATED;
public:
NetworkLoad(NetworkLoadClient&, WebCore::BlobRegistryImpl*, NetworkLoadParameters&&, NetworkSession&);
NetworkLoad(NetworkLoadClient&, NetworkLoadParameters&&, NetworkSession&);
NetworkLoad(NetworkLoadClient&, NetworkSession&, const Function<RefPtr<NetworkDataTask>(NetworkDataTaskClient&)>&);
~NetworkLoad();

Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ void NetworkResourceLoader::startNetworkLoad(ResourceRequest&& request, FirstLoa

parameters.request = WTFMove(request);
parameters.isNavigatingToAppBoundDomain = m_parameters.isNavigatingToAppBoundDomain;
m_networkLoad = makeUnique<NetworkLoad>(*this, &networkSession->blobRegistry(), WTFMove(parameters), *networkSession);
m_networkLoad = makeUnique<NetworkLoad>(*this, WTFMove(parameters), *networkSession);

WeakPtr weakThis { *this };
if (isSynchronous())
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/NetworkProcess/PreconnectTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ PreconnectTask::PreconnectTask(NetworkSession& networkSession, NetworkLoadParame
RELEASE_LOG(Network, "%p - PreconnectTask::PreconnectTask()", this);

ASSERT(parameters.shouldPreconnectOnly == PreconnectOnly::Yes);
m_networkLoad = makeUnique<NetworkLoad>(*this, nullptr, WTFMove(parameters), networkSession);
m_networkLoad = makeUnique<NetworkLoad>(*this, WTFMove(parameters), networkSession);
}

void PreconnectTask::setH2PingCallback(const URL& url, CompletionHandler<void(Expected<WTF::Seconds, WebCore::ResourceError>&&)>&& completionHandler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void ServiceWorkerNavigationPreloader::loadFromNetwork()
if (m_state.enabled)
m_parameters.request.addHTTPHeaderField(HTTPHeaderName::ServiceWorkerNavigationPreload, m_state.headerValue);

m_networkLoad = makeUnique<NetworkLoad>(*this, nullptr, WTFMove(m_parameters), *m_session);
m_networkLoad = makeUnique<NetworkLoad>(*this, WTFMove(m_parameters), *m_session);
m_networkLoad->start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void ServiceWorkerSoftUpdateLoader::loadFromNetwork(NetworkSession& session, Res
parameters.contentEncodingSniffingPolicy = ContentEncodingSniffingPolicy::Default;
parameters.needsCertificateInfo = true;
parameters.request = WTFMove(request);
m_networkLoad = makeUnique<NetworkLoad>(*this, nullptr, WTFMove(parameters), session);
m_networkLoad = makeUnique<NetworkLoad>(*this, WTFMove(parameters), session);
m_networkLoad->start();

#if PLATFORM(COCOA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ SpeculativeLoad::SpeculativeLoad(Cache& cache, const GlobalFrameID& globalFrameI
parameters.isNavigatingToAppBoundDomain = isNavigatingToAppBoundDomain;
parameters.allowPrivacyProxy = allowPrivacyProxy;
parameters.advancedPrivacyProtections = advancedPrivacyProtections;
m_networkLoad = makeUnique<NetworkLoad>(*this, nullptr, WTFMove(parameters), *networkSession);
m_networkLoad = makeUnique<NetworkLoad>(*this, WTFMove(parameters), *networkSession);
m_networkLoad->startWithScheduling();
}

Expand Down
4 changes: 4 additions & 0 deletions Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class NetworkSessionCocoa final : public NetworkSession {
void removeNetworkWebsiteData(std::optional<WallTime>, std::optional<HashSet<WebCore::RegistrableDomain>>&&, CompletionHandler<void()>&&) override;

void removeDataTask(DataTaskIdentifier);
void removeBlobDataTask(DataTaskIdentifier);

#if HAVE(NW_PROXY_CONFIG)
const Vector<RetainPtr<nw_proxy_config_t>> proxyConfigs() const { return m_nwProxyConfigs; }
Expand Down Expand Up @@ -210,6 +211,9 @@ class NetworkSessionCocoa final : public NetworkSession {
bool m_fastServerTrustEvaluationEnabled { false };
String m_dataConnectionServiceType;
bool m_preventsSystemHTTPProxyAuthentication { false };

class BlobDataTaskClient;
HashMap<DataTaskIdentifier, UniqueRef<BlobDataTaskClient>> m_blobDataTasksForAPI;
HashMap<DataTaskIdentifier, RetainPtr<NSURLSessionDataTask>> m_dataTasksForAPI;
};

Expand Down
76 changes: 75 additions & 1 deletion Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
#import "Download.h"
#import "LegacyCustomProtocolManager.h"
#import "Logging.h"
#import "NetworkDataTaskBlob.h"
#import "NetworkDataTaskCocoa.h"
#import "NetworkLoad.h"
#import "NetworkProcess.h"
#import "NetworkProcessProxyMessages.h"
#import "NetworkSessionCreationParameters.h"
#import "PrivateRelayed.h"
#import "WKURLSessionTaskDelegate.h"
Expand Down Expand Up @@ -1976,9 +1978,71 @@ static void activateSessionCleanup(NetworkSessionCocoa& session, const NetworkSe
m_attributedBundleIdentifierFromPageIdentifiers.add(pageID, parameters.attributedBundleIdentifier());
}

// FIXME: This and WKURLSessionTaskDelegate are kind of duplicate code. Remove this.
// NetworkSessionCocoa::dataTaskWithRequest and NetworkLoad's constructor are also kind of duplicate code.
// Make NetworkLoad's redirection and challenge handling code pass everything to the NetworkLoadClient
// and use NetworkLoad and a new NetworkLoadClient instead of BlobDataTaskClient and WKURLSessionTaskDelegate.
class NetworkSessionCocoa::BlobDataTaskClient final : public NetworkDataTaskClient {
WTF_MAKE_FAST_ALLOCATED;
public:
BlobDataTaskClient(WebCore::ResourceRequest&& request, NetworkSessionCocoa& session, IPC::Connection* connection, DataTaskIdentifier identifier)
: m_task(NetworkDataTaskBlob::create(session, *this, request, session.blobRegistry().filesInBlob(request.url())))
, m_connection(connection)
, m_identifier(identifier)
{
m_task->resume();
}
void cancel() { m_task->cancel(); }
private:
void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&) final { ASSERT_NOT_REACHED(); }
void didReceiveChallenge(WebCore::AuthenticationChallenge&&, NegotiatedLegacyTLS, ChallengeCompletionHandler&&) final { ASSERT_NOT_REACHED(); }
void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend) final { ASSERT_NOT_REACHED(); }
void wasBlocked() final { ASSERT_NOT_REACHED(); }
void cannotShowURL() final { ASSERT_NOT_REACHED(); }
void wasBlockedByRestrictions() final { ASSERT_NOT_REACHED(); }
void wasBlockedByDisabledFTP() final { ASSERT_NOT_REACHED(); }

void didReceiveResponse(WebCore::ResourceResponse&& response, NegotiatedLegacyTLS, PrivateRelayed, ResponseCompletionHandler&& completionHandler)
{
if (!m_connection)
return completionHandler(WebCore::PolicyAction::Ignore);
m_connection->sendWithAsyncReply(Messages::NetworkProcessProxy::DataTaskDidReceiveResponse(m_identifier, response), [completionHandler = WTFMove(completionHandler)] (bool allowed) mutable {
completionHandler(allowed ? WebCore::PolicyAction::Use : WebCore::PolicyAction::Ignore);
});
}

void didReceiveData(const WebCore::SharedBuffer& buffer)
{
if (!m_connection)
return;
buffer.forEachSegment([&] (auto& segment) {
m_connection->send(Messages::NetworkProcessProxy::DataTaskDidReceiveData(m_identifier, segment), 0);
});
}

void didCompleteWithError(const WebCore::ResourceError& error, const WebCore::NetworkLoadMetrics&)
{
if (!m_connection)
return;
m_connection->send(Messages::NetworkProcessProxy::DataTaskDidCompleteWithError(m_identifier, error), 0);
if (m_session)
m_session->removeBlobDataTask(m_identifier);
}

Ref<NetworkDataTask> m_task;
RefPtr<IPC::Connection> m_connection;
WeakPtr<NetworkSessionCocoa> m_session;
const DataTaskIdentifier m_identifier;
};

void NetworkSessionCocoa::dataTaskWithRequest(WebPageProxyIdentifier pageID, WebCore::ResourceRequest&& request, CompletionHandler<void(DataTaskIdentifier)>&& completionHandler)
{
auto identifier = DataTaskIdentifier::generate();
if (request.url().protocolIsBlob()) {
m_blobDataTasksForAPI.add(identifier, makeUniqueRef<BlobDataTaskClient>(WTFMove(request), *this, networkProcess().parentProcessConnection(), identifier));
return completionHandler(identifier);
}

auto nsRequest = request.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::UpdateHTTPBody);
auto session = sessionWrapperForTask(pageID, request, WebCore::StoredCredentialsPolicy::Use, std::nullopt).session;
auto task = [session dataTaskWithRequest:nsRequest];
Expand All @@ -1994,14 +2058,24 @@ static void activateSessionCleanup(NetworkSessionCocoa& session, const NetworkSe

void NetworkSessionCocoa::cancelDataTask(DataTaskIdentifier identifier)
{
[m_dataTasksForAPI.take(identifier) cancel];
if (auto dataTask = m_dataTasksForAPI.take(identifier))
[dataTask cancel];
else if (auto blobDataTask = m_blobDataTasksForAPI.take(identifier))
blobDataTask->cancel();
else
ASSERT_NOT_REACHED();
}

void NetworkSessionCocoa::removeDataTask(DataTaskIdentifier identifier)
{
m_dataTasksForAPI.remove(identifier);
}

void NetworkSessionCocoa::removeBlobDataTask(DataTaskIdentifier identifier)
{
m_blobDataTasksForAPI.remove(identifier);
}

void NetworkSessionCocoa::removeWebPageNetworkParameters(WebPageProxyIdentifier pageID)
{
m_perPageSessionSets.remove(pageID);
Expand Down
11 changes: 6 additions & 5 deletions Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -361,33 +361,34 @@ - (void)completeLoad

namespace WebKit {

void SystemPreviewController::begin(const URL& url, const WebCore::SystemPreviewInfo& systemPreviewInfo)
void SystemPreviewController::begin(const URL& url, const WebCore::SystemPreviewInfo& systemPreviewInfo, CompletionHandler<void()>&& completionHandler)
{
ASSERT(!m_qlPreviewController);
if (m_qlPreviewController)
return;
return completionHandler();

UIViewController *presentingViewController = m_webPageProxy.uiClient().presentingViewController();

if (!presentingViewController)
return;
return completionHandler();

m_systemPreviewInfo = systemPreviewInfo;

RELEASE_LOG(SystemPreview, "SystemPreview began on %lld", m_systemPreviewInfo.element.elementIdentifier.toUInt64());

auto request = WebCore::ResourceRequest(url);
WeakPtr weakThis { *this };
m_webPageProxy.dataTaskWithRequest(WTFMove(request), [weakThis] (Ref<API::DataTask>&& task) {
m_webPageProxy.dataTaskWithRequest(WTFMove(request), [weakThis, completionHandler = WTFMove(completionHandler)] (Ref<API::DataTask>&& task) mutable {
if (!weakThis)
return;
return completionHandler();

auto strongThis = weakThis.get();

_WKDataTask *dataTask = wrapper(task);
strongThis->m_wkSystemPreviewDataTaskDelegate = adoptNS([[_WKSystemPreviewDataTaskDelegate alloc] initWithSystemPreviewController:strongThis]);
[dataTask setDelegate:strongThis->m_wkSystemPreviewDataTaskDelegate.get()];
strongThis->takeActivityToken();
completionHandler();
});

m_downloadURL = url;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/UIProcess/SystemPreviewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SystemPreviewController : public CanMakeWeakPtr<SystemPreviewController> {

bool canPreview(const String& mimeType) const;

void begin(const URL&, const WebCore::SystemPreviewInfo&);
void begin(const URL&, const WebCore::SystemPreviewInfo&, CompletionHandler<void()>&&);
void updateProgress(float);
void loadStarted(const URL& localFileURL);
void loadCompleted(const URL& localFileURL);
Expand Down
7 changes: 4 additions & 3 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12822,10 +12822,11 @@ bool WebPageProxy::hasSleepDisabler() const
}

#if USE(SYSTEM_PREVIEW)
void WebPageProxy::handleSystemPreview(const URL& url, const SystemPreviewInfo& systemPreviewInfo)
void WebPageProxy::beginSystemPreview(const URL& url, const SystemPreviewInfo& systemPreviewInfo, CompletionHandler<void()>&& completionHandler)
{
if (m_systemPreviewController)
m_systemPreviewController->begin(url, systemPreviewInfo);
if (!m_systemPreviewController)
return completionHandler();
m_systemPreviewController->begin(url, systemPreviewInfo, WTFMove(completionHandler));
}

void WebPageProxy::setSystemPreviewCompletionHandlerForLoadTesting(CompletionHandler<void(bool)>&& handler)
Expand Down
Loading

0 comments on commit 9bf05cc

Please sign in to comment.