Title: [246300] trunk/Source
Revision
246300
Author
[email protected]
Date
2019-06-10 17:45:50 -0700 (Mon, 10 Jun 2019)

Log Message

[iOS] Use PDFKit SPI for taking snapshots when the hosting app is not entitled for global capture
https://bugs.webkit.org/show_bug.cgi?id=198731
<rdar://problem/46215174>

Reviewed by Tim Horton.

Source/WebKit:

PDFHostViewController renders PDF contents in a view service, and apps are unable to
snapshot views rendered out-of-process without an entitlement.

When an app is missing this entitlement and calls WKWebView's
takeSnapshotWithConfiguration: API when a PDF is displayed, fall back to calling
PDFHostViewController's snapshotting SPI.

Testing is blocked by <https://webkit.org/b/175204>.

* Platform/spi/ios/PDFKitSPI.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
* UIProcess/Cocoa/WKWebViewContentProvider.h:
* UIProcess/ios/WKPDFView.mm:
(+[WKPDFView web_requiresCustomSnapshotting]):
(-[WKPDFView web_snapshotRectInContentViewCoordinates:snapshotWidth:completionHandler:]):
* UIProcess/ios/WKSystemPreviewView.mm:
(+[WKSystemPreviewView web_requiresCustomSnapshotting]):

Source/WTF:

* wtf/FeatureDefines.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (246299 => 246300)


--- trunk/Source/WTF/ChangeLog	2019-06-11 00:38:48 UTC (rev 246299)
+++ trunk/Source/WTF/ChangeLog	2019-06-11 00:45:50 UTC (rev 246300)
@@ -1,3 +1,13 @@
+2019-06-10  Andy Estes  <[email protected]>
+
+        [iOS] Use PDFKit SPI for taking snapshots when the hosting app is not entitled for global capture
+        https://bugs.webkit.org/show_bug.cgi?id=198731
+        <rdar://problem/46215174>
+
+        Reviewed by Tim Horton.
+
+        * wtf/FeatureDefines.h:
+
 2019-06-10  Sam Weinig  <[email protected]>
 
         Remove Dashboard support

Modified: trunk/Source/WTF/wtf/FeatureDefines.h (246299 => 246300)


--- trunk/Source/WTF/wtf/FeatureDefines.h	2019-06-11 00:38:48 UTC (rev 246299)
+++ trunk/Source/WTF/wtf/FeatureDefines.h	2019-06-11 00:45:50 UTC (rev 246300)
@@ -172,11 +172,17 @@
 #endif
 
 #if !defined(ENABLE_WKPDFVIEW)
-#if PLATFORM(IOS_FAMILY) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && !PLATFORM(IOSMAC) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000
+#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && !PLATFORM(IOSMAC) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000
 #define ENABLE_WKPDFVIEW 1
 #endif
 #endif
 
+#if !defined(HAVE_PDFHOSTVIEWCONTROLLER_SNAPSHOTTING)
+#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && !PLATFORM(IOSMAC) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000
+#define HAVE_PDFHOSTVIEWCONTROLLER_SNAPSHOTTING 1
+#endif
+#endif
+
 #if !defined(HAVE_VISIBILITY_PROPAGATION_VIEW)
 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000
 #define HAVE_VISIBILITY_PROPAGATION_VIEW 1

Modified: trunk/Source/WebKit/ChangeLog (246299 => 246300)


