RESOLVED FIXED194362
Add afterScreenUpdates to WKSnapshotConfiguration
https://bugs.webkit.org/show_bug.cgi?id=194362
Summary Add afterScreenUpdates to WKSnapshotConfiguration
Beth Dakin
Reported 2019-02-06 14:48:55 PST
<rdar://problem/40655528> Please add an "after screen updates" property to WKSnapshotConfiguration (to solve blank snapshots)
Attachments
Patch (14.08 KB, patch)
2019-02-06 14:57 PST, Beth Dakin
no flags
Patch (13.25 KB, patch)
2019-02-07 14:48 PST, Beth Dakin
thorton: review+
Beth Dakin
Comment 1 2019-02-06 14:57:17 PST
EWS Watchlist
Comment 2 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.
Tim Horton
Comment 3 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.
Beth Dakin
Comment 4 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!
Beth Dakin
Comment 5 2019-02-07 14:48:39 PST
Tim Horton
Comment 6 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
Geoffrey Garen
Comment 7 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.
Beth Dakin
Comment 8 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.
Beth Dakin
Comment 9 2019-02-08 10:20:39 PST
Radar WebKit Bug Importer
Comment 10 2019-02-08 10:21:29 PST
Note You need to log in before you can comment on or make changes to this bug.