Bug 194362 - Add afterScreenUpdates to WKSnapshotConfiguration
Summary: Add afterScreenUpdates to WKSnapshotConfiguration
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Beth Dakin
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-02-06 14:48 PST by Beth Dakin
Modified: 2019-02-08 10:21 PST (History)
7 users (show)

See Also:


Attachments
Patch (14.08 KB, patch)
2019-02-06 14:57 PST, Beth Dakin
no flags Details | Formatted Diff | Diff
Patch (13.25 KB, patch)
2019-02-07 14:48 PST, Beth Dakin
thorton: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Beth Dakin 2019-02-06 14:48:55 PST
<rdar://problem/40655528> Please add an "after screen updates" property to WKSnapshotConfiguration (to solve blank snapshots)
Comment 1 Beth Dakin 2019-02-06 14:57:17 PST
Created attachment 361333 [details]
Patch
Comment 2 EWS Watchlist 2019-02-06 14:59:04 PST
Attachment 361333 [details] did not pass style-queue:


ERROR: Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1159:  Extra space before ( in function call  [whitespace/parens] [4]
Total errors found: 1 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Tim Horton 2019-02-06 15:07:38 PST
Comment on attachment 361333 [details]
Patch

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

> Source/WebKit/UIProcess/API/Cocoa/WKSnapshotConfiguration.h:51
> +@property (readwrite) BOOL afterScreenUpdates WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));

nonatomic, and you don't need the "readwrite"

> Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1159
> +- (void)_callCompletionHandler:(BlockPtr<void (UIImage *, NSError *)>)completionHandler withSnapshotImage:(CGImageRef)snapshotImage atDeviceScale:(CGFloat)deviceScale

_callCompletionHandler:withSnapshotImage:atDeviceScale: is a pretty odd name for a WKWebView method (mostly because _callCompletionHandler at the beginning is super vague)

Maybe this is _didTakeSnapshot:atDeviceScale:completionHandler:? But also maybe it doesn't need to be a WKWebView method at all? You could just shove this in a local block inside takeSnapshotWithConfiguration and call it from the two call sites... that would be a bit less weird.

> Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1193
> +            [strongSelf _snapshotRect:rectInViewCoordinates intoImageOfWidth:(snapshotWidth * deviceScale) completionHandler:[strongSelf, handler, deviceScale](CGImageRef snapshotImage) {
> +                if (!strongSelf)
> +                    return;
> +                [strongSelf _callCompletionHandler:handler withSnapshotImage:snapshotImage atDeviceScale:deviceScale];
> +            }];

Aren't all five of these lines shared between the two cases? We should share more! I think the lambda thing above is probably the way to go, but it can encapsulate all of these lines too.

> Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewSnapshot.mm:301
> +    // or without afterScreeUpdates set on the configuration. On device, afterScreeUpdates will be required to

scree! twice.
Comment 4 Beth Dakin 2019-02-07 14:48:17 PST
(In reply to Tim Horton from comment #3)
> Comment on attachment 361333 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=361333&action=review
> 
> > Source/WebKit/UIProcess/API/Cocoa/WKSnapshotConfiguration.h:51
> > +@property (readwrite) BOOL afterScreenUpdates WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
> 
> nonatomic, and you don't need the "readwrite"

Thanks, fixed!

> 
> > Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1159
> > +- (void)_callCompletionHandler:(BlockPtr<void (UIImage *, NSError *)>)completionHandler withSnapshotImage:(CGImageRef)snapshotImage atDeviceScale:(CGFloat)deviceScale
> 
> _callCompletionHandler:withSnapshotImage:atDeviceScale: is a pretty odd name
> for a WKWebView method (mostly because _callCompletionHandler at the
> beginning is super vague)
> 
> Maybe this is _didTakeSnapshot:atDeviceScale:completionHandler:? But also
> maybe it doesn't need to be a WKWebView method at all? You could just shove
> this in a local block inside takeSnapshotWithConfiguration and call it from
> the two call sites... that would be a bit less weird.
> 

Yeah, I know. Should be a local block, I was just having a hard time writing it. 🙃

> > Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1193
> > +            [strongSelf _snapshotRect:rectInViewCoordinates intoImageOfWidth:(snapshotWidth * deviceScale) completionHandler:[strongSelf, handler, deviceScale](CGImageRef snapshotImage) {
> > +                if (!strongSelf)
> > +                    return;
> > +                [strongSelf _callCompletionHandler:handler withSnapshotImage:snapshotImage atDeviceScale:deviceScale];
> > +            }];
> 
> Aren't all five of these lines shared between the two cases? We should share
> more! I think the lambda thing above is probably the way to go, but it can
> encapsulate all of these lines too.
> 

Fixed! With your help!

> > Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewSnapshot.mm:301
> > +    // or without afterScreeUpdates set on the configuration. On device, afterScreeUpdates will be required to
> 
> scree! twice.

Fixed!
Comment 5 Beth Dakin 2019-02-07 14:48:39 PST
Created attachment 361450 [details]
Patch
Comment 6 Tim Horton 2019-02-07 14:55:04 PST
Comment on attachment 361450 [details]
Patch

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

> Source/WebKit/UIProcess/API/Cocoa/WKSnapshotConfiguration.h:51
> +@property (nonatomic) BOOL afterScreenUpdates WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));

Obviously need to review this name.

> Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1188
> +    if (snapshotConfiguration && snapshotConfiguration.afterScreenUpdates) {

This could be inverted and be an early return (after calling callSnapshotRect), and then the code below could be outdented one line 🤷‍♂️ don't care
Comment 7 Geoffrey Garen 2019-02-07 16:26:09 PST
> > Source/WebKit/UIProcess/API/Cocoa/WKSnapshotConfiguration.h:51
> > +@property (nonatomic) BOOL afterScreenUpdates WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
> 
> Obviously need to review this name.

Hush. It is perfect.
Comment 8 Beth Dakin 2019-02-08 10:18:10 PST
(In reply to Tim Horton from comment #6)
> Comment on attachment 361450 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=361450&action=review
> 
> > Source/WebKit/UIProcess/API/Cocoa/WKSnapshotConfiguration.h:51
> > +@property (nonatomic) BOOL afterScreenUpdates WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
> 
> Obviously need to review this name.
> 
> > Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1188
> > +    if (snapshotConfiguration && snapshotConfiguration.afterScreenUpdates) {
> 
> This could be inverted and be an early return (after calling
> callSnapshotRect), and then the code below could be outdented one line 🤷‍♂️
> don't care

Yes, actually! Not only can this be done, but it should be so that a nil snapshotConfiguration has the same result as the default configuration.
Comment 9 Beth Dakin 2019-02-08 10:20:39 PST
https://trac.webkit.org/changeset/241199/webkit
Comment 10 Radar WebKit Bug Importer 2019-02-08 10:21:29 PST
<rdar://problem/47920880>