Chromium Code Reviews| Index: ui/base/clipboard/clipboard_mac.mm |
| diff --git a/ui/base/clipboard/clipboard_mac.mm b/ui/base/clipboard/clipboard_mac.mm |
| index f3a4c434704ca60926ab0cce3d0cf378cd9f347b..1bef10eb0822a9f6832c7154c72e4d0db5529c87 100644 |
| --- a/ui/base/clipboard/clipboard_mac.mm |
| +++ b/ui/base/clipboard/clipboard_mac.mm |
| @@ -39,11 +39,9 @@ NSString* const kPepperCustomDataPboardType = |
| @"org.chromium.pepper-custom-data"; |
| NSPasteboard* GetPasteboard() { |
| - // The pasteboard should not be nil in a UI session, but this handy DCHECK |
| - // can help track down problems if someone tries using clipboard code outside |
| - // of a UI session. |
| + // The pasteboard can always be nil, since there is a finite amount of storage |
| + // that must be shared between all pasteboards. |
| NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; |
| - DCHECK(pasteboard); |
| return pasteboard; |
| } |
| @@ -227,11 +225,12 @@ void ClipboardMac::ReadAvailableTypes(ClipboardType type, |
| types->push_back(base::UTF8ToUTF16(kMimeTypeHTML)); |
| if (IsFormatAvailable(Clipboard::GetRtfFormatType(), type)) |
| types->push_back(base::UTF8ToUTF16(kMimeTypeRTF)); |
| - if ([NSImage canInitWithPasteboard:GetPasteboard()]) |
| + |
| + NSPasteboard* pb = GetPasteboard(); |
| + if (pb && [NSImage canInitWithPasteboard:pb]) |
| types->push_back(base::UTF8ToUTF16(kMimeTypePNG)); |
| *contains_filenames = false; |
| - NSPasteboard* pb = GetPasteboard(); |
| if ([[pb types] containsObject:kWebCustomDataPboardType]) { |
| NSData* data = [pb dataForType:kWebCustomDataPboardType]; |
| if ([data length]) |
| @@ -320,7 +319,8 @@ SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { |
| initWithContentsOfURL:[NSURL fileURLWithPath:[paths lastObject]]]); |
| } |
| } else { |
| - image.reset([[NSImage alloc] initWithPasteboard:pb]); |
| + if (pb) |
| + image.reset([[NSImage alloc] initWithPasteboard:pb]); |
| } |
| } @catch (id exception) { |
| } |
| @@ -350,6 +350,8 @@ void ClipboardMac::ReadCustomData(ClipboardType clipboard_type, |
| void ClipboardMac::ReadBookmark(base::string16* title, std::string* url) const { |
| DCHECK(CalledOnValidThread()); |
| NSPasteboard* pb = GetPasteboard(); |
| + if (!pb) |
|
dcheng
2016/08/10 14:28:34
How come this one needs a null check too?
erikchen
2016/08/10 16:35:58
Unnecessary, removed.
|
| + return; |
| if (title) { |
| NSString* contents = ClipboardUtil::GetTitleFromPasteboardURL(pb); |