Title: [197050] trunk/Source/WebKit2
Revision
197050
Author
[email protected]
Date
2016-02-24 13:44:00 -0800 (Wed, 24 Feb 2016)

Log Message

Fix downloads when using NetworkSession
https://bugs.webkit.org/show_bug.cgi?id=154620

Reviewed by Brady Eidson.

This fixes all the _WKDownload API tests when using NetworkSession.

* NetworkProcess/Downloads/DownloadManager.cpp:
(WebKit::DownloadManager::willDecidePendingDownloadDestination):
When we store the NetworkDataTask in m_downloadsWaitingForDestination, we want to remove its owner
from m_pendingDownloads to prevent memory leaks.
(WebKit::DownloadManager::continueDecidePendingDownloadDestination):
If a file exists and the UIProcess has told us to overwrite the file, delete the file
before starting a new download in its place.  This used to be done by CFNetwork in
NSURLDownload's setDestination:allowOverwrite:, but the NSURLSession equivalent (setting
NSURLSessionDataTask's _pathToDownloadTaskFile attribute) does not overwrite the file for us.
(WebKit::DownloadManager::cancelDownload):
If a download is canceled while it is waiting for its destination from the UIProcess, the Download
object does not exist yet.  Instead, we have a completion handler stored in m_downloadsWaitingForDestination.
In this case, we want to send the UIProcess a DownloadProxy::DidCancel message, which I did through
NetworkProcess::pendingDownloadCanceled because the DownloadManager is not a MessageSender, and then
call the completion handler with PolicyIgnore to cancel the download.
(WebKit::DownloadManager::downloadFinished):
* NetworkProcess/Downloads/DownloadManager.h:
* NetworkProcess/Downloads/PendingDownload.cpp:
(WebKit::PendingDownload::continueCanAuthenticateAgainstProtectionSpace):
(WebKit::PendingDownload::didBecomeDownload):
(WebKit::PendingDownload::didFailLoading):
(WebKit::PendingDownload::messageSenderConnection):
(WebKit::PendingDownload::didConvertToDownload): Deleted.
* NetworkProcess/Downloads/PendingDownload.h:
* NetworkProcess/Downloads/cocoa/DownloadCocoa.mm:
(WebKit::Download::cancel):
Send a didCancel message to the UIProcess when a download was cancelled.
Use cancelByProducingResumeData so we can resume canceled downloads.
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::convertMainResourceLoadToDownload):
didConvertToDownload is needed when using NetworkSession to tell the NetworkResourceLoader
not to call cancel on the NetworkLoad after converting it to a download.
* NetworkProcess/NetworkDataTask.h:
(WebKit::NetworkDataTask::setPendingDownload):
(WebKit::NetworkDataTask::pendingDownloadLocation):
* NetworkProcess/NetworkLoad.cpp:
(WebKit::NetworkLoad::convertTaskToDownload):
(WebKit::NetworkLoad::setPendingDownloadID):
(WebKit::NetworkLoad::didReceiveResponseNetworkSession):
Don't call findPendingDownloadLocation as a method on the NetworkDataTask to avoid memory leaks
in DownloadManager.m_pendingDownloads.
(WebKit::NetworkLoad::didBecomeDownload):
Call m_client.didBecomeDownload which is being separated from didConvertToDownload.  The former is
called after the NetworkDataTask becomes a Download, the latter is called as soon as 
convertMainResourceLoadToDownload is called.
* NetworkProcess/NetworkLoadClient.h:
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::continueWillSendRequest):
(WebKit::NetworkProcess::pendingDownloadCanceled):
Send a DownloadProxy::DidCancel message when a pending download is canceled.
(WebKit::NetworkProcess::findPendingDownloadLocation):
(WebKit::NetworkProcess::continueDecidePendingDownloadDestination):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::didConvertToDownload):
(WebKit::NetworkResourceLoader::didBecomeDownload):
Separate setting m_didConvertToDownload, which needs to happen before the didReceiveResponse completion
handler is called to tell the NetworkResourceLoader not to call cancel in NetworkResourceLoader::abort,
from deleting the NetworkLoad, which can be done after the NSURLSessionDataTask has been converted to a
NSURLSessionDownloadTask.
* NetworkProcess/NetworkResourceLoader.h:
* NetworkProcess/cache/NetworkCacheSpeculativeLoad.h:
* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::NetworkDataTask::failureTimerFired):
(WebKit::NetworkDataTask::setPendingDownloadLocation):
(WebKit::NetworkDataTask::transferSandboxExtensionToDownload):
(WebKit::NetworkDataTask::suggestedFilename):
(WebKit::NetworkDataTask::currentRequest):
(WebKit::NetworkDataTask::findPendingDownloadLocation): Deleted.
* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(-[WKNetworkSessionDelegate URLSession:task:didCompleteWithError:]):
Take the downloadID if it failed because we will report that download as failed and not use it again.
(WebKit::NetworkSession::takeDownloadID):
* UIProcess/Downloads/DownloadProxy.cpp:
(WebKit::DownloadProxy::decideDestinationWithSuggestedFilenameAsync):
(WebKit::DownloadProxy::decideDestinationWithSuggestedFilename):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (197049 => 197050)


