Title: [145477] trunk/Source/WebKit2
Revision
145477
Author
[email protected]
Date
2013-03-11 22:10:03 -0700 (Mon, 11 Mar 2013)

Log Message

PDFPlugin: Return PDFKit's data instead of the original resource data for save/etc.
https://bugs.webkit.org/show_bug.cgi?id=111956
<rdar://problem/13352282>

Reviewed by Alexey Proskuryakov.

If we return the original resource data, we lose changes made to annotations.

* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::pdfDocumentDidLoad): Adopt the renamed rawData().
(WebKit::PDFPlugin::saveToPDF): Use liveData so that "Save to PDF" persists changes to annotations.
(WebKit::PDFPlugin::openWithNativeApplication): Use liveData so that "Open With [native application]" persists changes to annotations.

* WebProcess/Plugins/PDF/PDFPluginAnnotation.h:
* WebProcess/Plugins/PDF/PDFPluginAnnotation.mm:
(WebKit::PDFPluginAnnotation::commit): Added, inform PDFPlugin that we're mutating the document.
* WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm:
(WebKit::PDFPluginChoiceAnnotation::commit): Let PDFPluginAnnotation do what it needs to inform PDFPlugin that we're going to mutate the document.
* WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm:
(WebKit::PDFPluginTextAnnotation::commit): Let PDFPluginAnnotation do what it needs to inform PDFPlugin that we're going to mutate the document.

* WebProcess/Plugins/PDF/SimplePDFPlugin.h:
(WebKit::SimplePDFPlugin::didMutatePDFDocument): Added.
(WebKit::SimplePDFPlugin::liveData): Added.
(WebKit::SimplePDFPlugin::rawData): Renamed from data(). Return NSData for consistency.
(WebKit::SimplePDFPlugin::pdfDocumentWasMutated): Added.
* WebProcess/Plugins/PDF/SimplePDFPlugin.mm:
(WebKit::SimplePDFPlugin::liveData): Return PDFKit's data if the user has mutated the
document, otherwise the raw data. This way, PDFs that PDFKit can't process will still
be downloadable as long as the user doesn't interact with annotations.
(WebKit::SimplePDFPlugin::liveResourceData): Return a SharedData wrapping the PDFDocument's data.

* WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
* WebProcess/Plugins/Netscape/NetscapePlugin.h:
* WebProcess/Plugins/PDF/SimplePDFPlugin.h:
* WebProcess/Plugins/Plugin.h:
* WebProcess/Plugins/PluginProxy.h:
* WebProcess/Plugins/PluginView.cpp:
* WebProcess/Plugins/PluginView.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::getMainResourceDataOfFrame):
Use a SharedData instead of raw data for getResourceData, and rename it liveResourceData().

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (145476 => 145477)


--- trunk/Source/WebKit2/ChangeLog	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/ChangeLog	2013-03-12 05:10:03 UTC (rev 145477)
@@ -1,5 +1,50 @@
 2013-03-11  Tim Horton  <[email protected]>
 
+        PDFPlugin: Return PDFKit's data instead of the original resource data for save/etc.
+        https://bugs.webkit.org/show_bug.cgi?id=111956
+        <rdar://problem/13352282>
+
+        Reviewed by Alexey Proskuryakov.
+
+        If we return the original resource data, we lose changes made to annotations.
+
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::pdfDocumentDidLoad): Adopt the renamed rawData().
+        (WebKit::PDFPlugin::saveToPDF): Use liveData so that "Save to PDF" persists changes to annotations.
+        (WebKit::PDFPlugin::openWithNativeApplication): Use liveData so that "Open With [native application]" persists changes to annotations.
+
+        * WebProcess/Plugins/PDF/PDFPluginAnnotation.h:
+        * WebProcess/Plugins/PDF/PDFPluginAnnotation.mm:
+        (WebKit::PDFPluginAnnotation::commit): Added, inform PDFPlugin that we're mutating the document.
+        * WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm:
+        (WebKit::PDFPluginChoiceAnnotation::commit): Let PDFPluginAnnotation do what it needs to inform PDFPlugin that we're going to mutate the document.
+        * WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm:
+        (WebKit::PDFPluginTextAnnotation::commit): Let PDFPluginAnnotation do what it needs to inform PDFPlugin that we're going to mutate the document.
+
+        * WebProcess/Plugins/PDF/SimplePDFPlugin.h:
+        (WebKit::SimplePDFPlugin::didMutatePDFDocument): Added.
+        (WebKit::SimplePDFPlugin::liveData): Added.
+        (WebKit::SimplePDFPlugin::rawData): Renamed from data(). Return NSData for consistency.
+        (WebKit::SimplePDFPlugin::pdfDocumentWasMutated): Added.
+        * WebProcess/Plugins/PDF/SimplePDFPlugin.mm:
+        (WebKit::SimplePDFPlugin::liveData): Return PDFKit's data if the user has mutated the
+        document, otherwise the raw data. This way, PDFs that PDFKit can't process will still
+        be downloadable as long as the user doesn't interact with annotations.
+        (WebKit::SimplePDFPlugin::liveResourceData): Return a SharedData wrapping the PDFDocument's data.
+        
+        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
+        * WebProcess/Plugins/Netscape/NetscapePlugin.h:
+        * WebProcess/Plugins/PDF/SimplePDFPlugin.h:
+        * WebProcess/Plugins/Plugin.h:
+        * WebProcess/Plugins/PluginProxy.h:
+        * WebProcess/Plugins/PluginView.cpp:
+        * WebProcess/Plugins/PluginView.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::getMainResourceDataOfFrame):
+        Use a SharedData instead of raw data for getResourceData, and rename it liveResourceData().
+
+2013-03-11  Tim Horton  <[email protected]>
+
         [wk2] WebProcess and WebContentService don't respect system localization
         https://bugs.webkit.org/show_bug.cgi?id=112091
         <rdar://problem/13233590>

Modified: trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp	2013-03-12 05:10:03 UTC (rev 145477)
@@ -37,6 +37,7 @@
 #include <WebCore/HTTPHeaderMap.h>
 #include <WebCore/IntRect.h>
 #include <WebCore/KURL.h>
+#include <WebCore/SharedBuffer.h>
 #include <runtime/JSObject.h>
 #include <utility>
 #include <wtf/text/CString.h>
@@ -1050,6 +1051,11 @@
     return false;
 }
 
+PassRefPtr<WebCore::SharedBuffer> NetscapePlugin::liveResourceData() const
+{
+    return 0;
+}
+
 IntPoint NetscapePlugin::convertToRootView(const IntPoint& pointInPluginCoordinates) const
 {
     return m_pluginToRootViewTransform.mapPoint(pointInPluginCoordinates);

Modified: trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h	2013-03-12 05:10:03 UTC (rev 145477)
@@ -41,6 +41,7 @@
 namespace WebCore {
     class HTTPHeaderMap;
     class ProtectionSpace;
+    class SharedBuffer;
 }
 
 namespace WebKit {
@@ -248,7 +249,7 @@
     // converted (if the transformation matrix isn't invertible).
     bool convertFromRootView(const WebCore::IntPoint& pointInRootViewCoordinates, WebCore::IntPoint& pointInPluginCoordinates);
 
-    virtual bool getResourceData(const unsigned char*& /* bytes */, unsigned& /* length */) const OVERRIDE { return false; }
+    virtual PassRefPtr<WebCore::SharedBuffer> liveResourceData() const OVERRIDE;
 
     virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&) OVERRIDE { return false; }
 

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm	2013-03-12 05:10:03 UTC (rev 145477)
@@ -299,7 +299,7 @@
 {
     addArchiveResource();
     
-    RetainPtr<PDFDocument> document(AdoptNS, [[pdfDocumentClass() alloc] initWithData:(NSData *)data().get()]);
+    RetainPtr<PDFDocument> document(AdoptNS, [[pdfDocumentClass() alloc] initWithData:rawData()]);
 
     setPDFDocument(document);
 
@@ -779,8 +779,8 @@
     if (!pdfDocument())
         return;
 
-    RetainPtr<CFMutableDataRef> cfData = data();
-    webFrame()->page()->savePDFToFileInDownloadsFolder(suggestedFilename(), webFrame()->url(), CFDataGetBytePtr(cfData.get()), CFDataGetLength(cfData.get()));
+    NSData *data = ""
+    webFrame()->page()->savePDFToFileInDownloadsFolder(suggestedFilename(), webFrame()->url(), static_cast<const unsigned char *>([data bytes]), [data length]);
 }
 
 void PDFPlugin::openWithNativeApplication()
@@ -791,12 +791,12 @@
         if (!pdfDocument())
             return;
 
-        RetainPtr<CFMutableDataRef> cfData = data();
+        NSData *data = ""
 
         m_temporaryPDFUUID = WebCore::createCanonicalUUIDString();
         ASSERT(m_temporaryPDFUUID);
 
-        webFrame()->page()->savePDFToTemporaryFolderAndOpenWithNativeApplication(suggestedFilename(), webFrame()->url(), CFDataGetBytePtr(cfData.get()), CFDataGetLength(cfData.get()), m_temporaryPDFUUID);
+        webFrame()->page()->savePDFToTemporaryFolderAndOpenWithNativeApplication(suggestedFilename(), webFrame()->url(), static_cast<const unsigned char *>([data bytes]), [data length], m_temporaryPDFUUID);
         return;
     }
 

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginAnnotation.h (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginAnnotation.h	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginAnnotation.h	2013-03-12 05:10:03 UTC (rev 145477)
@@ -54,7 +54,7 @@
     PDFPlugin* plugin() const { return m_plugin; }
 
     virtual void updateGeometry();
-    virtual void commit() = 0;
+    virtual void commit();
 
     void attach(WebCore::Element*);
 

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginAnnotation.mm (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginAnnotation.mm	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginAnnotation.mm	2013-03-12 05:10:03 UTC (rev 145477)
@@ -80,6 +80,11 @@
     m_element->focus();
 }
 
+void PDFPluginAnnotation::commit()
+{
+    m_plugin->didMutatePDFDocument();
+}
+
 PDFPluginAnnotation::~PDFPluginAnnotation()
 {
     m_element->removeEventListener(eventNames().changeEvent, m_eventListener.get(), false);

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm	2013-03-12 05:10:03 UTC (rev 145477)
@@ -62,6 +62,8 @@
 void PDFPluginChoiceAnnotation::commit()
 {
     choiceAnnotation().stringValue = static_cast<HTMLSelectElement*>(element())->value();
+
+    PDFPluginAnnotation::commit();
 }
 
 PassRefPtr<Element> PDFPluginChoiceAnnotation::createAnnotationElement()

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm	2013-03-12 05:10:03 UTC (rev 145477)
@@ -127,6 +127,8 @@
         textAnnotation.stringValue = static_cast<HTMLTextAreaElement*>(element())->value();
     else
         textAnnotation.stringValue = static_cast<HTMLInputElement*>(element())->value();
+
+    PDFPluginAnnotation::commit();
 }
 
 void PDFPluginTextAnnotation::PDFPluginTextAnnotationEventListener::handleEvent(ScriptExecutionContext*, Event* event)

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


--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.h	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.h	2013-03-12 05:10:03 UTC (rev 145477)
@@ -53,6 +53,8 @@
     // In-process PDFViews don't support asynchronous initialization.
     virtual bool isBeingAsynchronouslyInitialized() const { return false; }
 
+    void didMutatePDFDocument() { m_pdfDocumentWasMutated = true; }
+
 protected:
     explicit SimplePDFPlugin(WebFrame*);
 
@@ -69,8 +71,11 @@
 
     const String& suggestedFilename() { return m_suggestedFilename; }
     
-    RetainPtr<CFMutableDataRef> data() const { return m_data; }
+    NSData *liveData() const;
+    NSData *rawData() const { return (NSData *)m_data.get(); }
 
+    bool pdfDocumentWasMutated() const { return m_pdfDocumentWasMutated; }
+
     // 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;
@@ -177,7 +182,7 @@
     virtual unsigned countFindMatches(const String&, WebCore::FindOptions, unsigned) OVERRIDE { return 0; }
     virtual bool findString(const String&, WebCore::FindOptions, unsigned) OVERRIDE { return false; }
 
-    virtual bool getResourceData(const unsigned char*& bytes, unsigned& length) const OVERRIDE;
+    virtual PassRefPtr<WebCore::SharedBuffer> liveResourceData() const OVERRIDE;
     virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&) OVERRIDE { return false; }
 
     virtual String getSelectionString() const OVERRIDE { return String(); }
