Skip to content
Permalink
Browse files
[iOS] Unable to open arxiv links on Chrome
https://bugs.webkit.org/show_bug.cgi?id=228205
rdar://78225849

Reviewed by Tim Horton.

-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:] currently
expects the width to be specified in pixels. However, the PDFKit SPI
used to snapshot a PDF expects a width in points. This led to WebKit
requesting extremely large snapshots, resulting in a crash in PDFKit.

To fix, use points instead of pixels in the PDF snapshotting path.
Also, ensure the scale factor of the returned image matches the
the scale used by PDFKit (the screen scale), as opposed to WebKit's
own "page" device scale factor, which can be overridden.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView takeSnapshotWithConfiguration:completionHandler:]):
* UIProcess/API/ios/WKWebViewIOS.mm:


Canonical link: https://commits.webkit.org/239901@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@280214 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
pxlcoder committed Jul 23, 2021
1 parent 57e7b1b commit 6a91cf41ab72a0faaa75add13b5473f40435194c
Showing 3 changed files with 31 additions and 3 deletions.
@@ -1,3 +1,25 @@
2021-07-22 Aditya Keerthi <akeerthi@apple.com>

[iOS] Unable to open arxiv links on Chrome
https://bugs.webkit.org/show_bug.cgi?id=228205
rdar://78225849

Reviewed by Tim Horton.

-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:] currently
expects the width to be specified in pixels. However, the PDFKit SPI
used to snapshot a PDF expects a width in points. This led to WebKit
requesting extremely large snapshots, resulting in a crash in PDFKit.

To fix, use points instead of pixels in the PDF snapshotting path.
Also, ensure the scale factor of the returned image matches the
the scale used by PDFKit (the screen scale), as opposed to WebKit's
own "page" device scale factor, which can be overridden.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView takeSnapshotWithConfiguration:completionHandler:]):
* UIProcess/API/ios/WKWebViewIOS.mm:

2021-07-22 Brent Fulgham <bfulgham@apple.com>

REGRESSION (r278877) [Cocoa] WebAuthn stopped working for non-Safari browsers
@@ -1213,10 +1213,13 @@ - (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfigu
handler(image.get(), nil);
});
#else
CGFloat deviceScale = _page->deviceScaleFactor();
auto useIntrinsicDeviceScaleFactor = [[_customContentView class] web_requiresCustomSnapshotting];

CGFloat deviceScale = useIntrinsicDeviceScaleFactor ? UIScreen.mainScreen.scale : _page->deviceScaleFactor();
CGFloat imageWidth = useIntrinsicDeviceScaleFactor ? snapshotWidth : snapshotWidth * deviceScale;
RetainPtr<WKWebView> strongSelf = self;
auto callSnapshotRect = [strongSelf, rectInViewCoordinates, snapshotWidth, deviceScale, handler] {
[strongSelf _snapshotRect:rectInViewCoordinates intoImageOfWidth:(snapshotWidth * deviceScale) completionHandler:[strongSelf, handler, deviceScale](CGImageRef snapshotImage) {
auto callSnapshotRect = [strongSelf, rectInViewCoordinates, imageWidth, deviceScale, handler] {
[strongSelf _snapshotRect:rectInViewCoordinates intoImageOfWidth:imageWidth completionHandler:[strongSelf, handler, deviceScale](CGImageRef snapshotImage) {
RetainPtr<NSError> error;
RetainPtr<UIImage> image;

@@ -3138,6 +3138,9 @@ - (void)_setSuppressSoftwareKeyboard:(BOOL)suppressSoftwareKeyboard
[_contentView updateSoftwareKeyboardSuppressionStateFromWebView];
}

// FIXME (<rdar://problem/80986330>): This method should be updated to take an image
// width in points (for consistency) and a completion handler with a UIImage parameter
// (to avoid redundant copies for PDFs), once it is no longer in use by internal clients.
- (void)_snapshotRect:(CGRect)rectInViewCoordinates intoImageOfWidth:(CGFloat)imageWidth completionHandler:(void(^)(CGImageRef))completionHandler
{
if (_dynamicViewportUpdateMode != WebKit::DynamicViewportUpdateMode::NotResizing) {

0 comments on commit 6a91cf4

Please sign in to comment.