Bug 151386 - WKWebView does not render PDF pages in AirPrint
Summary: WKWebView does not render PDF pages in AirPrint
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: iPhone / iPad iOS 9.0
: P2 Normal
Assignee: Andy Estes
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-11-18 05:23 PST by stkhapugin
Modified: 2016-06-09 15:03 PDT (History)
10 users (show)

See Also:


Attachments
Reproduction case. (52.02 KB, application/zip)
2015-11-18 05:23 PST, stkhapugin
no flags Details
Patch (40.47 KB, patch)
2016-06-09 13:04 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (40.46 KB, patch)
2016-06-09 13:22 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (40.52 KB, patch)
2016-06-09 14:33 PDT, Andy Estes
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description stkhapugin 2015-11-18 05:23:07 PST
Created attachment 265744 [details]
Reproduction case.

Summary:
When one attempts to AirPrint a PDF open in WKWebView using [WKWebView viewPrintFormatter], the previews and the printed output are blank. 
Note that Safari on iOS prints normally. This is reproducible both with iOS 9.1 SDK's WebKit and a nightly checkout. 

Is there a workaround Safari uses?

Steps to Reproduce:
Unzip attached project, build & run. A pdf document will be loaded, and once it's loaded, the print dialog will open.
Note that the repro is linked with iOS SDK's WebKit. You may want to relink it to your own WebKit.framework.

Expected Results:
Preview in print dialog shows a small PDF preview. PDF prints normally.

Actual Results:
Previews in print dialog shows a blank page. Printed page is blank.

Version:
iOS 9.1; tot.

Notes:
You can debug printing by downloading Hardware IO Tools for Xcode 7 on Apple Developer Portal and running an AirPrint simulator.
Also filed rdar://23556241.
Comment 1 Andy Estes 2015-11-18 19:55:16 PST
One workaround is to set UIPrintInteractionController's printingItem to an NSData containing the PDF. Unfortunately this probably requires you to load the PDF a second time.
Comment 2 Eugene But 2015-11-18 20:15:58 PST
Thank you for providing a workaround. Downloading PDF may not always work, because WKWebView does not provide reliable API to get cookie (NSHTTPCookieStorage is not always up to date). However being broken only in cases when auth is required is better than being always broken.

Please let us know if you see any alternative workarounds. Thanks!
Comment 3 Andy Estes 2016-01-22 15:18:12 PST
rdar://problem/22499157
Comment 4 Andy Estes 2016-01-23 01:18:47 PST
The issue here is that _WKWebViewPrintFormatter's _totalScaleFactor is 0 for PDFs. Setting it to 1 instead fixes the attached test case. We probably need to compute a per-page scale factor for PDFs.
Comment 5 Andy Estes 2016-06-09 13:04:34 PDT
Created attachment 280935 [details]
Patch
Comment 6 WebKit Commit Bot 2016-06-09 13:06:02 PDT
Attachment 280935 [details] did not pass style-queue:


ERROR: Source/WebKit2/UIProcess/ios/WKContentView.mm:632:  The parameter name "handle" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 1 in 17 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 Tim Horton 2016-06-09 13:14:48 PDT
Comment on attachment 280935 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=280935&action=review

> Source/WebKit2/UIProcess/WebPageProxy.h:260
> +using DrawToPDFCallback = GenericCallback<const IPC::DataReference&>;

Interesting! Why using instead of typedef like the others? Should we change the others?

> Source/WebKit2/UIProcess/WebPageProxy.h:910
> +        uint32_t computePagesForPrintingAndDrawToPDF(uint64_t frameID, const PrintInfo&, DrawToPDFCallback::CallbackFunction&&);

indentation is weird.
Comment 8 Andy Estes 2016-06-09 13:18:34 PDT
(In reply to comment #7)
> Comment on attachment 280935 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=280935&action=review
> 
> > Source/WebKit2/UIProcess/WebPageProxy.h:260
> > +using DrawToPDFCallback = GenericCallback<const IPC::DataReference&>;
> 
> Interesting! Why using instead of typedef like the others? Should we change
> the others?

using doesn't make me think about which order things go in like typedef does, and it's more C++11y, but I don't know if we should change the others!

> 
> > Source/WebKit2/UIProcess/WebPageProxy.h:910
> > +        uint32_t computePagesForPrintingAndDrawToPDF(uint64_t frameID, const PrintInfo&, DrawToPDFCallback::CallbackFunction&&);
> 
> indentation is weird.

Oops. Will fix.

Thank you for the review!
Comment 9 Andy Estes 2016-06-09 13:22:16 PDT
Created attachment 280939 [details]
Patch
Comment 10 WebKit Commit Bot 2016-06-09 13:24:59 PDT
Attachment 280939 [details] did not pass style-queue:


ERROR: Source/WebKit2/UIProcess/ios/WKContentView.mm:632:  The parameter name "handle" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 1 in 17 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 11 WebKit Commit Bot 2016-06-09 13:45:30 PDT
Comment on attachment 280939 [details]
Patch

Rejecting attachment 280939 [details] from commit-queue.

Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-02', 'build', '--no-clean', '--no-update', '--build-style=release', '--port=mac']" exit_code: 2 cwd: /Volumes/Data/EWS/WebKit

Last 500 characters of output:
CompileC /Volumes/Data/EWS/WebKit/WebKitBuild/WebKit2.build/Release/WebKit.build/Objects-normal/x86_64/_WKWebViewPrintFormatter.o UIProcess/_WKWebViewPrintFormatter.mm normal x86_64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

Failed to run "['Tools/Scripts/build-webkit', '--release']" exit_code: 65
d/Objects-normal/x86_64/_WKWebViewPrintFormatter.o UIProcess/_WKWebViewPrintFormatter.mm normal x86_64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

Full output: http://webkit-queues.webkit.org/results/1474107
Comment 12 Andy Estes 2016-06-09 14:33:02 PDT
Created attachment 280951 [details]
Patch
Comment 13 WebKit Commit Bot 2016-06-09 14:43:23 PDT
Attachment 280951 [details] did not pass style-queue:


ERROR: Source/WebKit2/UIProcess/ios/WKContentView.mm:632:  The parameter name "handle" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 1 in 17 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 14 WebKit Commit Bot 2016-06-09 15:03:34 PDT
Comment on attachment 280951 [details]
Patch

Clearing flags on attachment: 280951

Committed r201888: <http://trac.webkit.org/changeset/201888>
Comment 15 WebKit Commit Bot 2016-06-09 15:03:39 PDT
All reviewed patches have been landed.  Closing bug.