NSURLSession: Set download resume data when a download fails due to an error.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Mar 2016 23:53:44 +0000 (23:53 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Mar 2016 23:53:44 +0000 (23:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=155665

Reviewed by Alex Christensen.

* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(-[WKNetworkSessionDelegate URLSession:task:didCompleteWithError:]): Save the resume data from the
  NSError userInfo if it exists.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198453 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm

index 3858800..68838e7 100644 (file)
@@ -1,3 +1,14 @@
+2016-03-18  Brady Eidson  <beidson@apple.com>
+
+        NSURLSession: Set download resume data when a download fails due to an error.
+        https://bugs.webkit.org/show_bug.cgi?id=155665
+
+        Reviewed by Alex Christensen.
+
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (-[WKNetworkSessionDelegate URLSession:task:didCompleteWithError:]): Save the resume data from the
+          NSError userInfo if it exists.
+
 2016-03-18  Chris Dumez  <cdumez@apple.com>
 
         Speculative revalidation requests do not have their HTTP user-agent set
index d929be6..e6764ac 100644 (file)
@@ -170,8 +170,18 @@ static NSURLSessionAuthChallengeDisposition toNSURLSessionAuthChallengeDispositi
     else if (error) {
         auto downloadID = _session->takeDownloadID(task.taskIdentifier);
         if (downloadID.downloadID()) {
-            if (auto* download = WebKit::NetworkProcess::singleton().downloadManager().download(downloadID))
-                download->didFail(error, { });
+            if (auto* download = WebKit::NetworkProcess::singleton().downloadManager().download(downloadID)) {
+                NSData *resumeData = nil;
+                if (id userInfo = error.userInfo) {
+                    if ([userInfo isKindOfClass:[NSDictionary class]])
+                        resumeData = userInfo[@"NSURLSessionDownloadTaskResumeData"];
+                }
+                
+                if (resumeData && [resumeData isKindOfClass:[NSData class]])
+                    download->didFail(error, { static_cast<const uint8_t*>(resumeData.bytes), resumeData.length });
+                else
+                    download->didFail(error, { });
+            }
         }
     }
 }