Title: [105113] branches/safari-534.54-branch/Source
Revision
105113
Author
[email protected]
Date
2012-01-16 17:21:31 -0800 (Mon, 16 Jan 2012)

Log Message

Merge r103858.

Modified Paths

Diff

Modified: branches/safari-534.54-branch/Source/WebCore/ChangeLog (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebCore/ChangeLog	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebCore/ChangeLog	2012-01-17 01:21:31 UTC (rev 105113)
@@ -1,5 +1,20 @@
 2012-01-16  Mark Rowe  <[email protected]>
 
+        Merge r103858.
+
+    2011-12-31  Dan Bernstein  <[email protected]>
+
+        WebCore changes for <rdar://problem/8750356> REGRESSION (WebKit2): Printing a subframe containing a PDF prints the on-screen view instead of the entire PDF document
+        <http://webkit.org/b/75232>
+
+        Reviewed by Alexey Proskuryakov.
+
+        * WebCore.exp.in: Exported PluginDocument::pluginWidget().
+        * WebCore.xcodeproj/project.pbxproj: Promoted PluginDocument.h to private.
+        * html/PluginDocument.h: Fixed a typo in a comment.
+
+2012-01-16  Mark Rowe  <[email protected]>
+
         Fix <rdar://problem/10678175>.
 
         * platform/mac/ScrollAnimatorMac.mm:

Modified: branches/safari-534.54-branch/Source/WebCore/WebCore.exp.in (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebCore/WebCore.exp.in	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebCore/WebCore.exp.in	2012-01-17 01:21:31 UTC (rev 105113)
@@ -354,10 +354,11 @@
 __ZN7WebCore14FrameSelection15revealSelectionERKNS_15ScrollAlignmentEb
 __ZN7WebCore14FrameSelection16setSelectedRangeEPNS_5RangeENS_9EAffinityEb
 __ZN7WebCore14FrameSelection20setSelectionFromNoneEv
+__ZN7WebCore14FrameSelection5clearEv
 __ZN7WebCore14FrameSelection6modifyENS0_11EAlterationENS_18SelectionDirectionENS_15TextGranularityEb
-__ZN7WebCore14FrameSelection5clearEv
 __ZN7WebCore14FrameSelection9selectAllEv
 __ZN7WebCore14FrameSelectionC1EPNS_5FrameE
+__ZN7WebCore14PluginDocument12pluginWidgetEv
 __ZN7WebCore14ResourceHandle12releaseProxyEv
 __ZN7WebCore14ResourceHandle20forceContentSniffingEv
 __ZN7WebCore14ResourceHandle26synchronousLoadRunLoopModeEv

Modified: branches/safari-534.54-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-01-17 01:21:31 UTC (rev 105113)
@@ -3020,7 +3020,7 @@
 		97205AB71239291000B17380 /* MediaDocument.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97205AB31239291000B17380 /* MediaDocument.cpp */; };
 		97205AB81239291000B17380 /* MediaDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 97205AB41239291000B17380 /* MediaDocument.h */; };
 		97205ABB1239292700B17380 /* PluginDocument.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97205AB91239292700B17380 /* PluginDocument.cpp */; };
-		97205ABC1239292700B17380 /* PluginDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 97205ABA1239292700B17380 /* PluginDocument.h */; };
+		97205ABC1239292700B17380 /* PluginDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 97205ABA1239292700B17380 /* PluginDocument.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		9728C3131268E4390041E89B /* MarkupAccumulator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9728C3111268E4390041E89B /* MarkupAccumulator.cpp */; };
 		9728C3141268E4390041E89B /* MarkupAccumulator.h in Headers */ = {isa = PBXBuildFile; fileRef = 9728C3121268E4390041E89B /* MarkupAccumulator.h */; };
 		973889A0116EA9DC00ADF313 /* DocumentWriter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9738899E116EA9DC00ADF313 /* DocumentWriter.cpp */; };

Modified: branches/safari-534.54-branch/Source/WebCore/html/PluginDocument.h (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebCore/html/PluginDocument.h	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebCore/html/PluginDocument.h	2012-01-17 01:21:31 UTC (rev 105113)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2008, 2009Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions

Modified: branches/safari-534.54-branch/Source/WebKit2/ChangeLog (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/ChangeLog	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/ChangeLog	2012-01-17 01:21:31 UTC (rev 105113)
@@ -1,5 +1,62 @@
 2012-01-16  Mark Rowe  <[email protected]>
 
+        Merge r103858.
+
+    2011-12-31  Dan Bernstein  <[email protected]>
+
+        <rdar://problem/8750356> REGRESSION (WebKit2): Printing a subframe containing a PDF prints the on-screen view instead of the entire PDF document
+        <http://webkit.org/b/75232>
+
+        Reviewed by Alexey Proskuryakov.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageDrawPagesToPDF): Added WKPrintInfo parameter, which is passed through as a PrintInfo
+        to the WebPageProxy.
+        * UIProcess/API/C/WKPagePrivate.h:
+        * UIProcess/API/mac/WKPrintingView.mm:
+        (-[WKPrintingView _preparePDFDataForPrintingOnSecondaryThread]): Changed to pass the PrintInfo
+        down to WebPageProxy::drawPagesToPDF.
+        (-[WKPrintingView _drawPreview:]): Changed to pass the PrintInfo down to
+        WebPageProxy::drawRectToPDF.
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView canChangeFrameLayout:]): Changed to use WebFrameProxy::isDisplayingPDFDocument, which
+        works for subframes as well.
+        (-[WKView printOperationWithPrintInfo:forFrame:]): Added a FIXME.
+        * UIProcess/WebFrameProxy.cpp:
+        (WebKit::WebFrameProxy::isDisplayingPDFDocument): Added.
+        * UIProcess/WebFrameProxy.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::drawRectToPDF): Added a PrintInfo parameter, which is passed through to
+        the Web process.
+        (WebKit::WebPageProxy::drawPagesToPDF): Ditto.
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/Plugins/PDF/BuiltInPDFView.h:
+        Added an override of pdfDocumentForPrinting() which returns the PDFDocument.
+        * WebProcess/Plugins/Plugin.h:
+        (WebKit::Plugin::pdfDocumentForPrinting): Added. This base class implementation returns 0.
+        * WebProcess/Plugins/PluginView.h:
+        (WebKit::PluginView::pdfDocumentForPrinting): Added. Calls through to the Plugin.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::pdfDocumentForPrintingFrame): Added this helper function. If the frame is displaying
+        a plug-in document, allows the plug-in to provide a PDF document for printing.
+        (WebKit::WebPage::beginPrinting): Added an early return if the frame provides a PDF document
+        for printing.
+        (WebKit::WebPage::computePagesForPrinting): If the frame provides a PDF document for printing,
+        create for each page in the PDF document a page rect with the size available for printing.
+        (WebKit::drawPDFPage): Added this helper function, which draws a page from the PDF document
+        into one of the aforementioned page rects. It rotates the PDF page 90 degrees if necessary to
+        better match the aspect ratio of the paper, then it centers it on the paper. This matches the
+        behavior of a PDFView when printed with default settings.
+        (WebKit::WebPage::drawRectToPDF): If the frame provides a PDF document for printing, draw the
+        PDF pages falling within the requested rect.
+        (WebKit::WebPage::drawPagesToPDF): If the frame provides a PDF document for printing, draw
+        the requested pages.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in: Added a PrintInfo parameter to DrawRectToPDF and
+        DrawPagesToPDF.
+
+2012-01-16  Mark Rowe  <[email protected]>
+
         Merge r102540.
 
     2011-12-11  Andreas Kling  <[email protected]>

Modified: branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/C/WKPage.cpp (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/C/WKPage.cpp	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/C/WKPage.cpp	2012-01-17 01:21:31 UTC (rev 105113)
@@ -575,9 +575,9 @@
     toImpl(page)->beginPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo));
 }
 
-void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
+void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
 {
-    toImpl(page)->drawPagesToPDF(toImpl(frame), first, count, DataCallback::create(context, callback));
+    toImpl(page)->drawPagesToPDF(toImpl(frame), printInfoFromWKPrintInfo(printInfo), first, count, DataCallback::create(context, callback));
 }
 #endif
 

Modified: branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h	2012-01-17 01:21:31 UTC (rev 105113)
@@ -61,8 +61,8 @@
 WK_EXPORT void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo, WKPageComputePagesForPrintingFunction, void* context);
 
 typedef void (*WKPageDrawToPDFFunction)(WKDataRef data, WKErrorRef error, void* functionContext);
-WK_EXPORT void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo);
-WK_EXPORT void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context);
+WK_EXPORT void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo);
+WK_EXPORT void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context);
 
 // FIXME: This is in violation of the no synchronous messages to the Web Process policy and should
 // be removed as soon as possible.

Modified: branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm	2012-01-17 01:21:31 UTC (rev 105113)
@@ -252,8 +252,9 @@
     ASSERT(firstPage <= lastPage);
     LOG(View, "WKPrintingView requesting PDF data for pages %u...%u", firstPage, lastPage);
 
+    PrintInfo printInfo([_printOperation printInfo]);
     // Return to printing mode if we're already back to screen (e.g. due to window resizing).
-    _webFrame->page()->beginPrinting(_webFrame.get(), PrintInfo([_printOperation printInfo]));
+    _webFrame->page()->beginPrinting(_webFrame.get(), printInfo);
 
     IPCCallbackContext* context = new IPCCallbackContext;
     RefPtr<DataCallback> callback = DataCallback::create(context, pageDidDrawToPDF);
@@ -262,7 +263,7 @@
     context->view = self;
     context->callbackID = callback->callbackID();
 
-    _webFrame->page()->drawPagesToPDF(_webFrame.get(), firstPage - 1, lastPage - firstPage + 1, callback.get());
+    _webFrame->page()->drawPagesToPDF(_webFrame.get(), printInfo, firstPage - 1, lastPage - firstPage + 1, callback.get());
 }
 
 static void pageDidComputePageRects(const Vector<WebCore::IntRect>& pageRects, double totalScaleFactorForPrinting, WKErrorRef, void* untypedContext)
@@ -498,7 +499,7 @@
                 context->view = self;
                 context->callbackID = callback->callbackID();
 
-                _webFrame->page()->drawRectToPDF(_webFrame.get(), rect, callback.get());
+                _webFrame->page()->drawRectToPDF(_webFrame.get(), PrintInfo([_printOperation printInfo]), rect, callback.get());
                 return;
             }
         }

