Title: [261898] trunk
Revision
261898
Author
[email protected]
Date
2020-05-19 17:27:20 -0700 (Tue, 19 May 2020)

Log Message

Add _WKDownloadDelegate callback including totalBytesWritten
https://bugs.webkit.org/show_bug.cgi?id=212110
<rdar://problem/63358981>

Patch by Alex Christensen <[email protected]> on 2020-05-19
Reviewed by Geoffrey Garen.

Source/WebKit:

Without this new callback, after resuming a download, a client has no way to tell whether the download was successfully
resumed by a server that has proper etag and range request support or whether the download began at the beginning again.
A client was guessing that the download did not restart, causing incorrect reported download sizes when the download did restart.
Luckily, the data on disk was not corrupted, just the UI.  This allows us to fix the UI.

Testing covered by expanding the API test for resuming downloads.

* NetworkProcess/Downloads/Download.cpp:
(WebKit::Download::didReceiveData):
* NetworkProcess/Downloads/Download.h:
* NetworkProcess/NetworkDataTaskBlob.cpp:
(WebKit::NetworkDataTaskBlob::writeDownload):
* NetworkProcess/NetworkDataTaskBlob.h:
* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(-[WKNetworkSessionDelegate URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:]):
* UIProcess/API/APIDownloadClient.h:
(API::DownloadClient::didReceiveData):
* UIProcess/API/C/WKContext.cpp:
(WKContextSetDownloadClient):
* UIProcess/API/Cocoa/_WKDownloadDelegate.h:
* UIProcess/Cocoa/DownloadClient.h:
* UIProcess/Cocoa/DownloadClient.mm:
(WebKit::DownloadClient::DownloadClient):
(WebKit::DownloadClient::didReceiveResponse):
(WebKit::DownloadClient::didReceiveData):
* UIProcess/Downloads/DownloadProxy.cpp:
(WebKit::DownloadProxy::didReceiveData):
* UIProcess/Downloads/DownloadProxy.h:
(WebKit::DownloadProxy::expectedContentLength const): Deleted.
(WebKit::DownloadProxy::setExpectedContentLength): Deleted.
(WebKit::DownloadProxy::bytesLoaded const): Deleted.
(WebKit::DownloadProxy::setBytesLoaded): Deleted.
* UIProcess/Downloads/DownloadProxy.messages.in:

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/Download.mm:
(TEST):
* TestWebKitAPI/cocoa/TestDownloadDelegate.h:
* TestWebKitAPI/cocoa/TestDownloadDelegate.mm:
(-[TestDownloadDelegate _download:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:]):
(-[TestDownloadDelegate _download:didReceiveData:]): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (261897 => 261898)


