Title: [136265] trunk/Source
Revision
136265
Author
[email protected]
Date
2012-11-30 13:24:56 -0800 (Fri, 30 Nov 2012)

Log Message

(Simple)PDFPlugin: Support conversion of PostScript documents
https://bugs.webkit.org/show_bug.cgi?id=103289
<rdar://problem/10235708>

Reviewed by Dan Bernstein.

SimplePDFPlugin (and PDFPlugin) should support converting PostScript files
to PDF before handing them off to their respective backends.

As PDFPlugin inherits from SimplePDFPlugin, it gets the new functionality automatically.

* WebProcess/Plugins/PDF/SimplePDFPlugin.h: Add convertPostScriptDataIfNeeded(), and m_isPostScript.
* WebProcess/Plugins/PDF/SimplePDFPlugin.mm:
(WebKit::SimplePDFPlugin::pluginInfo): SimplePDFPlugin should claim to support PDF and PostScript.
(WebKit::convertPostScriptDataSourceToPDF): PS->PDF conversion code, copied from PDFViewController (which I intend to remove).
(WebKit::SimplePDFPlugin::convertPostScriptDataIfNeeded): Check if the loaded data represents a PS file; if so, convert it.
(WebKit::SimplePDFPlugin::streamDidReceiveResponse): Check if the loaded data is of MIME type application/postscript, and store that in m_isPostScript.
(WebKit::SimplePDFPlugin::streamDidFinishLoading): Call convertPostScriptDataIfNeeded when we finish loading.
(WebKit::SimplePDFPlugin::manualStreamDidReceiveResponse): Ditto from streamDidReceiveResponse.
(WebKit::SimplePDFPlugin::manualStreamDidFinishLoading): Ditto from streamDidFinishLoading.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::createPlugin): Use (Simple)PDFPlugin for PostScript files too.

* English.lproj/Localizable.strings:
* WebCore.exp.in:
* platform/LocalizedStrings.cpp:
(WebCore::postScriptDocumentTypeDescription):
* platform/LocalizedStrings.h:
Add and export postScriptDocumentTypeDescription, for PostScript files.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (136264 => 136265)


--- trunk/Source/WebCore/ChangeLog	2012-11-30 21:21:45 UTC (rev 136264)
+++ trunk/Source/WebCore/ChangeLog	2012-11-30 21:24:56 UTC (rev 136265)
@@ -1,3 +1,21 @@
+2012-11-30  Tim Horton  <[email protected]>
+
+        (Simple)PDFPlugin: Support conversion of PostScript documents
+        https://bugs.webkit.org/show_bug.cgi?id=103289
+        <rdar://problem/10235708>
+
+        Reviewed by Dan Bernstein.
+
+        SimplePDFPlugin (and PDFPlugin) should support converting PostScript files
+        to PDF before handing them off to their respective backends.
+
+        * English.lproj/Localizable.strings:
+        * WebCore.exp.in:
+        * platform/LocalizedStrings.cpp:
+        (WebCore::postScriptDocumentTypeDescription):
+        * platform/LocalizedStrings.h:
+        Add and export postScriptDocumentTypeDescription, for PostScript files.
+
 2012-11-30  Justin Novosad  <[email protected]>
 
         [Chromium] Animation updates fail when using a canvas as a CSS backround-image style with -webkit-canvas

Modified: trunk/Source/WebCore/English.lproj/Localizable.strings (136264 => 136265)


--- trunk/Source/WebCore/English.lproj/Localizable.strings	2012-11-30 21:21:45 UTC (rev 136264)
+++ trunk/Source/WebCore/English.lproj/Localizable.strings	2012-11-30 21:24:56 UTC (rev 136265)
@@ -316,9 +316,12 @@
 /* WebKitErrorPlugInWillHandleLoad description */
 "Plug-in handled load" = "Plug-in handled load";
 
-/* Description of the (only) type supported by PDF pseudo plug-in. Visible in Installed Plug-ins page in Safari. */
+/* Description of the primary type supported by PDF pseudo plug-in. Visible in the Installed Plug-ins page in Safari. */
 "Portable Document Format" = "Portable Document Format";
 
