Diff
Modified: trunk/Source/WebKit2/ChangeLog (208520 => 208521)
--- trunk/Source/WebKit2/ChangeLog 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/ChangeLog 2016-11-10 04:49:09 UTC (rev 208521)
@@ -1,3 +1,89 @@
+2016-11-09 Carlos Garcia Campos <[email protected]>
+
+ NetworkSession: Network process crash when converting main resource to download
+ https://bugs.webkit.org/show_bug.cgi?id=164220
+
+ Reviewed by Alex Christensen.
+
+ Right after the main resource load is converted to a download, the web process deletes the ResourceLoader which
+ sends the RemoveLoadIdentifier to the network process and the load is aborted. Sometimes it happens that
+ NetworkResourceLoader::abort() is called while the NetworkLoad is still deciding the destination of the
+ download. In such case, NetworkResourceLoader::didConvertToDownload() has already been called, but not
+ NetworkResourceLoader::didBecomeDownload(). In NetworkResourceLoader::abort() we already handle the case of
+ having a NetworkLoad after NetworkResourceLoader::didConvertToDownload() has been called, to avoid canceling the
+ load in such case, however cleanup() is always called unconditionally and the NetworkLoad is deleted before
+ NetworkResourceLoader::didBecomeDownload() is called. When the NetworkLoad is destroyed the NetworkDataTask
+ client becomes nullptr, leaving it in a state where both the client is nullptr and the download hasn't been
+ created yet. That's not expected to happen and when the response completion handler is called in the
+ NetworkDataTask it tries to use either the client or the download and it crashes.
+ We need to cleanup and destroy the ResourceLoader as soon as it becomes a download, because that's the expected
+ behavior, but at the same time we need to keep the NetworkLoad alive until the NetworkDataTask finishes to become
+ a download. This patch creates a PendingDownload to take the ownership of the NetworkLoad, so that
+ ResourceLoader can be cleaned up and destroyed. The DownloadManager now will handle the PendingDownload as if it
+ was created by startDownload(), but ensuring it's deleted right before the final Download object is added to the
+ downloads map. That way NetworkDataTask will always have a valid client until the final Download is created,
+ first the ResourceLoader and then the PendingDownload. Since the DownloadManager is the owner of the
+ PendingDownload we no longer need the didBecomeDownload() callback to delete the NetworkLoad, because the
+ NetworkLoad will always be owned by the PendingDownload now that will be deleted by the DownloadManager.
+
+ * NetworkProcess/Downloads/DownloadManager.cpp:
+ (WebKit::DownloadManager::dataTaskBecameDownloadTask): Change the ASSERT because at this point we should always
+ have a PendingDownload, and then remove it from the map here before adding the final Download to the map.
+ (WebKit::DownloadManager::convertNetworkLoadToDownload): This replaces convertHandleToDownload, but it also now
+ used for the NetworkSession. It creates a PendingDownload for the given NetworkLoad.
+ (WebKit::DownloadManager::continueDecidePendingDownloadDestination): Do not take the PendingDownload from the
+ map here, just check it's present, because it will be removed from dataTaskBecameDownloadTask().
+ (WebKit::DownloadManager::convertHandleToDownload): Deleted.
+ * NetworkProcess/Downloads/DownloadManager.h:
+ * NetworkProcess/Downloads/PendingDownload.cpp:
+ (WebKit::PendingDownload::PendingDownload): Add a constructor that receives a NetworkLoad.
+ * NetworkProcess/Downloads/PendingDownload.h:
+ * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+ (WebKit::NetworkConnectionToWebProcess::convertMainResourceLoadToDownload): Just ask the ResourceLoader to be
+ converted to a download.
+ * NetworkProcess/NetworkDataTask.h:
+ * NetworkProcess/NetworkDataTaskBlob.cpp:
+ (WebKit::NetworkDataTaskBlob::download): Do not call didBecomeDownload() and add an assert to ensure the client
+ has already been removed right after the final Download object is created.
+ * NetworkProcess/NetworkLoad.cpp:
+ (WebKit::NetworkLoad::NetworkLoad): Use a pointer for the client instead of a reference because now we need to
+ change the client when the load is converted to a download. We don't need to null check the client in any case
+ because the member is only updated internally and always from a passed reference.
+ (WebKit::NetworkLoad::sharedDidReceiveResponse):
+ (WebKit::NetworkLoad::sharedWillSendRedirectedRequest):
+ (WebKit::NetworkLoad::convertTaskToDownload): This now receives a PendingDownload. It updates the client and no
+ longer sends DidStart, because the PendingDownload sends it now.
+ (WebKit::NetworkLoad::didReceiveChallenge):
+ (WebKit::NetworkLoad::didReceiveData):
+ (WebKit::NetworkLoad::didCompleteWithError):
+ (WebKit::NetworkLoad::didSendData):
+ (WebKit::NetworkLoad::wasBlocked):
+ (WebKit::NetworkLoad::cannotShowURL):
+ (WebKit::NetworkLoad::didReceiveBuffer):
+ (WebKit::NetworkLoad::didFinishLoading):
+ (WebKit::NetworkLoad::didFail):
+ (WebKit::NetworkLoad::canAuthenticateAgainstProtectionSpaceAsync):
+ (WebKit::NetworkLoad::didBecomeDownload): Deleted.
+ * NetworkProcess/NetworkLoad.h:
+ * NetworkProcess/NetworkLoadClient.h: Remove didBecomeDownload().
+ * NetworkProcess/NetworkResourceLoader.cpp:
+ (WebKit::NetworkResourceLoader::convertToDownload): This replaces didBecomeDownload() and
+ didConvertToDownload(). It transfers the NetworkLoad to the DownloadManager.
+ (WebKit::NetworkResourceLoader::abort): We don't need to check if the load was converted to a download here,
+ because m_networkLoad will always be null here in such case.
+ (WebKit::NetworkResourceLoader::didBecomeDownload): Deleted
+ (WebKit::NetworkResourceLoader::didConvertToDownload): Deleted
+ * NetworkProcess/NetworkResourceLoader.h:
+ * NetworkProcess/PingLoad.h: Remove didBecomeDownload().
+ * NetworkProcess/cache/NetworkCacheSpeculativeLoad.h: Ditto.
+ * NetworkProcess/cocoa/NetworkDataTaskCocoa.h: Ditto.
+ * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm: Ditto.
+ * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+ (-[WKNetworkSessionDelegate URLSession:dataTask:didBecomeDownloadTask:]): Do not call didBecomeDownload().
+ * NetworkProcess/soup/NetworkDataTaskSoup.cpp:
+ (WebKit::NetworkDataTaskSoup::download): Do not call didBecomeDownload() and add an assert to ensure the client
+ has already been removed right after the final Download object is created.
+
2016-11-09 Alex Christensen <[email protected]>
Unreviewed, rolling out r208438.
Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.cpp (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.cpp 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.cpp 2016-11-10 04:49:09 UTC (rev 208521)
@@ -67,7 +67,8 @@
#if USE(NETWORK_SESSION)
void DownloadManager::dataTaskBecameDownloadTask(DownloadID downloadID, std::unique_ptr<Download>&& download)
{
- ASSERT(!m_pendingDownloads.contains(downloadID));
+ ASSERT(m_pendingDownloads.contains(downloadID));
+ m_pendingDownloads.remove(downloadID);
ASSERT(!m_downloads.contains(downloadID));
m_downloadsAfterDestinationDecided.remove(downloadID);
m_downloads.add(downloadID, WTFMove(download));
@@ -97,28 +98,37 @@
auto addResult = m_downloadsWaitingForDestination.set(downloadID, std::make_pair<RefPtr<NetworkDataTask>, ResponseCompletionHandler>(&networkDataTask, WTFMove(completionHandler)));
ASSERT_UNUSED(addResult, addResult.isNewEntry);
}
+#endif // USE(NETWORK_SESSION)
+
+void DownloadManager::convertNetworkLoadToDownload(DownloadID downloadID, std::unique_ptr<NetworkLoad>&& networkLoad, const ResourceRequest& request, const ResourceResponse& response)
+{
+#if USE(NETWORK_SESSION)
+ ASSERT(!m_pendingDownloads.contains(downloadID));
+ m_pendingDownloads.add(downloadID, std::make_unique<PendingDownload>(WTFMove(networkLoad), downloadID, request, response));
#else
-void DownloadManager::convertHandleToDownload(DownloadID downloadID, ResourceHandle* handle, const ResourceRequest& request, const ResourceResponse& response)
-{
auto download = std::make_unique<Download>(*this, downloadID, request);
+ auto* handle = networkLoad->handle();
+ ASSERT(handle);
download->startWithHandle(handle, response);
ASSERT(!m_downloads.contains(downloadID));
m_downloads.add(downloadID, WTFMove(download));
+
+ // Unblock the URL connection operation queue.
+ handle->continueDidReceiveResponse();
+#endif
}
-#endif // USE(NETWORK_SESSION)
void DownloadManager::continueDecidePendingDownloadDestination(DownloadID downloadID, String destination, const SandboxExtension::Handle& sandboxExtensionHandle, bool allowOverwrite)
{
#if USE(NETWORK_SESSION)
if (m_downloadsWaitingForDestination.contains(downloadID)) {
- auto pendingDownload = m_pendingDownloads.take(downloadID);
auto pair = m_downloadsWaitingForDestination.take(downloadID);
auto networkDataTask = WTFMove(pair.first);
auto completionHandler = WTFMove(pair.second);
ASSERT(networkDataTask);
ASSERT(completionHandler);
- ASSERT(!pendingDownload || pendingDownload.get() == networkDataTask->pendingDownload());
+ ASSERT(m_pendingDownloads.contains(downloadID));
networkDataTask->setPendingDownloadLocation(destination, sandboxExtensionHandle, allowOverwrite);
completionHandler(PolicyDownload);
Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.h (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.h 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.h 2016-11-10 04:49:09 UTC (rev 208521)
@@ -51,6 +51,7 @@
class AuthenticationManager;
class Download;
+class NetworkLoad;
class PendingDownload;
class DownloadManager {
@@ -80,9 +81,8 @@
#endif
void continueWillSendRequest(DownloadID, WebCore::ResourceRequest&&);
void willDecidePendingDownloadDestination(NetworkDataTask&, ResponseCompletionHandler&&);
-#else
- void convertHandleToDownload(DownloadID, WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
#endif
+ void convertNetworkLoadToDownload(DownloadID, std::unique_ptr<NetworkLoad>&&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
void continueDecidePendingDownloadDestination(DownloadID, String destination, const SandboxExtension::Handle&, bool allowOverwrite);
void resumeDownload(WebCore::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, const SandboxExtension::Handle&);
Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.cpp (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.cpp 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.cpp 2016-11-10 04:49:09 UTC (rev 208521)
@@ -48,6 +48,15 @@
send(Messages::DownloadProxy::DidStart(m_networkLoad->currentRequest(), suggestedName));
}
+PendingDownload::PendingDownload(std::unique_ptr<NetworkLoad>&& networkLoad, DownloadID downloadID, const ResourceRequest& request, const ResourceResponse& response)
+ : m_networkLoad(WTFMove(networkLoad))
+{
+ m_networkLoad->setPendingDownloadID(downloadID);
+ send(Messages::DownloadProxy::DidStart(request, String()));
+
+ m_networkLoad->convertTaskToDownload(*this, request, response);
+}
+
void PendingDownload::willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&& redirectResponse)
{
send(Messages::DownloadProxy::WillSendRequest(WTFMove(redirectRequest), WTFMove(redirectResponse)));
@@ -77,11 +86,6 @@
}
#endif
-void PendingDownload::didBecomeDownload()
-{
- m_networkLoad = nullptr;
-}
-
void PendingDownload::didFailLoading(const WebCore::ResourceError& error)
{
send(Messages::DownloadProxy::DidFail(error, { }));
Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.h (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.h 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.h 2016-11-10 04:49:09 UTC (rev 208521)
@@ -46,6 +46,7 @@
WTF_MAKE_FAST_ALLOCATED;
public:
PendingDownload(NetworkLoadParameters&&, DownloadID, NetworkSession&, const String& suggestedName);
+ PendingDownload(std::unique_ptr<NetworkLoad>&&, DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
void continueWillSendRequest(WebCore::ResourceRequest&&);
#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
@@ -65,8 +66,7 @@
void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override { };
void didFinishLoading(double finishTime) override { };
void didFailLoading(const WebCore::ResourceError&) override;
- void didBecomeDownload() override;
-
+
// MessageSender.
IPC::Connection* messageSenderConnection() override;
uint64_t messageSenderDestinationID() override;
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp 2016-11-10 04:49:09 UTC (rev 208521)
@@ -206,17 +206,7 @@
return;
}
-#if USE(NETWORK_SESSION)
- loader->networkLoad()->convertTaskToDownload(downloadID, request, response);
- loader->didConvertToDownload();
-#else
- networkProcess.downloadManager().convertHandleToDownload(downloadID, loader->networkLoad()->handle(), request, response);
-
- // Unblock the URL connection operation queue.
- loader->networkLoad()->handle()->continueDidReceiveResponse();
-
- loader->didConvertToDownload();
-#endif
+ loader->convertToDownload(downloadID, request, response);
}
void NetworkConnectionToWebProcess::cookiesForDOM(SessionID sessionID, const URL& firstParty, const URL& url, String& result)
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkDataTask.h (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/NetworkDataTask.h 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkDataTask.h 2016-11-10 04:49:09 UTC (rev 208521)
@@ -63,7 +63,6 @@
virtual void didReceiveResponseNetworkSession(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) = 0;
virtual void didReceiveData(Ref<WebCore::SharedBuffer>&&) = 0;
virtual void didCompleteWithError(const WebCore::ResourceError&) = 0;
- virtual void didBecomeDownload() = 0;
virtual void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend) = 0;
virtual void wasBlocked() = 0;
virtual void cannotShowURL() = 0;
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.cpp (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.cpp 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.cpp 2016-11-10 04:49:09 UTC (rev 208521)
@@ -472,9 +472,7 @@
downloadManager.dataTaskBecameDownloadTask(m_pendingDownloadID, WTFMove(download));
downloadPtr->didCreateDestination(m_pendingDownloadLocation);
- ASSERT(m_client);
- m_client->didBecomeDownload();
-
+ ASSERT(!m_client);
m_buffer.resize(bufferSize);
read();
}
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp 2016-11-10 04:49:09 UTC (rev 208521)
@@ -185,7 +185,7 @@
if (m_parameters.needsCertificateInfo)
response.includeCertificateInfo();
- return m_client.didReceiveResponse(WTFMove(response));
+ return m_client.get().didReceiveResponse(WTFMove(response));
}
void NetworkLoad::sharedWillSendRedirectedRequest(ResourceRequest&& request, ResourceResponse&& redirectResponse)
@@ -196,21 +196,20 @@
auto oldRequest = WTFMove(m_currentRequest);
m_currentRequest = request;
- m_client.willSendRedirectedRequest(WTFMove(oldRequest), WTFMove(request), WTFMove(redirectResponse));
+ m_client.get().willSendRedirectedRequest(WTFMove(oldRequest), WTFMove(request), WTFMove(redirectResponse));
}
#if USE(NETWORK_SESSION)
-void NetworkLoad::convertTaskToDownload(DownloadID downloadID, const ResourceRequest& updatedRequest, const ResourceResponse& response)
+void NetworkLoad::convertTaskToDownload(PendingDownload& pendingDownload, const ResourceRequest& updatedRequest, const ResourceResponse& response)
{
if (!m_task)
return;
+ m_client = pendingDownload;
m_currentRequest = updatedRequest;
- NetworkProcess::singleton().downloadManager().downloadProxyConnection()->send(Messages::DownloadProxy::DidStart(m_currentRequest, String()), downloadID.downloadID());
- m_task->setPendingDownloadID(downloadID);
-
- ASSERT(m_responseCompletionHandler);
+ m_task->setPendingDownload(pendingDownload);
+
if (m_responseCompletionHandler)
NetworkProcess::singleton().findPendingDownloadLocation(*m_task.get(), std::exchange(m_responseCompletionHandler, nullptr), response);
}
@@ -263,7 +262,7 @@
m_challenge = challenge;
#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
m_challengeCompletionHandler = WTFMove(completionHandler);
- m_client.canAuthenticateAgainstProtectionSpaceAsync(challenge.protectionSpace());
+ m_client.get().canAuthenticateAgainstProtectionSpaceAsync(challenge.protectionSpace());
#else
completeAuthenticationChallenge(WTFMove(completionHandler));
#endif
@@ -338,7 +337,7 @@
// FIXME: This should be the encoded data length, not the decoded data length.
auto size = buffer->size();
- m_client.didReceiveBuffer(WTFMove(buffer), size);
+ m_client.get().didReceiveBuffer(WTFMove(buffer), size);
}
void NetworkLoad::didCompleteWithError(const ResourceError& error)
@@ -346,9 +345,9 @@
ASSERT(!m_throttle);
if (error.isNull())
- m_client.didFinishLoading(WTF::monotonicallyIncreasingTime());
+ m_client.get().didFinishLoading(WTF::monotonicallyIncreasingTime());
else
- m_client.didFailLoading(error);
+ m_client.get().didFailLoading(error);
}
void NetworkLoad::throttleDelayCompleted()
@@ -360,24 +359,19 @@
notifyDidReceiveResponse(WTFMove(throttle->response), WTFMove(throttle->responseCompletionHandler));
}
-void NetworkLoad::didBecomeDownload()
-{
- m_client.didBecomeDownload();
-}
-
void NetworkLoad::didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend)
{
- m_client.didSendData(totalBytesSent, totalBytesExpectedToSend);
+ m_client.get().didSendData(totalBytesSent, totalBytesExpectedToSend);
}
void NetworkLoad::wasBlocked()
{
- m_client.didFailLoading(blockedError(m_currentRequest));
+ m_client.get().didFailLoading(blockedError(m_currentRequest));
}
void NetworkLoad::cannotShowURL()
{
- m_client.didFailLoading(cannotShowURLError(m_currentRequest));
+ m_client.get().didFailLoading(cannotShowURLError(m_currentRequest));
}
#else
@@ -399,13 +393,13 @@
void NetworkLoad::didReceiveBuffer(ResourceHandle* handle, Ref<SharedBuffer>&& buffer, int reportedEncodedDataLength)
{
ASSERT_UNUSED(handle, handle == m_handle);
- m_client.didReceiveBuffer(WTFMove(buffer), reportedEncodedDataLength);
+ m_client.get().didReceiveBuffer(WTFMove(buffer), reportedEncodedDataLength);
}
void NetworkLoad::didFinishLoading(ResourceHandle* handle, double finishTime)
{
ASSERT_UNUSED(handle, handle == m_handle);
- m_client.didFinishLoading(finishTime);
+ m_client.get().didFinishLoading(finishTime);
}
void NetworkLoad::didFail(ResourceHandle* handle, const ResourceError& error)
@@ -413,7 +407,7 @@
ASSERT_UNUSED(handle, !handle || handle == m_handle);
ASSERT(!error.isNull());
- m_client.didFailLoading(error);
+ m_client.get().didFailLoading(error);
}
void NetworkLoad::willSendRequestAsync(ResourceHandle* handle, ResourceRequest&& request, ResourceResponse&& redirectResponse)
@@ -436,7 +430,7 @@
}
m_waitingForContinueCanAuthenticateAgainstProtectionSpace = true;
- m_client.canAuthenticateAgainstProtectionSpaceAsync(protectionSpace);
+ m_client.get().canAuthenticateAgainstProtectionSpaceAsync(protectionSpace);
}
void NetworkLoad::continueCanAuthenticateAgainstProtectionSpace(bool result)
@@ -465,7 +459,7 @@
{
ASSERT_UNUSED(handle, handle == m_handle);
- m_client.didSendData(bytesSent, totalBytesToBeSent);
+ m_client.get().didSendData(bytesSent, totalBytesToBeSent);
}
void NetworkLoad::wasBlocked(ResourceHandle* handle)
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkLoad.h (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/NetworkLoad.h 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkLoad.h 2016-11-10 04:49:09 UTC (rev 208521)
@@ -66,7 +66,7 @@
void continueDidReceiveResponse();
#if USE(NETWORK_SESSION)
- void convertTaskToDownload(DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
+ void convertTaskToDownload(PendingDownload&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
void setPendingDownloadID(DownloadID);
void setSuggestedFilename(const String&);
void setPendingDownload(PendingDownload&);
@@ -113,7 +113,7 @@
void didReceiveAuthenticationChallenge(WebCore::ResourceHandle*, const WebCore::AuthenticationChallenge&) final;
void receivedCancellation(WebCore::ResourceHandle*, const WebCore::AuthenticationChallenge&) final;
bool usesAsyncCallbacks() final { return true; }
- bool loadingSynchronousXHR() final { return m_client.isSynchronous(); }
+ bool loadingSynchronousXHR() final { return m_client.get().isSynchronous(); }
#else
// NetworkDataTaskClient
void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&) final;
@@ -121,7 +121,6 @@
void didReceiveResponseNetworkSession(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) final;
void didReceiveData(Ref<WebCore::SharedBuffer>&&) final;
void didCompleteWithError(const WebCore::ResourceError&) final;
- void didBecomeDownload() final;
void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend) final;
void wasBlocked() final;
void cannotShowURL() final;
@@ -132,7 +131,7 @@
void completeAuthenticationChallenge(ChallengeCompletionHandler&&);
#endif
- NetworkLoadClient& m_client;
+ std::reference_wrapper<NetworkLoadClient> m_client;
const NetworkLoadParameters m_parameters;
#if USE(NETWORK_SESSION)
RefPtr<NetworkDataTask> m_task;
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkLoadClient.h (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/NetworkLoadClient.h 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkLoadClient.h 2016-11-10 04:49:09 UTC (rev 208521)
@@ -57,9 +57,6 @@
virtual void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) = 0;
virtual void didFinishLoading(double finishTime) = 0;
virtual void didFailLoading(const WebCore::ResourceError&) = 0;
-#if USE(NETWORK_SESSION)
- virtual void didBecomeDownload() = 0;
-#endif
};
} // namespace WebKit
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp 2016-11-10 04:49:09 UTC (rev 208521)
@@ -274,21 +274,11 @@
m_connection->didCleanupResourceLoader(*this);
}
-void NetworkResourceLoader::didConvertToDownload()
+void NetworkResourceLoader::convertToDownload(DownloadID downloadID, const ResourceRequest& request, const ResourceResponse& response)
{
- ASSERT(!m_didConvertToDownload);
ASSERT(m_networkLoad);
- m_didConvertToDownload = true;
+ NetworkProcess::singleton().downloadManager().convertNetworkLoadToDownload(downloadID, WTFMove(m_networkLoad), request, response);
}
-
-#if USE(NETWORK_SESSION)
-void NetworkResourceLoader::didBecomeDownload()
-{
- ASSERT(m_didConvertToDownload);
- ASSERT(m_networkLoad);
- m_networkLoad = nullptr;
-}
-#endif
void NetworkResourceLoader::abort()
{
@@ -297,7 +287,7 @@
RELEASE_LOG_IF_ALLOWED("abort: Canceling resource load (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")",
m_parameters.webPageID, m_parameters.webFrameID, m_parameters.identifier);
- if (m_networkLoad && !m_didConvertToDownload) {
+ if (m_networkLoad) {
#if ENABLE(NETWORK_CACHE)
if (canUseCache(m_networkLoad->currentRequest())) {
// We might already have used data from this incomplete load. Ensure older versions don't remain in the cache after cancel.
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h 2016-11-10 04:49:09 UTC (rev 208521)
@@ -26,6 +26,7 @@
#ifndef NetworkResourceLoader_h
#define NetworkResourceLoader_h
+#include "DownloadID.h"
#include "MessageSender.h"
#include "NetworkConnectionToWebProcessMessages.h"
#include "NetworkLoadClient.h"
@@ -95,12 +96,9 @@
void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override;
void didFinishLoading(double finishTime) override;
void didFailLoading(const WebCore::ResourceError&) override;
-#if USE(NETWORK_SESSION)
- void didBecomeDownload() override;
-#endif
-
- void didConvertToDownload();
+ void convertToDownload(DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
+
bool isMainResource() const { return m_parameters.request.requester() == WebCore::ResourceRequest::Requester::Main; }
bool isAlwaysOnLoggingAllowed() const;
@@ -152,7 +150,6 @@
std::unique_ptr<SynchronousLoadData> m_synchronousLoadData;
Vector<RefPtr<WebCore::BlobDataFileReference>> m_fileReferences;
- bool m_didConvertToDownload { false };
bool m_didConsumeSandboxExtensions { false };
bool m_defersLoading { false };
bool m_hasReceivedData { false };
Modified: trunk/Source/WebKit2/NetworkProcess/PingLoad.h (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/PingLoad.h 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/PingLoad.h 2016-11-10 04:49:09 UTC (rev 208521)
@@ -66,7 +66,6 @@
}
void didReceiveData(Ref<WebCore::SharedBuffer>&&) final { ASSERT_NOT_REACHED(); }
void didCompleteWithError(const WebCore::ResourceError&) final { delete this; }
- void didBecomeDownload() final { ASSERT_NOT_REACHED(); }
void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend) final { }
void wasBlocked() final { delete this; }
void cannotShowURL() final { delete this; }
Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h 2016-11-10 04:49:09 UTC (rev 208521)
@@ -63,9 +63,6 @@
void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override;
void didFinishLoading(double finishTime) override;
void didFailLoading(const WebCore::ResourceError&) override;
-#if USE(NETWORK_SESSION)
- void didBecomeDownload() override { ASSERT_NOT_REACHED(); }
-#endif
void abort();
void didComplete();
Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.h (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.h 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.h 2016-11-10 04:49:09 UTC (rev 208521)
@@ -53,7 +53,6 @@
void didCompleteWithError(const WebCore::ResourceError&);
void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&);
void didReceiveData(Ref<WebCore::SharedBuffer>&&);
- void didBecomeDownload();
void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&);
void transferSandboxExtensionToDownload(Download&);
Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm 2016-11-10 04:49:09 UTC (rev 208521)
@@ -171,12 +171,6 @@
m_client->didReceiveData(WTFMove(data));
}
-void NetworkDataTaskCocoa::didBecomeDownload()
-{
- if (m_client)
- m_client->didBecomeDownload();
-}
-
void NetworkDataTaskCocoa::willPerformHTTPRedirection(WebCore::ResourceResponse&& redirectResponse, WebCore::ResourceRequest&& request, RedirectCompletionHandler&& completionHandler)
{
if (redirectResponse.httpStatusCode() == 307 || redirectResponse.httpStatusCode() == 308) {
Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm 2016-11-10 04:49:09 UTC (rev 208521)
@@ -304,7 +304,6 @@
ASSERT(WebCore::fileExists(networkDataTask->pendingDownloadLocation()));
download->didCreateDestination(networkDataTask->pendingDownloadLocation());
downloadManager.dataTaskBecameDownloadTask(downloadID, WTFMove(download));
- networkDataTask->didBecomeDownload();
_session->addDownloadID([downloadTask taskIdentifier], downloadID);
}
Modified: trunk/Source/WebKit2/NetworkProcess/soup/NetworkDataTaskSoup.cpp (208520 => 208521)
--- trunk/Source/WebKit2/NetworkProcess/soup/NetworkDataTaskSoup.cpp 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Source/WebKit2/NetworkProcess/soup/NetworkDataTaskSoup.cpp 2016-11-10 04:49:09 UTC (rev 208521)
@@ -862,9 +862,7 @@
downloadManager.dataTaskBecameDownloadTask(m_pendingDownloadID, WTFMove(download));
downloadPtr->didCreateDestination(m_pendingDownloadLocation);
- ASSERT(m_client);
- m_client->didBecomeDownload();
-
+ ASSERT(!m_client);
read();
}
Modified: trunk/Tools/ChangeLog (208520 => 208521)
--- trunk/Tools/ChangeLog 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Tools/ChangeLog 2016-11-10 04:49:09 UTC (rev 208521)
@@ -1,3 +1,20 @@
+2016-11-09 Carlos Garcia Campos <[email protected]>
+
+ NetworkSession: Network process crash when converting main resource to download
+ https://bugs.webkit.org/show_bug.cgi?id=164220
+
+ Reviewed by Alex Christensen.
+
+ Split /webkit2/Downloads/policy-decision-download in two, one to test the full load when main resource is
+ converted to a download and another one to test the cancellation as the test was doing before. When doing the
+ full load, delay a bit the decide destination to ensure the load is aborted before the data task has became a
+ download.
+
+ * TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp:
+ (testPolicyResponseDownload):
+ (testPolicyResponseDownloadCancel):
+ (beforeAll):
+
2016-11-09 KwangHyuk Kim <[email protected]>
[EFL] fix error message caused by eina log
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp (208520 => 208521)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp 2016-11-10 03:54:06 UTC (rev 208520)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp 2016-11-10 04:49:09 UTC (rev 208521)
@@ -515,6 +515,8 @@
{
test->m_download = download;
test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download));
+ g_signal_connect(download, "decide-destination", G_CALLBACK(downloadDecideDestinationCallback), test);
+ g_signal_connect(download, "finished", G_CALLBACK(downloadFinishedCallback), test);
test->quitMainLoop();
}
@@ -539,6 +541,8 @@
{
GUniquePtr<char> destination(g_build_filename(Test::dataDirectory(), suggestedFilename, nullptr));
GUniquePtr<char> destinationURI(g_filename_to_uri(destination.get(), 0, 0));
+ if (test->m_shouldDelayDecideDestination)
+ g_usleep(0.2 * G_USEC_PER_SEC);
webkit_download_set_destination(download, destinationURI.get());
return TRUE;
}
@@ -550,12 +554,11 @@
void waitUntilDownloadFinished()
{
- g_signal_connect(m_download.get(), "decide-destination", G_CALLBACK(downloadDecideDestinationCallback), this);
- g_signal_connect(m_download.get(), "finished", G_CALLBACK(downloadFinishedCallback), this);
g_main_loop_run(m_mainLoop);
}
GRefPtr<WebKitDownload> m_download;
+ bool m_shouldDelayDecideDestination { false };
};
static void testWebViewDownloadURI(WebViewDownloadTest* test, gconstpointer)
@@ -604,8 +607,10 @@
static void testPolicyResponseDownload(PolicyResponseDownloadTest* test, gconstpointer)
{
- // Test that a download started by the the policy checker contains the web view.
CString requestURI = kServer->getURIForPath("/test.pdf").data();
+ // Delay the DecideDestination to ensure that the load is aborted before the network task has became a download.
+ // See https://bugs.webkit.org/show_bug.cgi?id=164220.
+ test->m_shouldDelayDecideDestination = true;
test->loadURI(requestURI.data());
test->waitUntilDownloadStarted();
@@ -614,6 +619,25 @@
ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, requestURI);
g_assert(test->m_webView == webkit_download_get_web_view(test->m_download.get()));
+ test->waitUntilDownloadFinished();
+
+ GRefPtr<GFile> downloadFile = adoptGRef(g_file_new_for_uri(webkit_download_get_destination(test->m_download.get())));
+ GRefPtr<GFileInfo> downloadFileInfo = adoptGRef(g_file_query_info(downloadFile.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE, static_cast<GFileQueryInfoFlags>(0), nullptr, nullptr));
+ g_assert_cmpint(g_file_info_get_size(downloadFileInfo.get()), >, 0);
+ g_file_delete(downloadFile.get(), nullptr, nullptr);
+}
+
+static void testPolicyResponseDownloadCancel(PolicyResponseDownloadTest* test, gconstpointer)
+{
+ CString requestURI = kServer->getURIForPath("/test.pdf").data();
+ test->loadURI(requestURI.data());
+ test->waitUntilDownloadStarted();
+
+ WebKitURIRequest* request = webkit_download_get_request(test->m_download.get());
+ g_assert(request);
+ ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, requestURI);
+
+ g_assert(test->m_webView == webkit_download_get_web_view(test->m_download.get()));
test->cancelDownloadAndWaitUntilFinished();
}
@@ -657,6 +681,7 @@
DownloadErrorTest::add("Downloads", "remote-file-error", testDownloadRemoteFileError);
WebViewDownloadTest::add("WebKitWebView", "download-uri", testWebViewDownloadURI);
PolicyResponseDownloadTest::add("Downloads", "policy-decision-download", testPolicyResponseDownload);
+ PolicyResponseDownloadTest::add("Downloads", "policy-decision-download-cancel", testPolicyResponseDownloadCancel);
DownloadTest::add("Downloads", "mime-type", testDownloadMIMEType);
}