--- trunk/Source/WebKit/ChangeLog	2019-06-11 00:38:48 UTC (rev 246299)
+++ trunk/Source/WebKit/ChangeLog	2019-06-11 00:45:50 UTC (rev 246300)
@@ -1,3 +1,30 @@
+2019-06-10  Andy Estes  <[email protected]>
+
+        [iOS] Use PDFKit SPI for taking snapshots when the hosting app is not entitled for global capture
+        https://bugs.webkit.org/show_bug.cgi?id=198731
+        <rdar://problem/46215174>
+
+        Reviewed by Tim Horton.
+
+        PDFHostViewController renders PDF contents in a view service, and apps are unable to
+        snapshot views rendered out-of-process without an entitlement.
+
+        When an app is missing this entitlement and calls WKWebView's
+        takeSnapshotWithConfiguration: API when a PDF is displayed, fall back to calling
+        PDFHostViewController's snapshotting SPI.
+
+        Testing is blocked by <https://webkit.org/b/175204>.
+
+        * Platform/spi/ios/PDFKitSPI.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
+        * UIProcess/Cocoa/WKWebViewContentProvider.h:
+        * UIProcess/ios/WKPDFView.mm:
+        (+[WKPDFView web_requiresCustomSnapshotting]):
+        (-[WKPDFView web_snapshotRectInContentViewCoordinates:snapshotWidth:completionHandler:]):
+        * UIProcess/ios/WKSystemPreviewView.mm:
+        (+[WKSystemPreviewView web_requiresCustomSnapshotting]):
+
 2019-06-10  Sam Weinig  <[email protected]>
 
         Remove Dashboard support

Modified: trunk/Source/WebKit/Platform/spi/ios/PDFKitSPI.h (246299 => 246300)


--- trunk/Source/WebKit/Platform/spi/ios/PDFKitSPI.h	2019-06-11 00:38:48 UTC (rev 246299)
+++ trunk/Source/WebKit/Platform/spi/ios/PDFKitSPI.h	2019-06-11 00:45:50 UTC (rev 246300)
@@ -57,6 +57,10 @@
 - (void) beginPDFViewRotation;
 - (void) endPDFViewRotation;
 
+#if HAVE(PDFHOSTVIEWCONTROLLER_SNAPSHOTTING)
+- (void) snapshotViewRect: (CGRect) rect snapshotWidth: (NSNumber*) width afterScreenUpdates: (BOOL) afterScreenUpdates withResult: (void (^)(UIImage* image)) completion;
+#endif
+
 @end
 
 #endif

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (246299 => 246300)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2019-06-11 00:38:48 UTC (rev 246299)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2019-06-11 00:45:50 UTC (rev 246300)
@@ -6198,6 +6198,11 @@
     CGFloat imageHeight = imageScale * snapshotRectInContentCoordinates.size.height;
     CGSize imageSize = CGSizeMake(imageWidth, imageHeight);
 
