Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/utility/importer/firefox_importer.h" | 5 #include "chrome/utility/importer/firefox_importer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 // Loads the default bookmarks in the Firefox installed at |app_path|, | 43 // Loads the default bookmarks in the Firefox installed at |app_path|, |
| 44 // and stores their locations in |urls|. | 44 // and stores their locations in |urls|. |
| 45 void LoadDefaultBookmarks(const base::FilePath& app_path, | 45 void LoadDefaultBookmarks(const base::FilePath& app_path, |
| 46 std::set<GURL>* urls) { | 46 std::set<GURL>* urls) { |
| 47 base::FilePath file = app_path.AppendASCII("defaults") | 47 base::FilePath file = app_path.AppendASCII("defaults") |
| 48 .AppendASCII("profile") | 48 .AppendASCII("profile") |
| 49 .AppendASCII("bookmarks.html"); | 49 .AppendASCII("bookmarks.html"); |
| 50 urls->clear(); | 50 urls->clear(); |
| 51 | 51 |
| 52 std::vector<ImportedBookmarkEntry> bookmarks; | 52 std::vector<ImportedBookmarkEntry> bookmarks; |
| 53 std::vector<importer::SearchEngineInfo> search_engines; | |
| 53 bookmark_html_reader::ImportBookmarksFile(base::Callback<bool(void)>(), | 54 bookmark_html_reader::ImportBookmarksFile(base::Callback<bool(void)>(), |
| 54 base::Callback<bool(const GURL&)>(), | 55 base::Callback<bool(const GURL&)>(), |
| 55 file, | 56 file, |
| 56 &bookmarks, | 57 &bookmarks, |
| 58 &search_engines, | |
| 57 NULL); | 59 NULL); |
| 58 for (size_t i = 0; i < bookmarks.size(); ++i) | 60 for (size_t i = 0; i < bookmarks.size(); ++i) |
| 59 urls->insert(bookmarks[i].url); | 61 urls->insert(bookmarks[i].url); |
| 60 } | 62 } |
| 61 | 63 |
| 62 // Returns true if |url| has a valid scheme that we allow to import. We | 64 // Returns true if |url| has a valid scheme that we allow to import. We |
| 63 // filter out the URL with a unsupported scheme. | 65 // filter out the URL with a unsupported scheme. |
| 64 bool CanImportURL(const GURL& url) { | 66 bool CanImportURL(const GURL& url) { |
| 65 // The URL is not valid. | 67 // The URL is not valid. |
| 66 if (!url.is_valid()) | 68 if (!url.is_valid()) |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 | 220 |
| 219 BookmarkList list; | 221 BookmarkList list; |
| 220 GetTopBookmarkFolder(&db, toolbar_folder_id, &list); | 222 GetTopBookmarkFolder(&db, toolbar_folder_id, &list); |
| 221 GetTopBookmarkFolder(&db, menu_folder_id, &list); | 223 GetTopBookmarkFolder(&db, menu_folder_id, &list); |
| 222 GetTopBookmarkFolder(&db, unsorted_folder_id, &list); | 224 GetTopBookmarkFolder(&db, unsorted_folder_id, &list); |
| 223 size_t count = list.size(); | 225 size_t count = list.size(); |
| 224 for (size_t i = 0; i < count; ++i) | 226 for (size_t i = 0; i < count; ++i) |
| 225 GetWholeBookmarkFolder(&db, &list, i, NULL); | 227 GetWholeBookmarkFolder(&db, &list, i, NULL); |
| 226 | 228 |
| 227 std::vector<ImportedBookmarkEntry> bookmarks; | 229 std::vector<ImportedBookmarkEntry> bookmarks; |
| 228 std::vector<importer::URLKeywordInfo> url_keywords; | 230 std::vector<importer::SearchEngineInfo> search_engines; |
| 229 FaviconMap favicon_map; | 231 FaviconMap favicon_map; |
| 230 | 232 |
| 231 // TODO(jcampan): http://b/issue?id=1196285 we do not support POST based | 233 // TODO(jcampan): http://b/issue?id=1196285 we do not support POST based |
| 232 // keywords yet. We won't include them in the list. | 234 // keywords yet. We won't include them in the list. |
| 233 std::set<int> post_keyword_ids; | 235 std::set<int> post_keyword_ids; |
| 234 const char query[] = | 236 const char query[] = |
| 235 "SELECT b.id FROM moz_bookmarks b " | 237 "SELECT b.id FROM moz_bookmarks b " |
| 236 "INNER JOIN moz_items_annos ia ON ia.item_id = b.id " | 238 "INNER JOIN moz_items_annos ia ON ia.item_id = b.id " |
| 237 "INNER JOIN moz_anno_attributes aa ON ia.anno_attribute_id = aa.id " | 239 "INNER JOIN moz_anno_attributes aa ON ia.anno_attribute_id = aa.id " |
| 238 "WHERE aa.name = 'bookmarkProperties/POSTData'"; | 240 "WHERE aa.name = 'bookmarkProperties/POSTData'"; |
| 239 sql::Statement s(db.GetUniqueStatement(query)); | 241 sql::Statement s(db.GetUniqueStatement(query)); |
| 240 | 242 |
| 241 if (!s.is_valid()) | 243 if (!s.is_valid()) |
| 242 return; | 244 return; |
| 243 | 245 |
| 244 while (s.Step() && !cancelled()) | 246 while (s.Step() && !cancelled()) |
| 245 post_keyword_ids.insert(s.ColumnInt(0)); | 247 post_keyword_ids.insert(s.ColumnInt(0)); |
| 246 | 248 |
| 247 for (size_t i = 0; i < list.size(); ++i) { | 249 for (size_t i = 0; i < list.size(); ++i) { |
| 248 BookmarkItem* item = list[i]; | 250 BookmarkItem* item = list[i]; |
| 249 | 251 |
| 250 if (item->type == TYPE_FOLDER) { | 252 if (item->type != TYPE_BOOKMARK) { |
| 251 // Folders are added implicitly on adding children, so we only explicitly | 253 // Folders are added implicitly on adding children, so we only explicitly |
| 252 // add empty folders. | 254 // add empty folders. |
| 253 if (!item->empty_folder) | 255 if ((item->type != TYPE_FOLDER) || !item->empty_folder) |
| 254 continue; | 256 continue; |
| 255 } else if (item->type == TYPE_BOOKMARK) { | 257 } else if (!CanImportURL(item->url)) { |
|
Peter Kasting
2014/11/11 22:42:12
This will only convert invalid bookmark URLs to se
Tapu Ghose
2014/11/15 05:22:20
I think valid bookmark URLs are handled at line 32
Peter Kasting
2014/11/17 21:30:35
It's really confusing that we add things as search
Tapu Ghose
2014/12/07 02:49:54
Agreed.
| |
| 256 // Import only valid bookmarks | 258 importer::SearchEngineInfo search_engine_info; |
| 257 if (!CanImportURL(item->url)) | 259 // Import invalid bookmark's keyword as search engine, provided that the |
| 258 continue; | 260 // bookmark's url is a valid search engine url. |
| 259 } else { | 261 if (!item->keyword.empty() && |
|
Peter Kasting
2014/11/11 22:42:12
Shouldn't we be willing to import bookmarks with e
Tapu Ghose
2014/11/15 05:22:20
You are right.
| |
| 262 bookmark_html_reader::CanImportURLAsSearchEngine( | |
| 263 item->url, | |
| 264 base::UTF8ToUTF16(item->keyword), | |
| 265 item->title, | |
| 266 &search_engine_info)) { | |
| 267 search_engines.push_back(search_engine_info); | |
| 268 } | |
| 260 continue; | 269 continue; |
| 261 } | 270 } |
| 262 | 271 |
| 263 // Skip the default bookmarks and unwanted URLs. | 272 // Skip the default bookmarks and unwanted URLs. |
| 264 if (default_urls.find(item->url) != default_urls.end() || | 273 if (default_urls.find(item->url) != default_urls.end() || |
| 265 post_keyword_ids.find(item->id) != post_keyword_ids.end()) | 274 post_keyword_ids.find(item->id) != post_keyword_ids.end()) |
| 266 continue; | 275 continue; |
| 267 | 276 |
| 268 // Find the bookmark path by tracing their links to parent folders. | 277 // Find the bookmark path by tracing their links to parent folders. |
| 269 std::vector<base::string16> path; | 278 std::vector<base::string16> path; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 entry.is_folder = item->type == TYPE_FOLDER; | 318 entry.is_folder = item->type == TYPE_FOLDER; |
| 310 | 319 |
| 311 bookmarks.push_back(entry); | 320 bookmarks.push_back(entry); |
| 312 | 321 |
| 313 if (item->type == TYPE_BOOKMARK) { | 322 if (item->type == TYPE_BOOKMARK) { |
| 314 if (item->favicon) | 323 if (item->favicon) |
| 315 favicon_map[item->favicon].insert(item->url); | 324 favicon_map[item->favicon].insert(item->url); |
| 316 | 325 |
| 317 // This bookmark has a keyword, we should import it. | 326 // This bookmark has a keyword, we should import it. |
| 318 if (!item->keyword.empty() && item->url.is_valid()) { | 327 if (!item->keyword.empty() && item->url.is_valid()) { |
| 319 importer::URLKeywordInfo url_keyword_info; | 328 importer::SearchEngineInfo search_engine_info; |
| 320 url_keyword_info.url = item->url; | 329 search_engine_info.url.assign(base::UTF8ToUTF16(item->url.spec())); |
| 321 url_keyword_info.keyword.assign(base::UTF8ToUTF16(item->keyword)); | 330 search_engine_info.keyword.assign(base::UTF8ToUTF16(item->keyword)); |
| 322 url_keyword_info.display_name = item->title; | 331 search_engine_info.display_name = item->title; |
| 323 url_keywords.push_back(url_keyword_info); | 332 search_engines.push_back(search_engine_info); |
| 324 } | 333 } |
| 325 } | 334 } |
| 326 } | 335 } |
| 327 | 336 |
| 328 STLDeleteElements(&list); | 337 STLDeleteElements(&list); |
| 329 | 338 |
| 330 // Write into profile. | 339 // Write into profile. |
| 331 if (!bookmarks.empty() && !cancelled()) { | 340 if (!bookmarks.empty() && !cancelled()) { |
| 332 const base::string16& first_folder_name = | 341 const base::string16& first_folder_name = |
| 333 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_FIREFOX); | 342 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_FIREFOX); |
| 334 bridge_->AddBookmarks(bookmarks, first_folder_name); | 343 bridge_->AddBookmarks(bookmarks, first_folder_name); |
| 335 } | 344 } |
| 336 if (!url_keywords.empty() && !cancelled()) { | 345 if (!search_engines.empty() && !cancelled()) { |
| 337 bridge_->SetKeywords(url_keywords, false); | 346 bridge_->SetKeywords(search_engines, false); |
| 338 } | 347 } |
| 339 if (!favicon_map.empty() && !cancelled()) { | 348 if (!favicon_map.empty() && !cancelled()) { |
| 340 std::vector<ImportedFaviconUsage> favicons; | 349 std::vector<ImportedFaviconUsage> favicons; |
| 341 LoadFavicons(&db, favicon_map, &favicons); | 350 LoadFavicons(&db, favicon_map, &favicons); |
| 342 bridge_->SetFavicons(favicons); | 351 bridge_->SetFavicons(favicons); |
| 343 } | 352 } |
| 344 } | 353 } |
| 345 | 354 |
| 346 void FirefoxImporter::ImportPasswords() { | 355 void FirefoxImporter::ImportPasswords() { |
| 347 // Initializes NSS3. | 356 // Initializes NSS3. |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 | 780 |
| 772 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 781 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) |
| 773 continue; // Unable to decode. | 782 continue; // Unable to decode. |
| 774 | 783 |
| 775 usage.urls = i->second; | 784 usage.urls = i->second; |
| 776 favicons->push_back(usage); | 785 favicons->push_back(usage); |
| 777 } | 786 } |
| 778 s.Reset(true); | 787 s.Reset(true); |
| 779 } | 788 } |
| 780 } | 789 } |
| OLD | NEW |