| 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/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 #include <stddef.h> |
| 9 #include <stdint.h> |
| 8 | 10 |
| 9 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 11 #include "components/bookmarks/browser/bookmark_node.h" | 13 #include "components/bookmarks/browser/bookmark_node.h" |
| 12 #include "ui/base/clipboard/clipboard.h" | 14 #include "ui/base/clipboard/clipboard.h" |
| 13 | 15 |
| 14 NSString* const kBookmarkDictionaryListPboardType = | 16 NSString* const kBookmarkDictionaryListPboardType = |
| 15 @"BookmarkDictionaryListPboardType"; | 17 @"BookmarkDictionaryListPboardType"; |
| 16 | 18 |
| 17 namespace bookmarks { | 19 namespace bookmarks { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 57 |
| 56 return meta_info_map; | 58 return meta_info_map; |
| 57 } | 59 } |
| 58 | 60 |
| 59 void ConvertPlistToElements(NSArray* input, | 61 void ConvertPlistToElements(NSArray* input, |
| 60 std::vector<BookmarkNodeData::Element>& elements) { | 62 std::vector<BookmarkNodeData::Element>& elements) { |
| 61 NSUInteger len = [input count]; | 63 NSUInteger len = [input count]; |
| 62 for (NSUInteger i = 0; i < len; ++i) { | 64 for (NSUInteger i = 0; i < len; ++i) { |
| 63 NSDictionary* pboardBookmark = [input objectAtIndex:i]; | 65 NSDictionary* pboardBookmark = [input objectAtIndex:i]; |
| 64 scoped_ptr<BookmarkNode> new_node(new BookmarkNode(GURL())); | 66 scoped_ptr<BookmarkNode> new_node(new BookmarkNode(GURL())); |
| 65 int64 node_id = | 67 int64_t node_id = |
| 66 [[pboardBookmark objectForKey:kChromiumBookmarkId] longLongValue]; | 68 [[pboardBookmark objectForKey:kChromiumBookmarkId] longLongValue]; |
| 67 new_node->set_id(node_id); | 69 new_node->set_id(node_id); |
| 68 | 70 |
| 69 NSDictionary* metaInfoDictionary = | 71 NSDictionary* metaInfoDictionary = |
| 70 [pboardBookmark objectForKey:kChromiumBookmarkMetaInfo]; | 72 [pboardBookmark objectForKey:kChromiumBookmarkMetaInfo]; |
| 71 if (metaInfoDictionary) | 73 if (metaInfoDictionary) |
| 72 new_node->SetMetaInfoMap(MetaInfoMapFromDictionary(metaInfoDictionary)); | 74 new_node->SetMetaInfoMap(MetaInfoMapFromDictionary(metaInfoDictionary)); |
| 73 | 75 |
| 74 BOOL is_folder = [[pboardBookmark objectForKey:kWebBookmarkType] | 76 BOOL is_folder = [[pboardBookmark objectForKey:kWebBookmarkType] |
| 75 isEqualToString:kWebBookmarkTypeList]; | 77 isEqualToString:kWebBookmarkTypeList]; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 NSArray* GetPlistForBookmarkList( | 174 NSArray* GetPlistForBookmarkList( |
| 173 const std::vector<BookmarkNodeData::Element>& elements) { | 175 const std::vector<BookmarkNodeData::Element>& elements) { |
| 174 NSMutableArray* plist = [NSMutableArray array]; | 176 NSMutableArray* plist = [NSMutableArray array]; |
| 175 for (size_t i = 0; i < elements.size(); ++i) { | 177 for (size_t i = 0; i < elements.size(); ++i) { |
| 176 BookmarkNodeData::Element element = elements[i]; | 178 BookmarkNodeData::Element element = elements[i]; |
| 177 NSDictionary* metaInfoDictionary = | 179 NSDictionary* metaInfoDictionary = |
| 178 DictionaryFromBookmarkMetaInfo(element.meta_info_map); | 180 DictionaryFromBookmarkMetaInfo(element.meta_info_map); |
| 179 if (element.is_url) { | 181 if (element.is_url) { |
| 180 NSString* title = base::SysUTF16ToNSString(element.title); | 182 NSString* title = base::SysUTF16ToNSString(element.title); |
| 181 NSString* url = base::SysUTF8ToNSString(element.url.spec()); | 183 NSString* url = base::SysUTF8ToNSString(element.url.spec()); |
| 182 int64 elementId = element.id(); | 184 int64_t elementId = element.id(); |
| 183 NSNumber* idNum = [NSNumber numberWithLongLong:elementId]; | 185 NSNumber* idNum = [NSNumber numberWithLongLong:elementId]; |
| 184 NSDictionary* uriDictionary = [NSDictionary dictionaryWithObjectsAndKeys: | 186 NSDictionary* uriDictionary = [NSDictionary dictionaryWithObjectsAndKeys: |
| 185 title, @"title", nil]; | 187 title, @"title", nil]; |
| 186 NSDictionary* object = [NSDictionary dictionaryWithObjectsAndKeys: | 188 NSDictionary* object = [NSDictionary dictionaryWithObjectsAndKeys: |
| 187 uriDictionary, @"URIDictionary", | 189 uriDictionary, @"URIDictionary", |
| 188 url, @"URLString", | 190 url, @"URLString", |
| 189 kWebBookmarkTypeLeaf, kWebBookmarkType, | 191 kWebBookmarkTypeLeaf, kWebBookmarkType, |
| 190 idNum, kChromiumBookmarkId, | 192 idNum, kChromiumBookmarkId, |
| 191 metaInfoDictionary, kChromiumBookmarkMetaInfo, | 193 metaInfoDictionary, kChromiumBookmarkMetaInfo, |
| 192 nil]; | 194 nil]; |
| 193 [plist addObject:object]; | 195 [plist addObject:object]; |
| 194 } else { | 196 } else { |
| 195 NSString* title = base::SysUTF16ToNSString(element.title); | 197 NSString* title = base::SysUTF16ToNSString(element.title); |
| 196 NSArray* children = GetPlistForBookmarkList(element.children); | 198 NSArray* children = GetPlistForBookmarkList(element.children); |
| 197 int64 elementId = element.id(); | 199 int64_t elementId = element.id(); |
| 198 NSNumber* idNum = [NSNumber numberWithLongLong:elementId]; | 200 NSNumber* idNum = [NSNumber numberWithLongLong:elementId]; |
| 199 NSDictionary* object = [NSDictionary dictionaryWithObjectsAndKeys: | 201 NSDictionary* object = [NSDictionary dictionaryWithObjectsAndKeys: |
| 200 title, @"Title", | 202 title, @"Title", |
| 201 children, @"Children", | 203 children, @"Children", |
| 202 kWebBookmarkTypeList, kWebBookmarkType, | 204 kWebBookmarkTypeList, kWebBookmarkType, |
| 203 idNum, kChromiumBookmarkId, | 205 idNum, kChromiumBookmarkId, |
| 204 metaInfoDictionary, kChromiumBookmarkMetaInfo, | 206 metaInfoDictionary, kChromiumBookmarkMetaInfo, |
| 205 nil]; | 207 nil]; |
| 206 [plist addObject:object]; | 208 [plist addObject:object]; |
| 207 } | 209 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 328 |
| 327 NSArray* availableTypes = | 329 NSArray* availableTypes = |
| 328 [NSArray arrayWithObjects:kBookmarkDictionaryListPboardType, | 330 [NSArray arrayWithObjects:kBookmarkDictionaryListPboardType, |
| 329 kCrWebURLsWithTitlesPboardType, | 331 kCrWebURLsWithTitlesPboardType, |
| 330 NSURLPboardType, | 332 NSURLPboardType, |
| 331 nil]; | 333 nil]; |
| 332 return [pb availableTypeFromArray:availableTypes] != nil; | 334 return [pb availableTypeFromArray:availableTypes] != nil; |
| 333 } | 335 } |
| 334 | 336 |
| 335 } // namespace bookmarks | 337 } // namespace bookmarks |
| OLD | NEW |