+    if ([[_customContentView class] web_requiresCustomSnapshotting]) {
+        [_customContentView web_snapshotRectInContentViewCoordinates:snapshotRectInContentCoordinates snapshotWidth:imageWidth completionHandler:completionHandler];
+        return;
+    }
+
 #if HAVE(CORE_ANIMATION_RENDER_SERVER) && HAVE(IOSURFACE)
     // If we are parented and thus won't incur a significant penalty from paging in tiles, snapshot the view hierarchy directly.
     if (NSString *displayName = self.window.screen.displayConfiguration.name) {
@@ -6216,6 +6221,7 @@
 #endif
 
     if (_customContentView) {
+        ASSERT(![[_customContentView class] web_requiresCustomSnapshotting]);
         UIGraphicsBeginImageContextWithOptions(imageSize, YES, 1);
 
         UIView *customContentView = _customContentView.get();

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProvider.h (246299 => 246300)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProvider.h	2019-06-11 00:38:48 UTC (rev 246299)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProvider.h	2019-06-11 00:45:50 UTC (rev 246300)
@@ -52,6 +52,7 @@
 - (void)web_findString:(NSString *)string options:(_WKFindOptions)options maxCount:(NSUInteger)maxCount;
 - (void)web_hideFindUI;
 @property (nonatomic, readonly) UIView *web_contentView;
+@property (nonatomic, readonly, class) BOOL web_requiresCustomSnapshotting;
 
 @optional
 - (void)web_scrollViewDidScroll:(UIScrollView *)scrollView;
@@ -60,6 +61,7 @@
 - (void)web_scrollViewDidZoom:(UIScrollView *)scrollView;
 - (void)web_beginAnimatedResizeWithUpdates:(void (^)(void))updateBlock;
 - (BOOL)web_handleKeyEvent:(UIEvent *)event;
+- (void)web_snapshotRectInContentViewCoordinates:(CGRect)contentViewCoordinates snapshotWidth:(CGFloat)snapshotWidth completionHandler:(void (^)(CGImageRef))completionHandler;
 @property (nonatomic, readonly) NSData *web_dataRepresentation;
 @property (nonatomic, readonly) NSString *web_suggestedFilename;
 @property (nonatomic, readonly) BOOL web_isBackground;

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (246299 => 246300)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-06-11 00:38:48 UTC (rev 246299)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-06-11 00:45:50 UTC (rev 246300)
@@ -7565,9 +7565,11 @@
         if ([uiDelegate respondsToSelector:@selector(webView:previewingViewControllerForElement:defaultActions:)]) {
             auto previewActions = adoptNS([[NSMutableArray alloc] init]);
             for (_WKElementAction *elementAction in actions.get()) {
+                ALLOW_DEPRECATED_DECLARATIONS_BEGIN
                 WKPreviewAction *previewAction = [WKPreviewAction actionWithIdentifier:previewIdentifierForElementAction(elementAction) title:[elementAction title] style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *, UIViewController *) {
                     [elementAction runActionWithElementInfo:elementInfo.get()];
                 }];
+                ALLOW_DEPRECATED_DECLARATIONS_END
                 [previewActions addObject:previewAction];
             }
             ALLOW_DEPRECATED_DECLARATIONS_BEGIN

Modified: trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm (246299 => 246300)


--- trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm	2019-06-11 00:38:48 UTC (rev 246299)
+++ trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm	2019-06-11 00:45:50 UTC (rev 246300)
@@ -45,6 +45,7 @@
 #import <wtf/MainThread.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/WeakObjCPtr.h>
+#import <wtf/cocoa/Entitlements.h>
 #import <wtf/cocoa/NSURLExtras.h>
 
 @interface WKPDFView () <PDFHostViewControllerDelegate, WKActionSheetAssistantDelegate>
@@ -357,6 +358,16 @@
     return self._contentView;
 }
 
++ (BOOL)web_requiresCustomSnapshotting
+{
+#if HAVE(PDFHOSTVIEWCONTROLLER_SNAPSHOTTING)
+    static bool hasGlobalCaptureEntitlement = WTF::processHasEntitlement("com.apple.QuartzCore.global-capture");
+    return !hasGlobalCaptureEntitlement;
+#else
+    return false;
+#endif
+}
+
 - (void)web_scrollViewDidScroll:(UIScrollView *)scrollView
 {
     [_hostViewController updatePDFViewLayout];
@@ -384,6 +395,16 @@
     [_hostViewController endPDFViewRotation];
 }
 
+- (void)web_snapshotRectInContentViewCoordinates:(CGRect)rectInContentViewCoordinates snapshotWidth:(CGFloat)snapshotWidth completionHandler:(void (^)(CGImageRef))completionHandler
+{
+#if HAVE(PDFHOSTVIEWCONTROLLER_SNAPSHOTTING)
+    CGRect rectInHostViewCoordinates = [self._contentView convertRect:rectInContentViewCoordinates toView:[_hostViewController view]];
+    [_hostViewController snapshotViewRect:rectInHostViewCoordinates snapshotWidth:@(snapshotWidth) afterScreenUpdates:NO withResult:^(UIImage *image) {
+        completionHandler(image.CGImage);
+    }];
+#endif
+}
+
 - (NSData *)web_dataRepresentation
 {
     return _data.get();

Modified: trunk/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm (246299 => 246300)


--- trunk/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm	2019-06-11 00:38:48 UTC (rev 246299)
+++ trunk/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm	2019-06-11 00:45:50 UTC (rev 246300)
@@ -144,6 +144,11 @@
     return self;
 }
 
++ (BOOL)web_requiresCustomSnapshotting
+{
+    return false;
+}
+
 - (void)web_setMinimumSize:(CGSize)size
 {
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to