Modified: branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/mac/WKView.mm (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/mac/WKView.mm	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/mac/WKView.mm	2012-01-17 01:21:31 UTC (rev 105113)
@@ -1992,7 +1992,7 @@
 - (BOOL)canChangeFrameLayout:(WKFrameRef)frameRef
 {
     // PDF documents are already paginated, so we can't change them to add headers and footers.
-    return !toImpl(frameRef)->isMainFrame() || !_data->_pdfViewController;
+    return !toImpl(frameRef)->isDisplayingPDFDocument();
 }
 
 - (NSPrintOperation *)printOperationWithPrintInfo:(NSPrintInfo *)printInfo forFrame:(WKFrameRef)frameRef
@@ -2005,6 +2005,8 @@
             return 0;
         return _data->_pdfViewController->makePrintOperation(printInfo);
     } else {
+        // FIXME: If the frame cannot be printed (e.g. if it contains an encrypted PDF that disallows
+        // printing), this function should return nil.
         RetainPtr<WKPrintingView> printingView(AdoptNS, [[WKPrintingView alloc] initWithFrameProxy:toImpl(frameRef) view:self]);
         // NSPrintOperation takes ownership of the view.
         NSPrintOperation *printOperation = [NSPrintOperation printOperationWithView:printingView.get()];

Modified: branches/safari-534.54-branch/Source/WebKit2/UIProcess/WebFrameProxy.cpp (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/UIProcess/WebFrameProxy.cpp	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/UIProcess/WebFrameProxy.cpp	2012-01-17 01:21:31 UTC (rev 105113)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -128,6 +128,14 @@
     return m_MIMEType == "text/html" || m_MIMEType == "image/svg+xml" || DOMImplementation::isXMLMIMEType(m_MIMEType);
 }
 
+bool WebFrameProxy::isDisplayingPDFDocument() const
+{
+    if (m_MIMEType.isEmpty())
+        return false;
+
+    return WebContext::pdfAndPostScriptMIMETypes().contains(m_MIMEType);
+}
+
 void WebFrameProxy::didStartProvisionalLoad(const String& url)
 {
     ASSERT(m_loadState == LoadStateFinished);

Modified: branches/safari-534.54-branch/Source/WebKit2/UIProcess/WebFrameProxy.h (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/UIProcess/WebFrameProxy.h	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/UIProcess/WebFrameProxy.h	2012-01-17 01:21:31 UTC (rev 105113)
@@ -106,6 +106,7 @@
 
     bool isDisplayingStandaloneImageDocument() const;
     bool isDisplayingMarkupDocument() const;
+    bool isDisplayingPDFDocument() const;
 
     void getWebArchive(PassRefPtr<DataCallback>);
     void getMainResourceData(PassRefPtr<DataCallback>);

Modified: branches/safari-534.54-branch/Source/WebKit2/UIProcess/WebPageProxy.cpp (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/UIProcess/WebPageProxy.cpp	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/UIProcess/WebPageProxy.cpp	2012-01-17 01:21:31 UTC (rev 105113)
@@ -3237,7 +3237,7 @@
 }
 
 #if PLATFORM(MAC) || PLATFORM(WIN)
-void WebPageProxy::drawRectToPDF(WebFrameProxy* frame, const IntRect& rect, PassRefPtr<DataCallback> prpCallback)
+void WebPageProxy::drawRectToPDF(WebFrameProxy* frame, const PrintInfo& printInfo, const IntRect& rect, PassRefPtr<DataCallback> prpCallback)
 {
     RefPtr<DataCallback> callback = prpCallback;
     if (!isValid()) {
@@ -3247,10 +3247,10 @@
     
     uint64_t callbackID = callback->callbackID();
     m_dataCallbacks.set(callbackID, callback.get());
-    process()->send(Messages::WebPage::DrawRectToPDF(frame->frameID(), rect, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
+    process()->send(Messages::WebPage::DrawRectToPDF(frame->frameID(), printInfo, rect, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
 }
 
-void WebPageProxy::drawPagesToPDF(WebFrameProxy* frame, uint32_t first, uint32_t count, PassRefPtr<DataCallback> prpCallback)
+void WebPageProxy::drawPagesToPDF(WebFrameProxy* frame, const PrintInfo& printInfo, uint32_t first, uint32_t count, PassRefPtr<DataCallback> prpCallback)
 {
     RefPtr<DataCallback> callback = prpCallback;
     if (!isValid()) {
@@ -3260,7 +3260,7 @@
     
     uint64_t callbackID = callback->callbackID();
     m_dataCallbacks.set(callbackID, callback.get());
-    process()->send(Messages::WebPage::DrawPagesToPDF(frame->frameID(), first, count, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
+    process()->send(Messages::WebPage::DrawPagesToPDF(frame->frameID(), printInfo, first, count, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
 }
 #endif
 

Modified: branches/safari-534.54-branch/Source/WebKit2/UIProcess/WebPageProxy.h (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/UIProcess/WebPageProxy.h	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/UIProcess/WebPageProxy.h	2012-01-17 01:21:31 UTC (rev 105113)
@@ -504,8 +504,8 @@
     void endPrinting();
     void computePagesForPrinting(WebFrameProxy*, const PrintInfo&, PassRefPtr<ComputedPagesCallback>);
 #if PLATFORM(MAC) || PLATFORM(WIN)
-    void drawRectToPDF(WebFrameProxy*, const WebCore::IntRect&, PassRefPtr<DataCallback>);
-    void drawPagesToPDF(WebFrameProxy*, uint32_t first, uint32_t count, PassRefPtr<DataCallback>);
+    void drawRectToPDF(WebFrameProxy*, const PrintInfo&, const WebCore::IntRect&, PassRefPtr<DataCallback>);
+    void drawPagesToPDF(WebFrameProxy*, const PrintInfo&, uint32_t first, uint32_t count, PassRefPtr<DataCallback>);
 #endif
 
     const String& pendingAPIRequestURL() const { return m_pendingAPIRequestURL; }

Modified: branches/safari-534.54-branch/Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.h (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.h	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.h	2012-01-17 01:21:31 UTC (rev 105113)
@@ -118,6 +118,8 @@
     virtual WebCore::Scrollbar* horizontalScrollbar();
     virtual WebCore::Scrollbar* verticalScrollbar();
 
+    virtual RetainPtr<CGPDFDocumentRef> pdfDocumentForPrinting() const { return m_pdfDocument; }
+
     // ScrollableArea methods.
     virtual WebCore::IntRect scrollCornerRect() const;
     virtual WebCore::ScrollableArea* enclosingScrollableArea() const;

Modified: branches/safari-534.54-branch/Source/WebKit2/WebProcess/Plugins/Plugin.h (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/WebProcess/Plugins/Plugin.h	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/WebProcess/Plugins/Plugin.h	2012-01-17 01:21:31 UTC (rev 105113)
@@ -30,6 +30,7 @@
 #include <WebCore/KURL.h>
 #include <WebCore/ScrollTypes.h>
 #include <wtf/RefCounted.h>
+#include <wtf/RetainPtr.h>
 #include <wtf/Vector.h>
 
 struct NPObject;
@@ -210,6 +211,10 @@
     virtual WebCore::Scrollbar* horizontalScrollbar() = 0;
     virtual WebCore::Scrollbar* verticalScrollbar() = 0;
 
+#if USE(CG)
+    virtual RetainPtr<CGPDFDocumentRef> pdfDocumentForPrinting() const { return 0; }
+#endif
+
 protected:
     Plugin();
 };

Modified: branches/safari-534.54-branch/Source/WebKit2/WebProcess/Plugins/PluginView.h (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/WebProcess/Plugins/PluginView.h	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/WebProcess/Plugins/PluginView.h	2012-01-17 01:21:31 UTC (rev 105113)
@@ -68,6 +68,10 @@
     bool sendComplexTextInput(uint64_t pluginComplexTextInputIdentifier, const String& textInput);
 #endif
 
+#if USE(CG)
+    RetainPtr<CGPDFDocumentRef> pdfDocumentForPrinting() const { return m_plugin->pdfDocumentForPrinting(); }
+#endif
+
     // FIXME: Remove this; nobody should have to know about the plug-in view's renderer except the plug-in view itself.
     WebCore::RenderBoxModelObject* renderer() const;
 

Modified: branches/safari-534.54-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-01-17 01:21:31 UTC (rev 105113)
@@ -91,6 +91,7 @@
 #include <WebCore/MouseEvent.h>
 #include <WebCore/Page.h>
 #include <WebCore/PlatformKeyboardEvent.h>
+#include <WebCore/PluginDocument.h>
 #include <WebCore/PrintContext.h>
 #include <WebCore/RenderLayer.h>
 #include <WebCore/RenderTreeAsText.h>
@@ -135,6 +136,7 @@
 
 using namespace JSC;
 using namespace WebCore;
+using namespace std;
 
 namespace WebKit {
 
@@ -2250,6 +2252,24 @@
 
 #endif
 
+#if USE(CG)
+static RetainPtr<CGPDFDocumentRef> pdfDocumentForPrintingFrame(Frame* coreFrame)
+{
+    Document* document = coreFrame->document();
+    if (!document)
+        return 0;
+
+    if (!document->isPluginDocument())
+        return 0;
+
+    PluginView* pluginView = static_cast<PluginView*>(toPluginDocument(document)->pluginWidget());
+    if (!pluginView)
+        return 0;
+
+    return pluginView->pdfDocumentForPrinting();
+}
+#endif // USE(CG)
+
 void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo)
 {
     WebFrame* frame = WebProcess::shared().webFrame(frameID);
@@ -2260,6 +2280,11 @@
     if (!coreFrame)
         return;
 
+#if USE(CG)
+    if (pdfDocumentForPrintingFrame(coreFrame))
+        return;
+#endif // USE(CG)
+
     if (!m_printContext)
         m_printContext = adoptPtr(new PrintContext(coreFrame));
 
@@ -2285,6 +2310,21 @@
         resultPageRects = m_printContext->pageRects();
         resultTotalScaleFactorForPrinting = m_printContext->computeAutomaticScaleFactor(FloatSize(printInfo.availablePaperWidth, printInfo.availablePaperHeight)) * printInfo.pageSetupScaleFactor;
     }
+#if USE(CG)
+    else {
+        WebFrame* frame = WebProcess::shared().webFrame(frameID);
+        Frame* coreFrame = frame ? frame->coreFrame() : 0;
+        RetainPtr<CGPDFDocumentRef> pdfDocument = coreFrame ? pdfDocumentForPrintingFrame(coreFrame) : 0;
+        if (pdfDocument && CGPDFDocumentAllowsPrinting(pdfDocument.get())) {
+            CFIndex pageCount = CGPDFDocumentGetNumberOfPages(pdfDocument.get());
+            IntRect pageRect(0, 0, ceilf(printInfo.availablePaperWidth), ceilf(printInfo.availablePaperHeight));
+            for (CFIndex i = 1; i <= pageCount; ++i) {
+                resultPageRects.append(pageRect);
+                pageRect.move(0, pageRect.height());
+            }
+        }
+    }
+#endif // USE(CG)
 
     // If we're asked to print, we should actually print at least a blank page.
     if (resultPageRects.isEmpty())
@@ -2293,8 +2333,50 @@
     send(Messages::WebPageProxy::ComputedPagesCallback(resultPageRects, resultTotalScaleFactorForPrinting, callbackID));
 }
 
+#if USE(CG)
+static inline CGFloat roundCGFloat(CGFloat f)
+{
+    if (sizeof(CGFloat) == sizeof(float))
+        return roundf(static_cast<float>(f));
+    return static_cast<CGFloat>(round(f));
+}
+
+static void drawPDFPage(CGPDFDocumentRef pdfDocument, CFIndex pageIndex, CGContextRef context, CGFloat pageSetupScaleFactor, CGSize paperSize)
+{
+    CGContextSaveGState(context);
+
+    CGContextScaleCTM(context, pageSetupScaleFactor, pageSetupScaleFactor);
+
+    CGPDFPageRef page = CGPDFDocumentGetPage(pdfDocument, pageIndex + 1);
+    CGRect cropBox = CGPDFPageGetBoxRect(page, kCGPDFCropBox);
+    if (CGRectIsEmpty(cropBox))
+        cropBox = CGRectIntersection(cropBox, CGPDFPageGetBoxRect(page, kCGPDFMediaBox));
+    else
+        cropBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
+
+    bool shouldRotate = (paperSize.width < paperSize.height) != (cropBox.size.width < cropBox.size.height);
+    if (shouldRotate)
+        swap(cropBox.size.width, cropBox.size.height);
+
+    // Center.
+    CGFloat widthDifference = paperSize.width / pageSetupScaleFactor - cropBox.size.width;
+    CGFloat heightDifference = paperSize.height / pageSetupScaleFactor - cropBox.size.height;
+    if (widthDifference || heightDifference)
+        CGContextTranslateCTM(context, roundCGFloat(widthDifference / 2), roundCGFloat(heightDifference / 2));
+
+    if (shouldRotate) {
+        CGContextRotateCTM(context, M_PI_2);
+        CGContextTranslateCTM(context, 0, -cropBox.size.width);
+    }
+
+    CGContextDrawPDFPage(context, page);
+
+    CGContextRestoreGState(context);
+}
+#endif // USE(CG)
+
 #if PLATFORM(MAC) || PLATFORM(WIN)
-void WebPage::drawRectToPDF(uint64_t frameID, const WebCore::IntRect& rect, uint64_t callbackID)
+void WebPage::drawRectToPDF(uint64_t frameID, const PrintInfo& printInfo, const WebCore::IntRect& rect, uint64_t callbackID)
 {
     WebFrame* frame = WebProcess::shared().webFrame(frameID);
     Frame* coreFrame = frame ? frame->coreFrame() : 0;
@@ -2302,7 +2384,11 @@
     RetainPtr<CFMutableDataRef> pdfPageData(AdoptCF, CFDataCreateMutable(0, 0));
 
     if (coreFrame) {
-        ASSERT(coreFrame->document()->printing());
+        ASSERT(coreFrame->document()->printing()
+#if USE(CG)
+            || pdfDocumentForPrintingFrame(coreFrame)
+#endif
+        );
 
 #if USE(CG)
         // FIXME: Use CGDataConsumerCreate with callbacks to avoid copying the data.
@@ -2313,20 +2399,39 @@
         RetainPtr<CFDictionaryRef> pageInfo(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
         CGPDFContextBeginPage(context.get(), pageInfo.get());
 
-        GraphicsContext ctx(context.get());
-        ctx.scale(FloatSize(1, -1));
-        ctx.translate(0, -rect.height());
-        m_printContext->spoolRect(ctx, rect);
+        if (RetainPtr<CGPDFDocumentRef> pdfDocument = pdfDocumentForPrintingFrame(coreFrame)) {
+            CFIndex pageCount = CGPDFDocumentGetNumberOfPages(pdfDocument.get());
+            IntSize paperSize(ceilf(printInfo.availablePaperWidth), ceilf(printInfo.availablePaperHeight));
+            IntRect pageRect(IntPoint(), paperSize);
+            for (CFIndex i = 0; i < pageCount; ++i) {
+                if (pageRect.intersects(rect)) {
+                    CGContextSaveGState(context.get());
 
+                    CGContextTranslateCTM(context.get(), pageRect.x() - rect.x(), pageRect.y() - rect.y());
+                    drawPDFPage(pdfDocument.get(), i, context.get(), printInfo.pageSetupScaleFactor, paperSize);
+
+                    CGContextRestoreGState(context.get());
+                }
+                pageRect.move(0, pageRect.height());
+            }
+        } else {
+            GraphicsContext ctx(context.get());
+            ctx.scale(FloatSize(1, -1));
+            ctx.translate(0, -rect.height());
+            m_printContext->spoolRect(ctx, rect);
+        }
+
         CGPDFContextEndPage(context.get());
         CGPDFContextClose(context.get());
+#else
+        UNUSED_PARAM(printInfo);
 #endif
     }
 
     send(Messages::WebPageProxy::DataCallback(CoreIPC::DataReference(CFDataGetBytePtr(pdfPageData.get()), CFDataGetLength(pdfPageData.get())), callbackID));
 }
 
-void WebPage::drawPagesToPDF(uint64_t frameID, uint32_t first, uint32_t count, uint64_t callbackID)
+void WebPage::drawPagesToPDF(uint64_t frameID, const PrintInfo& printInfo, uint32_t first, uint32_t count, uint64_t callbackID)
 {
     WebFrame* frame = WebProcess::shared().webFrame(frameID);
     Frame* coreFrame = frame ? frame->coreFrame() : 0;
@@ -2334,25 +2439,37 @@
     RetainPtr<CFMutableDataRef> pdfPageData(AdoptCF, CFDataCreateMutable(0, 0));
 
     if (coreFrame) {
-        ASSERT(coreFrame->document()->printing());
 
+        ASSERT(coreFrame->document()->printing()
 #if USE(CG)
+            || pdfDocumentForPrintingFrame(coreFrame)
+#endif
+        );
+
+#if USE(CG)
+        RetainPtr<CGPDFDocumentRef> pdfDocument = pdfDocumentForPrintingFrame(coreFrame);
+
         // FIXME: Use CGDataConsumerCreate with callbacks to avoid copying the data.
         RetainPtr<CGDataConsumerRef> pdfDataConsumer(AdoptCF, CGDataConsumerCreateWithCFData(pdfPageData.get()));
 
-        CGRect mediaBox = m_printContext->pageCount() ? m_printContext->pageRect(0) : CGRectMake(0, 0, 1, 1);
+        CGRect mediaBox = m_printContext && m_printContext->pageCount() ? m_printContext->pageRect(0) : CGRectMake(0, 0, printInfo.availablePaperWidth, printInfo.availablePaperHeight);
         RetainPtr<CGContextRef> context(AdoptCF, CGPDFContextCreate(pdfDataConsumer.get(), &mediaBox, 0));
+        size_t pageCount = m_printContext ? m_printContext->pageCount() : CGPDFDocumentGetNumberOfPages(pdfDocument.get());
         for (uint32_t page = first; page < first + count; ++page) {
-            if (page >= m_printContext->pageCount())
+            if (page >= pageCount)
                 break;
 
             RetainPtr<CFDictionaryRef> pageInfo(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
             CGPDFContextBeginPage(context.get(), pageInfo.get());
 
-            GraphicsContext ctx(context.get());
-            ctx.scale(FloatSize(1, -1));
-            ctx.translate(0, -m_printContext->pageRect(page).height());
-            m_printContext->spoolPage(ctx, page, m_printContext->pageRect(page).width());
+            if (pdfDocument)
+                drawPDFPage(pdfDocument.get(), page, context.get(), printInfo.pageSetupScaleFactor, CGSizeMake(printInfo.availablePaperWidth, printInfo.availablePaperHeight));
+            else {
+                GraphicsContext ctx(context.get());
+                ctx.scale(FloatSize(1, -1));
+                ctx.translate(0, -m_printContext->pageRect(page).height());
+                m_printContext->spoolPage(ctx, page, m_printContext->pageRect(page).width());
+            }
 
             CGPDFContextEndPage(context.get());
         }

Modified: branches/safari-534.54-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h	2012-01-17 01:21:31 UTC (rev 105113)
@@ -383,8 +383,8 @@
     void endPrinting();
     void computePagesForPrinting(uint64_t frameID, const PrintInfo&, uint64_t callbackID);
 #if PLATFORM(MAC) || PLATFORM(WIN)
-    void drawRectToPDF(uint64_t frameID, const WebCore::IntRect&, uint64_t callbackID);
-    void drawPagesToPDF(uint64_t frameID, uint32_t first, uint32_t count, uint64_t callbackID);
+    void drawRectToPDF(uint64_t frameID, const PrintInfo&, const WebCore::IntRect&, uint64_t callbackID);
+    void drawPagesToPDF(uint64_t frameID, const PrintInfo&, uint32_t first, uint32_t count, uint64_t callbackID);
 #endif
 
     bool mainFrameHasCustomRepresentation() const;

Modified: branches/safari-534.54-branch/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (105112 => 105113)


--- branches/safari-534.54-branch/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2012-01-17 01:17:48 UTC (rev 105112)
+++ branches/safari-534.54-branch/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2012-01-17 01:21:31 UTC (rev 105113)
@@ -164,8 +164,8 @@
     EndPrinting();
     ComputePagesForPrinting(uint64_t frameID, WebKit::PrintInfo printInfo, uint64_t callbackID)
 #if PLATFORM(MAC) || PLATFORM(WIN)
-    DrawRectToPDF(uint64_t frameID, WebCore::IntRect rect, uint64_t callbackID)
-    DrawPagesToPDF(uint64_t frameID, uint32_t first, uint32_t count, uint64_t callbackID)
+    DrawRectToPDF(uint64_t frameID, WebKit::PrintInfo printInfo, WebCore::IntRect rect, uint64_t callbackID)
+    DrawPagesToPDF(uint64_t frameID, WebKit::PrintInfo printInfo, uint32_t first, uint32_t count, uint64_t callbackID)
 #endif
 
     SetMemoryCacheMessagesEnabled(bool memoryCacheMessagesEnabled)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to