<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[169175] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/169175">169175</a></dd>
<dt>Author</dt> <dd>aestes@apple.com</dd>
<dt>Date</dt> <dd>2014-05-21 13:39:36 -0700 (Wed, 21 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] Create a UIPrintFormatter for WKWebView
https://bugs.webkit.org/show_bug.cgi?id=133005

Reviewed by Tim Horton.

Implemented a UIPrintFormatter subclass to support printing WKWebViews using UIPrintInteractionController.
Overrode -_recalcPageCount: to synchronously ask the web process to lay out for printing and return the number
of page rects. The web process returns the page rects immediately and then starts rendering the page to a PDF,
returning the PDF data to the UI process asynchronously. When UIPrintInteractionController later calls our
overridden -drawInRect:forPageAtIndex:, we block and wait for the PDF data to be returned. Since
UIPrintInteractionController draws each page after a delay, it's possible that the web process has already
returned the PDF data to us by the time we print the first page.

* Shared/WebPreferencesStore.h: Correctly initialized shouldPrintBackgrounds for iOS.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _dataForDisplayedPDF]): Now that WKPDFView vends its CGPDFDocument directly, extract its data here.
(-[WKWebView _printFormatterClass]): Tell UIView which UIPrintFormatter to alloc.
(-[WKWebView _computePageCountAndStartDrawingToPDFWithPrintInfo:WebKit::firstPage:computedTotalScaleFactor:]):
If we're displaying a PDF, return its page count directly. Otherwise, synchronously ask the web process to
compute page rects for printing and then return the number of rects.
(-[WKWebView _endPrinting]): Cleared state and sent the WebPage::EndPrinting message to the web process.
(-[WKWebView _printedDocument]): If we're displaying a PDF, return its data directly. Otherwise, if we haven't
received PDF data from the web process yet, wait for it indefinitely (there's no sensible timeout to use here
since failing to receive the data results in printing some number of blank pages).
(-[WKWebView _setPrintedDocument:]): Set the CGPDFDocument received from the web process.
* UIProcess/API/Cocoa/WKWebViewInternal.h: Declared methods called by WKWebViewPrintFormatter.
* UIProcess/PageClient.h: Declared didFinishDrawingPagesToPDF.
* UIProcess/WKWebViewPrintFormatter.h: Added.
* UIProcess/WKWebViewPrintFormatter.mm: Added.
(-[WKWebViewPrintFormatter dealloc]): Cleared state and called -[WKWebView _endPrinting].
(-[WKWebViewPrintFormatter webView]): Returned the WKWebView for this print formatter.
(-[WKWebViewPrintFormatter _recalcPageCount]): Set up a PrintInfo object given the formatter's content rect
and called -_computePageCountAndStartDrawingToPDFWithPrintInfo:...
(-[WKWebViewPrintFormatter rectForPageAtIndex:]): Called -_recalcIfNecessary and then returned the rect from
-_pageContentRect.
(-[WKWebViewPrintFormatter drawInRect:forPageAtIndex:]): Taught to draw the given page of the printed PDF
document into the given rect and context provided to us.
* UIProcess/WebPageProxy.h: Declared didFinishDrawingPagesToPDF.
* UIProcess/WebPageProxy.messages.in: Added DidFinishDrawingPagesToPDF. Made this a delayed syncrhonous message
so that additoinal work could be performed after sending the response.
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::didFinishDrawingPagesToPDF): Created a CGPDFDocument from the data sent to us by the
web process and called -[WKWebView _setPrintedDocument:].
* UIProcess/ios/WKPDFView.h:
* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView pdfDocument]): Returned the underlying CGPDFDocument.
(-[WKPDFView documentData]): Deleted.
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::didFinishDrawingPagesToPDF):
* WebKit2.xcodeproj/project.pbxproj:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::computePagesForPrinting): Changed to call computePagesForPrintingImpl.
(WebKit::WebPage::computePagesForPrintingImpl): Moved the common logic of computePagesForPrinting to here so it
could be called by computePagesForPrintingAndStartDrawingToPDF.
(WebKit::WebPage::drawPagesToPDF): Changed to call drawPagesToPDFImpl
(WebKit::WebPage::drawPagesToPDFImpl): Moved the common logic of drawPagesToPDF to here so it could be called
by computePagesForPrintingAndStartDrawingToPDF.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::computePagesForPrintingAndStartDrawingToPDF): Computed page rects and returned them as a
synchronous response. Afterwards called drawPagesToPDFImpl() and returned the PDF data by sending
WebPageProxy::DidFinishDrawingPagesToPDF.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedWebPreferencesStoreh">trunk/Source/WebKit2/Shared/WebPreferencesStore.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewInternalh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessPageClienth">trunk/Source/WebKit2/UIProcess/PageClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxymessagesin">trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosPageClientImplIOSh">trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosPageClientImplIOSmm">trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKPDFViewh">trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKPDFViewmm">trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWebPageProxyIOSmm">trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagecpp">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPageh">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagemessagesin">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2UIProcessWKWebViewPrintFormatterh">trunk/Source/WebKit2/UIProcess/WKWebViewPrintFormatter.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWKWebViewPrintFormattermm">trunk/Source/WebKit2/UIProcess/WKWebViewPrintFormatter.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/ChangeLog        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -1,3 +1,70 @@
</span><ins>+2014-05-21  Andy Estes  &lt;aestes@apple.com&gt;
+
+        [iOS] Create a UIPrintFormatter for WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=133005
+
+        Reviewed by Tim Horton.
+
+        Implemented a UIPrintFormatter subclass to support printing WKWebViews using UIPrintInteractionController.
+        Overrode -_recalcPageCount: to synchronously ask the web process to lay out for printing and return the number
+        of page rects. The web process returns the page rects immediately and then starts rendering the page to a PDF,
+        returning the PDF data to the UI process asynchronously. When UIPrintInteractionController later calls our
+        overridden -drawInRect:forPageAtIndex:, we block and wait for the PDF data to be returned. Since
+        UIPrintInteractionController draws each page after a delay, it's possible that the web process has already
+        returned the PDF data to us by the time we print the first page.
+
+        * Shared/WebPreferencesStore.h: Correctly initialized shouldPrintBackgrounds for iOS.
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _dataForDisplayedPDF]): Now that WKPDFView vends its CGPDFDocument directly, extract its data here.
+        (-[WKWebView _printFormatterClass]): Tell UIView which UIPrintFormatter to alloc.
+        (-[WKWebView _computePageCountAndStartDrawingToPDFWithPrintInfo:WebKit::firstPage:computedTotalScaleFactor:]):
+        If we're displaying a PDF, return its page count directly. Otherwise, synchronously ask the web process to
+        compute page rects for printing and then return the number of rects.
+        (-[WKWebView _endPrinting]): Cleared state and sent the WebPage::EndPrinting message to the web process.
+        (-[WKWebView _printedDocument]): If we're displaying a PDF, return its data directly. Otherwise, if we haven't
+        received PDF data from the web process yet, wait for it indefinitely (there's no sensible timeout to use here
+        since failing to receive the data results in printing some number of blank pages).
+        (-[WKWebView _setPrintedDocument:]): Set the CGPDFDocument received from the web process.
+        * UIProcess/API/Cocoa/WKWebViewInternal.h: Declared methods called by WKWebViewPrintFormatter.
+        * UIProcess/PageClient.h: Declared didFinishDrawingPagesToPDF.
+        * UIProcess/WKWebViewPrintFormatter.h: Added.
+        * UIProcess/WKWebViewPrintFormatter.mm: Added.
+        (-[WKWebViewPrintFormatter dealloc]): Cleared state and called -[WKWebView _endPrinting].
+        (-[WKWebViewPrintFormatter webView]): Returned the WKWebView for this print formatter.
+        (-[WKWebViewPrintFormatter _recalcPageCount]): Set up a PrintInfo object given the formatter's content rect
+        and called -_computePageCountAndStartDrawingToPDFWithPrintInfo:...
+        (-[WKWebViewPrintFormatter rectForPageAtIndex:]): Called -_recalcIfNecessary and then returned the rect from
+        -_pageContentRect.
+        (-[WKWebViewPrintFormatter drawInRect:forPageAtIndex:]): Taught to draw the given page of the printed PDF
+        document into the given rect and context provided to us.
+        * UIProcess/WebPageProxy.h: Declared didFinishDrawingPagesToPDF.
+        * UIProcess/WebPageProxy.messages.in: Added DidFinishDrawingPagesToPDF. Made this a delayed syncrhonous message
+        so that additoinal work could be performed after sending the response.
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::didFinishDrawingPagesToPDF): Created a CGPDFDocument from the data sent to us by the
+        web process and called -[WKWebView _setPrintedDocument:].
+        * UIProcess/ios/WKPDFView.h:
+        * UIProcess/ios/WKPDFView.mm:
+        (-[WKPDFView pdfDocument]): Returned the underlying CGPDFDocument.
+        (-[WKPDFView documentData]): Deleted.
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::didFinishDrawingPagesToPDF):
+        * WebKit2.xcodeproj/project.pbxproj:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::computePagesForPrinting): Changed to call computePagesForPrintingImpl.
+        (WebKit::WebPage::computePagesForPrintingImpl): Moved the common logic of computePagesForPrinting to here so it
+        could be called by computePagesForPrintingAndStartDrawingToPDF.
+        (WebKit::WebPage::drawPagesToPDF): Changed to call drawPagesToPDFImpl
+        (WebKit::WebPage::drawPagesToPDFImpl): Moved the common logic of drawPagesToPDF to here so it could be called
+        by computePagesForPrintingAndStartDrawingToPDF.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::computePagesForPrintingAndStartDrawingToPDF): Computed page rects and returned them as a
+        synchronous response. Afterwards called drawPagesToPDFImpl() and returned the PDF data by sending
+        WebPageProxy::DidFinishDrawingPagesToPDF.
+
</ins><span class="cx"> 2014-05-21  Michał Pakuła vel Rutka  &lt;m.pakula@samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [EFL] Turn on ENABLE_CSS_FILTERS
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedWebPreferencesStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/WebPreferencesStore.h (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/WebPreferencesStore.h        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/Shared/WebPreferencesStore.h        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -144,7 +144,7 @@
</span><span class="cx">     macro(PaginateDuringLayoutEnabled, paginateDuringLayoutEnabled, Bool, bool, false) \
</span><span class="cx">     macro(DOMPasteAllowed, domPasteAllowed, Bool, bool, false) \
</span><span class="cx">     macro(JavaScriptCanAccessClipboard, javaScriptCanAccessClipboard, Bool, bool, false) \
</span><del>-    macro(ShouldPrintBackgrounds, shouldPrintBackgrounds, Bool, bool, false) \
</del><ins>+    macro(ShouldPrintBackgrounds, shouldPrintBackgrounds, Bool, bool, DEFAULT_SHOULD_PRINT_BACKGROUNDS) \
</ins><span class="cx">     macro(FullScreenEnabled, fullScreenEnabled, Bool, bool, false) \
</span><span class="cx">     macro(AsynchronousSpellCheckingEnabled, asynchronousSpellCheckingEnabled, Bool, bool, false) \
</span><span class="cx">     macro(WebSecurityEnabled, webSecurityEnabled, Bool, bool, true) \
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -69,11 +69,15 @@
</span><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><ins>+#import &quot;PrintInfo.h&quot;
</ins><span class="cx"> #import &quot;ProcessThrottler.h&quot;
</span><span class="cx"> #import &quot;WKPDFView.h&quot;
</span><span class="cx"> #import &quot;WKScrollView.h&quot;
</span><span class="cx"> #import &quot;WKWebViewContentProviderRegistry.h&quot;
</span><ins>+#import &quot;WKWebViewPrintFormatter.h&quot;
+#import &quot;WebPageMessages.h&quot;
</ins><span class="cx"> #import &lt;CoreGraphics/CGFloat.h&gt;
</span><ins>+#import &lt;CoreGraphics/CGPDFDocumentPrivate.h&gt;
</ins><span class="cx"> #import &lt;UIKit/UIPeripheralHost_Private.h&gt;
</span><span class="cx"> #import &lt;QuartzCore/CARenderServer.h&gt;
</span><span class="cx"> #import &lt;QuartzCore/QuartzCorePrivate.h&gt;
</span><span class="lines">@@ -154,6 +158,9 @@
</span><span class="cx"> 
</span><span class="cx">     BOOL _delayUpdateVisibleContentRects;
</span><span class="cx">     BOOL _hadDelayedUpdateVisibleContentRects;
</span><ins>+
+    BOOL _pageIsPrintingToPDF;
+    RetainPtr&lt;CGPDFDocumentRef&gt; _printedDocument;
</ins><span class="cx"> #endif
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     RetainPtr&lt;WKView&gt; _wkView;
</span><span class="lines">@@ -1738,7 +1745,8 @@
</span><span class="cx"> {
</span><span class="cx">     if (![self _isDisplayingPDF])
</span><span class="cx">         return nil;
</span><del>-    return [(WKPDFView *)_customContentView.get() documentData];
</del><ins>+    CGPDFDocumentRef pdfDocument = [(WKPDFView *)_customContentView pdfDocument];
+    return [(NSData *)CGDataProviderCopyData(CGPDFDocumentGetDataProvider(pdfDocument)) autorelease];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (NSString *)_suggestedFilenameForDisplayedPDF
</span><span class="lines">@@ -1852,4 +1860,65 @@
</span><span class="cx"> 
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS)
+@implementation WKWebView (WKWebViewPrintFormatter)
+
+- (Class)_printFormatterClass
+{
+    return [WKWebViewPrintFormatter class];
+}
+
+- (NSInteger)_computePageCountAndStartDrawingToPDFWithPrintInfo:(const WebKit::PrintInfo&amp;)printInfo firstPage:(uint32_t)firstPage computedTotalScaleFactor:(double&amp;)totalScaleFactor
+{
+    if ([self _isDisplayingPDF])
+        return CGPDFDocumentGetNumberOfPages([(WKPDFView *)_customContentView pdfDocument]);
+
+    _pageIsPrintingToPDF = YES;
+    Vector&lt;WebCore::IntRect&gt; pageRects;
+    if (!_page-&gt;sendSync(Messages::WebPage::ComputePagesForPrintingAndStartDrawingToPDF(_page-&gt;mainFrame()-&gt;frameID(), printInfo, firstPage), Messages::WebPage::ComputePagesForPrintingAndStartDrawingToPDF::Reply(pageRects, totalScaleFactor)))
+        return 0;
+    return pageRects.size();
+}
+
+- (void)_endPrinting
+{
+    _pageIsPrintingToPDF = NO;
+    _printedDocument = nullptr;
+    _page-&gt;send(Messages::WebPage::EndPrinting());
+}
+
+// FIXME: milliseconds::max() overflows when converted to nanoseconds, causing condition_variable::wait_for() to believe
+// a timeout occurred on any spurious wakeup. Use nanoseconds::max() (converted to ms) to avoid this. We should perhaps
+// change waitForAndDispatchImmediately() to take nanoseconds to avoid this issue.
+static constexpr std::chrono::milliseconds didFinishLoadingTimeout = std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(std::chrono::nanoseconds::max());
+
+- (CGPDFDocumentRef)_printedDocument
+{
+    if ([self _isDisplayingPDF]) {
+        ASSERT(!_pageIsPrintingToPDF);
+        return [(WKPDFView *)_customContentView pdfDocument];
+    }
+
+    if (_pageIsPrintingToPDF) {
+        if (!_page-&gt;process().connection()-&gt;waitForAndDispatchImmediately&lt;Messages::WebPageProxy::DidFinishDrawingPagesToPDF&gt;(_page-&gt;pageID(), didFinishLoadingTimeout)) {
+            ASSERT_NOT_REACHED();
+            return nullptr;
+        }
+        ASSERT(!_pageIsPrintingToPDF);
+    }
+    return _printedDocument.get();
+}
+
+- (void)_setPrintedDocument:(CGPDFDocumentRef)printedDocument
+{
+    if (!_pageIsPrintingToPDF)
+        return;
+    ASSERT(![self _isDisplayingPDF]);
+    _printedDocument = printedDocument;
+    _pageIsPrintingToPDF = NO;
+}
+
+@end
+#endif
+
</ins><span class="cx"> #endif // WK_API_ENABLED
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewInternalh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -46,9 +46,12 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> class WebPageProxy;
</span><ins>+struct PrintInfo;
</ins><span class="cx"> struct ViewSnapshot;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+@class WKWebViewPrintFormatter;
+
</ins><span class="cx"> @interface WKWebView () WK_WEB_VIEW_PROTOCOLS {
</span><span class="cx"> 
</span><span class="cx"> @package
</span><span class="lines">@@ -82,4 +85,12 @@
</span><span class="cx"> 
</span><span class="cx"> WKWebView* fromWebPageProxy(WebKit::WebPageProxy&amp;);
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS)
+@interface WKWebView (WKWebViewPrintFormatter)
+- (NSInteger)_computePageCountAndStartDrawingToPDFWithPrintInfo:(const WebKit::PrintInfo&amp;)printInfo firstPage:(uint32_t)firstPage computedTotalScaleFactor:(double&amp;)totalScaleFactor;
+- (void)_endPrinting;
+@property (nonatomic, setter=_setPrintedDocument:) CGPDFDocumentRef _printedDocument;
+@end
</ins><span class="cx"> #endif
</span><ins>+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessPageClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/PageClient.h        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -259,6 +259,7 @@
</span><span class="cx">     virtual void didChangeViewportMetaTagWidth(float) = 0;
</span><span class="cx">     virtual double minimumZoomScale() const = 0;
</span><span class="cx">     virtual WebCore::FloatSize contentsSize() const = 0;
</span><ins>+    virtual void didFinishDrawingPagesToPDF(const IPC::DataReference&amp;) = 0;
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(INSPECTOR)
</span><span class="cx">     virtual void showInspectorIndication() = 0;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWKWebViewPrintFormatterhfromrev169173trunkSourceWebKit2UIProcessiosWKPDFViewh"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebKit2/UIProcess/WKWebViewPrintFormatter.h (from rev 169173, trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h) (0 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WKWebViewPrintFormatter.h                                (rev 0)
+++ trunk/Source/WebKit2/UIProcess/WKWebViewPrintFormatter.h        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -0,0 +1,35 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if PLATFORM(IOS)
+
+#import &lt;UIKit/UIPrintFormatter.h&gt;
+#import &lt;WebCore/IntRect.h&gt;
+#import &lt;wtf/Vector.h&gt;
+
+@interface WKWebViewPrintFormatter : UIViewPrintFormatter
+@end
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWKWebViewPrintFormattermm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/UIProcess/WKWebViewPrintFormatter.mm (0 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WKWebViewPrintFormatter.mm                                (rev 0)
+++ trunk/Source/WebKit2/UIProcess/WKWebViewPrintFormatter.mm        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -0,0 +1,107 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;config.h&quot;
+#import &quot;WKWebViewPrintFormatter.h&quot;
+
+#if PLATFORM(IOS)
+
+#import &quot;PrintInfo.h&quot;
+#import &quot;WKWebViewInternal.h&quot;
+#import &lt;wtf/RetainPtr.h&gt;
+
+@interface UIPrintFormatter (Details)
+- (CGRect)_pageContentRect:(BOOL)firstPage;
+- (void)_recalcIfNecessary;
+@end
+
+@interface WKWebViewPrintFormatter ()
+@property (nonatomic, readonly) WKWebView *webView;
+@end
+
+@implementation WKWebViewPrintFormatter {
+    double _totalScaleFactor;
+    WebKit::PrintInfo _printInfo;
+}
+
+- (void)dealloc
+{
+    [self.webView _endPrinting];
+    [super dealloc];
+}
+
+- (WKWebView *)webView
+{
+    ASSERT([self.view isKindOfClass:[WKWebView class]]);
+    return static_cast&lt;WKWebView *&gt;(self.view);
+}
+
+- (NSInteger)_recalcPageCount
+{
+    ASSERT([self respondsToSelector:@selector(_pageContentRect:)]);
+
+    CGRect firstRect = [self _pageContentRect:YES];
+    CGRect nextRect = [self _pageContentRect:NO];
+    if (CGRectIsEmpty(firstRect) || CGRectIsEmpty(nextRect))
+        return 0;
+
+    // The first page can have a smaller content rect than subsequent pages if a top content inset is specified. Since
+    // WebKit requires a uniform content rect for each page during layout, use the first page rect for all pages if it's
+    // smaller. This is what UIWebView's print formatter does.
+    ASSERT(firstRect.size.width == nextRect.size.width);
+    ASSERT(firstRect.origin.y &gt;= nextRect.origin.y);
+    _printInfo.pageSetupScaleFactor = 1;
+    _printInfo.availablePaperWidth = nextRect.size.width;
+    _printInfo.availablePaperHeight = nextRect.size.height - (firstRect.origin.y - nextRect.origin.y);
+
+    return [self.webView _computePageCountAndStartDrawingToPDFWithPrintInfo:_printInfo firstPage:self.startPage computedTotalScaleFactor:_totalScaleFactor];
+}
+
+- (CGRect)rectForPageAtIndex:(NSInteger)pageIndex
+{
+    ASSERT([self respondsToSelector:@selector(_recalcIfNecessary)]);
+    [self _recalcIfNecessary];
+    return [self _pageContentRect:pageIndex == self.startPage];
+}
+
+- (void)drawInRect:(CGRect)rect forPageAtIndex:(NSInteger)pageIndex
+{
+    // CGPDFDocuments use 1-based page indexing.
+    CGPDFPageRef pdfPage = CGPDFDocumentGetPage(self.webView._printedDocument, pageIndex - self.startPage + 1);
+
+    CGContextRef context = UIGraphicsGetCurrentContext();
+    CGContextSaveGState(context);
+
+    CGContextTranslateCTM(context, rect.origin.x, rect.origin.y);
+    CGContextScaleCTM(context, _totalScaleFactor, -_totalScaleFactor);
+    CGContextTranslateCTM(context, 0, -CGPDFPageGetBoxRect(pdfPage, kCGPDFMediaBox).size.height);
+    CGContextDrawPDFPage(context, pdfPage);
+
+    CGContextRestoreGState(context);
+}
+
+@end
+
+#endif // PLATFORM(IOS)
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -633,6 +633,7 @@
</span><span class="cx">     void commitPotentialTapFailed();
</span><span class="cx">     void didNotHandleTapAsClick(const WebCore::IntPoint&amp;);
</span><span class="cx">     void viewportMetaTagWidthDidChange(float width);
</span><ins>+    void didFinishDrawingPagesToPDF(const IPC::DataReference&amp;);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     const EditorState&amp; editorState() const { return m_editorState; }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -172,6 +172,7 @@
</span><span class="cx">     CommitPotentialTapFailed()
</span><span class="cx">     DidNotHandleTapAsClick(WebCore::IntPoint point)
</span><span class="cx">     ViewportMetaTagWidthDidChange(float width)
</span><ins>+    DidFinishDrawingPagesToPDF(IPC::DataReference pdfData)
</ins><span class="cx"> #endif
</span><span class="cx"> #if PLATFORM(GTK)
</span><span class="cx">     PrintFinishedCallback(WebCore::ResourceError error, uint64_t callbackID)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosPageClientImplIOSh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -132,6 +132,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     virtual void zoomToRect(WebCore::FloatRect, double minimumScale, double maximumScale) override;
</span><ins>+    virtual void didFinishDrawingPagesToPDF(const IPC::DataReference&amp;) override;
</ins><span class="cx"> 
</span><span class="cx">     // Auxiliary Client Creation
</span><span class="cx"> #if ENABLE(FULLSCREEN_API)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosPageClientImplIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -505,6 +505,13 @@
</span><span class="cx">     [m_contentView _zoomToRect:rect withOrigin:rect.center() fitEntireRect:YES minimumScale:minimumScale maximumScale:maximumScale minimumScrollDistance:0];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void PageClientImpl::didFinishDrawingPagesToPDF(const IPC::DataReference&amp; pdfData)
+{
+    RetainPtr&lt;CFDataRef&gt; data = adoptCF(CFDataCreate(kCFAllocatorDefault, pdfData.data(), pdfData.size()));
+    RetainPtr&lt;CGDataProviderRef&gt; dataProvider = adoptCF(CGDataProviderCreateWithCFData(data.get()));
+    m_webView._printedDocument = adoptCF(CGPDFDocumentCreateWithProvider(dataProvider.get())).get();
+}
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #endif // PLATFORM(IOS)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKPDFViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -30,8 +30,8 @@
</span><span class="cx"> 
</span><span class="cx"> @interface WKPDFView : UIView &lt;WKWebViewContentProvider&gt;
</span><span class="cx"> 
</span><del>-@property (nonatomic, readonly) NSData *documentData;
</del><span class="cx"> @property (nonatomic, readonly) NSString *suggestedFilename;
</span><ins>+@property (nonatomic, readonly) CGPDFDocumentRef pdfDocument;
</ins><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKPDFViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -28,7 +28,6 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> 
</span><del>-#import &lt;CoreGraphics/CGPDFDocumentPrivate.h&gt;
</del><span class="cx"> #import &lt;CorePDF/UIPDFDocument.h&gt;
</span><span class="cx"> #import &lt;CorePDF/UIPDFPageView.h&gt;
</span><span class="cx"> #import &lt;WebCore/FloatRect.h&gt;
</span><span class="lines">@@ -70,16 +69,16 @@
</span><span class="cx">     return self;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (NSData *)documentData
-{    
-    return [(NSData *)CGDataProviderCopyData(CGPDFDocumentGetDataProvider([_pdfDocument CGDocument])) autorelease];
-}
-
</del><span class="cx"> - (NSString *)suggestedFilename
</span><span class="cx"> {
</span><span class="cx">     return _suggestedFilename.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (CGPDFDocumentRef)pdfDocument
+{
+    return [_pdfDocument CGDocument];
+}
+
</ins><span class="cx"> - (void)web_setContentProviderData:(NSData *)data suggestedFilename:(NSString *)filename
</span><span class="cx"> {
</span><span class="cx">     _suggestedFilename = adoptNS([filename copy]);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWebPageProxyIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -649,6 +649,11 @@
</span><span class="cx">     m_pageClient.didChangeViewportMetaTagWidth(width);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::didFinishDrawingPagesToPDF(const IPC::DataReference&amp; pdfData)
+{
+    m_pageClient.didFinishDrawingPagesToPDF(pdfData);
+}
+
</ins><span class="cx"> #if USE(QUICK_LOOK)
</span><span class="cx">     
</span><span class="cx"> void WebPageProxy::didStartLoadForQuickLookDocumentInMainFrame(const String&amp; fileName, const String&amp; uti)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -1053,6 +1053,8 @@
</span><span class="cx">                 9F54F8951648AE0F007DF81A /* PluginProcessManagerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9F54F8941648AE0E007DF81A /* PluginProcessManagerMac.mm */; };
</span><span class="cx">                 9FB5F394169E6A80002C25BF /* WKContextPrivateMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9FB5F392169E6A80002C25BF /* WKContextPrivateMac.mm */; };
</span><span class="cx">                 9FB5F395169E6A80002C25BF /* WKContextPrivateMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+                A115DC71191D82D700DA8072 /* WKWebViewPrintFormatter.mm in Sources */ = {isa = PBXBuildFile; fileRef = A115DC6D191D82AB00DA8072 /* WKWebViewPrintFormatter.mm */; };
+                A115DC72191D82DA00DA8072 /* WKWebViewPrintFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = A115DC6E191D82AB00DA8072 /* WKWebViewPrintFormatter.h */; };
</ins><span class="cx">                 A118A9EE1907AD6F00F7C92B /* QuickLookDocumentData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A118A9EC1907AD6F00F7C92B /* QuickLookDocumentData.cpp */; };
</span><span class="cx">                 A118A9EF1907AD6F00F7C92B /* QuickLookDocumentData.h in Headers */ = {isa = PBXBuildFile; fileRef = A118A9ED1907AD6F00F7C92B /* QuickLookDocumentData.h */; };
</span><span class="cx">                 A118A9F21908B8EA00F7C92B /* _WKNSFileManagerExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = A118A9F01908B8EA00F7C92B /* _WKNSFileManagerExtras.mm */; };
</span><span class="lines">@@ -3045,6 +3047,8 @@
</span><span class="cx">                 9F54F8941648AE0E007DF81A /* PluginProcessManagerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PluginProcessManagerMac.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 9FB5F392169E6A80002C25BF /* WKContextPrivateMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKContextPrivateMac.mm; path = mac/WKContextPrivateMac.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKContextPrivateMac.h; path = mac/WKContextPrivateMac.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                A115DC6D191D82AB00DA8072 /* WKWebViewPrintFormatter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewPrintFormatter.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
+                A115DC6E191D82AB00DA8072 /* WKWebViewPrintFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebViewPrintFormatter.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 A118A9EC1907AD6F00F7C92B /* QuickLookDocumentData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = QuickLookDocumentData.cpp; path = ios/QuickLookDocumentData.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 A118A9ED1907AD6F00F7C92B /* QuickLookDocumentData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QuickLookDocumentData.h; path = ios/QuickLookDocumentData.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 A118A9F01908B8EA00F7C92B /* _WKNSFileManagerExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKNSFileManagerExtras.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -4713,6 +4717,8 @@
</span><span class="cx">                                 0FCB4E4118BBE044000FCFC9 /* WKGeolocationProviderIOSObjCSecurityOrigin.mm */,
</span><span class="cx">                                 0FCB4E4418BBE044000FCFC9 /* WKScrollView.h */,
</span><span class="cx">                                 0FCB4E4518BBE044000FCFC9 /* WKScrollView.mm */,
</span><ins>+                                A115DC6E191D82AB00DA8072 /* WKWebViewPrintFormatter.h */,
+                                A115DC6D191D82AB00DA8072 /* WKWebViewPrintFormatter.mm */,
</ins><span class="cx">                         );
</span><span class="cx">                         name = ios;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span><span class="lines">@@ -7026,6 +7032,7 @@
</span><span class="cx">                                 1A9E32891821636900F5D04C /* _WKRemoteObjectRegistry.h in Headers */,
</span><span class="cx">                                 51654EFE184EF33F007DC837 /* UniqueIDBDatabaseBackingStoreSQLite.h in Headers */,
</span><span class="cx">                                 BC33E0D112408E8600360F3F /* InjectedBundleRangeHandle.h in Headers */,
</span><ins>+                                A115DC72191D82DA00DA8072 /* WKWebViewPrintFormatter.h in Headers */,
</ins><span class="cx">                                 0FCB4E6018BBE3D9000FCFC9 /* FindIndicatorWindow.h in Headers */,
</span><span class="cx">                                 BC14DF77120B5B7900826C0C /* InjectedBundleScriptWorld.h in Headers */,
</span><span class="cx">                                 BCB0B0DE12305A8C00B1341E /* InjectedBundleUserMessageCoders.h in Headers */,
</span><span class="lines">@@ -8984,6 +8991,7 @@
</span><span class="cx">                                 519EF58E18EF770D0003B7F4 /* TelephoneNumberOverlayControllerMac.mm in Sources */,
</span><span class="cx">                                 BCF69FA31176D01400471A52 /* APINavigationData.cpp in Sources */,
</span><span class="cx">                                 31A2EC48148997C200810D71 /* WebNotification.cpp in Sources */,
</span><ins>+                                A115DC71191D82D700DA8072 /* WKWebViewPrintFormatter.mm in Sources */,
</ins><span class="cx">                                 31099973146C75A20029DEB9 /* WebNotificationClient.cpp in Sources */,
</span><span class="cx">                                 2DDE0AFB18298CC900F97EAA /* RemoteLayerTreePropertyApplier.mm in Sources */,
</span><span class="cx">                                 31312620148FF82C00BA2A39 /* WebNotificationManager.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -3608,7 +3608,14 @@
</span><span class="cx"> {
</span><span class="cx">     Vector&lt;IntRect&gt; resultPageRects;
</span><span class="cx">     double resultTotalScaleFactorForPrinting = 1;
</span><ins>+    computePagesForPrintingImpl(frameID, printInfo, resultPageRects, resultTotalScaleFactorForPrinting);
+    send(Messages::WebPageProxy::ComputedPagesCallback(resultPageRects, resultTotalScaleFactorForPrinting, callbackID));
+}
</ins><span class="cx"> 
</span><ins>+void WebPage::computePagesForPrintingImpl(uint64_t frameID, const PrintInfo&amp; printInfo, Vector&lt;WebCore::IntRect&gt;&amp; resultPageRects, double&amp; resultTotalScaleFactorForPrinting)
+{
+    ASSERT(resultPageRects.isEmpty());
+
</ins><span class="cx">     beginPrinting(frameID, printInfo);
</span><span class="cx"> 
</span><span class="cx">     if (m_printContext) {
</span><span class="lines">@@ -3623,8 +3630,6 @@
</span><span class="cx">     // If we're asked to print, we should actually print at least a blank page.
</span><span class="cx">     if (resultPageRects.isEmpty())
</span><span class="cx">         resultPageRects.append(IntRect(0, 0, 1, 1));
</span><del>-
-    send(Messages::WebPageProxy::ComputedPagesCallback(resultPageRects, resultTotalScaleFactorForPrinting, callbackID));
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="lines">@@ -3675,10 +3680,17 @@
</span><span class="cx"> 
</span><span class="cx"> void WebPage::drawPagesToPDF(uint64_t frameID, const PrintInfo&amp; printInfo, uint32_t first, uint32_t count, uint64_t callbackID)
</span><span class="cx"> {
</span><ins>+    RetainPtr&lt;CFMutableDataRef&gt; pdfPageData;
+    drawPagesToPDFImpl(frameID, printInfo, first, count, pdfPageData);
+    send(Messages::WebPageProxy::DataCallback(IPC::DataReference(CFDataGetBytePtr(pdfPageData.get()), CFDataGetLength(pdfPageData.get())), callbackID));
+}
+
+void WebPage::drawPagesToPDFImpl(uint64_t frameID, const PrintInfo&amp; printInfo, uint32_t first, uint32_t count, RetainPtr&lt;CFMutableDataRef&gt;&amp; pdfPageData)
+{
</ins><span class="cx">     WebFrame* frame = WebProcess::shared().webFrame(frameID);
</span><span class="cx">     Frame* coreFrame = frame ? frame-&gt;coreFrame() : 0;
</span><span class="cx"> 
</span><del>-    RetainPtr&lt;CFMutableDataRef&gt; pdfPageData = adoptCF(CFDataCreateMutable(0, 0));
</del><ins>+    pdfPageData = adoptCF(CFDataCreateMutable(0, 0));
</ins><span class="cx"> 
</span><span class="cx"> #if USE(CG)
</span><span class="cx">     if (coreFrame) {
</span><span class="lines">@@ -3721,8 +3733,6 @@
</span><span class="cx">         CGPDFContextClose(context.get());
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><del>-
-    send(Messages::WebPageProxy::DataCallback(IPC::DataReference(CFDataGetBytePtr(pdfPageData.get()), CFDataGetLength(pdfPageData.get())), callbackID));
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #elif PLATFORM(GTK)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -77,6 +77,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> #include &quot;GestureTypes.h&quot;
</span><ins>+#import &quot;WebPageMessages.h&quot;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(TOUCH_EVENTS)
</span><span class="lines">@@ -651,9 +652,14 @@
</span><span class="cx">     void beginPrinting(uint64_t frameID, const PrintInfo&amp;);
</span><span class="cx">     void endPrinting();
</span><span class="cx">     void computePagesForPrinting(uint64_t frameID, const PrintInfo&amp;, uint64_t callbackID);
</span><ins>+    void computePagesForPrintingImpl(uint64_t frameID, const PrintInfo&amp;, Vector&lt;WebCore::IntRect&gt;&amp; pageRects, double&amp; totalScaleFactor);
</ins><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     void drawRectToImage(uint64_t frameID, const PrintInfo&amp;, const WebCore::IntRect&amp;, const WebCore::IntSize&amp;, uint64_t callbackID);
</span><span class="cx">     void drawPagesToPDF(uint64_t frameID, const PrintInfo&amp;, uint32_t first, uint32_t count, uint64_t callbackID);
</span><ins>+    void drawPagesToPDFImpl(uint64_t frameID, const PrintInfo&amp;, uint32_t first, uint32_t count, RetainPtr&lt;CFMutableDataRef&gt;&amp; pdfPageData);
+#if PLATFORM(IOS)
+    void computePagesForPrintingAndStartDrawingToPDF(uint64_t frameID, const PrintInfo&amp;, uint32_t firstPage, PassRefPtr&lt;Messages::WebPage::ComputePagesForPrintingAndStartDrawingToPDF::DelayedReply&gt;);
+#endif
</ins><span class="cx"> #elif PLATFORM(GTK)
</span><span class="cx">     void drawPagesForPrinting(uint64_t frameID, const PrintInfo&amp;, uint64_t callbackID);
</span><span class="cx">     void didFinishPrintOperation(const WebCore::ResourceError&amp;, uint64_t callbackID);
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -268,7 +268,10 @@
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     DrawRectToImage(uint64_t frameID, WebKit::PrintInfo printInfo, WebCore::IntRect rect, WebCore::IntSize imageSize, uint64_t callbackID)
</span><span class="cx">     DrawPagesToPDF(uint64_t frameID, WebKit::PrintInfo printInfo, uint32_t first, uint32_t count, uint64_t callbackID)
</span><ins>+#if PLATFORM(IOS)
+    ComputePagesForPrintingAndStartDrawingToPDF(uint64_t frameID, WebKit::PrintInfo printInfo, uint32_t firstPage) -&gt; (Vector&lt;WebCore::IntRect&gt; pageRects, double totalScaleFactor) Delayed
</ins><span class="cx"> #endif
</span><ins>+#endif
</ins><span class="cx"> #if PLATFORM(GTK)
</span><span class="cx">     DrawPagesForPrinting(uint64_t frameID, WebKit::PrintInfo printInfo, uint64_t callbackID)
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (169174 => 169175)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-05-21 19:48:16 UTC (rev 169174)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-05-21 20:39:36 UTC (rev 169175)
</span><span class="lines">@@ -2304,6 +2304,19 @@
</span><span class="cx">         dispatchTouchEvent(event, ignored);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPage::computePagesForPrintingAndStartDrawingToPDF(uint64_t frameID, const PrintInfo&amp; printInfo, uint32_t firstPage, PassRefPtr&lt;Messages::WebPage::ComputePagesForPrintingAndStartDrawingToPDF::DelayedReply&gt; reply)
+{
+    Vector&lt;WebCore::IntRect&gt; pageRects;
+    double totalScaleFactor = 1;
+    computePagesForPrintingImpl(frameID, printInfo, pageRects, totalScaleFactor);
+    std::size_t pageCount = pageRects.size();
+    reply-&gt;send(std::move(pageRects), totalScaleFactor);
+
+    RetainPtr&lt;CFMutableDataRef&gt; pdfPageData;
+    drawPagesToPDFImpl(frameID, printInfo, firstPage, pageCount - firstPage, pdfPageData);
+    send(Messages::WebPageProxy::DidFinishDrawingPagesToPDF(IPC::DataReference(CFDataGetBytePtr(pdfPageData.get()), CFDataGetLength(pdfPageData.get()))));
+}
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #endif // PLATFORM(IOS)
</span></span></pre>
</div>
</div>

</body>
</html>