Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3200)

Unified Diff: chrome/utility/importer/firefox_importer.cc

Issue 426653002: Import keywords for search engines imported from Firefox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback (two nit fixes) Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/utility/importer/firefox_importer.cc
diff --git a/chrome/utility/importer/firefox_importer.cc b/chrome/utility/importer/firefox_importer.cc
index 8b216bdc1ca6c18cc7760509797b71474e40ecc6..1711d144e33867f817c50d1395ff3bda204f629a 100644
--- a/chrome/utility/importer/firefox_importer.cc
+++ b/chrome/utility/importer/firefox_importer.cc
@@ -480,6 +480,18 @@ void FirefoxImporter::GetSearchEnginesXMLData(
void FirefoxImporter::GetSearchEnginesXMLDataFromJSON(
std::vector<std::string>* search_engine_data) {
+ // search-metadata.json contains keywords for search engines. This
+ // file exists only if the user has set keywords for search engines.
+ base::FilePath search_metadata_json_file =
+ source_path_.AppendASCII("search-metadata.json");
+ JSONFileValueSerializer metadata_serializer(search_metadata_json_file);
+ scoped_ptr<base::Value> metadata_root(
+ metadata_serializer.Deserialize(NULL, NULL));
+ const base::DictionaryValue* search_metadata_root = NULL;
+ if (metadata_root)
+ metadata_root->GetAsDictionary(&search_metadata_root);
+
+ // search.json contains information about search engines to import.
base::FilePath search_json_file = source_path_.AppendASCII("search.json");
if (!base::PathExists(search_json_file))
return;
@@ -556,6 +568,22 @@ void FirefoxImporter::GetSearchEnginesXMLDataFromJSON(
std::string file_data;
base::ReadFileToString(xml_file, &file_data);
+
+ // If a keyword is mentioned for this search engine, then add
+ // it to the XML string as an <Alias> element and use this updated
+ // string.
+ const base::DictionaryValue* search_xml_path = NULL;
+ if (search_metadata_root && search_metadata_root->HasKey(file_path) &&
+ search_metadata_root->GetDictionaryWithoutPathExpansion(
+ file_path, &search_xml_path)) {
+ std::string alias;
+ search_xml_path->GetString("alias", &alias);
+
+ // Add <Alias> element as the last child element.
+ size_t end_of_parent = file_data.find("</SearchPlugin>");
+ if (end_of_parent != std::string::npos && !alias.empty())
+ file_data.insert(end_of_parent, "<Alias>" + alias + "</Alias> \n");
+ }
search_engine_data->push_back(file_data);
}
}
« no previous file with comments | « chrome/test/data/firefox_profile/search-metadata.json ('k') | components/search_engines/template_url_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698