+/* Description of the PostScript type supported by the PDF pseudo plug-in. Visible in the Installed Plug-ins page in Safari. */
+"PostScript" = "PostScript";
+
 /* Undo action name */
 "Raise Baseline (Undo action name)" = "Raise Baseline";
 

Modified: trunk/Source/WebCore/WebCore.exp.in (136264 => 136265)


--- trunk/Source/WebCore/WebCore.exp.in	2012-11-30 21:21:45 UTC (rev 136264)
+++ trunk/Source/WebCore/WebCore.exp.in	2012-11-30 21:24:56 UTC (rev 136265)
@@ -1685,6 +1685,7 @@
 __ZN7WebCore32applicationIsAOLInstantMessengerEv
 __ZN7WebCore32contextMenuItemTagInspectElementEv
 __ZN7WebCore32contextMenuItemTagSmartCopyPasteEv
+__ZN7WebCore33postScriptDocumentTypeDescriptionEv
 __ZN7WebCore33contextMenuItemTagTextReplacementEv
 __ZN7WebCore33setDefaultThreadViolationBehaviorENS_23ThreadViolationBehaviorENS_20ThreadViolationRoundE
 __ZN7WebCore34contextMenuItemTagDefaultDirectionEv

Modified: trunk/Source/WebCore/platform/LocalizedStrings.cpp (136264 => 136265)


--- trunk/Source/WebCore/platform/LocalizedStrings.cpp	2012-11-30 21:21:45 UTC (rev 136264)
+++ trunk/Source/WebCore/platform/LocalizedStrings.cpp	2012-11-30 21:24:56 UTC (rev 136265)
@@ -721,15 +721,21 @@
 String builtInPDFPluginName()
 {
     // Also exposed to DOM.
-    return WEB_UI_STRING("WebKit built-in PDF", "Pseudo plug-in name, visible in Installed Plug-ins page in Safari.");
+    return WEB_UI_STRING("WebKit built-in PDF", "Pseudo plug-in name, visible in the Installed Plug-ins page in Safari.");
 }
 
 String pdfDocumentTypeDescription()
 {
     // Also exposed to DOM.
-    return WEB_UI_STRING("Portable Document Format", "Description of the (only) type supported by PDF pseudo plug-in. Visible in Installed Plug-ins page in Safari.");
+    return WEB_UI_STRING("Portable Document Format", "Description of the primary type supported by the PDF pseudo plug-in. Visible in the Installed Plug-ins page in Safari.");
 }
 
+String postScriptDocumentTypeDescription()
+{
+    // Also exposed to DOM.
+    return WEB_UI_STRING("PostScript", "Description of the PostScript type supported by the PDF pseudo plug-in. Visible in the Installed Plug-ins page in Safari.");
+}
+
 String keygenMenuItem512()
 {
     return WEB_UI_STRING("512 (Low Grade)", "Menu item title for KEYGEN pop-up menu");

Modified: trunk/Source/WebCore/platform/LocalizedStrings.h (136264 => 136265)


--- trunk/Source/WebCore/platform/LocalizedStrings.h	2012-11-30 21:21:45 UTC (rev 136264)
+++ trunk/Source/WebCore/platform/LocalizedStrings.h	2012-11-30 21:24:56 UTC (rev 136265)
@@ -219,6 +219,7 @@
 #if PLATFORM(MAC)
     String builtInPDFPluginName();
     String pdfDocumentTypeDescription();
+    String postScriptDocumentTypeDescription();
     String keygenMenuItem512();
     String keygenMenuItem1024();
     String keygenMenuItem2048();

Modified: trunk/Source/WebKit2/ChangeLog (136264 => 136265)


--- trunk/Source/WebKit2/ChangeLog	2012-11-30 21:21:45 UTC (rev 136264)
+++ trunk/Source/WebKit2/ChangeLog	2012-11-30 21:24:56 UTC (rev 136265)
@@ -1,5 +1,30 @@
 2012-11-30  Tim Horton  <[email protected]>
 
+        (Simple)PDFPlugin: Support conversion of PostScript documents
+        https://bugs.webkit.org/show_bug.cgi?id=103289
+        <rdar://problem/10235708>
+
+        Reviewed by Dan Bernstein.
+
+        SimplePDFPlugin (and PDFPlugin) should support converting PostScript files
+        to PDF before handing them off to their respective backends.
+
+        As PDFPlugin inherits from SimplePDFPlugin, it gets the new functionality automatically.
+
+        * WebProcess/Plugins/PDF/SimplePDFPlugin.h: Add convertPostScriptDataIfNeeded(), and m_isPostScript.
+        * WebProcess/Plugins/PDF/SimplePDFPlugin.mm:
+        (WebKit::SimplePDFPlugin::pluginInfo): SimplePDFPlugin should claim to support PDF and PostScript.
+        (WebKit::convertPostScriptDataSourceToPDF): PS->PDF conversion code, copied from PDFViewController (which I intend to remove).
+        (WebKit::SimplePDFPlugin::convertPostScriptDataIfNeeded): Check if the loaded data represents a PS file; if so, convert it.
+        (WebKit::SimplePDFPlugin::streamDidReceiveResponse): Check if the loaded data is of MIME type application/postscript, and store that in m_isPostScript.
+        (WebKit::SimplePDFPlugin::streamDidFinishLoading): Call convertPostScriptDataIfNeeded when we finish loading.
+        (WebKit::SimplePDFPlugin::manualStreamDidReceiveResponse): Ditto from streamDidReceiveResponse.
+        (WebKit::SimplePDFPlugin::manualStreamDidFinishLoading): Ditto from streamDidFinishLoading.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::createPlugin): Use (Simple)PDFPlugin for PostScript files too.
+
+2012-11-30  Tim Horton  <[email protected]>
+
         PDFPlugin: "Show Definition" context menu item should be implemented
         https://bugs.webkit.org/show_bug.cgi?id=103389
         <rdar://problem/12710751>

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.h (136264 => 136265)


