Index: ui/base/clipboard/clipboard_mac.mm |
diff --git a/ui/base/clipboard/clipboard_mac.mm b/ui/base/clipboard/clipboard_mac.mm |
index fcc4a3a662f02b6d5318a069904751a680a81aa3..ce4badae6549eafc0a405ed24be37f5eeaba58ae 100644 |
--- a/ui/base/clipboard/clipboard_mac.mm |
+++ b/ui/base/clipboard/clipboard_mac.mm |
@@ -324,17 +324,27 @@ SkBitmap ClipboardMac::ReadImage(ClipboardType type, NSPasteboard* pb) const { |
} @catch (id exception) { |
} |
- if (image.get()) { |
- if ([[image representations] count] == 1u) { |
- NSImageRep* rep = [[image representations] objectAtIndex:0]; |
+ if (!image) |
+ return SkBitmap(); |
+ if ([[image representations] count] == 0u) |
+ return SkBitmap(); |
+ |
+ // This logic prevents loss of pixels from retina images, where size != pixel |
+ // size. In an ideal world, the concept of "retina-ness" would be plumbed all |
+ // the way through to the web, but the clipboard API doesn't support the |
+ // additional metainformation. |
+ if ([[image representations] count] == 1u) { |
+ NSImageRep* rep = [[image representations] objectAtIndex:0]; |
+ NSInteger width = [rep pixelsWide]; |
+ NSInteger height = [rep pixelsHigh]; |
+ if (width != 0 && height != 0) { |
return skia::NSImageRepToSkBitmapWithColorSpace( |
- rep, NSMakeSize([rep pixelsWide], [rep pixelsHigh]), |
- /*is_opaque=*/false, base::mac::GetSystemColorSpace()); |
+ rep, NSMakeSize(width, height), /*is_opaque=*/false, |
+ base::mac::GetSystemColorSpace()); |
} |
- return skia::NSImageToSkBitmapWithColorSpace( |
- image.get(), /*is_opaque=*/false, base::mac::GetSystemColorSpace()); |
} |
- return SkBitmap(); |
+ return skia::NSImageToSkBitmapWithColorSpace( |
+ image.get(), /*is_opaque=*/false, base::mac::GetSystemColorSpace()); |
} |
SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { |