summaryrefslogtreecommitdiff
path: root/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm')
-rw-r--r--Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm50
1 files changed, 41 insertions, 9 deletions
diff --git a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm
index f50fb8c0e..7417929bc 100644
--- a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm
+++ b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm
@@ -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 @@ static const char* annotationStyle =
- (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,44 @@ void PDFPlugin::saveToPDF()
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 = [items objectAtIndex:i];
+
+ // We don't expect the data for any items to be empty, but aren't completely sure.
+ // Avoid crashing in the SharedMemory constructor in release builds if we're wrong.
+ ASSERT(data.length);
+ if (!data.length)
+ continue;
+
+ 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)