Title: [204008] trunk
Revision
204008
Author
[email protected]
Date
2016-08-01 20:59:18 -0700 (Mon, 01 Aug 2016)

Log Message

_WKDownloadDelegate.didReceiveResponse should be called before decideDestinationWithSuggestedFilename
https://bugs.webkit.org/show_bug.cgi?id=160437
<rdar://problem/27578272>

Patch by Alex Christensen <[email protected]> on 2016-08-01
Reviewed by Brady Eidson.

Source/WebKit2:

This preserves the behavior of the NSURLConnection/NSURLDownload code path.
decideDestinationWithSuggestedFilename might need some information from the didReceiveResponse callback
in order to decide what the suggested filename should be.

* NetworkProcess/Downloads/Download.cpp:
(WebKit::Download::didReceiveAuthenticationChallenge):
(WebKit::Download::didReceiveResponse):
(WebKit::Download::didReceiveData):
* NetworkProcess/Downloads/Download.h:
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::convertMainResourceLoadToDownload):
* NetworkProcess/NetworkLoad.cpp:
(WebKit::NetworkLoad::convertTaskToDownload):
(WebKit::NetworkLoad::setPendingDownloadID):
(WebKit::NetworkLoad::didReceiveResponseNetworkSession):
* NetworkProcess/NetworkLoad.h:
(WebKit::NetworkLoad::pendingDownloadID):
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::pendingDownloadCanceled):
(WebKit::NetworkProcess::findPendingDownloadLocation):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(-[WKNetworkSessionDelegate URLSession:dataTask:didBecomeDownloadTask:]):

Tools:

* TestWebKitAPI/Tests/WebKit2Cocoa/Download.mm:
(-[DownloadDelegate _download:didReceiveResponse:]):
(-[DownloadDelegate _download:decideDestinationWithSuggestedFilename:allowOverwrite:]):
(runTest):
Add a boolean to make sure that didReceiveResponse is called before decideDestinationWithSuggestedFilename.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (204007 => 204008)


--- trunk/Source/WebKit2/ChangeLog	2016-08-02 01:50:16 UTC (rev 204007)
+++ trunk/Source/WebKit2/ChangeLog	2016-08-02 03:59:18 UTC (rev 204008)
@@ -1,3 +1,35 @@
+2016-08-01  Alex Christensen  <[email protected]>
+
+        _WKDownloadDelegate.didReceiveResponse should be called before decideDestinationWithSuggestedFilename
+        https://bugs.webkit.org/show_bug.cgi?id=160437
+        <rdar://problem/27578272>
+
+        Reviewed by Brady Eidson.
+
+        This preserves the behavior of the NSURLConnection/NSURLDownload code path.
+        decideDestinationWithSuggestedFilename might need some information from the didReceiveResponse callback
+        in order to decide what the suggested filename should be.
+
+        * NetworkProcess/Downloads/Download.cpp:
+        (WebKit::Download::didReceiveAuthenticationChallenge):
+        (WebKit::Download::didReceiveResponse):
+        (WebKit::Download::didReceiveData):
+        * NetworkProcess/Downloads/Download.h:
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::convertMainResourceLoadToDownload):
+        * NetworkProcess/NetworkLoad.cpp:
+        (WebKit::NetworkLoad::convertTaskToDownload):
+        (WebKit::NetworkLoad::setPendingDownloadID):
+        (WebKit::NetworkLoad::didReceiveResponseNetworkSession):
+        * NetworkProcess/NetworkLoad.h:
+        (WebKit::NetworkLoad::pendingDownloadID):
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::pendingDownloadCanceled):
+        (WebKit::NetworkProcess::findPendingDownloadLocation):
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (-[WKNetworkSessionDelegate URLSession:dataTask:didBecomeDownloadTask:]):
+
 2016-07-31  Adrian Perez de Castro  <[email protected]>
 
         [GTK][Unix] Implement missing WebKit::SharedMemory::create() function

Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/Download.cpp (204007 => 204008)


--- trunk/Source/WebKit2/NetworkProcess/Downloads/Download.cpp	2016-08-02 01:50:16 UTC (rev 204007)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/Download.cpp	2016-08-02 03:59:18 UTC (rev 204008)
@@ -82,7 +82,6 @@
 {
     m_downloadManager.downloadsAuthenticationManager().didReceiveAuthenticationChallenge(*this, authenticationChallenge);
 }
-#endif
 
 void Download::didReceiveResponse(const ResourceResponse& response)
 {
@@ -90,6 +89,7 @@
 
     send(Messages::DownloadProxy::DidReceiveResponse(response));
 }