--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.h	2012-11-30 21:21:45 UTC (rev 136264)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.h	2012-11-30 21:24:56 UTC (rev 136265)
@@ -180,6 +180,8 @@
     JSObjectRef makeJSPDFDoc(JSContextRef);
     static JSValueRef jsPDFDocPrint(JSContextRef, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
 
+    void convertPostScriptDataIfNeeded();
+
     WebCore::IntSize m_size;
 
     WebCore::KURL m_sourceURL;
@@ -195,6 +197,8 @@
     RefPtr<WebCore::Scrollbar> m_verticalScrollbar;
 
     WebFrame* m_frame;
+
+    bool m_isPostScript;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.mm (136264 => 136265)


--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.mm	2012-11-30 21:21:45 UTC (rev 136264)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.mm	2012-11-30 21:24:56 UTC (rev 136265)
@@ -54,6 +54,8 @@
 using namespace WebCore;
 using namespace std;
 
+static const char* postScriptMIMEType = "application/postscript";
+
 static void appendValuesInPDFNameSubtreeToVector(CGPDFDictionaryRef subtree, Vector<CGPDFObjectRef>& values)
 {
     CGPDFArrayRef names;
@@ -163,6 +165,7 @@
 
 SimplePDFPlugin::SimplePDFPlugin(WebFrame* frame)
     : m_frame(frame)
+    , m_isPostScript(false)
 {
 }
 
@@ -175,12 +178,18 @@
     PluginInfo info;
     info.name = builtInPDFPluginName();
 
-    MimeClassInfo mimeClassInfo;
-    mimeClassInfo.type = "application/pdf";
-    mimeClassInfo.desc = pdfDocumentTypeDescription();
-    mimeClassInfo.extensions.append("pdf");
+    MimeClassInfo pdfMimeClassInfo;
+    pdfMimeClassInfo.type = "application/pdf";
+    pdfMimeClassInfo.desc = pdfDocumentTypeDescription();
+    pdfMimeClassInfo.extensions.append("pdf");
+    info.mimes.append(pdfMimeClassInfo);
 
-    info.mimes.append(mimeClassInfo);
+    MimeClassInfo postScriptMimeClassInfo;
+    postScriptMimeClassInfo.type = postScriptMIMEType;
+    postScriptMimeClassInfo.desc = postScriptDocumentTypeDescription();
+    postScriptMimeClassInfo.extensions.append("ps");
+    info.mimes.append(postScriptMimeClassInfo);
+
     return info;
 }
 
@@ -343,6 +352,22 @@
     return JSObjectMake(ctx, jsPDFDocClass, this);
 }
 
