OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/clipboard/clipboard_mac.h" | 5 #include "ui/base/clipboard/clipboard_mac.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
14 #import "base/mac/scoped_nsexception_enabler.h" | |
15 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
16 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
17 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
18 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
19 #include "skia/ext/skia_utils_mac.h" | 18 #include "skia/ext/skia_utils_mac.h" |
20 #import "third_party/mozilla/NSPasteboard+Utils.h" | 19 #import "third_party/mozilla/NSPasteboard+Utils.h" |
21 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
22 #include "ui/base/clipboard/custom_data_helper.h" | 21 #include "ui/base/clipboard/custom_data_helper.h" |
23 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
24 #include "ui/gfx/geometry/size.h" | 23 #include "ui/gfx/geometry/size.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 return ReadData(GetRtfFormatType(), result); | 299 return ReadData(GetRtfFormatType(), result); |
301 } | 300 } |
302 | 301 |
303 SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { | 302 SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { |
304 DCHECK(CalledOnValidThread()); | 303 DCHECK(CalledOnValidThread()); |
305 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 304 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
306 | 305 |
307 // If the pasteboard's image data is not to its liking, the guts of NSImage | 306 // If the pasteboard's image data is not to its liking, the guts of NSImage |
308 // may throw, and that exception will leak. Prevent a crash in that case; | 307 // may throw, and that exception will leak. Prevent a crash in that case; |
309 // a blank image is better. | 308 // a blank image is better. |
310 base::scoped_nsobject<NSImage> image(base::mac::RunBlockIgnoringExceptions(^{ | 309 base::scoped_nsobject<NSImage> image; |
311 return [[NSImage alloc] initWithPasteboard:GetPasteboard()]; | 310 @try { |
312 })); | 311 image.reset([[NSImage alloc] initWithPasteboard:GetPasteboard()]); |
| 312 } @catch (id exception) { |
| 313 } |
| 314 |
313 SkBitmap bitmap; | 315 SkBitmap bitmap; |
314 if (image.get()) { | 316 if (image.get()) { |
315 bitmap = gfx::NSImageToSkBitmapWithColorSpace( | 317 bitmap = gfx::NSImageToSkBitmapWithColorSpace( |
316 image.get(), /*is_opaque=*/ false, base::mac::GetSystemColorSpace()); | 318 image.get(), /*is_opaque=*/ false, base::mac::GetSystemColorSpace()); |
317 } | 319 } |
318 return bitmap; | 320 return bitmap; |
319 } | 321 } |
320 | 322 |
321 void ClipboardMac::ReadCustomData(ClipboardType clipboard_type, | 323 void ClipboardMac::ReadCustomData(ClipboardType clipboard_type, |
322 const base::string16& type, | 324 const base::string16& type, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 // Write an extra flavor that signifies WebKit was the last to modify the | 450 // Write an extra flavor that signifies WebKit was the last to modify the |
449 // pasteboard. This flavor has no data. | 451 // pasteboard. This flavor has no data. |
450 void ClipboardMac::WriteWebSmartPaste() { | 452 void ClipboardMac::WriteWebSmartPaste() { |
451 NSPasteboard* pb = GetPasteboard(); | 453 NSPasteboard* pb = GetPasteboard(); |
452 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); | 454 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); |
453 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; | 455 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; |
454 [pb setData:nil forType:format]; | 456 [pb setData:nil forType:format]; |
455 } | 457 } |
456 | 458 |
457 } // namespace ui | 459 } // namespace ui |
OLD | NEW |