@@ -210,6 +215,7 @@
     WebFrame* m_frame;
 
     bool m_isPostScript;
+    bool m_pdfDocumentWasMutated;
 };
 
 } // namespace WebKit

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


--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.mm	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.mm	2013-03-12 05:10:03 UTC (rev 145477)
@@ -166,6 +166,7 @@
 SimplePDFPlugin::SimplePDFPlugin(WebFrame* frame)
     : m_frame(frame)
     , m_isPostScript(false)
+    , m_pdfDocumentWasMutated(false)
 {
 }
 
@@ -672,16 +673,24 @@
     pdfDocumentDidLoad();
 }
 
-bool SimplePDFPlugin::getResourceData(const unsigned char*& bytes, unsigned& length) const
+NSData *SimplePDFPlugin::liveData() const
 {
-    if (m_data && m_pdfDocument) {
-        bytes = CFDataGetBytePtr(m_data.get());
-        length = CFDataGetLength(m_data.get());
+    // Save data straight from the resource instead of PDFKit if the document is
+    // untouched by the user, so that PDFs which PDFKit can't display will still be downloadable.
+    if (pdfDocumentWasMutated())
+        return [m_pdfDocument.get() dataRepresentation];
+    else
+        return rawData();
+}
 
-        return length;
-    }
+PassRefPtr<SharedBuffer> SimplePDFPlugin::liveResourceData() const
+{
+    NSData *pdfData = liveData();
 
-    return false;
+    if (!pdfData)
+        return 0;
+
+    return SharedBuffer::wrapNSData(pdfData);
 }
 
 void SimplePDFPlugin::manualStreamDidFail(bool)

