Bug 143612 - [Mac] "Save to Downloads" does nothing for local images
Summary: [Mac] "Save to Downloads" does nothing for local images
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brent Fulgham
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-04-10 11:23 PDT by Brent Fulgham
Modified: 2015-04-21 18:28 PDT (History)
9 users (show)

See Also:


Attachments
Patch (8.68 KB, patch)
2015-04-10 11:29 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (8.14 KB, patch)
2015-04-10 12:01 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch v2 (iOS Build Fix) (8.12 KB, patch)
2015-04-10 13:46 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (8.10 KB, patch)
2015-04-10 17:40 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (revised per drain's comments) (10.28 KB, patch)
2015-04-12 21:45 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (10.27 KB, patch)
2015-04-13 09:20 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (12.84 KB, patch)
2015-04-14 19:24 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (v4 More improvements) (12.63 KB, patch)
2015-04-14 19:26 PDT, Brent Fulgham
darin: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brent Fulgham 2015-04-10 11:23:18 PDT
The 'Save to Downloads' menu option does nothing when you are viewing a local image in the browser.
Comment 1 Brent Fulgham 2015-04-10 11:29:31 PDT
Created attachment 250524 [details]
Patch
Comment 2 Brent Fulgham 2015-04-10 11:30:14 PDT
<rdar://problem/18858089>
Comment 3 WebKit Commit Bot 2015-04-10 11:31:21 PDT
Attachment 250524 [details] did not pass style-queue:


ERROR: Source/WebKit/mac/WebView/WebView.mm:1851:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit/mac/WebView/WebView.mm:1853:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm:479:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm:481:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
Total errors found: 4 in 7 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Brent Fulgham 2015-04-10 11:47:28 PDT
Comment on attachment 250524 [details]
Patch

After talking to thorton and andersca about this, we will move this away from Download code into the menu handling or view.
Comment 5 Brent Fulgham 2015-04-10 12:01:36 PDT
Created attachment 250525 [details]
Patch
Comment 6 WebKit Commit Bot 2015-04-10 12:03:08 PDT
Attachment 250525 [details] did not pass style-queue:


ERROR: Source/WebKit/mac/WebView/WebView.mm:1851:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit/mac/WebView/WebView.mm:1853:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm:479:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm:481:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
Total errors found: 4 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 Brent Fulgham 2015-04-10 13:45:56 PDT
(In reply to comment #4)
> Comment on attachment 250524 [details]
> Patch
> 
> After talking to thorton and andersca about this, we will move this away
> from Download code into the menu handling or view.

After looking at this, I think it's better to leave it in the WebProcessPool sources, because there are a number of entry points that use the "processPool().download(...)" method to invoke this operation.

I would have to add a test for the URL as a local file in each of the six places this happens, and dispatch to the "local file copy" or the original download method. The current patch hides that inside the download method.

Six locations:
1. Save image locally (Action menu)
2. Save image locally (Context menu)
3. Save media locally (Action menu)
4. Save media locally (Context menu)
5. Save link locally (Action menu)
6. Save link locally (Context menu).
Comment 8 Brent Fulgham 2015-04-10 13:46:29 PDT
Created attachment 250531 [details]
Patch v2 (iOS Build Fix)
Comment 9 Brent Fulgham 2015-04-10 13:47:05 PDT
Comment on attachment 250531 [details]
Patch v2 (iOS Build Fix)

The iOS build doesn't like NSInteger used as a format argument. I switched to using 'int' values for these simple counters.
Comment 10 WebKit Commit Bot 2015-04-10 13:48:24 PDT
Attachment 250531 [details] did not pass style-queue:


ERROR: Source/WebKit/mac/WebView/WebView.mm:1851:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit/mac/WebView/WebView.mm:1853:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm:479:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm:481:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
Total errors found: 4 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 11 Brent Fulgham 2015-04-10 13:48:55 PDT
(In reply to comment #10)
> Attachment 250531 [details] did not pass style-queue:
> 
> 
> ERROR: Source/WebKit/mac/WebView/WebView.mm:1851:  Weird number of spaces at
> line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
> ERROR: Source/WebKit/mac/WebView/WebView.mm:1853:  Weird number of spaces at
> line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
> ERROR: Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm:479:  Weird
> number of spaces at line-start.  Are you using a 4-space indent? 
> [whitespace/indent] [3]
> ERROR: Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm:481:  Weird
> number of spaces at line-start.  Are you using a 4-space indent? 
> [whitespace/indent] [3]
> Total errors found: 4 in 6 files
> 
> 
> If any of these errors are false positives, please file a bug against
> check-webkit-style.

This is just Objective C formatting.
Comment 12 Anders Carlsson 2015-04-10 16:48:47 PDT
Comment on attachment 250531 [details]
Patch v2 (iOS Build Fix)

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

> Source/WebKit/mac/WebView/WebView.mm:1847
> +static void performLocalFileDownload(NSURL* sourceURL)

I think this should be called "save to downloads" or something along those lines.
Comment 13 Brent Fulgham 2015-04-10 17:40:33 PDT
Created attachment 250545 [details]
Patch
Comment 14 WebKit Commit Bot 2015-04-10 17:43:02 PDT
Attachment 250545 [details] did not pass style-queue:


ERROR: Source/WebKit/mac/WebView/WebView.mm:1851:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit/mac/WebView/WebView.mm:1853:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm:479:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm:481:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
Total errors found: 4 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 15 Darin Adler 2015-04-10 19:59:33 PDT
Comment on attachment 250545 [details]
Patch

r=me but I don’t think this is quite right.

Did you test the case where the filename is already the maximum length and we can’t append the hyphen and number? What do we do in that case? I’m guessing we’ll just run an infinite loop.

Can we put this function somewhere we can use it in both cases so we don’t have to have two copies?

What prevents the app from being quit while it is still writing the file if it’s a long file that takes a long time to copy? I am guessing that in that case we’ll leave a partial file ("damaged image") in the file system. Also, do we need to do anything to prevent sudden termination while writing the file?
Comment 16 Brent Fulgham 2015-04-10 21:29:56 PDT
(In reply to comment #15)
> Comment on attachment 250545 [details]
> Patch
> 
> r=me but I don’t think this is quite right.
> 
> Did you test the case where the filename is already the maximum length and
> we can’t append the hyphen and number? What do we do in that case? I’m
> guessing we’ll just run an infinite loop.

The loop only iterates if the error is that the file already exists. I'll have to test whether attempting to copy to a file name that is longer than the max length (and we have an existing file name that matches the proposed name -- up to the limit) fails with the 'file exists' error, or a different error (e.g., file name is too long).

> Can we put this function somewhere we can use it in both cases so we don’t
> have to have two copies?

Yes. It seems like this should be something attached to the existing FileName class.

> What prevents the app from being quit while it is still writing the file if
> it’s a long file that takes a long time to copy? I am guessing that in that
> case we’ll leave a partial file ("damaged image") in the file system. Also,
> do we need to do anything to prevent sudden termination while writing the
> file?

It seems like the downside of early termination is low -- the file already exists on the user's disk, so it's not as if some ephemeral resource could be lost forever.

However, I might want to use the 'atomic' flag on the file copy, so the OS only places the file in the final location if the copy completes. I can make that change as well.
Comment 17 Brent Fulgham 2015-04-12 21:45:33 PDT
Created attachment 250622 [details]
Patch (revised per drain's comments)
Comment 18 WebKit Commit Bot 2015-04-12 21:47:07 PDT
Attachment 250622 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:107:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:109:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:159:  Multi line control clauses should use braces.  [whitespace/braces] [4]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:160:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:161:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:162:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:163:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:164:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
Total errors found: 8 in 7 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 19 Brent Fulgham 2015-04-12 21:47:21 PDT
Comment on attachment 250622 [details]
Patch (revised per drain's comments)

Updated patch to deal with:
1. Avoid partial/corrupt file copies by treating operations atomically:
(a) Initial copy to temp directory. If it fails, nothing is lost.
(b) Final move from temp directory to Downloads is an atomic operation.
2. Check for exceeding max path length.
Comment 20 Brent Fulgham 2015-04-12 21:48:02 PDT
(In reply to comment #15)
> Comment on attachment 250545 [details]
> Patch
> 
> r=me but I don’t think this is quite right.

I uploaded a new patch -- but it has enough changes that I'd appreciate you giving it another look.

Thanks!

-Brent
Comment 21 Brent Fulgham 2015-04-13 09:20:46 PDT
Created attachment 250641 [details]
Patch
Comment 22 WebKit Commit Bot 2015-04-13 09:22:42 PDT
Attachment 250641 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:107:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:109:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:159:  Multi line control clauses should use braces.  [whitespace/braces] [4]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:160:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:161:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:162:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:163:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:164:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
Total errors found: 8 in 7 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 23 Brent Fulgham 2015-04-13 09:24:00 PDT
(In reply to comment #22)
> Attachment 250641 [details] did not pass style-queue:
> 
These are just complaints about our Objective C indentation style.
Comment 24 Darin Adler 2015-04-13 10:16:21 PDT
Comment on attachment 250641 [details]
Patch

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

I know I already reviewed this once, but I think what we have here is the wrong approach. Safari, at least, doesn’t always download to the system downloads directory. I don’t think this can be done correctly without involving the host application. I think we want to work with the existing API or add some new API so we can plug this in to the existing downloads code in WebKit apps.

> Source/WebCore/platform/FileSystem.h:207
> +#if PLATFORM(MAC)

I like to keep the platform-specific stuff sorted in alphabetical order. So I would put MAC after GTK and before SOUP. And add a blank line for SOUP so it’s got its own paragraph.

> Source/WebCore/platform/FileSystem.h:208
> +class URL;

This forward declaration can be unconditional and be at the top of the file.

> Source/WebCore/platform/FileSystem.h:209
> +WEBCORE_EXPORT void saveToDownloadFolder(const URL&);

It’s a little peculiar that this uses URL and the rest of the file system stuff uses Strings for paths, but it’s certainly cleaner code this way. Since this is Mac-specific anyway, why not have it take an NSURL * directly?

> Source/WebCore/platform/FileSystem.h:211
>  } // namespace WebCore

Should add a blank line here.

> Source/WebCore/platform/mac/FileSystemMac.mm:119
> +    NSError *error = nil;
> +    NSURL *downloadDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDownloadsDirectory
> +                                                                         inDomain:NSUserDomainMask
> +                                                                appropriateForURL:nil
> +                                                                           create:NO
> +                                                                            error:&error];
> +    if (!downloadDirectoryURL) {
> +        LOG_ERROR("Unable to locate User's Download directory. %@", error);
> +        return;
> +    }
> +
> +    NSString *targetName = sourceURL.lastPathComponent;
> +    NSString *extension = sourceURL.pathExtension;
> +    NSInteger extensionLength = extension ? extension.length + 1 : 0;
> +    NSString *baseFileName = [targetName substringToIndex:targetName.length - extensionLength];

Should do all of this on the other thread too. No reason to do it on the main thread.

> Source/WebCore/platform/mac/FileSystemMac.mm:133
> +        // Copy file to temporary location:

It’s nice to do this atomically. But to get this right we also would want to make sure we don’t lose the file if we just happen to quit shortly after starting to write it. That can be done by synchronously waiting for the work to complete during app exit and by preventing sudden termination. This is done in IconDatabase, for example, although I’m not sure it will work properly when the work is done in the web process rather than the UI process; for our case, though, it’s the UI process. Outside of WebKit there is something I wrote called CoalescedAsynchronousWriter that deals with this too, but I can’t think of other code in WebKit that does this. To make it work we’d need to add a separate FileSystem.h function to call at quit time.

> Source/WebCore/platform/mac/FileSystemMac.mm:138
> +            LOG_ERROR("Error writing %@ to temporary location %@: %@", sourceURL, tempURL, copyError);
> +            return;

Not good to fail silently.

> Source/WebCore/platform/mac/FileSystemMac.mm:146
> +                return;

Not good to fail silently. Also, it will take a very long time to count up to 2^32, so this will probably hang the queue for a long time if this is happening.

> Source/WebCore/platform/mac/FileSystemMac.mm:154
> +            if (copyURL.absoluteString.length >= PATH_MAX) {
> +                LOG_ERROR("File path '%@' 'exceeds system path length. Unable to perform download.", copyURL);
> +                return;
> +            }

I don’t think this check is correct. For one thing, it’s checking the length of a URL against the path maximum, and the URL is longer than the file system path inside the URL. For another, PATH_MAX is the limit of the file system API, but not necessarily the actual practical limit of the file system itself. For example, I think there’s a 255 UTF-16 code unit limit on file names on HFS+ volumes. Not on the entire path, but just on the file name.

It’s also not good to have this fail silently. The real downloading machinery puts up a sheet if it fails.

> Source/WebCore/platform/mac/FileSystemMac.mm:166
> +            LOG_ERROR("Error copying '%@' from temporary location '%@' to final target '%@': %@", sourceURL, tempURL, copyURL, copyError);
> +            return;

Not good to fail silently.

> Source/WebKit/mac/WebView/WebView.mm:1852
> +    WebCore::URL coreUrl(URL);

WebKit style would be coreURL, not coreUrl.
Comment 25 Brent Fulgham 2015-04-14 10:05:48 PDT
Comment on attachment 250641 [details]
Patch

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

>> Source/WebCore/platform/FileSystem.h:207
>> +#if PLATFORM(MAC)
> 
> I like to keep the platform-specific stuff sorted in alphabetical order. So I would put MAC after GTK and before SOUP. And add a blank line for SOUP so it’s got its own paragraph.

OK!

>> Source/WebCore/platform/FileSystem.h:208
>> +class URL;
> 
> This forward declaration can be unconditional and be at the top of the file.

OK!

>> Source/WebCore/platform/FileSystem.h:209
>> +WEBCORE_EXPORT void saveToDownloadFolder(const URL&);
> 
> It’s a little peculiar that this uses URL and the rest of the file system stuff uses Strings for paths, but it’s certainly cleaner code this way. Since this is Mac-specific anyway, why not have it take an NSURL * directly?

Sure, I could use an NSURL instead. Done!

>> Source/WebCore/platform/FileSystem.h:211
>>  } // namespace WebCore
> 
> Should add a blank line here.

OK!

>> Source/WebCore/platform/mac/FileSystemMac.mm:119
>> +    NSString *baseFileName = [targetName substringToIndex:targetName.length - extensionLength];
> 
> Should do all of this on the other thread too. No reason to do it on the main thread.

OK!

>> Source/WebKit/mac/WebView/WebView.mm:1852
>> +    WebCore::URL coreUrl(URL);
> 
> WebKit style would be coreURL, not coreUrl.

OK!
Comment 26 Brent Fulgham 2015-04-14 19:24:41 PDT
Created attachment 250774 [details]
Patch
Comment 27 WebKit Commit Bot 2015-04-14 19:26:11 PDT
Attachment 250774 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:107:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:109:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:165:  Multi line control clauses should use braces.  [whitespace/braces] [4]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:166:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:167:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:168:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:169:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:170:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
Total errors found: 8 in 7 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 28 Brent Fulgham 2015-04-14 19:26:33 PDT
Created attachment 250775 [details]
Patch (v4 More improvements)
Comment 29 Brent Fulgham 2015-04-14 19:27:38 PDT
Comment on attachment 250775 [details]
Patch (v4 More improvements)

This change includes a mechanism to give feedback to the caller (and delegates). This is sufficient, for example, to allow a registered download client to see that the download (file copy) failed due to disk space or other issues.
Comment 30 WebKit Commit Bot 2015-04-14 19:29:11 PDT
Attachment 250775 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:107:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:109:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:165:  Multi line control clauses should use braces.  [whitespace/braces] [4]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:166:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:167:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:168:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:169:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/mac/FileSystemMac.mm:170:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
Total errors found: 8 in 7 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 31 Darin Adler 2015-04-17 09:13:07 PDT
Comment on attachment 250775 [details]
Patch (v4 More improvements)

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

We discussed these comments and many others in your office. This is getting closer to the right approach but still not something we should land.

> Source/WebKit2/UIProcess/WebProcessPool.cpp:883
> +        WebCore::saveToDownloadFolder(request.url(), ^(bool success, String path, NSError *error) {

These should use C++ lambdas instead of Objective-C blocks so we can see what is captured and make sure there are no threading mistakes. You can pass a lambda to a function that takes a block in Objective-C++.

> Source/WebKit2/UIProcess/WebProcessPool.cpp:885
> +            dispatch_async(dispatch_get_main_queue(), ^() {

These should use C++ lambdas instead of Objective-C blocks so we can see what is captured and make sure there are no threading mistakes. You can pass a lambda to a function that takes a block in Objective-C++.

> Source/WebKit/mac/WebView/WebView.mm:1861
> +        WebCore::saveToDownloadFolder(URL, ^(bool success, String destination, NSError *error) {

These should use C++ lambdas instead of Objective-C blocks so we can see what is captured and make sure there are no threading mistakes. You can pass a lambda to a function that takes a block in Objective-C++.

> Source/WebKit/mac/WebView/WebView.mm:1863
> +            dispatch_async(dispatch_get_main_queue(), ^{

These should use C++ lambdas instead of Objective-C blocks so we can see what is captured and make sure there are no threading mistakes. You can pass a lambda to a function that takes a block in Objective-C++.

> Source/WebKit/mac/WebView/WebView.mm:1865
> +                    [_private->downloadDelegate download:download didCreateDestination:destination];

I don’t think it’s safe to capture the String in this block. Instead I think you need to convert it to a RetainPtr<NSString> before calling dispatch_async, and capture that.

Similarly, I think we need to capture a RetainPtr<WebDownload>, not a raw pointer to a WebDownload, to guarantee we won’t be accessing a deleted object. Same thing for self.
Comment 32 Jon Lee 2015-04-21 18:28:30 PDT
<rdar://problem/20644982>