⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 136154 in webkit


Ignore:
Timestamp:
Nov 29, 2012, 1:05:19 PM (14 years ago)
Author:
timothy_horton@apple.com
Message:

PDFPlugin: Only plain text can be copied out of PDFs
​https://bugs.webkit.org/show_bug.cgi?id=103591
<rdar://problem/12555161>

Reviewed by Alexey Proskuryakov.

Enable rich data to be copied from PDFKit to the pasteboard.

  • WebProcess/Plugins/PDF/PDFPlugin.h:

(PDFPlugin): Add writeItemsToPasteboard.

  • WebProcess/Plugins/PDF/PDFPlugin.mm:

(-[WKPDFLayerControllerDelegate writeItemsToPasteboard:withTypes:]): Move implementation to PDFPlugin.
(WebKit::PDFPlugin::writeItemsToPasteboard): Don't round-trip through WebCore for pasteboard operations,
use WebContext directly. This provides a simple way to hand over a buffer for complex pasteboard types
(RTF, HTML, etc.). Use this interface for arbitrary non-plain-text pasteboard data that PDFKit hands us.

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r136152 r136154  
     12012-11-29  Tim Horton  <timothy_horton@apple.com>
     2
     3        PDFPlugin: Only plain text can be copied out of PDFs
     4        https://bugs.webkit.org/show_bug.cgi?id=103591
     5        <rdar://problem/12555161>
     6
     7        Reviewed by Alexey Proskuryakov.
     8
     9        Enable rich data to be copied from PDFKit to the pasteboard.
     10
     11        * WebProcess/Plugins/PDF/PDFPlugin.h:
     12        (PDFPlugin): Add writeItemsToPasteboard.
     13        * WebProcess/Plugins/PDF/PDFPlugin.mm:
     14        (-[WKPDFLayerControllerDelegate writeItemsToPasteboard:withTypes:]): Move implementation to PDFPlugin.
     15        (WebKit::PDFPlugin::writeItemsToPasteboard): Don't round-trip through WebCore for pasteboard operations,
     16        use WebContext directly. This provides a simple way to hand over a buffer for complex pasteboard types
     17        (RTF, HTML, etc.). Use this interface for arbitrary non-plain-text pasteboard data that PDFKit hands us.
     18
    1192012-11-29  Martin Robinson  <mrobinson@igalia.com>
    220
  • trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h

    r135925 r136154  
    6868    void clickedLink(NSURL *);
    6969    void saveToPDF();
     70    void writeItemsToPasteboard(NSArray *items, NSArray *types);
    7071
    7172private:
  • trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm

    r135958 r136154  
    3737#import "PluginView.h"
    3838#import "ShareableBitmap.h"
     39#import "WebContextMessages.h"
    3940#import "WebEvent.h"
    4041#import "WebEventConversion.h"
    4142#import "WebPage.h"
    4243#import "WebPageProxyMessages.h"
     44#import "WebProcess.h"
    4345#import <PDFKit/PDFKit.h>
    4446#import <QuartzCore/QuartzCore.h>
    … …  
    155157- (void)writeItemsToPasteboard:(NSArray *)items withTypes:(NSArray *)types
    156158{
    157     // FIXME: Handle types other than plain text.
    158 
    159     for (NSUInteger i = 0, count = items.count; i < count; ++i) {
    160         NSString *type = [types objectAtIndex:i];
    161         if ([type isEqualToString:NSStringPboardType] || [type isEqualToString:NSPasteboardTypeString]) {
    162             RetainPtr<NSString> plainTextString(AdoptNS, [[NSString alloc] initWithData:[items objectAtIndex:i] encoding:NSUTF8StringEncoding]);
    163             Pasteboard::generalPasteboard()->writePlainText(plainTextString.get(), Pasteboard::CannotSmartReplace);
    164         }
    165     }
     159    _pdfPlugin->writeItemsToPasteboard(items, types);
    166160}
    167161
    … …  
    766760}
    767761
     762void PDFPlugin::writeItemsToPasteboard(NSArray *items, NSArray *types)
     763{
     764    Vector<String> pasteboardTypes;
     765
     766    for (NSString *type in types)
     767        pasteboardTypes.append(type);
     768
     769    WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardTypes(NSGeneralPboard, pasteboardTypes), 0);
     770
     771    for (NSUInteger i = 0, count = items.count; i < count; ++i) {
     772        NSString *type = [types objectAtIndex:i];
     773        NSData *data = [items objectAtIndex:i];
     774
     775        if ([type isEqualToString:NSStringPboardType] || [type isEqualToString:NSPasteboardTypeString]) {
     776            RetainPtr<NSString> plainTextString(AdoptNS, [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
     777            WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardStringForType(NSGeneralPboard, type, plainTextString.get()), 0);
     778        } else {
     779            RefPtr<SharedBuffer> buffer = SharedBuffer::wrapNSData(data);
     780
     781            if (!buffer)
     782                continue;
     783
     784            SharedMemory::Handle handle;
     785            RefPtr<SharedMemory> sharedMemory = SharedMemory::create(buffer->size());
     786            memcpy(sharedMemory->data(), buffer->data(), buffer->size());
     787            sharedMemory->createHandle(handle, SharedMemory::ReadOnly);
     788            WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardBufferForType(NSGeneralPboard, type, handle, buffer->size()), 0);
     789        }
     790    }
     791
     792}
     793
    768794} // namespace WebKit
    769795
Note: See TracChangeset for help on using the changeset viewer.