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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 | 105 |
106 #if defined(OS_POSIX) | 106 #if defined(OS_POSIX) |
107 locale_ = source_profile.locale; | 107 locale_ = source_profile.locale; |
108 #endif | 108 #endif |
109 | 109 |
110 // The order here is important! | 110 // The order here is important! |
111 bridge_->NotifyStarted(); | 111 bridge_->NotifyStarted(); |
112 if ((items & importer::HOME_PAGE) && !cancelled()) { | 112 if ((items & importer::HOME_PAGE) && !cancelled()) { |
113 bridge_->NotifyItemStarted(importer::HOME_PAGE); | 113 bridge_->NotifyItemStarted(importer::HOME_PAGE); |
114 ImportHomepage(); // Doesn't have a UI item. | 114 ImportHomepage(); // Doesn't have a UI item. |
115 ImportHomepage(); // Doesn't have a UI item. | |
tfarina
2014/04/22 23:49:12
I don't think you meant to call ImportHomepage() t
| |
115 bridge_->NotifyItemEnded(importer::HOME_PAGE); | 116 bridge_->NotifyItemEnded(importer::HOME_PAGE); |
116 } | 117 } |
117 | 118 |
118 // Note history should be imported before bookmarks because bookmark import | 119 // Note history should be imported before bookmarks because bookmark import |
119 // will also import favicons and we store favicon for a URL only if the URL | 120 // will also import favicons and we store favicon for a URL only if the URL |
120 // exist in history or bookmarks. | 121 // exist in history or bookmarks. |
121 if ((items & importer::HISTORY) && !cancelled()) { | 122 if ((items & importer::HISTORY) && !cancelled()) { |
122 bridge_->NotifyItemStarted(importer::HISTORY); | 123 bridge_->NotifyItemStarted(importer::HISTORY); |
123 ImportHistory(); | 124 ImportHistory(); |
124 bridge_->NotifyItemEnded(importer::HISTORY); | 125 bridge_->NotifyItemEnded(importer::HISTORY); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 | 377 |
377 void FirefoxImporter::ImportHomepage() { | 378 void FirefoxImporter::ImportHomepage() { |
378 GURL home_page = GetHomepage(source_path_); | 379 GURL home_page = GetHomepage(source_path_); |
379 if (home_page.is_valid() && !IsDefaultHomepage(home_page, app_path_)) { | 380 if (home_page.is_valid() && !IsDefaultHomepage(home_page, app_path_)) { |
380 bridge_->AddHomePage(home_page); | 381 bridge_->AddHomePage(home_page); |
381 } | 382 } |
382 } | 383 } |
383 | 384 |
384 void FirefoxImporter::GetSearchEnginesXMLData( | 385 void FirefoxImporter::GetSearchEnginesXMLData( |
385 std::vector<std::string>* search_engine_data) { | 386 std::vector<std::string>* search_engine_data) { |
386 // TODO(mpawlowski): This may no longer work, search engines are stored in | 387 |
387 // search.json since Firefox 3.5, not in search.sqlite. XML definitions are | |
388 // still necessary. http://crbug.com/329175 | |
389 base::FilePath file = source_path_.AppendASCII("search.sqlite"); | 388 base::FilePath file = source_path_.AppendASCII("search.sqlite"); |
390 if (!base::PathExists(file)) | 389 if (!base::PathExists(file)) { |
390 // since Firefox 3.5, search engines are no longer stored in search.sqlite. | |
391 // Instead, search.json is used for storing search engines. | |
392 | |
393 base::FilePath search_json_file = source_path_.AppendASCII("search.json"); | |
394 if (!base::PathExists(search_json_file)) | |
395 return; | |
396 | |
397 JSONFileValueSerializer serializer(search_json_file); | |
398 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); | |
399 | |
400 if (!root.get()) | |
401 return; | |
402 | |
403 base::DictionaryValue* search_root = | |
404 static_cast<base::DictionaryValue*>(root.release()); | |
405 const std::string kDirectories("directories"); | |
406 const base::DictionaryValue* search_directories = NULL; | |
407 | |
408 if (!search_root->GetDictionary(kDirectories, &search_directories)) | |
409 return; | |
410 | |
411 // search engine list can be found from key <engines> of the dictionary. | |
412 // key <engines> is a grandchild of key <directories>. | |
413 // However, key <engines> parent's key is dynamic which | |
414 // depends on operating systems. For example, | |
415 // Ubuntu: /usr/lib/firefox/distribution/searchplugins/locale/en-US | |
416 // Windows: C:\\Program Files (x86)\\Mozilla Firefox\\browser\\searchplugins | |
417 // Therefore, it needs to be retrieved by using iterator | |
418 | |
419 base::DictionaryValue::Iterator it(*search_directories); | |
420 const base::ListValue* search_engines = NULL; | |
421 const std::string kEngines(it.key() + ".engines"); | |
422 | |
423 if (search_directories->GetList(kEngines, &search_engines)) { | |
424 const std::string kFilePath("filePath"); | |
425 for (size_t i = 0; i < search_engines->GetSize(); ++i) { | |
426 const base::DictionaryValue* engine_info = NULL; | |
427 if (search_engines->GetDictionary(i, &engine_info)) { | |
428 std::string file_path; | |
429 if (engine_info->GetString(kFilePath, &file_path)) { | |
430 std::string file_data; | |
431 base::FilePath xml_file = base::FilePath::FromUTF8Unsafe(file_path); | |
432 base::ReadFileToString(xml_file, &file_data); | |
433 search_engine_data->push_back(file_data); | |
434 } | |
435 } | |
436 } | |
437 } | |
391 return; | 438 return; |
439 } | |
392 | 440 |
393 sql::Connection db; | 441 sql::Connection db; |
394 if (!db.Open(file)) | 442 if (!db.Open(file)) |
395 return; | 443 return; |
396 | 444 |
397 const char* query = "SELECT engineid FROM engine_data " | 445 const char* query = "SELECT engineid FROM engine_data " |
398 "WHERE engineid NOT IN " | 446 "WHERE engineid NOT IN " |
399 "(SELECT engineid FROM engine_data " | 447 "(SELECT engineid FROM engine_data " |
400 "WHERE name='hidden') " | 448 "WHERE name='hidden') " |
401 "ORDER BY value ASC"; | 449 "ORDER BY value ASC"; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 int* unsorted_folder_id) { | 530 int* unsorted_folder_id) { |
483 static const char* kToolbarFolderName = "toolbar"; | 531 static const char* kToolbarFolderName = "toolbar"; |
484 static const char* kMenuFolderName = "menu"; | 532 static const char* kMenuFolderName = "menu"; |
485 static const char* kUnsortedFolderName = "unfiled"; | 533 static const char* kUnsortedFolderName = "unfiled"; |
486 | 534 |
487 const char* query = "SELECT root_name, folder_id FROM moz_bookmarks_roots"; | 535 const char* query = "SELECT root_name, folder_id FROM moz_bookmarks_roots"; |
488 sql::Statement s(db->GetUniqueStatement(query)); | 536 sql::Statement s(db->GetUniqueStatement(query)); |
489 | 537 |
490 while (s.Step()) { | 538 while (s.Step()) { |
491 std::string folder = s.ColumnString(0); | 539 std::string folder = s.ColumnString(0); |
492 int id = s.ColumnInt(1); | |
493 if (folder == kToolbarFolderName) | |
494 *toolbar_folder_id = id; | |
495 else if (folder == kMenuFolderName) | |
496 *menu_folder_id = id; | |
497 else if (folder == kUnsortedFolderName) | |
498 *unsorted_folder_id = id; | |
499 } | |
500 } | |
501 | |
502 void FirefoxImporter::LoadLivemarkIDs(sql::Connection* db, | |
503 std::set<int>* livemark) { | |
504 static const char* kFeedAnnotation = "livemark/feedURI"; | |
505 livemark->clear(); | |
506 | |
507 const char* query = "SELECT b.item_id " | |
508 "FROM moz_anno_attributes a " | |
509 "JOIN moz_items_annos b ON a.id = b.anno_attribute_id " | |
510 "WHERE a.name = ? "; | |
511 sql::Statement s(db->GetUniqueStatement(query)); | |
512 s.BindString(0, kFeedAnnotation); | |
513 | |
514 while (s.Step() && !cancelled()) | |
515 livemark->insert(s.ColumnInt(0)); | |
516 } | |
517 | |
518 void FirefoxImporter::GetTopBookmarkFolder(sql::Connection* db, | |
519 int folder_id, | |
520 BookmarkList* list) { | |
521 const char* query = "SELECT b.title " | |
522 "FROM moz_bookmarks b " | |
523 "WHERE b.type = 2 AND b.id = ? " | |
524 "ORDER BY b.position"; | |
525 sql::Statement s(db->GetUniqueStatement(query)); | |
526 s.BindInt(0, folder_id); | |
527 | |
528 if (s.Step()) { | |
529 BookmarkItem* item = new BookmarkItem; | |
530 item->parent = -1; // The top level folder has no parent. | |
531 item->id = folder_id; | |
532 item->title = s.ColumnString16(0); | |
533 item->type = TYPE_FOLDER; | |
534 item->favicon = 0; | |
535 item->empty_folder = true; | |
536 list->push_back(item); | |
537 } | |
538 } | |
539 | |
540 void FirefoxImporter::GetWholeBookmarkFolder(sql::Connection* db, | 540 void FirefoxImporter::GetWholeBookmarkFolder(sql::Connection* db, |
541 BookmarkList* list, | 541 BookmarkList* list, |
542 size_t position, | 542 size_t position, |
543 bool* empty_folder) { | 543 bool* empty_folder) { |
544 if (position >= list->size()) { | 544 if (position >= list->size()) { |
545 NOTREACHED(); | 545 NOTREACHED(); |
546 return; | 546 return; |
547 } | 547 } |
548 | 548 |
549 const char* query = "SELECT b.id, h.url, COALESCE(b.title, h.title), " | 549 const char* query = "SELECT b.id, h.url, COALESCE(b.title, h.title), " |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 | 611 |
612 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 612 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) |
613 continue; // Unable to decode. | 613 continue; // Unable to decode. |
614 | 614 |
615 usage.urls = i->second; | 615 usage.urls = i->second; |
616 favicons->push_back(usage); | 616 favicons->push_back(usage); |
617 } | 617 } |
618 s.Reset(true); | 618 s.Reset(true); |
619 } | 619 } |
620 } | 620 } |
OLD | NEW |