Bug 137507 - WKContext needs to provide an API to resume a download
Summary: WKContext needs to provide an API to resume a download
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac Unspecified
: P2 Normal
Assignee: Jeff Miller
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2014-10-07 16:41 PDT by Jeff Miller
Modified: 2014-10-21 10:46 PDT (History)
3 users (show)

See Also:


Attachments
Patch (17.85 KB, patch)
2014-10-08 13:48 PDT, Jeff Miller
no flags Details | Formatted Diff | Diff
Patch (17.86 KB, patch)
2014-10-15 13:30 PDT, Jeff Miller
no flags Details | Formatted Diff | Diff
Patch (17.90 KB, patch)
2014-10-20 12:01 PDT, Jeff Miller
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Miller 2014-10-07 16:41:24 PDT
We currently have an API to start a new download:

WK_EXPORT WKDownloadRef WKContextDownloadURLRequest(WKContextRef context, const WKURLRequestRef request);

but there's no API to resume a partially completed download. Presumably, such an API would take the data returned by WKDownloadGetResumeData() as well as a path which can be used by NSURLDownload.
Comment 1 Radar WebKit Bug Importer 2014-10-07 16:42:03 PDT
<rdar://problem/18576259>
Comment 2 Jeff Miller 2014-10-08 13:48:08 PDT
Created attachment 239494 [details]
Patch
Comment 3 Joseph Pecoraro 2014-10-14 18:08:08 PDT
Comment on attachment 239494 [details]
Patch

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

> Source/WebKit2/Shared/Downloads/mac/DownloadMac.mm:99
> +    m_nsURLDownload = [[NSURLDownload alloc] initWithResumeData:nsData.get() delegate:m_delegate.get() path:path];

Nit: Needs adoptNS(...) here.
Comment 4 Conrad Shultz 2014-10-15 09:46:14 PDT
Comment on attachment 239494 [details]
Patch

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

> Source/WebKit2/WebProcess/WebProcess.messages.in:64
> +    # three messages.

There are other messages files with fewer messages; since you're having to change the comment I wonder whether this would be an opportune time to spin off a Download.messages.in.
Comment 5 Jeff Miller 2014-10-15 10:46:47 PDT
Comment on attachment 239494 [details]
Patch

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

>> Source/WebKit2/Shared/Downloads/mac/DownloadMac.mm:99
>> +    m_nsURLDownload = [[NSURLDownload alloc] initWithResumeData:nsData.get() delegate:m_delegate.get() path:path];
> 
> Nit: Needs adoptNS(...) here.

I'll fix this.

>> Source/WebKit2/WebProcess/WebProcess.messages.in:64
>> +    # three messages.
> 
> There are other messages files with fewer messages; since you're having to change the comment I wonder whether this would be an opportune time to spin off a Download.messages.in.

Fair point. I'll do that with a separate bug.
Comment 6 Jeff Miller 2014-10-15 10:49:42 PDT
Comment on attachment 239494 [details]
Patch

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

>>> Source/WebKit2/WebProcess/WebProcess.messages.in:64
>>> +    # three messages.
>> 
>> There are other messages files with fewer messages; since you're having to change the comment I wonder whether this would be an opportune time to spin off a Download.messages.in.
> 
> Fair point. I'll do that with a separate bug.

I filed bug 137744 to track this.
Comment 7 Jeff Miller 2014-10-15 13:30:31 PDT
Created attachment 239891 [details]
Patch
Comment 8 Anders Carlsson 2014-10-20 10:47:14 PDT
Comment on attachment 239494 [details]
Patch

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

> Source/WebKit2/Shared/Downloads/mac/DownloadMac.mm:98
> +    RetainPtr<NSData> nsData = adoptNS([[NSData alloc] initWithBytes:resumeData.data() length:resumeData.size()]);

Can use auto nsData =

> Source/WebKit2/UIProcess/API/C/WKContext.cpp:285
> +WKDownloadRef WKContextResumeDownload(WKContextRef contextRef, WKDataRef resumeData, WKStringRef path)

I'm not in love with this name, since it reads like a getter. I don't have a better idea though.
Comment 9 Jeff Miller 2014-10-20 12:00:01 PDT
Comment on attachment 239494 [details]
Patch

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

>> Source/WebKit2/Shared/Downloads/mac/DownloadMac.mm:98
>> +    RetainPtr<NSData> nsData = adoptNS([[NSData alloc] initWithBytes:resumeData.data() length:resumeData.size()]);
> 
> Can use auto nsData =

Fixed.

>> Source/WebKit2/UIProcess/API/C/WKContext.cpp:285
>> +WKDownloadRef WKContextResumeDownload(WKContextRef contextRef, WKDataRef resumeData, WKStringRef path)
> 
> I'm not in love with this name, since it reads like a getter. I don't have a better idea though.

I don't, either.
Comment 10 Jeff Miller 2014-10-20 12:01:00 PDT
Created attachment 240135 [details]
Patch
Comment 11 Darin Adler 2014-10-20 17:46:03 PDT
Comment on attachment 240135 [details]
Patch

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

> Source/WebKit2/NetworkProcess/NetworkProcess.h:36
> +#include "SandboxExtension.h"

Not needed, because DownloadManager.h now includes this header too.

> Source/WebKit2/Shared/Downloads/mac/DownloadMac.mm:102
> +    auto nsData = adoptNS([[NSData alloc] initWithBytes:resumeData.data() length:resumeData.size()]);

Is this always how we turn an IPC::DataReference into an NSData? I would have expected a more streamlined idiom.

> Source/WebKit2/Shared/Downloads/mac/DownloadMac.mm:105
> +    m_request = ResourceRequest([m_nsURLDownload request]);

Is the explicit constructor needed here?

> Source/WebKit2/UIProcess/API/C/WKContext.h:113
>  WK_EXPORT WKDownloadRef WKContextDownloadURLRequest(WKContextRef context, const WKURLRequestRef request);

Not new to this patch: This const is a mistake.

> Source/WebKit2/UIProcess/WebContext.cpp:908
> +

Should leave out this blank line, I think.
Comment 12 Jeff Miller 2014-10-21 10:42:39 PDT
Comment on attachment 240135 [details]
Patch

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

>> Source/WebKit2/NetworkProcess/NetworkProcess.h:36
>> +#include "SandboxExtension.h"
> 
> Not needed, because DownloadManager.h now includes this header too.

Removed.

>> Source/WebKit2/Shared/Downloads/mac/DownloadMac.mm:102
>> +    auto nsData = adoptNS([[NSData alloc] initWithBytes:resumeData.data() length:resumeData.size()]);
> 
> Is this always how we turn an IPC::DataReference into an NSData? I would have expected a more streamlined idiom.

As far as I can tell, yes. I see this idiom used in other places.

>> Source/WebKit2/Shared/Downloads/mac/DownloadMac.mm:105
>> +    m_request = ResourceRequest([m_nsURLDownload request]);
> 
> Is the explicit constructor needed here?

It isn't. I'll remove the explicit constructor.

>> Source/WebKit2/UIProcess/API/C/WKContext.h:113
>>  WK_EXPORT WKDownloadRef WKContextDownloadURLRequest(WKContextRef context, const WKURLRequestRef request);
> 
> Not new to this patch: This const is a mistake.

I'll fix this in a separate patch.

>> Source/WebKit2/UIProcess/WebContext.cpp:908
>> +
> 
> Should leave out this blank line, I think.

Done.
Comment 13 Jeff Miller 2014-10-21 10:46:07 PDT
Committed r174987: <http://trac.webkit.org/changeset/174987>