Changeset 246300 in webkit


Ignore:
Timestamp:
Jun 10, 2019 5:45:50 PM (5 years ago)
Author:
aestes@apple.com
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:
Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r246285 r246300  
     12019-06-10  Andy Estes  <aestes@apple.com>
     2
     3        [iOS] Use PDFKit SPI for taking snapshots when the hosting app is not entitled for global capture
     4        https://bugs.webkit.org/show_bug.cgi?id=198731
     5        <rdar://problem/46215174>
     6
     7        Reviewed by Tim Horton.
     8
     9        * wtf/FeatureDefines.h:
     10
    1112019-06-10  Sam Weinig  <weinig@apple.com>
    212
  • trunk/Source/WTF/wtf/FeatureDefines.h

    r246285 r246300  
    173173
    174174#if !defined(ENABLE_WKPDFVIEW)
    175 #if PLATFORM(IOS_FAMILY) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && !PLATFORM(IOSMAC) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000
     175#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && !PLATFORM(IOSMAC) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000
    176176#define ENABLE_WKPDFVIEW 1
     177#endif
     178#endif
     179
     180#if !defined(HAVE_PDFHOSTVIEWCONTROLLER_SNAPSHOTTING)
     181#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && !PLATFORM(IOSMAC) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000
     182#define HAVE_PDFHOSTVIEWCONTROLLER_SNAPSHOTTING 1
    177183#endif
    178184#endif
  • trunk/Source/WebKit/ChangeLog

    r246285 r246300  
     12019-06-10  Andy Estes  <aestes@apple.com>
     2
     3        [iOS] Use PDFKit SPI for taking snapshots when the hosting app is not entitled for global capture
     4        https://bugs.webkit.org/show_bug.cgi?id=198731
     5        <rdar://problem/46215174>
     6
     7        Reviewed by Tim Horton.
     8
     9        PDFHostViewController renders PDF contents in a view service, and apps are unable to
     10        snapshot views rendered out-of-process without an entitlement.
     11
     12        When an app is missing this entitlement and calls WKWebView's
     13        takeSnapshotWithConfiguration: API when a PDF is displayed, fall back to calling
     14        PDFHostViewController's snapshotting SPI.
     15
     16        Testing is blocked by <https://webkit.org/b/175204>.
     17
     18        * Platform/spi/ios/PDFKitSPI.h:
     19        * UIProcess/API/Cocoa/WKWebView.mm:
     20        (-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
     21        * UIProcess/Cocoa/WKWebViewContentProvider.h:
     22        * UIProcess/ios/WKPDFView.mm:
     23        (+[WKPDFView web_requiresCustomSnapshotting]):
     24        (-[WKPDFView web_snapshotRectInContentViewCoordinates:snapshotWidth:completionHandler:]):
     25        * UIProcess/ios/WKSystemPreviewView.mm:
     26        (+[WKSystemPreviewView web_requiresCustomSnapshotting]):
     27
    1282019-06-10  Sam Weinig  <weinig@apple.com>
    229
  • trunk/Source/WebKit/Platform/spi/ios/PDFKitSPI.h

    r244955 r246300  
    5858- (void) endPDFViewRotation;
    5959
     60#if HAVE(PDFHOSTVIEWCONTROLLER_SNAPSHOTTING)
     61- (void) snapshotViewRect: (CGRect) rect snapshotWidth: (NSNumber*) width afterScreenUpdates: (BOOL) afterScreenUpdates withResult: (void (^)(UIImage* image)) completion;
     62#endif
     63
    6064@end
    6165
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r246270 r246300  
    61996199    CGSize imageSize = CGSizeMake(imageWidth, imageHeight);
    62006200
     6201    if ([[_customContentView class] web_requiresCustomSnapshotting]) {
     6202        [_customContentView web_snapshotRectInContentViewCoordinates:snapshotRectInContentCoordinates snapshotWidth:imageWidth completionHandler:completionHandler];
     6203        return;
     6204    }
     6205
    62016206#if HAVE(CORE_ANIMATION_RENDER_SERVER) && HAVE(IOSURFACE)
    62026207    // If we are parented and thus won't incur a significant penalty from paging in tiles, snapshot the view hierarchy directly.
     
    62176222
    62186223    if (_customContentView) {
     6224        ASSERT(![[_customContentView class] web_requiresCustomSnapshotting]);
    62196225        UIGraphicsBeginImageContextWithOptions(imageSize, YES, 1);
    62206226
  • trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProvider.h

    r242339 r246300  
    5353- (void)web_hideFindUI;
    5454@property (nonatomic, readonly) UIView *web_contentView;
     55@property (nonatomic, readonly, class) BOOL web_requiresCustomSnapshotting;
    5556
    5657@optional
     
    6162- (void)web_beginAnimatedResizeWithUpdates:(void (^)(void))updateBlock;
    6263- (BOOL)web_handleKeyEvent:(UIEvent *)event;
     64- (void)web_snapshotRectInContentViewCoordinates:(CGRect)contentViewCoordinates snapshotWidth:(CGFloat)snapshotWidth completionHandler:(void (^)(CGImageRef))completionHandler;
    6365@property (nonatomic, readonly) NSData *web_dataRepresentation;
    6466@property (nonatomic, readonly) NSString *web_suggestedFilename;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r246239 r246300  
    75667566            auto previewActions = adoptNS([[NSMutableArray alloc] init]);
    75677567            for (_WKElementAction *elementAction in actions.get()) {
     7568                ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    75687569                WKPreviewAction *previewAction = [WKPreviewAction actionWithIdentifier:previewIdentifierForElementAction(elementAction) title:[elementAction title] style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *, UIViewController *) {
    75697570                    [elementAction runActionWithElementInfo:elementInfo.get()];
    75707571                }];
     7572                ALLOW_DEPRECATED_DECLARATIONS_END
    75717573                [previewActions addObject:previewAction];
    75727574            }
  • trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm

    r246116 r246300  
    4646#import <wtf/RetainPtr.h>
    4747#import <wtf/WeakObjCPtr.h>
     48#import <wtf/cocoa/Entitlements.h>
    4849#import <wtf/cocoa/NSURLExtras.h>
    4950
     
    358359}
    359360
     361+ (BOOL)web_requiresCustomSnapshotting
     362{
     363#if HAVE(PDFHOSTVIEWCONTROLLER_SNAPSHOTTING)
     364    static bool hasGlobalCaptureEntitlement = WTF::processHasEntitlement("com.apple.QuartzCore.global-capture");
     365    return !hasGlobalCaptureEntitlement;
     366#else
     367    return false;
     368#endif
     369}
     370
    360371- (void)web_scrollViewDidScroll:(UIScrollView *)scrollView
    361372{
     
    383394    updateBlock();
    384395    [_hostViewController endPDFViewRotation];
     396}
     397
     398- (void)web_snapshotRectInContentViewCoordinates:(CGRect)rectInContentViewCoordinates snapshotWidth:(CGFloat)snapshotWidth completionHandler:(void (^)(CGImageRef))completionHandler
     399{
     400#if HAVE(PDFHOSTVIEWCONTROLLER_SNAPSHOTTING)
     401    CGRect rectInHostViewCoordinates = [self._contentView convertRect:rectInContentViewCoordinates toView:[_hostViewController view]];
     402    [_hostViewController snapshotViewRect:rectInHostViewCoordinates snapshotWidth:@(snapshotWidth) afterScreenUpdates:NO withResult:^(UIImage *image) {
     403        completionHandler(image.CGImage);
     404    }];
     405#endif
    385406}
    386407
  • trunk/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm

    r244201 r246300  
    145145}
    146146
     147+ (BOOL)web_requiresCustomSnapshotting
     148{
     149    return false;
     150}
     151
    147152- (void)web_setMinimumSize:(CGSize)size
    148153{
Note: See TracChangeset for help on using the changeset viewer.