Modified: trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h	2013-03-12 05:10:03 UTC (rev 145477)
@@ -55,6 +55,7 @@
     class IntRect;
     class IntSize;
     class Scrollbar;
+    class SharedBuffer;
 }
 
 namespace WebKit {
@@ -263,7 +264,7 @@
 
     virtual bool shouldAlwaysAutoStart() const { return false; }
 
-    virtual bool getResourceData(const unsigned char*& bytes, unsigned& length) const = 0;
+    virtual PassRefPtr<WebCore::SharedBuffer> liveResourceData() const = 0;
 
     virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&) = 0;
 

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp	2013-03-12 05:10:03 UTC (rev 145477)
@@ -44,6 +44,7 @@
 #include "WebProcessConnectionMessages.h"
 #include <WebCore/GraphicsContext.h>
 #include <WebCore/NotImplemented.h>
+#include <WebCore/SharedBuffer.h>
 
 using namespace WebCore;
 
@@ -671,6 +672,11 @@
     return m_pluginToRootViewTransform.mapPoint(point);
 }
 
+PassRefPtr<WebCore::SharedBuffer> PluginProxy::liveResourceData() const
+{
+    return 0;
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(PLUGIN_PROCESS)

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h	2013-03-12 05:10:03 UTC (rev 145477)
@@ -133,7 +133,7 @@
 
     virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint&) const OVERRIDE;
 
-    virtual bool getResourceData(const unsigned char*& /* bytes */, unsigned& /* length */) const OVERRIDE { return false; }
+    virtual PassRefPtr<WebCore::SharedBuffer> liveResourceData() const OVERRIDE;
     virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&) OVERRIDE { return false; }
 
     virtual String getSelectionString() const OVERRIDE { return String(); }

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp	2013-03-12 05:10:03 UTC (rev 145477)
@@ -903,12 +903,12 @@
     return m_plugin->shouldAllowNavigationFromDrags();
 }
 
-bool PluginView::getResourceData(const unsigned char*& bytes, unsigned& length) const
+PassRefPtr<SharedBuffer> PluginView::liveResourceData() const
 {
     if (!m_isInitialized || !m_plugin)
-        return false;
+        return 0;
 
-    return m_plugin->getResourceData(bytes, length);
+    return m_plugin->liveResourceData();
 }
 
 bool PluginView::performDictionaryLookupAtLocation(const WebCore::FloatPoint& point)

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h	2013-03-12 05:10:03 UTC (rev 145477)
@@ -101,7 +101,7 @@
 
     bool shouldAllowScripting();
 
-    bool getResourceData(const unsigned char*& bytes, unsigned& length) const;
+    PassRefPtr<WebCore::SharedBuffer> liveResourceData() const;
     bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&);
 
 private:

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (145476 => 145477)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2013-03-12 05:00:00 UTC (rev 145476)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2013-03-12 05:10:03 UTC (rev 145477)
@@ -2164,13 +2164,11 @@
     CoreIPC::DataReference dataReference;
 
     RefPtr<ResourceBuffer> buffer;
+    RefPtr<SharedBuffer> pdfResource;
     if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
         if (PluginView* pluginView = pluginViewForFrame(frame->coreFrame())) {
-            const unsigned char* bytes;
-            unsigned length;
-
-            if (pluginView->getResourceData(bytes, length))
-                dataReference = CoreIPC::DataReference(bytes, length);
+            if ((pdfResource = pluginView->liveResourceData()))
+                dataReference = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(pdfResource->data()), pdfResource->size());
         }
 
         if (dataReference.isEmpty()) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to