| Index: ui/base/clipboard/clipboard_util_mac.mm
|
| diff --git a/ui/base/clipboard/clipboard_util_mac.mm b/ui/base/clipboard/clipboard_util_mac.mm
|
| index cff597880748b3020018bb223f8d27951c5d7cef..590ebf871d1578399520c8a60d4393483cec4266 100644
|
| --- a/ui/base/clipboard/clipboard_util_mac.mm
|
| +++ b/ui/base/clipboard/clipboard_util_mac.mm
|
| @@ -78,6 +78,20 @@ base::scoped_nsobject<NSPasteboardItem> ClipboardUtil::PasteboardItemFromUrl(
|
| }
|
|
|
| // static
|
| +base::scoped_nsobject<NSPasteboardItem> ClipboardUtil::PasteboardItemFromUrls(
|
| + NSArray* urls,
|
| + NSArray* titles) {
|
| + base::scoped_nsobject<NSPasteboardItem> item([[NSPasteboardItem alloc] init]);
|
| +
|
| + // Set Safari's URL + title arrays Pboard type.
|
| + NSArray* urlsAndTitles = @[ urls, titles ];
|
| + [item setPropertyList:urlsAndTitles
|
| + forType:UTIFromPboardType(kWebURLsWithTitlesPboardType)];
|
| +
|
| + return item;
|
| +}
|
| +
|
| +// static
|
| base::scoped_nsobject<NSPasteboardItem> ClipboardUtil::PasteboardItemFromString(
|
| NSString* string) {
|
| base::scoped_nsobject<NSPasteboardItem> item([[NSPasteboardItem alloc] init]);
|
| @@ -97,4 +111,69 @@ NSString* ClipboardUtil::GetURLFromPasteboardURL(NSPasteboard* pboard) {
|
| [pboard stringForType:UTIFromPboardType(kCorePasteboardFlavorType_url)];
|
| }
|
|
|
| +// static
|
| +NSString* ClipboardUtil::UTIForPasteboardType(NSString* type) {
|
| + return UTIFromPboardType(type);
|
| +}
|
| +
|
| +// static
|
| +NSString* ClipboardUtil::UTIForWebURLsAndTitles() {
|
| + return UTIFromPboardType(kWebURLsWithTitlesPboardType);
|
| +}
|
| +
|
| +// static
|
| +void ClipboardUtil::AddDataToPasteboard(NSPasteboard* pboard,
|
| + NSPasteboardItem* item) {
|
| + NSSet* oldTypes = [NSSet setWithArray:[pboard types]];
|
| + NSMutableSet* newTypes = [NSMutableSet setWithArray:[item types]];
|
| + [newTypes minusSet:oldTypes];
|
| +
|
| + [pboard addTypes:[newTypes allObjects] owner:nil];
|
| + for (NSString* type in newTypes) {
|
| + // Technically, the object associated with |type| might be an NSString or a
|
| + // property list. It doesn't matter though, since the type gets pulled from
|
| + // and shoved into an NSDictionary.
|
| + [pboard setData:[item dataForType:type] forType:type];
|
| + }
|
| +}
|
| +
|
| +// static
|
| +bool ClipboardUtil::URLsAndTitlesFromPasteboard(NSPasteboard* pboard,
|
| + NSArray** urls,
|
| + NSArray** titles) {
|
| + NSArray* bookmarkPairs = base::mac::ObjCCast<NSArray>([pboard
|
| + propertyListForType:UTIFromPboardType(kWebURLsWithTitlesPboardType)]);
|
| + if (!bookmarkPairs)
|
| + return false;
|
| +
|
| + if ([bookmarkPairs count] != 2)
|
| + return false;
|
| +
|
| + NSArray* urlsArr =
|
| + base::mac::ObjCCast<NSArray>([bookmarkPairs objectAtIndex:0]);
|
| + NSArray* titlesArr =
|
| + base::mac::ObjCCast<NSArray>([bookmarkPairs objectAtIndex:1]);
|
| +
|
| + if (!urlsArr || !titlesArr)
|
| + return false;
|
| + if ([urlsArr count] < 1)
|
| + return false;
|
| + if ([urlsArr count] != [titlesArr count])
|
| + return false;
|
| +
|
| + for (id obj in urlsArr) {
|
| + if (![obj isKindOfClass:[NSString class]])
|
| + return false;
|
| + }
|
| +
|
| + for (id obj in titlesArr) {
|
| + if (![obj isKindOfClass:[NSString class]])
|
| + return false;
|
| + }
|
| +
|
| + *urls = urlsArr;
|
| + *titles = titlesArr;
|
| + return true;
|
| +}
|
| +
|
| } // namespace ui
|
|
|