+#endif
 
 void Download::didReceiveData(uint64_t length)
 {

Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/Download.h (204007 => 204008)


--- trunk/Source/WebKit2/NetworkProcess/Downloads/Download.h	2016-08-02 01:50:16 UTC (rev 204007)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/Download.h	2016-08-02 03:59:18 UTC (rev 204008)
@@ -96,8 +96,8 @@
 #else
     void didStart();
     void didReceiveAuthenticationChallenge(const WebCore::AuthenticationChallenge&);
+    void didReceiveResponse(const WebCore::ResourceResponse&);
 #endif
-    void didReceiveResponse(const WebCore::ResourceResponse&);
     void didReceiveData(uint64_t length);
     bool shouldDecodeSourceDataOfMIMEType(const String& mimeType);
 #if !USE(NETWORK_SESSION)

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp (204007 => 204008)


--- trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp	2016-08-02 01:50:16 UTC (rev 204007)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp	2016-08-02 03:59:18 UTC (rev 204008)
@@ -209,7 +209,7 @@
     }
 
 #if USE(NETWORK_SESSION)
-    loader->networkLoad()->convertTaskToDownload(downloadID, request);
+    loader->networkLoad()->convertTaskToDownload(downloadID, request, response);
 #else
     networkProcess.downloadManager().convertHandleToDownload(downloadID, loader->networkLoad()->handle(), request, response);
 

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp (204007 => 204008)


--- trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp	2016-08-02 01:50:16 UTC (rev 204007)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp	2016-08-02 03:59:18 UTC (rev 204008)
@@ -181,7 +181,7 @@
 
 #if USE(NETWORK_SESSION)
 
-void NetworkLoad::convertTaskToDownload(DownloadID downloadID, const ResourceRequest& updatedRequest)
+void NetworkLoad::convertTaskToDownload(DownloadID downloadID, const ResourceRequest& updatedRequest, const ResourceResponse& response)
 {
     if (!m_task)
         return;
@@ -190,7 +190,7 @@
     
     ASSERT(m_responseCompletionHandler);
     if (m_responseCompletionHandler)
-        NetworkProcess::singleton().findPendingDownloadLocation(*m_task.get(), std::exchange(m_responseCompletionHandler, nullptr), updatedRequest);
+        NetworkProcess::singleton().findPendingDownloadLocation(*m_task.get(), std::exchange(m_responseCompletionHandler, nullptr), updatedRequest, response);
 }
 
 void NetworkLoad::setPendingDownloadID(DownloadID downloadID)
