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

Unified Diff: components/search_engines/template_url_parser.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
« no previous file with comments | « chrome/utility/importer/firefox_importer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/search_engines/template_url_parser.cc
diff --git a/components/search_engines/template_url_parser.cc b/components/search_engines/template_url_parser.cc
index 5c6eae5ef587141ae01d1cddb2f5123054ec9177..aa0fd46eba223d94f1f47b8f1d4d98739e880f30 100644
--- a/components/search_engines/template_url_parser.cc
+++ b/components/search_engines/template_url_parser.cc
@@ -34,6 +34,7 @@ const char kImageElement[] = "Image";
const char kOpenSearchDescriptionElement[] = "OpenSearchDescription";
const char kFirefoxSearchDescriptionElement[] = "SearchPlugin";
const char kInputEncodingElement[] = "InputEncoding";
+const char kAliasElement[] = "Alias";
// Various XML attributes used.
const char kURLTypeAttribute[] = "type";
@@ -115,6 +116,7 @@ class TemplateURLParsingContext {
SHORT_NAME,
IMAGE,
INPUT_ENCODING,
+ ALIAS,
};
enum Method {
@@ -180,6 +182,10 @@ class TemplateURLParsingContext {
// search. Note that we don't need a stack as URL nodes cannot be nested.
bool is_suggest_url_;
+ // If true, the user has set a keyword and we should use it. Otherwise,
+ // we generate a keyword based on the URL.
+ bool has_custom_keyword_;
+
// Whether we should derive the image from the URL (when images are data
// URLs).
bool derive_image_from_url_;
@@ -198,6 +204,7 @@ TemplateURLParsingContext::TemplateURLParsingContext(
method_(GET),
suggestion_method_(GET),
is_suggest_url_(false),
+ has_custom_keyword_(false),
derive_image_from_url_(false) {
if (kElementNameToElementTypeMap == NULL)
InitMapping();
@@ -240,6 +247,9 @@ void TemplateURLParsingContext::EndElementImpl(void* ctx, const xmlChar* name) {
TemplateURLParsingContext* context =
reinterpret_cast<TemplateURLParsingContext*>(ctx);
switch (context->GetKnownType()) {
+ case TemplateURLParsingContext::URL:
+ context->ProcessURLParams();
+ break;
case TemplateURLParsingContext::SHORT_NAME:
context->data_.short_name = context->string_;
break;
@@ -264,9 +274,11 @@ void TemplateURLParsingContext::EndElementImpl(void* ctx, const xmlChar* name) {
context->data_.input_encodings.push_back(input_encoding);
break;
}
- case TemplateURLParsingContext::URL:
- context->ProcessURLParams();
+ case TemplateURLParsingContext::ALIAS: {
+ context->data_.SetKeyword(context->string_);
+ context->has_custom_keyword_ = true;
break;
+ }
default:
break;
}
@@ -298,7 +310,11 @@ TemplateURL* TemplateURLParsingContext::GetTemplateURL(
if (derive_image_from_url_ && data_.favicon_url.is_empty())
data_.favicon_url = TemplateURL::GenerateFaviconURL(search_url);
- data_.SetKeyword(TemplateURL::GenerateKeyword(search_url));
+ // Generate a keyword for this search engine if a custom one was not present
+ // in the imported data.
+ if (!has_custom_keyword_)
+ data_.SetKeyword(TemplateURL::GenerateKeyword(search_url));
+
data_.show_in_default_list = show_in_default_list;
// Bail if the search URL is empty or if either TemplateURLRef is invalid.
@@ -325,6 +341,7 @@ void TemplateURLParsingContext::InitMapping() {
(*kElementNameToElementTypeMap)[kFirefoxSearchDescriptionElement] =
OPEN_SEARCH_DESCRIPTION;
(*kElementNameToElementTypeMap)[kInputEncodingElement] = INPUT_ENCODING;
+ (*kElementNameToElementTypeMap)[kAliasElement] = ALIAS;
}
void TemplateURLParsingContext::ParseURL(const xmlChar** atts) {
« no previous file with comments | « chrome/utility/importer/firefox_importer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698