+static RetainPtr<CFMutableDataRef> convertPostScriptDataToPDF(RetainPtr<CFDataRef> postScriptData)
+{
+    // Convert PostScript to PDF using the Quartz 2D API.
+    // http://developer.apple.com/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_ps_convert/chapter_16_section_1.html
+
+    CGPSConverterCallbacks callbacks = { 0, 0, 0, 0, 0, 0, 0, 0 };
+    RetainPtr<CGPSConverterRef> converter = adoptCF(CGPSConverterCreate(0, &callbacks, 0));
+    RetainPtr<CGDataProviderRef> provider = adoptCF(CGDataProviderCreateWithCFData(postScriptData.get()));
+    RetainPtr<CFMutableDataRef> pdfData = adoptCF(CFDataCreateMutable(kCFAllocatorDefault, 0));
+    RetainPtr<CGDataConsumerRef> consumer = adoptCF(CGDataConsumerCreateWithCFData(pdfData.get()));
+
+    CGPSConverterConvert(converter.get(), provider.get(), consumer.get(), 0);
+
+    return pdfData;
+}
+
 void SimplePDFPlugin::pdfDocumentDidLoad()
 {
     addArchiveResource();
@@ -581,11 +606,23 @@
     ASSERT_NOT_REACHED();
 }
 
-void SimplePDFPlugin::streamDidReceiveResponse(uint64_t streamID, const KURL&, uint32_t, uint32_t, const String&, const String&, const String& suggestedFilename)
+void SimplePDFPlugin::convertPostScriptDataIfNeeded()
 {
+    if (!m_isPostScript)
+        return;
+
+    m_suggestedFilename = String(m_suggestedFilename + ".pdf");
+    m_data = convertPostScriptDataToPDF(m_data);
+}
+
+void SimplePDFPlugin::streamDidReceiveResponse(uint64_t streamID, const KURL&, uint32_t, uint32_t, const String& mimeType, const String&, const String& suggestedFilename)
+{
     ASSERT_UNUSED(streamID, streamID == pdfDocumentRequestID);
 
     m_suggestedFilename = suggestedFilename;
+
+    if (equalIgnoringCase(mimeType, postScriptMIMEType))
+        m_isPostScript = true;
 }
                                            
 void SimplePDFPlugin::streamDidReceiveData(uint64_t streamID, const char* bytes, int length)
@@ -602,6 +639,7 @@
 {
     ASSERT_UNUSED(streamID, streamID == pdfDocumentRequestID);
 
+    convertPostScriptDataIfNeeded();
     pdfDocumentDidLoad();
 }
 
@@ -615,6 +653,9 @@
 void SimplePDFPlugin::manualStreamDidReceiveResponse(const KURL& responseURL, uint32_t streamLength,  uint32_t lastModifiedTime, const String& mimeType, const String& headers, const String& suggestedFilename)
 {
     m_suggestedFilename = suggestedFilename;
+
+    if (equalIgnoringCase(mimeType, postScriptMIMEType))
+        m_isPostScript = true;
 }
 
 void SimplePDFPlugin::manualStreamDidReceiveData(const char* bytes, int length)
@@ -627,6 +668,7 @@
 
 void SimplePDFPlugin::manualStreamDidFinishLoading()
 {
+    convertPostScriptDataIfNeeded();
     pdfDocumentDidLoad();
 }
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (136264 => 136265)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-11-30 21:21:45 UTC (rev 136264)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-11-30 21:24:56 UTC (rev 136265)
@@ -521,8 +521,9 @@
 
     if (pluginPath.isNull()) {
 #if PLATFORM(MAC)
-        if (parameters.mimeType == "application/pdf"
-            || (parameters.mimeType.isEmpty() && parameters.url.path().lower().endsWith(".pdf"))) {
+        String path = parameters.url.path();
+        if ((parameters.mimeType == "application/pdf" || parameters.mimeType == "application/postscript")
+            || (parameters.mimeType.isEmpty() && (path.endsWith(".pdf", false) || path.endsWith(".ps", false)))) {
 #if ENABLE(PDFKIT_PLUGIN)
             if (pdfPluginEnabled())
                 return PDFPlugin::create(frame);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to