OLD | NEW |
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 <Cocoa/Cocoa.h> | 5 #include <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "chrome/utility/importer/safari_importer.h" | 7 #include "chrome/utility/importer/safari_importer.h" |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 if ((items & importer::PASSWORDS) && !cancelled()) { | 71 if ((items & importer::PASSWORDS) && !cancelled()) { |
72 bridge_->NotifyItemStarted(importer::PASSWORDS); | 72 bridge_->NotifyItemStarted(importer::PASSWORDS); |
73 ImportPasswords(); | 73 ImportPasswords(); |
74 bridge_->NotifyItemEnded(importer::PASSWORDS); | 74 bridge_->NotifyItemEnded(importer::PASSWORDS); |
75 } | 75 } |
76 bridge_->NotifyEnded(); | 76 bridge_->NotifyEnded(); |
77 } | 77 } |
78 | 78 |
79 void SafariImporter::ImportBookmarks() { | 79 void SafariImporter::ImportBookmarks() { |
80 string16 toolbar_name = | 80 base::string16 toolbar_name = |
81 bridge_->GetLocalizedString(IDS_BOOKMARK_BAR_FOLDER_NAME); | 81 bridge_->GetLocalizedString(IDS_BOOKMARK_BAR_FOLDER_NAME); |
82 std::vector<ImportedBookmarkEntry> bookmarks; | 82 std::vector<ImportedBookmarkEntry> bookmarks; |
83 ParseBookmarks(toolbar_name, &bookmarks); | 83 ParseBookmarks(toolbar_name, &bookmarks); |
84 | 84 |
85 // Write bookmarks into profile. | 85 // Write bookmarks into profile. |
86 if (!bookmarks.empty() && !cancelled()) { | 86 if (!bookmarks.empty() && !cancelled()) { |
87 const string16& first_folder_name = | 87 const base::string16& first_folder_name = |
88 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_SAFARI); | 88 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_SAFARI); |
89 bridge_->AddBookmarks(bookmarks, first_folder_name); | 89 bridge_->AddBookmarks(bookmarks, first_folder_name); |
90 } | 90 } |
91 | 91 |
92 // Import favicons. | 92 // Import favicons. |
93 sql::Connection db; | 93 sql::Connection db; |
94 if (!OpenDatabase(&db)) | 94 if (!OpenDatabase(&db)) |
95 return; | 95 return; |
96 | 96 |
97 FaviconMap favicon_map; | 97 FaviconMap favicon_map; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 continue; // Unable to decode. | 159 continue; // Unable to decode. |
160 | 160 |
161 usage.urls = i->second; | 161 usage.urls = i->second; |
162 favicons->push_back(usage); | 162 favicons->push_back(usage); |
163 } | 163 } |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 void SafariImporter::RecursiveReadBookmarksFolder( | 167 void SafariImporter::RecursiveReadBookmarksFolder( |
168 NSDictionary* bookmark_folder, | 168 NSDictionary* bookmark_folder, |
169 const std::vector<string16>& parent_path_elements, | 169 const std::vector<base::string16>& parent_path_elements, |
170 bool is_in_toolbar, | 170 bool is_in_toolbar, |
171 const string16& toolbar_name, | 171 const base::string16& toolbar_name, |
172 std::vector<ImportedBookmarkEntry>* out_bookmarks) { | 172 std::vector<ImportedBookmarkEntry>* out_bookmarks) { |
173 DCHECK(bookmark_folder); | 173 DCHECK(bookmark_folder); |
174 | 174 |
175 NSString* type = [bookmark_folder objectForKey:@"WebBookmarkType"]; | 175 NSString* type = [bookmark_folder objectForKey:@"WebBookmarkType"]; |
176 NSString* title = [bookmark_folder objectForKey:@"Title"]; | 176 NSString* title = [bookmark_folder objectForKey:@"Title"]; |
177 | 177 |
178 // Are we the dictionary that contains all other bookmarks? | 178 // Are we the dictionary that contains all other bookmarks? |
179 // We need to know this so we don't add it to the path. | 179 // We need to know this so we don't add it to the path. |
180 bool is_top_level_bookmarks_container = [bookmark_folder | 180 bool is_top_level_bookmarks_container = [bookmark_folder |
181 objectForKey:@"WebBookmarkFileVersion"] != nil; | 181 objectForKey:@"WebBookmarkFileVersion"] != nil; |
(...skipping 21 matching lines...) Expand all Loading... |
203 entry.creation_time = base::Time::Now(); | 203 entry.creation_time = base::Time::Now(); |
204 entry.title = base::SysNSStringToUTF16(title); | 204 entry.title = base::SysNSStringToUTF16(title); |
205 entry.path = parent_path_elements; | 205 entry.path = parent_path_elements; |
206 entry.in_toolbar = is_in_toolbar; | 206 entry.in_toolbar = is_in_toolbar; |
207 entry.is_folder = true; | 207 entry.is_folder = true; |
208 | 208 |
209 out_bookmarks->push_back(entry); | 209 out_bookmarks->push_back(entry); |
210 return; | 210 return; |
211 } | 211 } |
212 | 212 |
213 std::vector<string16> path_elements(parent_path_elements); | 213 std::vector<base::string16> path_elements(parent_path_elements); |
214 // Create a folder for the toolbar, but not for the bookmarks menu. | 214 // Create a folder for the toolbar, but not for the bookmarks menu. |
215 if (path_elements.empty() && [title isEqualToString:@"BookmarksBar"]) { | 215 if (path_elements.empty() && [title isEqualToString:@"BookmarksBar"]) { |
216 is_in_toolbar = true; | 216 is_in_toolbar = true; |
217 path_elements.push_back(toolbar_name); | 217 path_elements.push_back(toolbar_name); |
218 } else if (!is_top_level_bookmarks_container && | 218 } else if (!is_top_level_bookmarks_container && |
219 !(path_elements.empty() && | 219 !(path_elements.empty() && |
220 [title isEqualToString:@"BookmarksMenu"])) { | 220 [title isEqualToString:@"BookmarksMenu"])) { |
221 if (title) | 221 if (title) |
222 path_elements.push_back(base::SysNSStringToUTF16(title)); | 222 path_elements.push_back(base::SysNSStringToUTF16(title)); |
223 } | 223 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 entry.title = base::SysNSStringToUTF16(title); | 256 entry.title = base::SysNSStringToUTF16(title); |
257 entry.url = GURL(base::SysNSStringToUTF8(url)); | 257 entry.url = GURL(base::SysNSStringToUTF8(url)); |
258 entry.path = path_elements; | 258 entry.path = path_elements; |
259 entry.in_toolbar = is_in_toolbar; | 259 entry.in_toolbar = is_in_toolbar; |
260 | 260 |
261 out_bookmarks->push_back(entry); | 261 out_bookmarks->push_back(entry); |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 void SafariImporter::ParseBookmarks( | 265 void SafariImporter::ParseBookmarks( |
266 const string16& toolbar_name, | 266 const base::string16& toolbar_name, |
267 std::vector<ImportedBookmarkEntry>* bookmarks) { | 267 std::vector<ImportedBookmarkEntry>* bookmarks) { |
268 DCHECK(bookmarks); | 268 DCHECK(bookmarks); |
269 | 269 |
270 // Construct ~/Library/Safari/Bookmarks.plist path | 270 // Construct ~/Library/Safari/Bookmarks.plist path |
271 NSString* library_dir = [NSString | 271 NSString* library_dir = [NSString |
272 stringWithUTF8String:library_dir_.value().c_str()]; | 272 stringWithUTF8String:library_dir_.value().c_str()]; |
273 NSString* safari_dir = [library_dir | 273 NSString* safari_dir = [library_dir |
274 stringByAppendingPathComponent:@"Safari"]; | 274 stringByAppendingPathComponent:@"Safari"]; |
275 NSString* bookmarks_plist = [safari_dir | 275 NSString* bookmarks_plist = [safari_dir |
276 stringByAppendingPathComponent:@"Bookmarks.plist"]; | 276 stringByAppendingPathComponent:@"Bookmarks.plist"]; |
277 | 277 |
278 // Load the plist file. | 278 // Load the plist file. |
279 NSDictionary* bookmarks_dict = [NSDictionary | 279 NSDictionary* bookmarks_dict = [NSDictionary |
280 dictionaryWithContentsOfFile:bookmarks_plist]; | 280 dictionaryWithContentsOfFile:bookmarks_plist]; |
281 if (!bookmarks_dict) | 281 if (!bookmarks_dict) |
282 return; | 282 return; |
283 | 283 |
284 // Recursively read in bookmarks. | 284 // Recursively read in bookmarks. |
285 std::vector<string16> parent_path_elements; | 285 std::vector<base::string16> parent_path_elements; |
286 RecursiveReadBookmarksFolder(bookmarks_dict, parent_path_elements, false, | 286 RecursiveReadBookmarksFolder(bookmarks_dict, parent_path_elements, false, |
287 toolbar_name, bookmarks); | 287 toolbar_name, bookmarks); |
288 } | 288 } |
289 | 289 |
290 void SafariImporter::ImportPasswords() { | 290 void SafariImporter::ImportPasswords() { |
291 // Safari stores it's passwords in the Keychain, same as us so we don't need | 291 // Safari stores it's passwords in the Keychain, same as us so we don't need |
292 // to import them. | 292 // to import them. |
293 // Note: that we don't automatically pick them up, there is some logic around | 293 // Note: that we don't automatically pick them up, there is some logic around |
294 // the user needing to explicitly input his username in a page and blurring | 294 // the user needing to explicitly input his username in a page and blurring |
295 // the field before we pick it up, but the details of that are beyond the | 295 // the field before we pick it up, but the details of that are beyond the |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 if (!last_visit_str) | 369 if (!last_visit_str) |
370 continue; | 370 continue; |
371 | 371 |
372 // Convert Safari's last visit time to Unix Epoch time. | 372 // Convert Safari's last visit time to Unix Epoch time. |
373 double seconds_since_unix_epoch = HistoryTimeToEpochTime(last_visit_str); | 373 double seconds_since_unix_epoch = HistoryTimeToEpochTime(last_visit_str); |
374 row.last_visit = base::Time::FromDoubleT(seconds_since_unix_epoch); | 374 row.last_visit = base::Time::FromDoubleT(seconds_since_unix_epoch); |
375 | 375 |
376 history_items->push_back(row); | 376 history_items->push_back(row); |
377 } | 377 } |
378 } | 378 } |
OLD | NEW |