Bug 217747

Summary: Introduce new download API
Product: WebKit Reporter: Alex Christensen <achristensen>
Component: New BugsAssignee: Alex Christensen <achristensen>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, annulen, beidson, berto, cgarcia, commit-queue, ews-watchlist, ggaren, gustavo, gyuyoung.kim, kc, michaeldo, mrskman, ryuan.choi, sam, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=219530
Bug Depends on: 219554    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Alex Christensen 2020-10-14 19:36:11 PDT
Introduce new download SPI
Comment 1 Alex Christensen 2020-10-14 19:52:33 PDT
Created attachment 411398 [details]
Patch
Comment 2 Alex Christensen 2020-10-14 19:53:07 PDT
Still needs a bunch of polish, but feel free to give feedback on the general direction.
Comment 3 EWS Watchlist 2020-10-14 19:53:27 PDT
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See https://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
Comment 4 Geoffrey Garen 2020-10-15 16:48:36 PDT
Comment on attachment 411398 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=411398&action=review

> Source/WebKit/UIProcess/API/Cocoa/_WKDownload2.h:40
> +- (void)cancelByProducingResumeData:(void (^)(NSData * _Nullable resumeData))completionHandler;

I would just call this cancel. The parameter name already describes what is passed to the completion handler.

> Source/WebKit/UIProcess/API/Cocoa/_WKDownloadDelegate2.h:47
> +// FIXME: Blobs don't have a response, but can still have a suggested filename.
> +// Separate callback, or nullable response and separate string?
> +- (void)download:(_WKDownload2 *)download decideDestinationWithResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURL *destination))completionHandler;

Seems like the suggested filename should be its own parameter, and response should be nullable. (Seems OK, since most people will only look at the suggested filename.)

> Source/WebKit/UIProcess/API/Cocoa/_WKDownloadDelegate2.h:55
> +- (void)downloadProcessDidTerminate:(_WKDownload2 *)download;

Does this have to be separate from the didFail case? A termination seems like a failure to me. And I'm not sure what we're expecting people to do with the termination.

Side note: Navigation delegate calls it "...WebContentProcessDidTerminate".
Comment 5 Alex Christensen 2020-10-20 16:56:39 PDT
Created attachment 411940 [details]
Patch
Comment 6 Radar WebKit Bug Importer 2020-10-21 19:37:14 PDT
<rdar://problem/70556859>
Comment 7 Alex Christensen 2020-11-09 20:31:33 PST
Created attachment 413659 [details]
Patch
Comment 8 Alex Christensen 2020-11-10 09:55:01 PST
Created attachment 413711 [details]
Patch
Comment 9 Alex Christensen 2020-11-11 23:14:13 PST
Created attachment 413914 [details]
Patch
Comment 10 Alex Christensen 2020-11-11 23:35:41 PST
Created attachment 413916 [details]
Patch
Comment 11 Alex Christensen 2020-11-12 14:30:37 PST
WKNavigationResponsePolicyBecomeDownload needs @constant header doc.  Will add before landing.
Comment 12 Alex Christensen 2020-11-12 14:31:23 PST
Comment on attachment 413916 [details]
Patch

Same with WKDownloadRedirectPolicy.  More header doc.
Comment 13 Brady Eidson 2020-11-12 14:37:27 PST
Comment on attachment 413916 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=413916&action=review

I'm still looking at implementation stuff, but have some header comments

> Source/WebKit/UIProcess/API/Cocoa/WKDownload.h:48
> + @discussion The completionHandler is passed data to be used to resume the download if possible.

I'd make it more clear that the data is used to *attempt* to resume the download, and maybe even call out that due to server side considerations, some downloads may not be resumable.

I would also say something like "to attempt to resume the download, call WKWebView resumeDownloadWithData:"

> Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegate.h:2
> + * Copyright (C) 2014 Apple Inc. All rights reserved.

While I know 2014 was a happier time, sadly, I am quite aware that it's 2020.

> Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegate.h:42
> + @param download The web view that received the redirect.

/s/web view/download/. (Same comment applies to all of these)

> Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegate.h:72
> + suggested download filename.  If the destination file URL is non-null, it must be a file
> + that does not exist yet in a directory that does exist.

"yet" is unnecessary.

The directory must exist and be writeable to the application.

> Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegate.h:95
> + @param resumeData The data to be used to resume this download if possible.

Call out the API where the resume data can be used (just like the cancel completion handler)

> Source/WebKit/UIProcess/API/Cocoa/WKWebView.h:458
> +/* @abstract Begins a download.
> + @param request The request specifying the URL to download.
> + @param completionHandler A block called when the download has started.
> + */
> +- (void)downloadRequest:(NSURLRequest *)request completionHandler:(void(^)(WKDownload *))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));

The purpose of this method is to begin downloading a resource *in the context of the currently displayed webpage as if the policy delegate made a load into a download instead"

I would explicitly call this out.
Comment 14 Alex Christensen 2020-11-12 15:48:50 PST
Created attachment 413978 [details]
Patch
Comment 15 Alex Christensen 2020-11-12 18:55:31 PST
Created attachment 413992 [details]
Patch
Comment 16 Alex Christensen 2020-11-13 08:27:55 PST
rdar://problem/26818508
Comment 17 Alex Christensen 2020-11-13 08:29:31 PST
*** Bug 158801 has been marked as a duplicate of this bug. ***
Comment 18 Alex Christensen 2020-11-17 22:57:38 PST
Created attachment 414415 [details]
Patch
Comment 19 Brady Eidson 2020-11-18 09:32:41 PST
Comment on attachment 414415 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=414415&action=review

Besides fixing EWSs, etc... seems fine.

Except for calling downloads "web views"

> Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegate.h:57
> + @param download The web view that received the authentication challenge.

Download

> Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegate.h:82
> + @param download The web view that has written data.

Download

> Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegate.h:93
> + @param download The web view that finished.

Download

> Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegate.h:98
> + @param download The web view that has failed.

Download
Comment 20 Alex Christensen 2020-11-18 15:09:03 PST
Created attachment 414491 [details]
Patch
Comment 21 Alex Christensen 2020-11-18 15:25:44 PST
Created attachment 414497 [details]
Patch
Comment 22 Alex Christensen 2020-11-18 15:47:15 PST
Created attachment 414502 [details]
Patch
Comment 23 Alex Christensen 2020-11-18 20:00:11 PST
Created attachment 414532 [details]
Patch
Comment 24 Alex Christensen 2020-11-19 09:51:48 PST
Created attachment 414596 [details]
Patch
Comment 25 Alex Christensen 2020-11-19 12:29:46 PST
Comment on attachment 414596 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=414596&action=review

> Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegate.h:70
> + @param response The server response, if this download was the result of an HTTP request.

I need to add "or a synthesized response for blob downloads"
Also, response should not be nullable.  I thought it would be with blobs but it's not.
Comment 26 Brady Eidson 2020-11-19 13:42:16 PST
Comment on attachment 414596 [details]
Patch

(Relatively) Minor changes from last time, still r+
Comment 27 Alex Christensen 2020-11-19 14:08:29 PST
Created attachment 414617 [details]
Patch
Comment 28 Alex Christensen 2020-11-19 15:40:21 PST
Comment on attachment 414617 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=414617&action=review

> Source/WebKit/UIProcess/API/Cocoa/WKNavigation.mm:48
> +- (BOOL)_wasUserInitiated

This is not actually needed.  Will remove.
Comment 29 Alex Christensen 2020-11-20 13:01:55 PST
Created attachment 414708 [details]
Patch
Comment 30 Alex Christensen 2020-12-03 16:37:02 PST
Created attachment 415365 [details]
Patch
Comment 31 EWS 2020-12-03 19:31:02 PST
Committed r270422: <https://trac.webkit.org/changeset/270422>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 415365 [details].
Comment 32 WebKit Commit Bot 2020-12-04 13:56:17 PST
Re-opened since this is blocked by bug 219554
Comment 33 Alexey Proskuryakov 2020-12-04 14:01:00 PST
Reverted in r270454, please see radar for details.
Comment 34 Alex Christensen 2020-12-08 11:18:43 PST
Comment on attachment 415365 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=415365&action=review

> Source/WebKit/UIProcess/API/Cocoa/WKDownloadDelegate.h:68
> +/* @abstract Invoked when the download needs to respond to an authentication challenge.

This isn't correct.  Also, I'm going to make decideDestinationWithResponse mandatory because downloads will always fail if it is not implemented.
Comment 35 Alex Christensen 2020-12-09 19:38:18 PST
Created attachment 415823 [details]
Patch
Comment 36 Alex Christensen 2020-12-09 19:43:26 PST
Created attachment 415824 [details]
Patch
Comment 37 EWS 2020-12-10 11:28:16 PST
Committed r270638: <https://trac.webkit.org/changeset/270638>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 415824 [details].