Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: ui/base/clipboard/clipboard_mac.mm

Issue 2227083003: Fix crash in ui::ClipboardMac::ReadAvailableTypes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from dcheng. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 21 matching lines...) Expand all
32 32
33 // Tells us if WebKit was the last to write to the pasteboard. There's no 33 // Tells us if WebKit was the last to write to the pasteboard. There's no
34 // actual data associated with this type. 34 // actual data associated with this type.
35 NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type"; 35 NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type";
36 36
37 // Pepper custom data format type. 37 // Pepper custom data format type.
38 NSString* const kPepperCustomDataPboardType = 38 NSString* const kPepperCustomDataPboardType =
39 @"org.chromium.pepper-custom-data"; 39 @"org.chromium.pepper-custom-data";
40 40
41 NSPasteboard* GetPasteboard() { 41 NSPasteboard* GetPasteboard() {
42 // The pasteboard should not be nil in a UI session, but this handy DCHECK 42 // The pasteboard can always be nil, since there is a finite amount of storage
43 // can help track down problems if someone tries using clipboard code outside 43 // that must be shared between all pasteboards.
44 // of a UI session.
45 NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; 44 NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
46 DCHECK(pasteboard);
47 return pasteboard; 45 return pasteboard;
48 } 46 }
49 47
50 } // namespace 48 } // namespace
51 49
52 // Clipboard::FormatType implementation. 50 // Clipboard::FormatType implementation.
53 Clipboard::FormatType::FormatType() : data_(nil) { 51 Clipboard::FormatType::FormatType() : data_(nil) {
54 } 52 }
55 53
56 Clipboard::FormatType::FormatType(NSString* native_format) 54 Clipboard::FormatType::FormatType(NSString* native_format)
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 std::vector<base::string16>* types, 218 std::vector<base::string16>* types,
221 bool* contains_filenames) const { 219 bool* contains_filenames) const {
222 DCHECK(CalledOnValidThread()); 220 DCHECK(CalledOnValidThread());
223 types->clear(); 221 types->clear();
224 if (IsFormatAvailable(Clipboard::GetPlainTextFormatType(), type)) 222 if (IsFormatAvailable(Clipboard::GetPlainTextFormatType(), type))
225 types->push_back(base::UTF8ToUTF16(kMimeTypeText)); 223 types->push_back(base::UTF8ToUTF16(kMimeTypeText));
226 if (IsFormatAvailable(Clipboard::GetHtmlFormatType(), type)) 224 if (IsFormatAvailable(Clipboard::GetHtmlFormatType(), type))
227 types->push_back(base::UTF8ToUTF16(kMimeTypeHTML)); 225 types->push_back(base::UTF8ToUTF16(kMimeTypeHTML));
228 if (IsFormatAvailable(Clipboard::GetRtfFormatType(), type)) 226 if (IsFormatAvailable(Clipboard::GetRtfFormatType(), type))
229 types->push_back(base::UTF8ToUTF16(kMimeTypeRTF)); 227 types->push_back(base::UTF8ToUTF16(kMimeTypeRTF));
230 if ([NSImage canInitWithPasteboard:GetPasteboard()]) 228
229 NSPasteboard* pb = GetPasteboard();
230 if (pb && [NSImage canInitWithPasteboard:pb])
231 types->push_back(base::UTF8ToUTF16(kMimeTypePNG)); 231 types->push_back(base::UTF8ToUTF16(kMimeTypePNG));
232 *contains_filenames = false; 232 *contains_filenames = false;
233 233
234 NSPasteboard* pb = GetPasteboard();
235 if ([[pb types] containsObject:kWebCustomDataPboardType]) { 234 if ([[pb types] containsObject:kWebCustomDataPboardType]) {
236 NSData* data = [pb dataForType:kWebCustomDataPboardType]; 235 NSData* data = [pb dataForType:kWebCustomDataPboardType];
237 if ([data length]) 236 if ([data length])
238 ReadCustomDataTypes([data bytes], [data length], types); 237 ReadCustomDataTypes([data bytes], [data length], types);
239 } 238 }
240 } 239 }
241 240
242 void ClipboardMac::ReadText(ClipboardType type, base::string16* result) const { 241 void ClipboardMac::ReadText(ClipboardType type, base::string16* result) const {
243 DCHECK(CalledOnValidThread()); 242 DCHECK(CalledOnValidThread());
244 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); 243 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // -[NSImage initWithPasteboard:] gets confused with copies of a single 312 // -[NSImage initWithPasteboard:] gets confused with copies of a single
314 // file from the Finder, so extract the path ourselves. 313 // file from the Finder, so extract the path ourselves.
315 // http://crbug.com/553686 314 // http://crbug.com/553686
316 NSArray* paths = [pb propertyListForType:NSFilenamesPboardType]; 315 NSArray* paths = [pb propertyListForType:NSFilenamesPboardType];
317 if ([paths count]) { 316 if ([paths count]) {
318 // If N number of files are selected from finder, choose the last one. 317 // If N number of files are selected from finder, choose the last one.
319 image.reset([[NSImage alloc] 318 image.reset([[NSImage alloc]
320 initWithContentsOfURL:[NSURL fileURLWithPath:[paths lastObject]]]); 319 initWithContentsOfURL:[NSURL fileURLWithPath:[paths lastObject]]]);
321 } 320 }
322 } else { 321 } else {
323 image.reset([[NSImage alloc] initWithPasteboard:pb]); 322 if (pb)
323 image.reset([[NSImage alloc] initWithPasteboard:pb]);
324 } 324 }
325 } @catch (id exception) { 325 } @catch (id exception) {
326 } 326 }
327 327
328 SkBitmap bitmap; 328 SkBitmap bitmap;
329 if (image.get()) { 329 if (image.get()) {
330 bitmap = skia::NSImageToSkBitmapWithColorSpace( 330 bitmap = skia::NSImageToSkBitmapWithColorSpace(
331 image.get(), /*is_opaque=*/ false, base::mac::GetSystemColorSpace()); 331 image.get(), /*is_opaque=*/ false, base::mac::GetSystemColorSpace());
332 } 332 }
333 return bitmap; 333 return bitmap;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 // Write an extra flavor that signifies WebKit was the last to modify the 455 // Write an extra flavor that signifies WebKit was the last to modify the
456 // pasteboard. This flavor has no data. 456 // pasteboard. This flavor has no data.
457 void ClipboardMac::WriteWebSmartPaste() { 457 void ClipboardMac::WriteWebSmartPaste() {
458 NSPasteboard* pb = GetPasteboard(); 458 NSPasteboard* pb = GetPasteboard();
459 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); 459 NSString* format = GetWebKitSmartPasteFormatType().ToNSString();
460 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; 460 [pb addTypes:[NSArray arrayWithObject:format] owner:nil];
461 [pb setData:nil forType:format]; 461 [pb setData:nil forType:format];
462 } 462 }
463 463
464 } // namespace ui 464 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698