Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_util_mac.h" | 5 #include "ui/base/clipboard/clipboard_util_mac.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/mac/scoped_cftyperef.h" | 8 #include "base/mac/scoped_cftyperef.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 NSString* const kWebURLsWithTitlesPboardType = @"WebURLsWithTitlesPboardType"; | 11 NSString* const kWebURLsWithTitlesPboardType = @"WebURLsWithTitlesPboardType"; |
| 12 NSString* const kCorePasteboardFlavorType_url = | 12 NSString* const kCorePasteboardFlavorType_url = |
| 13 @"CorePasteboardFlavorType 0x75726C20"; // 'url ' url | 13 @"CorePasteboardFlavorType 0x75726C20"; // 'url ' url |
| 14 NSString* const kCorePasteboardFlavorType_urln = | 14 NSString* const kCorePasteboardFlavorType_urln = |
| 15 @"CorePasteboardFlavorType 0x75726C6E"; // 'urln' title | 15 @"CorePasteboardFlavorType 0x75726C6E"; // 'urln' title |
| 16 | 16 |
| 17 // It's much more convenient to return an NSString than a | 17 // It's much more convenient to return an NSString than a |
| 18 // base::ScopedCFTypeRef<CFStringRef>, since the methods on NSPasteboardItem | 18 // base::ScopedCFTypeRef<CFStringRef>, since the methods on NSPasteboardItem |
| 19 // require an NSString*. | 19 // require an NSString*. |
| 20 NSString* UTIFromPboardType(NSString* type) { | 20 NSString* UTIFromPboardType(NSString* type) { |
| 21 return [base::mac::CFToNSCast(UTTypeCreatePreferredIdentifierForTag( | 21 return [base::mac::CFToNSCast(UTTypeCreatePreferredIdentifierForTag( |
| 22 kUTTagClassNSPboardType, base::mac::NSToCFCast(type), kUTTypeData)) | 22 kUTTagClassNSPboardType, base::mac::NSToCFCast(type), kUTTypeData)) |
| 23 autorelease]; | 23 autorelease]; |
| 24 } | 24 } |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 namespace ui { | 27 namespace ui { |
| 28 | 28 |
| 29 UniquePasteboard::UniquePasteboard() | |
| 30 : pasteboard_([[NSPasteboard pasteboardWithUniqueName] retain]) {} | |
| 31 | |
| 32 UniquePasteboard::~UniquePasteboard() { | |
| 33 [pasteboard_ releaseGlobally]; | |
|
Avi (use Gerrit)
2016/04/01 18:21:01
OMG
Yes, the docs imply this, but this isn't at a
| |
| 34 } | |
| 35 | |
| 29 // static | 36 // static |
| 30 base::scoped_nsobject<NSPasteboardItem> ClipboardUtil::PasteboardItemFromUrl( | 37 base::scoped_nsobject<NSPasteboardItem> ClipboardUtil::PasteboardItemFromUrl( |
| 31 NSString* urlString, | 38 NSString* urlString, |
| 32 NSString* title) { | 39 NSString* title) { |
| 33 DCHECK(urlString); | 40 DCHECK(urlString); |
| 34 if (!title) | 41 if (!title) |
| 35 title = urlString; | 42 title = urlString; |
| 36 | 43 |
| 37 base::scoped_nsobject<NSPasteboardItem> item([[NSPasteboardItem alloc] init]); | 44 base::scoped_nsobject<NSPasteboardItem> item([[NSPasteboardItem alloc] init]); |
| 38 | 45 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 64 | 71 |
| 65 [item setData:[urlString dataUsingEncoding:NSUTF8StringEncoding] | 72 [item setData:[urlString dataUsingEncoding:NSUTF8StringEncoding] |
| 66 forType:UTIFromPboardType(kCorePasteboardFlavorType_url)]; | 73 forType:UTIFromPboardType(kCorePasteboardFlavorType_url)]; |
| 67 | 74 |
| 68 [item setData:[title dataUsingEncoding:NSUTF8StringEncoding] | 75 [item setData:[title dataUsingEncoding:NSUTF8StringEncoding] |
| 69 forType:UTIFromPboardType(kCorePasteboardFlavorType_urln)]; | 76 forType:UTIFromPboardType(kCorePasteboardFlavorType_urln)]; |
| 70 return item; | 77 return item; |
| 71 } | 78 } |
| 72 | 79 |
| 73 } // namespace ui | 80 } // namespace ui |
| OLD | NEW |