[iOS] WKPDFView should conform to _WKWebViewPrintProvider
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Apr 2018 22:26:45 +0000 (22:26 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Apr 2018 22:26:45 +0000 (22:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184471

Reviewed by Dan Bernstein.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _printProvider]):

The print provider will always be either _contentView or _customContentView, but
might not be _currentContentView.

* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView _wk_pageCountForPrintFormatter:]):

Asked _hostViewController for the page count, clamped to 1 if
-[_WKWebViewPrintFormatter snapshotFirstPage] is YES.

(-[WKPDFView _wk_printedDocument]):

Created a CGPDFDocumentRef from _data and returned it.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230496 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/ios/WKPDFView.mm

index e12dfb4..8652571 100644 (file)
@@ -1,3 +1,26 @@
+2018-04-10  Andy Estes  <aestes@apple.com>
+
+        [iOS] WKPDFView should conform to _WKWebViewPrintProvider
+        https://bugs.webkit.org/show_bug.cgi?id=184471
+
+        Reviewed by Dan Bernstein.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _printProvider]):
+
+        The print provider will always be either _contentView or _customContentView, but
+        might not be _currentContentView.
+
+        * UIProcess/ios/WKPDFView.mm:
+        (-[WKPDFView _wk_pageCountForPrintFormatter:]):
+
+        Asked _hostViewController for the page count, clamped to 1 if
+        -[_WKWebViewPrintFormatter snapshotFirstPage] is YES.
+
+        (-[WKPDFView _wk_printedDocument]):
+
+        Created a CGPDFDocumentRef from _data and returned it.
+
 2018-04-10  Youenn Fablet  <youenn@apple.com>
 
         Beacon redirect responses should be CORS validated
 2018-04-10  Youenn Fablet  <youenn@apple.com>
 
         Beacon redirect responses should be CORS validated
index b893d83..8bb4b42 100644 (file)
@@ -6462,9 +6462,9 @@ static WebCore::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(UISe
 
 - (id <_WKWebViewPrintProvider>)_printProvider
 {
 
 - (id <_WKWebViewPrintProvider>)_printProvider
 {
-    id contentView = self._currentContentView;
-    if ([contentView conformsToProtocol:@protocol(_WKWebViewPrintProvider)])
-        return contentView;
+    id printProvider = _customContentView ? _customContentView.get() : _contentView.get();
+    if ([printProvider conformsToProtocol:@protocol(_WKWebViewPrintProvider)])
+        return printProvider;
     return nil;
 }
 
     return nil;
 }
 
index bd2b8fd..52d9d35 100644 (file)
@@ -31,6 +31,7 @@
 #import "WKWebViewInternal.h"
 #import "WeakObjCPtr.h"
 #import "WebPageProxy.h"
 #import "WKWebViewInternal.h"
 #import "WeakObjCPtr.h"
 #import "WebPageProxy.h"
+#import "_WKWebViewPrintFormatterInternal.h"
 #import <PDFKit/PDFHostViewController.h>
 #import <wtf/MainThread.h>
 #import <wtf/RetainPtr.h>
 #import <PDFKit/PDFHostViewController.h>
 #import <wtf/MainThread.h>
 #import <wtf/RetainPtr.h>
 
 @end
 
 
 @end
 
+#pragma mark _WKWebViewPrintProvider
+
+#if !ENABLE(MINIMAL_SIMULATOR)
+
+@interface WKPDFView (_WKWebViewPrintFormatter) <_WKWebViewPrintProvider>
+@end
+
+@implementation WKPDFView (_WKWebViewPrintFormatter)
+
+- (NSUInteger)_wk_pageCountForPrintFormatter:(_WKWebViewPrintFormatter *)printFormatter
+{
+    NSUInteger pageCount = std::max<NSInteger>([_hostViewController pageCount], 0);
+    if (printFormatter.snapshotFirstPage)
+        return std::min<NSUInteger>(pageCount, 1);
+    return pageCount;
+}
+
+- (CGPDFDocumentRef)_wk_printedDocument
+{
+    auto dataProvider = adoptCF(CGDataProviderCreateWithCFData((CFDataRef)_data.get()));
+    return adoptCF(CGPDFDocumentCreateWithProvider(dataProvider.get())).autorelease();
+}
+
+@end
+
+#endif // !ENABLE(MINIMAL_SIMULATOR)
+
 #endif // ENABLE(WKPDFVIEW)
 #endif // ENABLE(WKPDFVIEW)