From e344c910c5f4a1c88e3da37e074873a6360f3624 Mon Sep 17 00:00:00 2001 From: "jeremy@chromium.org" Date: Wed, 27 Jan 2010 10:24:59 +0000 Subject: POSIX: Use Shared Mem transport to copy images. Prior to this change images where copied inline in IPC messages on non-Windows platforms. Copying an oversized image would cause the IPC system to bork and crash the renderer. Changes in this CL: * All platforms use a unified mechanism to copy images using shared memory. * Introduced a new IPC message so the renderer can allocated a shared memory segment on OS X. * On OS X tried to keep as few copies of the image data in memory as possible. BUG=26822 TEST=1)On all platforms: navigate to a webpage, right click on an image and copy. Then try pasting into an image editor. 2)Repro steps in bug should no longer crash the Renderer on Mac/Linux Review URL: http://codereview.chromium.org/552129 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37247 0039d316-1c4b-4281-b951-d872f2087c98 --- app/clipboard/clipboard_mac.mm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'app/clipboard/clipboard_mac.mm') diff --git a/app/clipboard/clipboard_mac.mm b/app/clipboard/clipboard_mac.mm index ae3f1fe..1596eba 100644 --- a/app/clipboard/clipboard_mac.mm +++ b/app/clipboard/clipboard_mac.mm @@ -123,9 +123,14 @@ void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) { NULL, false, kCGRenderingIntentDefault)); + // Aggressively free storage since image buffers can potentially be very + // large. + data_provider.reset(); + data.reset(); scoped_nsobject bitmap( [[NSBitmapImageRep alloc] initWithCGImage:cgimage]); + cgimage.reset(); scoped_nsobject image([[NSImage alloc] init]); [image addRepresentation:bitmap]; @@ -134,7 +139,11 @@ void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) { // For now, spit out the image as a TIFF. NSPasteboard* pb = GetPasteboard(); [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil]; - [pb setData:[image TIFFRepresentation] forType:NSTIFFPboardType]; + NSData *tiff_data = [image TIFFRepresentation]; + LOG_IF(ERROR, tiff_data == NULL) << "Failed to allocate image for clipboard"; + if (tiff_data) { + [pb setData:tiff_data forType:NSTIFFPboardType]; + } } // Write an extra flavor that signifies WebKit was the last to modify the @@ -295,6 +304,12 @@ Clipboard::FormatType Clipboard::GetHtmlFormatType() { } // static +Clipboard::FormatType Clipboard::GetBitmapFormatType() { + static const std::string type = base::SysNSStringToUTF8(NSTIFFPboardType); + return type; +} + +// static Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { static const std::string type = base::SysNSStringToUTF8(kWebSmartPastePboardType); -- cgit v1.1