--- trunk/Source/WebKit/ChangeLog	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/ChangeLog	2020-05-20 00:27:20 UTC (rev 261898)
@@ -1,3 +1,45 @@
+2020-05-19  Alex Christensen  <[email protected]>
+
+        Add _WKDownloadDelegate callback including totalBytesWritten
+        https://bugs.webkit.org/show_bug.cgi?id=212110
+        <rdar://problem/63358981>
+
+        Reviewed by Geoffrey Garen.
+
+        Without this new callback, after resuming a download, a client has no way to tell whether the download was successfully
+        resumed by a server that has proper etag and range request support or whether the download began at the beginning again.
+        A client was guessing that the download did not restart, causing incorrect reported download sizes when the download did restart.
+        Luckily, the data on disk was not corrupted, just the UI.  This allows us to fix the UI.
+
+        Testing covered by expanding the API test for resuming downloads.
+
+        * NetworkProcess/Downloads/Download.cpp:
+        (WebKit::Download::didReceiveData):
+        * NetworkProcess/Downloads/Download.h:
+        * NetworkProcess/NetworkDataTaskBlob.cpp:
+        (WebKit::NetworkDataTaskBlob::writeDownload):
+        * NetworkProcess/NetworkDataTaskBlob.h:
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (-[WKNetworkSessionDelegate URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:]):
+        * UIProcess/API/APIDownloadClient.h:
+        (API::DownloadClient::didReceiveData):
+        * UIProcess/API/C/WKContext.cpp:
+        (WKContextSetDownloadClient):
+        * UIProcess/API/Cocoa/_WKDownloadDelegate.h:
+        * UIProcess/Cocoa/DownloadClient.h:
+        * UIProcess/Cocoa/DownloadClient.mm:
+        (WebKit::DownloadClient::DownloadClient):
+        (WebKit::DownloadClient::didReceiveResponse):
+        (WebKit::DownloadClient::didReceiveData):
+        * UIProcess/Downloads/DownloadProxy.cpp:
+        (WebKit::DownloadProxy::didReceiveData):
+        * UIProcess/Downloads/DownloadProxy.h:
+        (WebKit::DownloadProxy::expectedContentLength const): Deleted.
+        (WebKit::DownloadProxy::setExpectedContentLength): Deleted.
+        (WebKit::DownloadProxy::bytesLoaded const): Deleted.
+        (WebKit::DownloadProxy::setBytesLoaded): Deleted.
+        * UIProcess/Downloads/DownloadProxy.messages.in:
+
 2020-05-19  Kate Cheney  <[email protected]>
 
         ITP database should finalize all prepared statements before closing

Modified: trunk/Source/WebKit/NetworkProcess/Downloads/Download.cpp (261897 => 261898)


--- trunk/Source/WebKit/NetworkProcess/Downloads/Download.cpp	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/Download.cpp	2020-05-20 00:27:20 UTC (rev 261898)
@@ -117,7 +117,7 @@
     send(Messages::DownloadProxy::DidCreateDestination(path));
 }
 
-void Download::didReceiveData(uint64_t length)
+void Download::didReceiveData(uint64_t bytesWritten, uint64_t totalBytesWritten, uint64_t totalBytesExpectedToWrite)
 {
     if (!m_hasReceivedData) {
         RELEASE_LOG_IF_ALLOWED("didReceiveData: Started receiving data (id = %" PRIu64 ")", downloadID().downloadID());
@@ -124,9 +124,9 @@
         m_hasReceivedData = true;
     }
     
-    m_monitor.downloadReceivedBytes(length);
+    m_monitor.downloadReceivedBytes(bytesWritten);
 
-    send(Messages::DownloadProxy::DidReceiveData(length));
+    send(Messages::DownloadProxy::DidReceiveData(bytesWritten, totalBytesWritten, totalBytesExpectedToWrite));
 }
 
 void Download::didFinish()

Modified: trunk/Source/WebKit/NetworkProcess/Downloads/Download.h (261897 => 261898)


--- trunk/Source/WebKit/NetworkProcess/Downloads/Download.h	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/Download.h	2020-05-20 00:27:20 UTC (rev 261898)
@@ -88,7 +88,7 @@
     void setSandboxExtension(RefPtr<SandboxExtension>&& sandboxExtension) { m_sandboxExtension = WTFMove(sandboxExtension); }
     void didReceiveChallenge(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&&);
     void didCreateDestination(const String& path);
-    void didReceiveData(uint64_t length);
+    void didReceiveData(uint64_t bytesWritten, uint64_t totalBytesWritten, uint64_t totalBytesExpectedToWrite);
     void didFinish();
     void didFail(const WebCore::ResourceError&, const IPC::DataReference& resumeData);
     void didCancel(const IPC::DataReference& resumeData);

Modified: trunk/Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp (261897 => 261898)


--- trunk/Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp	2020-05-20 00:27:20 UTC (rev 261898)
@@ -483,15 +483,15 @@
 {
     ASSERT(isDownload());
     int bytesWritten = FileSystem::writeToFile(m_downloadFile, data, bytesRead);
-    if (bytesWritten == -1) {
+    if (bytesWritten != bytesRead) {
         didFailDownload(cancelledError(m_firstRequest));
         return false;
     }
 
-    ASSERT(bytesWritten == bytesRead);
+    m_downloadBytesWritten += bytesWritten;
     auto* download = m_networkProcess->downloadManager().download(m_pendingDownloadID);
     ASSERT(download);
-    download->didReceiveData(bytesWritten);
+    download->didReceiveData(bytesWritten, m_downloadBytesWritten, m_totalSize);
     return true;
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/NetworkDataTaskBlob.h (261897 => 261898)


--- trunk/Source/WebKit/NetworkProcess/NetworkDataTaskBlob.h	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/NetworkProcess/NetworkDataTaskBlob.h	2020-05-20 00:27:20 UTC (rev 261898)
@@ -108,6 +108,7 @@
     long long m_rangeEnd { kPositionNotSpecified };
     long long m_rangeSuffixLength { kPositionNotSpecified };
     long long m_totalSize { 0 };
+    long long m_downloadBytesWritten { 0 };
     long long m_totalRemainingSize { 0 };
     long long m_currentItemReadSize { 0 };
     unsigned m_sizeItemCount { 0 };

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm (261897 => 261898)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2020-05-20 00:27:20 UTC (rev 261898)
@@ -950,7 +950,7 @@
     auto* download = _session->networkProcess().downloadManager().download(downloadID);
     if (!download)
         return;
-    download->didReceiveData(bytesWritten);
+    download->didReceiveData(bytesWritten, totalBytesWritten, totalBytesExpectedToWrite);
 }
 
 - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes

Modified: trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp (261897 => 261898)


--- trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp	2020-05-20 00:27:20 UTC (rev 261898)
@@ -992,7 +992,7 @@
     ASSERT(bytesWritten == m_readBuffer.size());
     auto* download = m_session->networkProcess().downloadManager().download(m_pendingDownloadID);
     ASSERT(download);
-    download->didReceiveData(bytesWritten);
+    download->didReceiveData(bytesWritten, 0, 0);
     read();
 }
 

Modified: trunk/Source/WebKit/UIProcess/API/APIDownloadClient.h (261897 => 261898)


--- trunk/Source/WebKit/UIProcess/API/APIDownloadClient.h	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/UIProcess/API/APIDownloadClient.h	2020-05-20 00:27:20 UTC (rev 261898)
@@ -56,7 +56,7 @@
     virtual void didStart(WebKit::DownloadProxy&) { }
     virtual void didReceiveAuthenticationChallenge(WebKit::DownloadProxy&, WebKit::AuthenticationChallengeProxy& challenge) { challenge.listener().completeChallenge(WebKit::AuthenticationChallengeDisposition::Cancel); }
     virtual void didReceiveResponse(WebKit::DownloadProxy&, const WebCore::ResourceResponse&) { }
-    virtual void didReceiveData(WebKit::DownloadProxy&, uint64_t) { }
+    virtual void didReceiveData(WebKit::DownloadProxy&, uint64_t, uint64_t, uint64_t) { }
     virtual void decideDestinationWithSuggestedFilename(WebKit::DownloadProxy&, const WTF::String&, Function<void(WebKit::AllowOverwrite, WTF::String)>&& completionHandler) { completionHandler(WebKit::AllowOverwrite::No, { }); }
     virtual void didCreateDestination(WebKit::DownloadProxy&, const WTF::String&) { }
     virtual void didFinish(WebKit::DownloadProxy&) { }

Modified: trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp (261897 => 261898)


--- trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp	2020-05-20 00:27:20 UTC (rev 261898)
@@ -196,7 +196,7 @@
                 return;
             m_client.didReceiveResponse(m_context, WebKit::toAPI(&downloadProxy), WebKit::toAPI(API::URLResponse::create(response).ptr()), m_client.base.clientInfo);
         }
-        void didReceiveData(WebKit::DownloadProxy& downloadProxy, uint64_t length) final
+        void didReceiveData(WebKit::DownloadProxy& downloadProxy, uint64_t length, uint64_t, uint64_t) final
         {
             if (!m_client.didReceiveData)
                 return;

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadDelegate.h (261897 => 261898)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadDelegate.h	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadDelegate.h	2020-05-20 00:27:20 UTC (rev 261898)
@@ -35,6 +35,7 @@
 - (void)_download:(_WKDownload *)download didReceiveServerRedirectToURL:(NSURL *)url WK_API_AVAILABLE(macos(10.13.4), ios(11.3));
 - (void)_download:(_WKDownload *)download didReceiveResponse:(NSURLResponse *)response;
 - (void)_download:(_WKDownload *)download didReceiveData:(uint64_t)length;
+- (void)_download:(_WKDownload *)download didWriteData:(uint64_t)bytesWritten totalBytesWritten:(uint64_t)totalBytesWritten totalBytesExpectedToWrite:(uint64_t)totalBytesExpectedToWrite WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_download:(_WKDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename completionHandler:(void (^)(BOOL allowOverwrite, NSString *destination))completionHandler;
 - (void)_downloadDidFinish:(_WKDownload *)download;
 - (void)_download:(_WKDownload *)download didFailWithError:(NSError *)error;

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadClient.cpp (261897 => 261898)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadClient.cpp	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadClient.cpp	2020-05-20 00:27:20 UTC (rev 261898)
@@ -68,7 +68,7 @@
         webkitDownloadSetResponse(download.get(), response.get());
     }
 
-    void didReceiveData(DownloadProxy& downloadProxy, uint64_t length) override
+    void didReceiveData(DownloadProxy& downloadProxy, uint64_t length, uint64_t, uint64_t) override
     {
         GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(&downloadProxy);
         webkitDownloadNotifyProgress(download.get(), length);

Modified: trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.h (261897 => 261898)


--- trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.h	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.h	2020-05-20 00:27:20 UTC (rev 261898)
@@ -49,7 +49,7 @@
     // From API::DownloadClient
     void didStart(DownloadProxy&) final;
     void didReceiveResponse(DownloadProxy&, const WebCore::ResourceResponse&) final;
-    void didReceiveData(DownloadProxy&, uint64_t length) final;
+    void didReceiveData(DownloadProxy&, uint64_t, uint64_t, uint64_t) final;
     void decideDestinationWithSuggestedFilename(DownloadProxy&, const String& suggestedFilename, Function<void(AllowOverwrite, String)>&&) final;
     void didFinish(DownloadProxy&) final;
     void didFail(DownloadProxy&, const WebCore::ResourceError&) final;
@@ -74,6 +74,7 @@
         bool downloadDidStart : 1;            
         bool downloadDidReceiveResponse : 1;
         bool downloadDidReceiveData : 1;
+        bool downloadDidWriteDataTotalBytesWrittenTotalBytesExpectedToWrite : 1;
         bool downloadDecideDestinationWithSuggestedFilenameAllowOverwrite : 1;
         bool downloadDecideDestinationWithSuggestedFilenameCompletionHandler : 1;
         bool downloadDidFinish : 1;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm (261897 => 261898)


--- trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm	2020-05-20 00:27:20 UTC (rev 261898)
@@ -53,6 +53,7 @@
     m_delegateMethods.downloadDidStart = [delegate respondsToSelector:@selector(_downloadDidStart:)];
     m_delegateMethods.downloadDidReceiveResponse = [delegate respondsToSelector:@selector(_download:didReceiveResponse:)];
     m_delegateMethods.downloadDidReceiveData = [delegate respondsToSelector:@selector(_download:didReceiveData:)];
+    m_delegateMethods.downloadDidWriteDataTotalBytesWrittenTotalBytesExpectedToWrite = [delegate respondsToSelector:@selector(_download:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:)];
     m_delegateMethods.downloadDecideDestinationWithSuggestedFilenameAllowOverwrite = [delegate respondsToSelector:@selector(_download:decideDestinationWithSuggestedFilename:allowOverwrite:)];
     m_delegateMethods.downloadDecideDestinationWithSuggestedFilenameCompletionHandler = [delegate respondsToSelector:@selector(_download:decideDestinationWithSuggestedFilename:completionHandler:)];
     m_delegateMethods.downloadDidFinish = [delegate respondsToSelector:@selector(_downloadDidFinish:)];
@@ -96,8 +97,6 @@
 {
 #if USE(SYSTEM_PREVIEW)
     if (downloadProxy.isSystemPreviewDownload() && response.isSuccessful()) {
-        downloadProxy.setExpectedContentLength(response.expectedContentLength());
-        downloadProxy.setBytesLoaded(0);
         if (auto* controller = systemPreviewController(downloadProxy))
             controller->updateProgress(0);
         return;
@@ -108,19 +107,20 @@
         [m_delegate _download:wrapper(downloadProxy) didReceiveResponse:response.nsURLResponse()];
 }
 
-void DownloadClient::didReceiveData(DownloadProxy& downloadProxy, uint64_t length)
+void DownloadClient::didReceiveData(DownloadProxy& downloadProxy, uint64_t bytesWritten, uint64_t totalBytesWritten, uint64_t totalBytesExpectedToWrite)
 {
 #if USE(SYSTEM_PREVIEW)
     if (downloadProxy.isSystemPreviewDownload()) {
-        downloadProxy.setBytesLoaded(downloadProxy.bytesLoaded() + length);
         if (auto* controller = systemPreviewController(downloadProxy))
-            controller->updateProgress(static_cast<float>(downloadProxy.bytesLoaded()) / downloadProxy.expectedContentLength());
+            controller->updateProgress(static_cast<float>(totalBytesWritten) / totalBytesExpectedToWrite);
         return;
     }
 #endif
 
-    if (m_delegateMethods.downloadDidReceiveData)
-        [m_delegate _download:wrapper(downloadProxy) didReceiveData:length];
+    if (m_delegateMethods.downloadDidWriteDataTotalBytesWrittenTotalBytesExpectedToWrite)
+        [m_delegate _download:wrapper(downloadProxy) didWriteData:bytesWritten totalBytesWritten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite];
+    else if (m_delegateMethods.downloadDidReceiveData)
+        [m_delegate _download:wrapper(downloadProxy) didReceiveData:bytesWritten];
 }
 
 void DownloadClient::didReceiveAuthenticationChallenge(DownloadProxy& downloadProxy, AuthenticationChallengeProxy& authenticationChallenge)

Modified: trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp (261897 => 261898)


--- trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp	2020-05-20 00:27:20 UTC (rev 261898)
@@ -166,12 +166,12 @@
     m_processPool->downloadClient().didReceiveResponse(*this, response);
 }
 
-void DownloadProxy::didReceiveData(uint64_t length)
+void DownloadProxy::didReceiveData(uint64_t bytesWritten, uint64_t totalBytesWritten, uint64_t totalBytesExpectedToWrite)
 {
     if (!m_processPool)
         return;
 
-    m_processPool->downloadClient().didReceiveData(*this, length);
+    m_processPool->downloadClient().didReceiveData(*this, bytesWritten, totalBytesWritten, totalBytesExpectedToWrite);
 }
 
 void DownloadProxy::decideDestinationWithSuggestedFilenameAsync(DownloadID downloadID, const String& suggestedFilename)

Modified: trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.h (261897 => 261898)


--- trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.h	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.h	2020-05-20 00:27:20 UTC (rev 261898)
@@ -89,12 +89,6 @@
     String destinationFilename() const { return m_destinationFilename; }
     void setDestinationFilename(const String& d) { m_destinationFilename = d; }
 
-    uint64_t expectedContentLength() const { return m_expectedContentLength; }
-    void setExpectedContentLength(uint64_t expectedContentLength) { m_expectedContentLength = expectedContentLength; }
-
-    uint64_t bytesLoaded() const { return m_bytesLoaded; }
-    void setBytesLoaded(uint64_t bytesLoaded) { m_bytesLoaded = bytesLoaded; }
-
 #if USE(SYSTEM_PREVIEW)
     bool isSystemPreviewDownload() const { return request().isSystemPreview(); }
     WebCore::SystemPreviewInfo systemPreviewDownloadInfo() const { return request().systemPreviewInfo(); }
@@ -116,7 +110,7 @@
     void didStart(const WebCore::ResourceRequest&, const String& suggestedFilename);
     void didReceiveAuthenticationChallenge(WebCore::AuthenticationChallenge&&, uint64_t challengeID);
     void didReceiveResponse(const WebCore::ResourceResponse&);
-    void didReceiveData(uint64_t length);
+    void didReceiveData(uint64_t bytesWritten, uint64_t totalBytesWritten, uint64_t totalBytesExpectedToWrite);
     void shouldDecodeSourceDataOfMIMEType(const String& mimeType, bool& result);
     void didCreateDestination(const String& path);
     void didFinish();
@@ -134,8 +128,6 @@
     WebCore::ResourceRequest m_request;
     String m_suggestedFilename;
     String m_destinationFilename;
-    uint64_t m_expectedContentLength { 0 };
-    uint64_t m_bytesLoaded { 0 };
 
     WeakPtr<WebPageProxy> m_originatingPage;
     Vector<URL> m_redirectChain;

Modified: trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.messages.in (261897 => 261898)


--- trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.messages.in	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.messages.in	2020-05-20 00:27:20 UTC (rev 261898)
@@ -27,7 +27,7 @@
     DecideDestinationWithSuggestedFilenameAsync(WebKit::DownloadID downloadID, String suggestedFilename)
 
     DidReceiveResponse(WebCore::ResourceResponse response)
-    DidReceiveData(uint64_t length)
+    DidReceiveData(uint64_t bytesWritten, uint64_t totalBytesWritten, uint64_t totalBytesExpectedToWrite)
     DidCreateDestination(String path)
     DidFinish()
     DidFail(WebCore::ResourceError error, IPC::DataReference resumeData)

Modified: trunk/Tools/ChangeLog (261897 => 261898)


--- trunk/Tools/ChangeLog	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Tools/ChangeLog	2020-05-20 00:27:20 UTC (rev 261898)
@@ -1,3 +1,18 @@
+2020-05-19  Alex Christensen  <[email protected]>
+
+        Add _WKDownloadDelegate callback including totalBytesWritten
+        https://bugs.webkit.org/show_bug.cgi?id=212110
+        <rdar://problem/63358981>
+
+        Reviewed by Geoffrey Garen.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/Download.mm:
+        (TEST):
+        * TestWebKitAPI/cocoa/TestDownloadDelegate.h:
+        * TestWebKitAPI/cocoa/TestDownloadDelegate.mm:
+        (-[TestDownloadDelegate _download:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:]):
+        (-[TestDownloadDelegate _download:didReceiveData:]): Deleted.
+
 2020-05-19  Daniel Bates  <[email protected]>
 
         Blue dotted underline with alternatives only shown for last word, gets lost for previous insertions

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm (261897 => 261898)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm	2020-05-20 00:27:20 UTC (rev 261898)
@@ -1223,7 +1223,7 @@
         completionHandler(_WKNavigationResponsePolicyBecomeDownload);
     };
 
-    enum class Callback : uint8_t { Start, ReceiveData, DecideDestination, CreateDestination, Cancel, Finish };
+    enum class Callback : uint8_t { Start, WriteData, DecideDestination, CreateDestination, Cancel, Finish };
     __block Vector<Callback> callbacks;
     __block bool didCancel = false;
     __block bool didFinish = false;
@@ -1236,9 +1236,11 @@
         callbacks.append(Callback::DecideDestination);
         completionHandler(YES, [tempDir URLByAppendingPathComponent:suggestedFilename].path);
     };
