Title: [257390] trunk/Source/WebKit
Revision
257390
Author
[email protected]
Date
2020-02-25 16:20:56 -0800 (Tue, 25 Feb 2020)

Log Message

PDFPlugin: 'Open in Preview' and 'Save' don't work for blobs
https://bugs.webkit.org/show_bug.cgi?id=208221
<rdar://problem/22676176>

Reviewed by Alex Christensen.

* WebProcess/Plugins/PDF/PDFPlugin.h:
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::convertPostScriptDataIfNeeded):
(WebKit::PDFPlugin::setSuggestedFilename):
(WebKit::PDFPlugin::streamDidReceiveResponse):
(WebKit::PDFPlugin::manualStreamDidReceiveResponse):
Ensure that PDFPlugin's suggestedFilename always has a .pdf extension.
The UI process already requires this, and enforces it, causing operations
that use the suggestedFilename to fail if it does not have a .pdf extension.
However, in the case of a blob-loaded PDF, we get just the name "Unknown".
Slap the extension on there, and all is well!

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (257389 => 257390)


--- trunk/Source/WebKit/ChangeLog	2020-02-26 00:20:21 UTC (rev 257389)
+++ trunk/Source/WebKit/ChangeLog	2020-02-26 00:20:56 UTC (rev 257390)
@@ -1,3 +1,23 @@
+2020-02-25  Tim Horton  <[email protected]>
+
+        PDFPlugin: 'Open in Preview' and 'Save' don't work for blobs
+        https://bugs.webkit.org/show_bug.cgi?id=208221
+        <rdar://problem/22676176>
+
+        Reviewed by Alex Christensen.
+
+        * WebProcess/Plugins/PDF/PDFPlugin.h:
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::convertPostScriptDataIfNeeded):
+        (WebKit::PDFPlugin::setSuggestedFilename):
+        (WebKit::PDFPlugin::streamDidReceiveResponse):
+        (WebKit::PDFPlugin::manualStreamDidReceiveResponse):
+        Ensure that PDFPlugin's suggestedFilename always has a .pdf extension.
+        The UI process already requires this, and enforces it, causing operations
+        that use the suggestedFilename to fail if it does not have a .pdf extension.
+        However, in the case of a blob-loaded PDF, we get just the name "Unknown".
+        Slap the extension on there, and all is well!
+
 2020-02-25  Chris Dumez  <[email protected]>
 
         Make sure a client cannot cause a whole DOM tree to get leaked by simply holding on to a WKBundleNodeHandle

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h (257389 => 257390)


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h	2020-02-26 00:20:21 UTC (rev 257389)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h	2020-02-26 00:20:56 UTC (rev 257390)
@@ -259,6 +259,8 @@
 
     void convertPostScriptDataIfNeeded();
 
+    void setSuggestedFilename(const String&);
+
     // Regular plug-ins don't need access to view, but we add scrollbars to embedding FrameView for proper event handling.
     PluginView* pluginView();
     const PluginView* pluginView() const;

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm (257389 => 257390)


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2020-02-26 00:20:21 UTC (rev 257389)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2020-02-26 00:20:56 UTC (rev 257390)
@@ -68,6 +68,7 @@
 #import <WebCore/HTMLFormElement.h>
 #import <WebCore/HTMLPlugInElement.h>
 #import <WebCore/LegacyNSPasteboardTypes.h>
+#import <WebCore/LoaderNSURLExtras.h>
 #import <WebCore/LocalDefaultSystemAppearance.h>
 #import <WebCore/LocalizedStrings.h>
 #import <WebCore/MouseEvent.h>
@@ -937,7 +938,6 @@
     if (!m_isPostScript)
         return;
 
-    m_suggestedFilename = String(m_suggestedFilename + ".pdf");
     m_data = PDFDocumentImage::convertPostScriptDataToPDF(WTFMove(m_data));
 }
 
@@ -972,12 +972,23 @@
         [m_pdfLayerController setURLFragment:pdfURLFragment];
     }
 }
+
+void PDFPlugin::setSuggestedFilename(const String& suggestedFilename)
+{
+    m_suggestedFilename = suggestedFilename;
+
+    if (m_suggestedFilename.isEmpty())
+        m_suggestedFilename = suggestedFilenameWithMIMEType(nil, "application/pdf");
+
+    if (!m_suggestedFilename.endsWithIgnoringASCIICase(".pdf"))
+        m_suggestedFilename.append(".pdf");
+}
     
 void PDFPlugin::streamDidReceiveResponse(uint64_t streamID, const URL&, uint32_t, uint32_t, const String& mimeType, const String&, const String& suggestedFilename)
 {
     ASSERT_UNUSED(streamID, streamID == pdfDocumentRequestID);
 
-    m_suggestedFilename = suggestedFilename;
+    setSuggestedFilename(suggestedFilename);
 
     if (equalIgnoringASCIICase(mimeType, postScriptMIMEType))
         m_isPostScript = true;
@@ -1010,7 +1021,7 @@
 
 void PDFPlugin::manualStreamDidReceiveResponse(const URL& responseURL, uint32_t streamLength,  uint32_t lastModifiedTime, const String& mimeType, const String& headers, const String& suggestedFilename)
 {
-    m_suggestedFilename = suggestedFilename;
+    setSuggestedFilename(suggestedFilename);
 
     if (equalIgnoringASCIICase(mimeType, postScriptMIMEType))
         m_isPostScript = true;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to