[Cocoa] Downloads do not start if policy decision is made asynchronously
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Aug 2015 21:08:13 +0000 (21:08 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Aug 2015 21:08:13 +0000 (21:08 +0000)
commit86a0e638da978735682c3e74b3865326bc799e35
tree8dd4bd13bde17ad57515a481d5466023e5f1f598
parenta542782145b6fd1f3f88fe75b2b89bd7bfda5b4c
[Cocoa] Downloads do not start if policy decision is made asynchronously
https://bugs.webkit.org/show_bug.cgi?id=147985

Reviewed by Brady Eidson.

Source/WebCore:

It's only possible to convert a NSURLConnection to a download while the connection delegate's
-connection:didReceiveResponse: is being called. However, WebKit clients can decide content policy
asynchronously. If a client chooses to download a response asynchronously, we can no longer convert the
connection to a download, so we should start a new download instead.

New API test: _WKDownload.AsynchronousDownloadPolicy

* dom/Document.cpp: Updated to include SubresourceLoader.h.
* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::mainResourceLoader): Updated to return a SubresourceLoader.
(WebCore::DocumentLoader::continueAfterContentPolicy): Cast mainResourceLoader() to a ResourceLoader since
didFail() is private in SubresourceLoader.
* loader/DocumentLoader.h:
* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::SubresourceLoader): Initialized m_callingDidReceiveResponse to false.
(WebCore::SubresourceLoader::didReceiveResponse): Used TemporaryChange<> to set m_callingDidReceiveResponse to true.
* loader/SubresourceLoader.h:
* loader/appcache/ApplicationCacheHost.cpp: Updated to include SubresourceLoader.h.
* loader/mac/DocumentLoaderMac.cpp: Ditto.

Source/WebKit/mac:

* WebCoreSupport/WebFrameLoaderClient.mm:
(WebFrameLoaderClient::convertMainResourceLoadToDownload): Started a new download if the main resource loader is not calling didReceiveResponse.

Source/WebKit/win:

* WebCoreSupport/WebFrameLoaderClient.cpp: Updated to include SubresourceLoader.h.

Source/WebKit2:

* WebProcess/Network/WebResourceLoader.cpp: Updated to include SubresourceLoader.h.
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::convertMainResourceLoadToDownload): Started a new download if the main resource loader is not calling didReceiveResponse.

Tools:

Added a new API test.

* TestWebKitAPI/Tests/WebKit2Cocoa/Download.mm:
(-[AsynchronousDownloadNavigationDelegate webView:decidePolicyForNavigationResponse:decisionHandler:]):
(-[AsynchronousDownloadDelegate _downloadDidStart:]):
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@188486 268f45cc-cd09-0410-ab3c-d52691b4dbfc
17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/DocumentLoader.h
Source/WebCore/loader/SubresourceLoader.cpp
Source/WebCore/loader/SubresourceLoader.h
Source/WebCore/loader/appcache/ApplicationCacheHost.cpp
Source/WebCore/loader/mac/DocumentLoaderMac.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp
Source/WebKit2/WebProcess/WebPage/WebFrame.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Download.mm