Bug 111956 - PDFPlugin: Return PDFKit's data instead of the original resource data for save/etc.
Summary: PDFPlugin: Return PDFKit's data instead of the original resource data for sav...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: PDF (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tim Horton
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2013-03-10 23:20 PDT by Tim Horton
Modified: 2013-03-11 22:12 PDT (History)
3 users (show)

See Also:


Attachments
patch (7.96 KB, patch)
2013-03-10 23:25 PDT, Tim Horton
webkit-ews: commit-queue-
Details | Formatted Diff | Diff
patch (7.98 KB, patch)
2013-03-11 00:15 PDT, Tim Horton
ap: review+
ap: commit-queue-
Details | Formatted Diff | Diff
patch (17.21 KB, patch)
2013-03-11 14:59 PDT, Tim Horton
no flags Details | Formatted Diff | Diff
appease stylebot (17.21 KB, patch)
2013-03-11 15:17 PDT, Tim Horton
ap: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Horton 2013-03-10 23:20:22 PDT
<rdar://problem/13352282>
Comment 1 Tim Horton 2013-03-10 23:25:14 PDT
Created attachment 192407 [details]
patch
Comment 2 Early Warning System Bot 2013-03-10 23:36:54 PDT
Comment on attachment 192407 [details]
patch

Attachment 192407 [details] did not pass qt-wk2-ews (qt):
Output: http://webkit-commit-queue.appspot.com/results/17149011
Comment 3 EFL EWS Bot 2013-03-11 00:02:16 PDT
Comment on attachment 192407 [details]
patch

Attachment 192407 [details] did not pass efl-ews (efl):
Output: http://webkit-commit-queue.appspot.com/results/17134079
Comment 4 Tim Horton 2013-03-11 00:15:43 PDT
Created attachment 192411 [details]
patch
Comment 5 Alexey Proskuryakov 2013-03-11 10:09:06 PDT
Comment on attachment 192411 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=192411&action=review

Looks fine overall, and the comments should be easily addressable.

> Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h:251
> -    virtual bool getResourceData(const unsigned char*& /* bytes */, unsigned& /* length */) const OVERRIDE { return false; }
> +    virtual PassRefPtr<WebCore::SharedBuffer> getResourceData() const OVERRIDE { return WebCore::SharedBuffer::create(); }

I think that returning 0 would be more idiomatic than returning an empty buffer.

It probably doesn't match too much here, but PassRefPtr<WebCore::SharedBuffer>() is a little faster than returning 0.

> Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.mm:-679
> -    if (m_data && m_pdfDocument) {
> -        bytes = CFDataGetBytePtr(m_data.get());
> -        length = CFDataGetLength(m_data.get());

Do we still have a reason to preserve m_data?

> Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.mm:680
> +    NSData* pdfData = [m_pdfDocument.get() dataRepresentation];

Misplaced star.

> Source/WebKit2/WebProcess/Plugins/Plugin.h:34
> +#include <WebCore/SharedBuffer.h>

Is this #include actually needed?

> Source/WebKit2/WebProcess/Plugins/Plugin.h:267
> -    virtual bool getResourceData(const unsigned char*& bytes, unsigned& length) const = 0;
> +    virtual PassRefPtr<WebCore::SharedBuffer> getResourceData() const = 0;

We normally use "get" prefix with functions that return result in a reference, like this one used to do. Also, there is nothing in the name that allows for the proposed behavior - it doesn't say "ForSaving", for example.

Did you check other call sites to confirm that it's OK to return mutated PDF data? I see that there is only one call site changed in the patch, but I didn't check what happens in UI process.

> Source/WebKit2/WebProcess/Plugins/PluginProxy.h:136
> +    virtual PassRefPtr<WebCore::SharedBuffer> getResourceData() const OVERRIDE { return WebCore::SharedBuffer::create(); }

Here as well, I'd return a null pointer.

> Source/WebKit2/WebProcess/Plugins/PluginView.h:104
> -    bool getResourceData(const unsigned char*& bytes, unsigned& length) const;
> +    virtual PassRefPtr<WebCore::SharedBuffer> getResourceData() const;

Unsure why this this function is virtual now.
Comment 6 Tim Horton 2013-03-11 13:20:07 PDT
(In reply to comment #5)
> (From update of attachment 192411 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=192411&action=review
> 
> Looks fine overall, and the comments should be easily addressable.
> 
> > Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h:251
> > -    virtual bool getResourceData(const unsigned char*& /* bytes */, unsigned& /* length */) const OVERRIDE { return false; }
> > +    virtual PassRefPtr<WebCore::SharedBuffer> getResourceData() const OVERRIDE { return WebCore::SharedBuffer::create(); }
> 
> I think that returning 0 would be more idiomatic than returning an empty buffer.
> 
> It probably doesn't match too much here, but PassRefPtr<WebCore::SharedBuffer>() is a little faster than returning 0.
> 
> > Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.mm:-679
> > -    if (m_data && m_pdfDocument) {
> > -        bytes = CFDataGetBytePtr(m_data.get());
> > -        length = CFDataGetLength(m_data.get());
> 
> Do we still have a reason to preserve m_data?

Not ... really. We construct it piecemeal, so we need to have it while loading, but once we create our PDFDocument we could throw it away.

This brought up a good point, though, download and open-in-preview should use the mutated data too.

> > Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.mm:680
> > +    NSData* pdfData = [m_pdfDocument.get() dataRepresentation];
> 
> Misplaced star.
> 
> > Source/WebKit2/WebProcess/Plugins/Plugin.h:34
> > +#include <WebCore/SharedBuffer.h>
> 
> Is this #include actually needed?

I think so, I'll check.

> > Source/WebKit2/WebProcess/Plugins/Plugin.h:267
> > -    virtual bool getResourceData(const unsigned char*& bytes, unsigned& length) const = 0;
> > +    virtual PassRefPtr<WebCore::SharedBuffer> getResourceData() const = 0;
> 
> We normally use "get" prefix with functions that return result in a reference, like this one used to do. Also, there is nothing in the name that allows for the proposed behavior - it doesn't say "ForSaving", for example.

liveResourceData()? (it's not necessarily just for saving)

> Did you check other call sites to confirm that it's OK to return mutated PDF data? I see that there is only one call site changed in the patch, but I didn't check what happens in UI process.

I added getResourceData, so it shouldn't be a problem.

> > Source/WebKit2/WebProcess/Plugins/PluginProxy.h:136
> > +    virtual PassRefPtr<WebCore::SharedBuffer> getResourceData() const OVERRIDE { return WebCore::SharedBuffer::create(); }
> 
> Here as well, I'd return a null pointer.
> 
> > Source/WebKit2/WebProcess/Plugins/PluginView.h:104
> > -    bool getResourceData(const unsigned char*& bytes, unsigned& length) const;
> > +    virtual PassRefPtr<WebCore::SharedBuffer> getResourceData() const;
> 
> Unsure why this this function is virtual now.

Copy-paste-o.
Comment 7 Alexey Proskuryakov 2013-03-11 13:37:49 PDT
> > Is this #include actually needed?
>
> I think so, I'll check.

A forward declaration is sufficient for a type in RefPtr or OwnPtr, as long as the object itself is not accessed. Most of the time, this means that constructors and destructors should not be inline, which is a good idea for polymorphic classes anyway.
Comment 8 Tim Horton 2013-03-11 14:59:44 PDT
Created attachment 192568 [details]
patch
Comment 9 WebKit Review Bot 2013-03-11 15:01:14 PDT
Attachment 192568 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebKit2/ChangeLog', u'Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp', u'Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h', u'Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm', u'Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginAnnotation.h', u'Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginAnnotation.mm', u'Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm', u'Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm', u'Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.h', u'Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.mm', u'Source/WebKit2/WebProcess/Plugins/Plugin.h', u'Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp', u'Source/WebKit2/WebProcess/Plugins/PluginProxy.h', u'Source/WebKit2/WebProcess/Plugins/PluginView.cpp', u'Source/WebKit2/WebProcess/Plugins/PluginView.h', u'Source/WebKit2/WebProcess/WebPage/WebPage.cpp']" exit_code: 1
Source/WebKit2/ChangeLog:35:  Need whitespace between colon and description  [changelog/filechangedescriptionwhitespace] [5]
Total errors found: 1 in 16 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 10 Tim Horton 2013-03-11 15:17:45 PDT
Created attachment 192572 [details]
appease stylebot
Comment 11 Alexey Proskuryakov 2013-03-11 15:51:52 PDT
Comment on attachment 192572 [details]
appease stylebot

View in context: https://bugs.webkit.org/attachment.cgi?id=192572&action=review

> Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.h:75
> +    RetainPtr<NSData> liveData() const;
> +    RetainPtr<NSData> rawData() const { return (NSData *)m_data.get(); }

Looks like returning a pointer should work for both.

> Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.mm:689
> +    if (!m_pdfDocument)
> +        return 0;

Is this check necessary?

> Source/WebKit2/WebProcess/Plugins/PluginView.cpp:909
> -        return false;
> +        return PassRefPtr<WebCore::SharedBuffer>();

My advice was probably not that good - the unimportant win in performance is not worth it.
Comment 12 Tim Horton 2013-03-11 22:12:43 PDT
http://trac.webkit.org/changeset/145477