-    downloadDelegate.get().didReceiveData = ^(_WKDownload *download, uint64_t length) {
-        callbacks.append(Callback::ReceiveData);
-        EXPECT_EQ(length, 5000u);
+    downloadDelegate.get().didWriteData = ^(_WKDownload *download, uint64_t bytesWritten, uint64_t totalBytesWritten, uint64_t totalBytesExpectedToWrite) {
+        callbacks.append(Callback::WriteData);
+        EXPECT_EQ(bytesWritten, 5000u);
+        EXPECT_EQ(totalBytesWritten, didCancel ? 10000u : 5000u);
+        EXPECT_EQ(totalBytesExpectedToWrite, 10000u);
         receivedData = true;
     };
     downloadDelegate.get().downloadDidStart = ^(_WKDownload *downloadFromDelegate) {
@@ -1274,9 +1276,9 @@
     EXPECT_EQ(callbacks[0], Callback::Start);
     EXPECT_EQ(callbacks[1], Callback::DecideDestination);
     EXPECT_EQ(callbacks[2], Callback::CreateDestination);
-    EXPECT_EQ(callbacks[3], Callback::ReceiveData);
+    EXPECT_EQ(callbacks[3], Callback::WriteData);
     EXPECT_EQ(callbacks[4], Callback::Cancel);
-    EXPECT_EQ(callbacks[5], Callback::ReceiveData);
+    EXPECT_EQ(callbacks[5], Callback::WriteData);
     EXPECT_EQ(callbacks[6], Callback::Finish);
 
     // Give CFNetwork enough time to unlink the downloaded file if it would have.

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestDownloadDelegate.h (261897 => 261898)


--- trunk/Tools/TestWebKitAPI/cocoa/TestDownloadDelegate.h	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestDownloadDelegate.h	2020-05-20 00:27:20 UTC (rev 261898)
@@ -30,7 +30,7 @@
 @property (nonatomic, copy) void (^downloadDidStart)(_WKDownload *);
 @property (nonatomic, copy) void (^didReceiveServerRedirectToURL)(_WKDownload *, NSURL *);
 @property (nonatomic, copy) void (^didReceiveResponse)(_WKDownload *, NSURLResponse *);
-@property (nonatomic, copy) void (^didReceiveData)(_WKDownload *, uint64_t);
+@property (nonatomic, copy) void (^didWriteData)(_WKDownload *, uint64_t, uint64_t, uint64_t);
 @property (nonatomic, copy) void (^decideDestinationWithSuggestedFilename)(_WKDownload *, NSString *, void (^)(BOOL, NSString *));
 @property (nonatomic, copy) void (^downloadDidFinish)(_WKDownload *);
 @property (nonatomic, copy) void (^didFailWithError)(_WKDownload *, NSError *);

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestDownloadDelegate.mm (261897 => 261898)


--- trunk/Tools/TestWebKitAPI/cocoa/TestDownloadDelegate.mm	2020-05-20 00:05:46 UTC (rev 261897)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestDownloadDelegate.mm	2020-05-20 00:27:20 UTC (rev 261898)
@@ -46,10 +46,10 @@
         _didReceiveResponse(download, response);
 }
 
-- (void)_download:(_WKDownload *)download didReceiveData:(uint64_t)length
+- (void)_download:(_WKDownload *)download didWriteData:(uint64_t)bytesWritten totalBytesWritten:(uint64_t)totalBytesWritten totalBytesExpectedToWrite:(uint64_t)totalBytesExpectedToWrite
 {
-    if (_didReceiveData)
-        _didReceiveData(download, length);
+    if (_didWriteData)
+        _didWriteData(download, bytesWritten, totalBytesWritten, totalBytesExpectedToWrite);
 }
 
 - (void)_download:(_WKDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename completionHandler:(void (^)(BOOL allowOverwrite, NSString *destination))completionHandler
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to