Title: [136154] trunk/Source/WebKit2
- Revision
- 136154
- Author
- [email protected]
- Date
- 2012-11-29 13:05:19 -0800 (Thu, 29 Nov 2012)
Log 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.
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (136153 => 136154)
--- trunk/Source/WebKit2/ChangeLog 2012-11-29 20:44:03 UTC (rev 136153)
+++ trunk/Source/WebKit2/ChangeLog 2012-11-29 21:05:19 UTC (rev 136154)
@@ -1,3 +1,21 @@
+2012-11-29 Tim Horton <[email protected]>
+
+ 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.
+
2012-11-29 Martin Robinson <[email protected]>
[GTK] [WebKit2] Embed the HTTP authentication dialog into the WebView
Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h (136153 => 136154)
--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h 2012-11-29 20:44:03 UTC (rev 136153)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h 2012-11-29 21:05:19 UTC (rev 136154)
@@ -67,6 +67,7 @@
void clickedLink(NSURL *);
void saveToPDF();
+ void writeItemsToPasteboard(NSArray *items, NSArray *types);
private:
explicit PDFPlugin(WebFrame*);
Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm (136153 => 136154)
--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm 2012-11-29 20:44:03 UTC (rev 136153)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm 2012-11-29 21:05:19 UTC (rev 136154)
@@ -36,10 +36,12 @@
#import "PDFPluginAnnotation.h"
#import "PluginView.h"
#import "ShareableBitmap.h"
+#import "WebContextMessages.h"
#import "WebEvent.h"
#import "WebEventConversion.h"
#import "WebPage.h"
#import "WebPageProxyMessages.h"
+#import "WebProcess.h"
#import <PDFKit/PDFKit.h>
#import <QuartzCore/QuartzCore.h>
#import <WebCore/ArchiveResource.h>
@@ -154,15 +156,7 @@
- (void)writeItemsToPasteboard:(NSArray *)items withTypes:(NSArray *)types
{
- // FIXME: Handle types other than plain text.
-
- for (NSUInteger i = 0, count = items.count; i < count; ++i) {
- NSString *type = [types objectAtIndex:i];
- if ([type isEqualToString:NSStringPboardType] || [type isEqualToString:NSPasteboardTypeString]) {
- RetainPtr<NSString> plainTextString(AdoptNS, [[NSString alloc] initWithData:[items objectAtIndex:i] encoding:NSUTF8StringEncoding]);
- Pasteboard::generalPasteboard()->writePlainText(plainTextString.get(), Pasteboard::CannotSmartReplace);
- }
- }
+ _pdfPlugin->writeItemsToPasteboard(items, types);
}
- (void)showDefinitionForAttributedString:(NSAttributedString *)string atPoint:(CGPoint)point
@@ -765,6 +759,38 @@
webFrame()->page()->send(Messages::WebPageProxy::SavePDFToFileInDownloadsFolder(suggestedFilename(), webFrame()->url(), dataReference));
}
+void PDFPlugin::writeItemsToPasteboard(NSArray *items, NSArray *types)
+{
+ Vector<String> pasteboardTypes;
+
+ for (NSString *type in types)
+ pasteboardTypes.append(type);
+
+ WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardTypes(NSGeneralPboard, pasteboardTypes), 0);
+
+ for (NSUInteger i = 0, count = items.count; i < count; ++i) {
+ NSString *type = [types objectAtIndex:i];
+ NSData *data = "" objectAtIndex:i];
+
+ if ([type isEqualToString:NSStringPboardType] || [type isEqualToString:NSPasteboardTypeString]) {
+ RetainPtr<NSString> plainTextString(AdoptNS, [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
+ WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardStringForType(NSGeneralPboard, type, plainTextString.get()), 0);
+ } else {
+ RefPtr<SharedBuffer> buffer = SharedBuffer::wrapNSData(data);
+
+ if (!buffer)
+ continue;
+
+ SharedMemory::Handle handle;
+ RefPtr<SharedMemory> sharedMemory = SharedMemory::create(buffer->size());
+ memcpy(sharedMemory->data(), buffer->data(), buffer->size());
+ sharedMemory->createHandle(handle, SharedMemory::ReadOnly);
+ WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardBufferForType(NSGeneralPboard, type, handle, buffer->size()), 0);
+ }
+ }
+
+}
+
} // namespace WebKit
#endif // ENABLE(PDFKIT_PLUGIN)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes