Index: chrome/utility/importer/firefox_importer.cc |
diff --git a/chrome/utility/importer/firefox_importer.cc b/chrome/utility/importer/firefox_importer.cc |
index c74947b685e91f288f07952175711e58a8890a2b..d03741ceffbd9275a754408ce54f2cbe9cd854c6 100644 |
--- a/chrome/utility/importer/firefox_importer.cc |
+++ b/chrome/utility/importer/firefox_importer.cc |
@@ -112,6 +112,7 @@ void FirefoxImporter::StartImport( |
if ((items & importer::HOME_PAGE) && !cancelled()) { |
bridge_->NotifyItemStarted(importer::HOME_PAGE); |
ImportHomepage(); // Doesn't have a UI item. |
+ ImportHomepage(); // Doesn't have a UI item. |
tfarina
2014/04/22 23:49:12
I don't think you meant to call ImportHomepage() t
|
bridge_->NotifyItemEnded(importer::HOME_PAGE); |
} |
@@ -383,12 +384,59 @@ void FirefoxImporter::ImportHomepage() { |
void FirefoxImporter::GetSearchEnginesXMLData( |
std::vector<std::string>* search_engine_data) { |
- // TODO(mpawlowski): This may no longer work, search engines are stored in |
- // search.json since Firefox 3.5, not in search.sqlite. XML definitions are |
- // still necessary. http://crbug.com/329175 |
+ |
base::FilePath file = source_path_.AppendASCII("search.sqlite"); |
- if (!base::PathExists(file)) |
+ if (!base::PathExists(file)) { |
+ // since Firefox 3.5, search engines are no longer stored in search.sqlite. |
+ // Instead, search.json is used for storing search engines. |
+ |
+ base::FilePath search_json_file = source_path_.AppendASCII("search.json"); |
+ if (!base::PathExists(search_json_file)) |
+ return; |
+ |
+ JSONFileValueSerializer serializer(search_json_file); |
+ scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); |
+ |
+ if (!root.get()) |
+ return; |
+ |
+ base::DictionaryValue* search_root = |
+ static_cast<base::DictionaryValue*>(root.release()); |
+ const std::string kDirectories("directories"); |
+ const base::DictionaryValue* search_directories = NULL; |
+ |
+ if (!search_root->GetDictionary(kDirectories, &search_directories)) |
+ return; |
+ |
+ // search engine list can be found from key <engines> of the dictionary. |
+ // key <engines> is a grandchild of key <directories>. |
+ // However, key <engines> parent's key is dynamic which |
+ // depends on operating systems. For example, |
+ // Ubuntu: /usr/lib/firefox/distribution/searchplugins/locale/en-US |
+ // Windows: C:\\Program Files (x86)\\Mozilla Firefox\\browser\\searchplugins |
+ // Therefore, it needs to be retrieved by using iterator |
+ |
+ base::DictionaryValue::Iterator it(*search_directories); |
+ const base::ListValue* search_engines = NULL; |
+ const std::string kEngines(it.key() + ".engines"); |
+ |
+ if (search_directories->GetList(kEngines, &search_engines)) { |
+ const std::string kFilePath("filePath"); |
+ for (size_t i = 0; i < search_engines->GetSize(); ++i) { |
+ const base::DictionaryValue* engine_info = NULL; |
+ if (search_engines->GetDictionary(i, &engine_info)) { |
+ std::string file_path; |
+ if (engine_info->GetString(kFilePath, &file_path)) { |
+ std::string file_data; |
+ base::FilePath xml_file = base::FilePath::FromUTF8Unsafe(file_path); |
+ base::ReadFileToString(xml_file, &file_data); |
+ search_engine_data->push_back(file_data); |
+ } |
+ } |
+ } |
+ } |
return; |
+ } |
sql::Connection db; |
if (!db.Open(file)) |
@@ -489,54 +537,6 @@ void FirefoxImporter::LoadRootNodeID(sql::Connection* db, |
while (s.Step()) { |
std::string folder = s.ColumnString(0); |
- int id = s.ColumnInt(1); |
- if (folder == kToolbarFolderName) |
- *toolbar_folder_id = id; |
- else if (folder == kMenuFolderName) |
- *menu_folder_id = id; |
- else if (folder == kUnsortedFolderName) |
- *unsorted_folder_id = id; |
- } |
-} |
- |
-void FirefoxImporter::LoadLivemarkIDs(sql::Connection* db, |
- std::set<int>* livemark) { |
- static const char* kFeedAnnotation = "livemark/feedURI"; |
- livemark->clear(); |
- |
- const char* query = "SELECT b.item_id " |
- "FROM moz_anno_attributes a " |
- "JOIN moz_items_annos b ON a.id = b.anno_attribute_id " |
- "WHERE a.name = ? "; |
- sql::Statement s(db->GetUniqueStatement(query)); |
- s.BindString(0, kFeedAnnotation); |
- |
- while (s.Step() && !cancelled()) |
- livemark->insert(s.ColumnInt(0)); |
-} |
- |
-void FirefoxImporter::GetTopBookmarkFolder(sql::Connection* db, |
- int folder_id, |
- BookmarkList* list) { |
- const char* query = "SELECT b.title " |
- "FROM moz_bookmarks b " |
- "WHERE b.type = 2 AND b.id = ? " |
- "ORDER BY b.position"; |
- sql::Statement s(db->GetUniqueStatement(query)); |
- s.BindInt(0, folder_id); |
- |
- if (s.Step()) { |
- BookmarkItem* item = new BookmarkItem; |
- item->parent = -1; // The top level folder has no parent. |
- item->id = folder_id; |
- item->title = s.ColumnString16(0); |
- item->type = TYPE_FOLDER; |
- item->favicon = 0; |
- item->empty_folder = true; |
- list->push_back(item); |
- } |
-} |
- |
void FirefoxImporter::GetWholeBookmarkFolder(sql::Connection* db, |
BookmarkList* list, |
size_t position, |