OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/bookmarks/core/browser/bookmark_pasteboard_helper_mac.h" | 5 #include "components/bookmarks/browser/bookmark_pasteboard_helper_mac.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "components/bookmarks/core/browser/bookmark_node.h" | 11 #include "components/bookmarks/browser/bookmark_node.h" |
12 #include "ui/base/clipboard/clipboard.h" | 12 #include "ui/base/clipboard/clipboard.h" |
13 | 13 |
14 NSString* const kBookmarkDictionaryListPboardType = | 14 NSString* const kBookmarkDictionaryListPboardType = |
15 @"BookmarkDictionaryListPboardType"; | 15 @"BookmarkDictionaryListPboardType"; |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // An unofficial standard pasteboard title type to be provided alongside the | 19 // An unofficial standard pasteboard title type to be provided alongside the |
20 // |NSURLPboardType|. | 20 // |NSURLPboardType|. |
21 NSString* const kNSURLTitlePboardType = @"public.url-name"; | 21 NSString* const kNSURLTitlePboardType = @"public.url-name"; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 NSArray* urlsArr = [bookmarkPairs objectAtIndex:0]; | 94 NSArray* urlsArr = [bookmarkPairs objectAtIndex:0]; |
95 NSArray* titlesArr = [bookmarkPairs objectAtIndex:1]; | 95 NSArray* titlesArr = [bookmarkPairs objectAtIndex:1]; |
96 if ([urlsArr count] < 1) | 96 if ([urlsArr count] < 1) |
97 return false; | 97 return false; |
98 if ([urlsArr count] != [titlesArr count]) | 98 if ([urlsArr count] != [titlesArr count]) |
99 return false; | 99 return false; |
100 | 100 |
101 NSUInteger len = [titlesArr count]; | 101 NSUInteger len = [titlesArr count]; |
102 for (NSUInteger i = 0; i < len; ++i) { | 102 for (NSUInteger i = 0; i < len; ++i) { |
103 base::string16 title = base::SysNSStringToUTF16([titlesArr objectAtIndex:i])
; | 103 base::string16 title = |
| 104 base::SysNSStringToUTF16([titlesArr objectAtIndex:i]); |
104 std::string url = base::SysNSStringToUTF8([urlsArr objectAtIndex:i]); | 105 std::string url = base::SysNSStringToUTF8([urlsArr objectAtIndex:i]); |
105 if (!url.empty()) { | 106 if (!url.empty()) { |
106 BookmarkNodeData::Element element; | 107 BookmarkNodeData::Element element; |
107 element.is_url = true; | 108 element.is_url = true; |
108 element.url = GURL(url); | 109 element.url = GURL(url); |
109 element.title = title; | 110 element.title = title; |
110 elements.push_back(element); | 111 elements.push_back(element); |
111 } | 112 } |
112 } | 113 } |
113 return true; | 114 return true; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 bool PasteboardContainsBookmarks(ui::ClipboardType type) { | 278 bool PasteboardContainsBookmarks(ui::ClipboardType type) { |
278 NSPasteboard* pb = PasteboardFromType(type); | 279 NSPasteboard* pb = PasteboardFromType(type); |
279 | 280 |
280 NSArray* availableTypes = | 281 NSArray* availableTypes = |
281 [NSArray arrayWithObjects:kBookmarkDictionaryListPboardType, | 282 [NSArray arrayWithObjects:kBookmarkDictionaryListPboardType, |
282 kCrWebURLsWithTitlesPboardType, | 283 kCrWebURLsWithTitlesPboardType, |
283 NSURLPboardType, | 284 NSURLPboardType, |
284 nil]; | 285 nil]; |
285 return [pb availableTypeFromArray:availableTypes] != nil; | 286 return [pb availableTypeFromArray:availableTypes] != nil; |
286 } | 287 } |
OLD | NEW |