--- trunk/Source/WebKit2/ChangeLog	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/ChangeLog	2016-02-24 21:44:00 UTC (rev 197050)
@@ -1,3 +1,90 @@
+2016-02-24  Alex Christensen  <[email protected]>
+
+        Fix downloads when using NetworkSession
+        https://bugs.webkit.org/show_bug.cgi?id=154620
+
+        Reviewed by Brady Eidson.
+
+        This fixes all the _WKDownload API tests when using NetworkSession.
+
+        * NetworkProcess/Downloads/DownloadManager.cpp:
+        (WebKit::DownloadManager::willDecidePendingDownloadDestination):
+        When we store the NetworkDataTask in m_downloadsWaitingForDestination, we want to remove its owner
+        from m_pendingDownloads to prevent memory leaks.
+        (WebKit::DownloadManager::continueDecidePendingDownloadDestination):
+        If a file exists and the UIProcess has told us to overwrite the file, delete the file
+        before starting a new download in its place.  This used to be done by CFNetwork in
+        NSURLDownload's setDestination:allowOverwrite:, but the NSURLSession equivalent (setting
+        NSURLSessionDataTask's _pathToDownloadTaskFile attribute) does not overwrite the file for us.
+        (WebKit::DownloadManager::cancelDownload):
+        If a download is canceled while it is waiting for its destination from the UIProcess, the Download
+        object does not exist yet.  Instead, we have a completion handler stored in m_downloadsWaitingForDestination.
+        In this case, we want to send the UIProcess a DownloadProxy::DidCancel message, which I did through
+        NetworkProcess::pendingDownloadCanceled because the DownloadManager is not a MessageSender, and then
+        call the completion handler with PolicyIgnore to cancel the download.
+        (WebKit::DownloadManager::downloadFinished):
+        * NetworkProcess/Downloads/DownloadManager.h:
+        * NetworkProcess/Downloads/PendingDownload.cpp:
+        (WebKit::PendingDownload::continueCanAuthenticateAgainstProtectionSpace):
+        (WebKit::PendingDownload::didBecomeDownload):
+        (WebKit::PendingDownload::didFailLoading):
+        (WebKit::PendingDownload::messageSenderConnection):
+        (WebKit::PendingDownload::didConvertToDownload): Deleted.
+        * NetworkProcess/Downloads/PendingDownload.h:
+        * NetworkProcess/Downloads/cocoa/DownloadCocoa.mm:
+        (WebKit::Download::cancel):
+        Send a didCancel message to the UIProcess when a download was cancelled.
+        Use cancelByProducingResumeData so we can resume canceled downloads.
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::convertMainResourceLoadToDownload):
+        didConvertToDownload is needed when using NetworkSession to tell the NetworkResourceLoader
+        not to call cancel on the NetworkLoad after converting it to a download.
+        * NetworkProcess/NetworkDataTask.h:
+        (WebKit::NetworkDataTask::setPendingDownload):
+        (WebKit::NetworkDataTask::pendingDownloadLocation):
+        * NetworkProcess/NetworkLoad.cpp:
+        (WebKit::NetworkLoad::convertTaskToDownload):
+        (WebKit::NetworkLoad::setPendingDownloadID):
+        (WebKit::NetworkLoad::didReceiveResponseNetworkSession):
+        Don't call findPendingDownloadLocation as a method on the NetworkDataTask to avoid memory leaks
+        in DownloadManager.m_pendingDownloads.
+        (WebKit::NetworkLoad::didBecomeDownload):
+        Call m_client.didBecomeDownload which is being separated from didConvertToDownload.  The former is
+        called after the NetworkDataTask becomes a Download, the latter is called as soon as 
+        convertMainResourceLoadToDownload is called.
+        * NetworkProcess/NetworkLoadClient.h:
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::continueWillSendRequest):
+        (WebKit::NetworkProcess::pendingDownloadCanceled):
+        Send a DownloadProxy::DidCancel message when a pending download is canceled.
+        (WebKit::NetworkProcess::findPendingDownloadLocation):
+        (WebKit::NetworkProcess::continueDecidePendingDownloadDestination):
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkProcess.messages.in:
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::didConvertToDownload):
+        (WebKit::NetworkResourceLoader::didBecomeDownload):
+        Separate setting m_didConvertToDownload, which needs to happen before the didReceiveResponse completion
+        handler is called to tell the NetworkResourceLoader not to call cancel in NetworkResourceLoader::abort,
+        from deleting the NetworkLoad, which can be done after the NSURLSessionDataTask has been converted to a
+        NSURLSessionDownloadTask.
+        * NetworkProcess/NetworkResourceLoader.h:
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoad.h:
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
+        (WebKit::NetworkDataTask::failureTimerFired):
+        (WebKit::NetworkDataTask::setPendingDownloadLocation):
+        (WebKit::NetworkDataTask::transferSandboxExtensionToDownload):
+        (WebKit::NetworkDataTask::suggestedFilename):
+        (WebKit::NetworkDataTask::currentRequest):
+        (WebKit::NetworkDataTask::findPendingDownloadLocation): Deleted.
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (-[WKNetworkSessionDelegate URLSession:task:didCompleteWithError:]):
+        Take the downloadID if it failed because we will report that download as failed and not use it again.
+        (WebKit::NetworkSession::takeDownloadID):
+        * UIProcess/Downloads/DownloadProxy.cpp:
+        (WebKit::DownloadProxy::decideDestinationWithSuggestedFilenameAsync):
+        (WebKit::DownloadProxy::decideDestinationWithSuggestedFilename):
+
 2016-02-24  Anders Carlsson  <[email protected]>
 
         Add more WebKitAdditions extension points

Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.cpp (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.cpp	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.cpp	2016-02-24 21:44:00 UTC (rev 197050)
@@ -97,20 +97,26 @@
 
 void DownloadManager::willDecidePendingDownloadDestination(NetworkDataTask& networkDataTask, ResponseCompletionHandler completionHandler)
 {
-    auto addResult = m_downloadsWaitingForDestination.set(networkDataTask.pendingDownloadID(), std::make_pair<RefPtr<NetworkDataTask>, ResponseCompletionHandler>(&networkDataTask, WTFMove(completionHandler)));
+    auto downloadID = networkDataTask.pendingDownloadID();
+    auto pendingDownload = m_pendingDownloads.take(downloadID);
+    ASSERT(networkDataTask.pendingDownload() == pendingDownload.get());
+    auto addResult = m_downloadsWaitingForDestination.set(downloadID, std::make_pair<RefPtr<NetworkDataTask>, ResponseCompletionHandler>(&networkDataTask, WTFMove(completionHandler)));
     ASSERT_UNUSED(addResult, addResult.isNewEntry);
 }
 
-void DownloadManager::continueDecidePendingDownloadDestination(DownloadID downloadID, String destination, const SandboxExtension::Handle& sandboxExtensionHandle)
+void DownloadManager::continueDecidePendingDownloadDestination(DownloadID downloadID, String destination, const SandboxExtension::Handle& sandboxExtensionHandle, bool allowOverwrite)
 {
     auto pair = m_downloadsWaitingForDestination.take(downloadID);
     auto networkDataTask = pair.first;
     auto completionHandler = pair.second;
-    if (!networkDataTask || !completionHandler) {
-        ASSERT_NOT_REACHED();
+    if (!networkDataTask || !completionHandler)
         return;
-    }
+
     networkDataTask->setPendingDownloadLocation(destination, sandboxExtensionHandle);
+    
+    if (allowOverwrite && fileExists(destination))
+        deleteFile(destination);
+
     completionHandler(PolicyDownload);
     
     ASSERT(!m_downloadsAfterDestinationDecided.contains(downloadID));
@@ -143,11 +149,17 @@
 
 void DownloadManager::cancelDownload(DownloadID downloadID)
 {
-    Download* download = m_downloads.get(downloadID);
-    if (!download)
+    if (Download* download = m_downloads.get(downloadID)) {
+        download->cancel();
         return;
-
-    download->cancel();
+    }
+#if USE(NETWORK_SESSION)
+    if (auto completionHandler = m_downloadsWaitingForDestination.take(downloadID).second) {
+        m_client.pendingDownloadCanceled(downloadID);
+        completionHandler(PolicyIgnore);
+        return;
+    }
+#endif
 }
 
 void DownloadManager::downloadFinished(Download* download)

Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.h (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.h	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.h	2016-02-24 21:44:00 UTC (rev 197050)
@@ -67,6 +67,9 @@
         virtual void didDestroyDownload() = 0;
         virtual IPC::Connection* downloadProxyConnection() = 0;
         virtual AuthenticationManager& downloadsAuthenticationManager() = 0;
+#if USE(NETWORK_SESSION)
+        virtual void pendingDownloadCanceled(DownloadID) = 0;
+#endif
     };
 
     explicit DownloadManager(Client&);
@@ -77,7 +80,7 @@
     void continueCanAuthenticateAgainstProtectionSpace(DownloadID, bool canAuthenticate);
     void continueWillSendRequest(DownloadID, const WebCore::ResourceRequest&);
     void willDecidePendingDownloadDestination(NetworkDataTask&, ResponseCompletionHandler);
-    void continueDecidePendingDownloadDestination(DownloadID, String destination, const SandboxExtension::Handle&);
+    void continueDecidePendingDownloadDestination(DownloadID, String destination, const SandboxExtension::Handle&, bool allowOverwrite);
 #else
     void convertHandleToDownload(DownloadID, WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
 #endif

Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.cpp (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.cpp	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.cpp	2016-02-24 21:44:00 UTC (rev 197050)
@@ -28,6 +28,7 @@
 
 #if USE(NETWORK_SESSION)
 
+#include "DataReference.h"
 #include "DownloadProxyMessages.h"
 #include "NetworkLoad.h"
 #include "NetworkProcess.h"
@@ -64,11 +65,16 @@
     m_networkLoad->continueCanAuthenticateAgainstProtectionSpace(canAuthenticate);
 }
 
-void PendingDownload::didConvertToDownload()
+void PendingDownload::didBecomeDownload()
 {
     m_networkLoad = nullptr;
 }
     
+void PendingDownload::didFailLoading(const WebCore::ResourceError& error)
+{
+    send(Messages::DownloadProxy::DidFail(error, { }));
+}
+    
 IPC::Connection* PendingDownload::messageSenderConnection()
 {
     return NetworkProcess::singleton().parentProcessConnection();

Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.h (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.h	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.h	2016-02-24 21:44:00 UTC (rev 197050)
@@ -57,8 +57,8 @@
     virtual ShouldContinueDidReceiveResponse didReceiveResponse(const WebCore::ResourceResponse&) override { return ShouldContinueDidReceiveResponse::No; };
     virtual void didReceiveBuffer(RefPtr<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override { };
     virtual void didFinishLoading(double finishTime) override { };
-    virtual void didFailLoading(const WebCore::ResourceError&) override { };
-    virtual void didConvertToDownload() override;
+    virtual void didFailLoading(const WebCore::ResourceError&) override;
+    virtual void didBecomeDownload() override;
 #if PLATFORM(COCOA)
     virtual void willCacheResponseAsync(CFCachedURLResponseRef) override { }
 #endif

Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm	2016-02-24 21:44:00 UTC (rev 197050)
@@ -28,6 +28,7 @@
 
 #if USE(NETWORK_SESSION)
 
+#import "DataReference.h"
 #import <WebCore/NotImplemented.h>
 
 namespace WebKit {
@@ -39,7 +40,10 @@
     
 void Download::cancel()
 {
-    [m_download cancel];
+    [m_download cancelByProducingResumeData: ^(NSData *resumeData)
+    {
+        didCancel(IPC::DataReference(reinterpret_cast<const uint8_t*>([resumeData bytes]), [resumeData length]));
+    }];
 }
 
 void Download::platformInvalidate()

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp	2016-02-24 21:44:00 UTC (rev 197050)
@@ -204,8 +204,8 @@
     // Unblock the URL connection operation queue.
     loader->networkLoad()->handle()->continueDidReceiveResponse();
     
+#endif
     loader->didConvertToDownload();
-#endif
 }
 
 void NetworkConnectionToWebProcess::cookiesForDOM(SessionID sessionID, const URL& firstParty, const URL& url, String& result)

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkDataTask.h (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/NetworkDataTask.h	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkDataTask.h	2016-02-24 21:44:00 UTC (rev 197050)
@@ -119,10 +119,10 @@
         ASSERT(!m_pendingDownload);
         m_pendingDownload = &pendingDownload;
     }
-    void findPendingDownloadLocation(ResponseCompletionHandler);
     void setPendingDownloadLocation(const String& filename, const SandboxExtension::Handle&);
     const String& pendingDownloadLocation() { return m_pendingDownloadLocation; }
     WebCore::ResourceRequest currentRequest();
+    String suggestedFilename();
     bool tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler);
     void willPerformHTTPRedirection(const WebCore::ResourceResponse&, WebCore::ResourceRequest&&, RedirectCompletionHandler);
     void transferSandboxExtensionToDownload(Download&);

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp	2016-02-24 21:44:00 UTC (rev 197050)
@@ -172,7 +172,7 @@
     
     ASSERT(m_responseCompletionHandler);
     if (m_responseCompletionHandler)
-        m_task->findPendingDownloadLocation(WTFMove(m_responseCompletionHandler));
+        NetworkProcess::singleton().findPendingDownloadLocation(*m_task.get(), WTFMove(m_responseCompletionHandler));
 }
 
 void NetworkLoad::setPendingDownloadID(DownloadID downloadID)
@@ -221,7 +221,7 @@
 {
     ASSERT(isMainThread());
     if (m_task && m_task->pendingDownloadID().downloadID())
-        m_task->findPendingDownloadLocation(completionHandler);
+        NetworkProcess::singleton().findPendingDownloadLocation(*m_task.get(), completionHandler);
     else if (sharedDidReceiveResponse(response) == NetworkLoadClient::ShouldContinueDidReceiveResponse::Yes)
         completionHandler(PolicyUse);
     else
@@ -245,7 +245,7 @@
 
 void NetworkLoad::didBecomeDownload()
 {
-    m_client.didConvertToDownload();
+    m_client.didBecomeDownload();
 }
 
 void NetworkLoad::didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend)

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkLoadClient.h (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/NetworkLoadClient.h	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkLoadClient.h	2016-02-24 21:44:00 UTC (rev 197050)
@@ -56,7 +56,9 @@
     virtual void didReceiveBuffer(RefPtr<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) = 0;
     virtual void didFinishLoading(double finishTime) = 0;
     virtual void didFailLoading(const WebCore::ResourceError&) = 0;
-    virtual void didConvertToDownload() = 0;
+#if USE(NETWORK_SESSION)
+    virtual void didBecomeDownload() = 0;
+#endif
 
 #if PLATFORM(COCOA)
     virtual void willCacheResponseAsync(CFCachedURLResponseRef) = 0;

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp	2016-02-24 21:44:00 UTC (rev 197050)
@@ -31,6 +31,7 @@
 #include "AuthenticationManager.h"
 #include "ChildProcessMessages.h"
 #include "CustomProtocolManager.h"
+#include "DataReference.h"
 #include "DownloadProxyMessages.h"
 #include "Logging.h"
 #include "NetworkConnectionToWebProcess.h"
@@ -471,18 +472,23 @@
     downloadManager().continueWillSendRequest(downloadID, request);
 }
 
-void NetworkProcess::findPendingDownloadLocation(NetworkDataTask& networkDataTask, String suggestedFilename, ResponseCompletionHandler completionHandler)
+void NetworkProcess::pendingDownloadCanceled(DownloadID downloadID)
 {
+    downloadProxyConnection()->send(Messages::DownloadProxy::DidCancel({ }), downloadID.downloadID());
+}
+
+void NetworkProcess::findPendingDownloadLocation(NetworkDataTask& networkDataTask, ResponseCompletionHandler completionHandler)
+{
     uint64_t destinationID = networkDataTask.pendingDownloadID().downloadID();
     downloadProxyConnection()->send(Messages::DownloadProxy::DidStart(networkDataTask.currentRequest()), destinationID);
     
     downloadManager().willDecidePendingDownloadDestination(networkDataTask, completionHandler);
-    downloadProxyConnection()->send(Messages::DownloadProxy::DecideDestinationWithSuggestedFilenameAsync(networkDataTask.pendingDownloadID(), suggestedFilename), destinationID);
+    downloadProxyConnection()->send(Messages::DownloadProxy::DecideDestinationWithSuggestedFilenameAsync(networkDataTask.pendingDownloadID(), networkDataTask.suggestedFilename()), destinationID);
 }
     
-void NetworkProcess::continueDecidePendingDownloadDestination(DownloadID downloadID, String destination, const SandboxExtension::Handle& sandboxExtensionHandle)
+void NetworkProcess::continueDecidePendingDownloadDestination(DownloadID downloadID, String destination, const SandboxExtension::Handle& sandboxExtensionHandle, bool allowOverwrite)
 {
-    downloadManager().continueDecidePendingDownloadDestination(downloadID, destination, sandboxExtensionHandle);
+    downloadManager().continueDecidePendingDownloadDestination(downloadID, destination, sandboxExtensionHandle, allowOverwrite);
 }
 #endif
 

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h	2016-02-24 21:44:00 UTC (rev 197050)
@@ -101,7 +101,7 @@
 #endif
 
 #if USE(NETWORK_SESSION)
-    void findPendingDownloadLocation(NetworkDataTask&, String suggestedFilename, ResponseCompletionHandler);
+    void findPendingDownloadLocation(NetworkDataTask&, ResponseCompletionHandler);
 #endif
     
     void prefetchDNS(const String&);
@@ -138,6 +138,9 @@
     virtual void didDestroyDownload() override;
     virtual IPC::Connection* downloadProxyConnection() override;
     virtual AuthenticationManager& downloadsAuthenticationManager() override;
+#if USE(NETWORK_SESSION)
+    virtual void pendingDownloadCanceled(DownloadID) override;
+#endif
 
     // Message Handlers
     void didReceiveNetworkProcessMessage(IPC::Connection&, IPC::MessageDecoder&);
@@ -162,7 +165,7 @@
 #if USE(NETWORK_SESSION)
     void continueCanAuthenticateAgainstProtectionSpace(DownloadID, bool canAuthenticate);
     void continueWillSendRequest(DownloadID, const WebCore::ResourceRequest&);
-    void continueDecidePendingDownloadDestination(DownloadID, String destination, const SandboxExtension::Handle& sandboxExtensionHandle);
+    void continueDecidePendingDownloadDestination(DownloadID, String destination, const SandboxExtension::Handle& sandboxExtensionHandle, bool allowOverwrite);
 #endif
     void setCacheModel(uint32_t);
     void allowSpecificHTTPSCertificateForHost(const WebCore::CertificateInfo&, const String& host);

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in	2016-02-24 21:44:00 UTC (rev 197050)
@@ -47,7 +47,7 @@
 #if USE(NETWORK_SESSION)
     ContinueCanAuthenticateAgainstProtectionSpace(WebKit::DownloadID downloadID, bool canAuthenticate)
     ContinueWillSendRequest(WebKit::DownloadID downloadID, WebCore::ResourceRequest request)
-    ContinueDecidePendingDownloadDestination(WebKit::DownloadID downloadID, String destination, WebKit::SandboxExtension::Handle sandboxExtensionHandle)
+    ContinueDecidePendingDownloadDestination(WebKit::DownloadID downloadID, String destination, WebKit::SandboxExtension::Handle sandboxExtensionHandle, bool allowOverwrite)
 #endif
 
     SetProcessSuppressionEnabled(bool flag)

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2016-02-24 21:44:00 UTC (rev 197050)
@@ -237,12 +237,19 @@
 
 void NetworkResourceLoader::didConvertToDownload()
 {
+    ASSERT(!m_didConvertToDownload);
     ASSERT(m_networkLoad);
     m_didConvertToDownload = true;
+}
+    
 #if USE(NETWORK_SESSION)
+void NetworkResourceLoader::didBecomeDownload()
+{
+    ASSERT(m_didConvertToDownload);
+    ASSERT(m_networkLoad);
     m_networkLoad = nullptr;
+}
 #endif
-}
 
 void NetworkResourceLoader::abort()
 {

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h	2016-02-24 21:44:00 UTC (rev 197050)
@@ -102,7 +102,11 @@
     virtual void didReceiveBuffer(RefPtr<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override;
     virtual void didFinishLoading(double finishTime) override;
     virtual void didFailLoading(const WebCore::ResourceError&) override;
-    virtual void didConvertToDownload() override;
+#if USE(NETWORK_SESSION)
+    virtual void didBecomeDownload() override;
+#endif
+    
+    void didConvertToDownload();
 
 private:
     NetworkResourceLoader(const NetworkResourceLoadParameters&, NetworkConnectionToWebProcess&, RefPtr<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>&&);

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h	2016-02-24 21:44:00 UTC (rev 197050)
@@ -59,7 +59,9 @@
     virtual void didReceiveBuffer(RefPtr<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override;
     virtual void didFinishLoading(double finishTime) override;
     virtual void didFailLoading(const WebCore::ResourceError&) override;
-    virtual void didConvertToDownload() override { ASSERT_NOT_REACHED(); }
+#if USE(NETWORK_SESSION)
+    virtual void didBecomeDownload() override { ASSERT_NOT_REACHED(); }
+#endif
 #if PLATFORM(COCOA)
     virtual void willCacheResponseAsync(CFCachedURLResponseRef) override { }
 #endif

Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2016-02-24 21:44:00 UTC (rev 197050)
@@ -193,11 +193,6 @@
     ASSERT_NOT_REACHED();
 }
 
-void NetworkDataTask::findPendingDownloadLocation(ResponseCompletionHandler completionHandler)
-{
-    NetworkProcess::singleton().findPendingDownloadLocation(*this, m_task.get().response.suggestedFilename, completionHandler);
-}
-
 void NetworkDataTask::setPendingDownloadLocation(const WTF::String& filename, const SandboxExtension::Handle& sandboxExtensionHandle)
 {
     ASSERT(!m_sandboxExtension);
@@ -234,6 +229,11 @@
     download.setSandboxExtension(WTFMove(m_sandboxExtension));
 }
 
+String NetworkDataTask::suggestedFilename()
+{
+    return m_task.get().response.suggestedFilename;
+}
+
 WebCore::ResourceRequest NetworkDataTask::currentRequest()
 {
     return [m_task currentRequest];

Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm (197049 => 197050)


--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2016-02-24 21:44:00 UTC (rev 197050)
@@ -134,9 +134,12 @@
 {
     if (auto* networkDataTask = _session->dataTaskForIdentifier(task.taskIdentifier))
         networkDataTask->didCompleteWithError(error);
-    else if (auto* download = WebKit::NetworkProcess::singleton().downloadManager().download(_session->downloadID(task.taskIdentifier))) {
-        if (error)
-            download->didFail(error, { }); // FIXME: Give some actual data here for resuming.
+    else if (error) {
+        auto downloadID = _session->takeDownloadID(task.taskIdentifier);
+        if (downloadID.downloadID()) {
+            if (auto* download = WebKit::NetworkProcess::singleton().downloadManager().download(downloadID))
+                download->didFail(error, { });
+        }
     }
 }
 
@@ -275,7 +278,6 @@
 DownloadID NetworkSession::takeDownloadID(NetworkDataTask::TaskIdentifier taskIdentifier)
 {
     auto downloadID = m_downloadMap.take(taskIdentifier);
-    ASSERT(downloadID.downloadID());
     return downloadID;
 }
 

Modified: trunk/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp (197049 => 197050)


--- trunk/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp	2016-02-24 21:41:51 UTC (rev 197049)
+++ trunk/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp	2016-02-24 21:44:00 UTC (rev 197050)
@@ -184,9 +184,9 @@
     SandboxExtension::Handle sandboxExtensionHandle;
     if (!destination.isNull())
         SandboxExtension::createHandle(destination, SandboxExtension::ReadWrite, sandboxExtensionHandle);
-    
+
     if (NetworkProcessProxy* networkProcess = m_processPool->networkProcess())
-        networkProcess->connection()->send(Messages::NetworkProcess::ContinueDecidePendingDownloadDestination(downloadID, destination, sandboxExtensionHandle), 0);
+        networkProcess->connection()->send(Messages::NetworkProcess::ContinueDecidePendingDownloadDestination(downloadID, destination, sandboxExtensionHandle, allowOverwrite), 0);
 }
 #else
 void DownloadProxy::decideDestinationWithSuggestedFilename(const String& filename, String& destination, bool& allowOverwrite, SandboxExtension::Handle& sandboxExtensionHandle)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to