@@ -238,7 +238,7 @@
 {
     ASSERT(isMainThread());
     if (m_task && m_task->pendingDownloadID().downloadID())
-        NetworkProcess::singleton().findPendingDownloadLocation(*m_task.get(), WTFMove(completionHandler), m_task->currentRequest());
+        NetworkProcess::singleton().findPendingDownloadLocation(*m_task.get(), WTFMove(completionHandler), m_task->currentRequest(), response);
     else if (sharedDidReceiveResponse(WTFMove(response)) == NetworkLoadClient::ShouldContinueDidReceiveResponse::Yes)
         completionHandler(PolicyUse);
     else

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkLoad.h (204007 => 204008)


--- trunk/Source/WebKit2/NetworkProcess/NetworkLoad.h	2016-08-02 01:50:16 UTC (rev 204007)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkLoad.h	2016-08-02 03:59:18 UTC (rev 204008)
@@ -64,7 +64,7 @@
     void continueDidReceiveResponse();
 
 #if USE(NETWORK_SESSION)
-    void convertTaskToDownload(DownloadID, const WebCore::ResourceRequest&);
+    void convertTaskToDownload(DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
     void setPendingDownloadID(DownloadID);
     void setPendingDownload(PendingDownload&);
     DownloadID pendingDownloadID() { return m_task->pendingDownloadID(); }

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp (204007 => 204008)


--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp	2016-08-02 01:50:16 UTC (rev 204007)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp	2016-08-02 03:59:18 UTC (rev 204008)
@@ -516,10 +516,11 @@
     downloadProxyConnection()->send(Messages::DownloadProxy::DidCancel({ }), downloadID.downloadID());
 }
 
-void NetworkProcess::findPendingDownloadLocation(NetworkDataTask& networkDataTask, ResponseCompletionHandler&& completionHandler, const ResourceRequest& updatedRequest)
+void NetworkProcess::findPendingDownloadLocation(NetworkDataTask& networkDataTask, ResponseCompletionHandler&& completionHandler, const ResourceRequest& updatedRequest, const ResourceResponse& response)
 {
     uint64_t destinationID = networkDataTask.pendingDownloadID().downloadID();
     downloadProxyConnection()->send(Messages::DownloadProxy::DidStart(updatedRequest, String()), destinationID);
+    downloadProxyConnection()->send(Messages::DownloadProxy::DidReceiveResponse(response), destinationID);
 
     downloadManager().willDecidePendingDownloadDestination(networkDataTask, WTFMove(completionHandler));
     downloadProxyConnection()->send(Messages::DownloadProxy::DecideDestinationWithSuggestedFilenameAsync(networkDataTask.pendingDownloadID(), networkDataTask.suggestedFilename()), destinationID);

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h (204007 => 204008)


--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h	2016-08-02 01:50:16 UTC (rev 204007)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h	2016-08-02 03:59:18 UTC (rev 204008)
@@ -107,7 +107,7 @@
 #endif
 
 #if USE(NETWORK_SESSION)
-    void findPendingDownloadLocation(NetworkDataTask&, ResponseCompletionHandler&&, const WebCore::ResourceRequest&);
+    void findPendingDownloadLocation(NetworkDataTask&, ResponseCompletionHandler&&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
 #endif
 
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)

Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm (204007 => 204008)


--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2016-08-02 01:50:16 UTC (rev 204007)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2016-08-02 03:59:18 UTC (rev 204008)
@@ -301,7 +301,6 @@
         networkDataTask->transferSandboxExtensionToDownload(*download);
         ASSERT(WebCore::fileExists(networkDataTask->pendingDownloadLocation()));
         download->didCreateDestination(networkDataTask->pendingDownloadLocation());
-        download->didReceiveResponse([downloadTask response]);
         auto pendingDownload = downloadManager.dataTaskBecameDownloadTask(downloadID, WTFMove(download));
 
         networkDataTask->didBecomeDownload();

Modified: trunk/Tools/ChangeLog (204007 => 204008)


--- trunk/Tools/ChangeLog	2016-08-02 01:50:16 UTC (rev 204007)
+++ trunk/Tools/ChangeLog	2016-08-02 03:59:18 UTC (rev 204008)
@@ -1,3 +1,17 @@
+2016-08-01  Alex Christensen  <[email protected]>
+
+        _WKDownloadDelegate.didReceiveResponse should be called before decideDestinationWithSuggestedFilename
+        https://bugs.webkit.org/show_bug.cgi?id=160437
+        <rdar://problem/27578272>
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/Download.mm:
+        (-[DownloadDelegate _download:didReceiveResponse:]):
+        (-[DownloadDelegate _download:decideDestinationWithSuggestedFilename:allowOverwrite:]):
+        (runTest):
+        Add a boolean to make sure that didReceiveResponse is called before decideDestinationWithSuggestedFilename.
+
 2016-08-01  Carlos Alberto Lopez Perez  <[email protected]>
 
         [Tools] The GDB backtrace report tool don't checks the gdb return code.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Download.mm (204007 => 204008)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Download.mm	2016-08-02 01:50:16 UTC (rev 204007)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Download.mm	2016-08-02 03:59:18 UTC (rev 204008)
@@ -42,6 +42,7 @@
 #import <wtf/text/WTFString.h>
 
 static bool isDone;
+static bool hasReceivedResponse;
 static NSURL *sourceURL = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
 
 @interface DownloadDelegate : NSObject <_WKDownloadDelegate>
@@ -64,6 +65,7 @@
 
 - (void)_download:(_WKDownload *)download didReceiveResponse:(NSURLResponse *)response
 {
+    hasReceivedResponse = true;
     EXPECT_EQ(_download, download);
     EXPECT_TRUE(_expectedContentLength == 0);
     EXPECT_TRUE(_receivedContentLength == 0);
@@ -79,6 +81,7 @@
 
 - (NSString *)_download:(_WKDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename allowOverwrite:(BOOL *)allowOverwrite
 {
+    EXPECT_TRUE(hasReceivedResponse);
     EXPECT_EQ(_download, download);
 
     WebCore::PlatformFileHandle fileHandle;
@@ -122,6 +125,7 @@
     [[[webView configuration] processPool] _setDownloadDelegate:downloadDelegate];
 
     isDone = false;
+    hasReceivedResponse = false;
     [webView loadRequest:[NSURLRequest requestWithURL:url]];
     TestWebKitAPI::Util::run(&isDone);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to