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

Unified Diff: components/search_engines/template_url.cc

Issue 1238683003: Unpunycode search keywords and short names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Fix comments, naming, code style. Created 5 years, 5 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: components/search_engines/template_url.cc
diff --git a/components/search_engines/template_url.cc b/components/search_engines/template_url.cc
index dbb74fc77853e1fe3c15533b7a1740a360ecf6fe..9d4dde80ef6ffe2ed97ca488ab45f8dab12b67a3 100644
--- a/components/search_engines/template_url.cc
+++ b/components/search_engines/template_url.cc
@@ -1210,14 +1210,20 @@ TemplateURL::~TemplateURL() {
}
// static
-base::string16 TemplateURL::GenerateKeyword(const GURL& url) {
+base::string16 TemplateURL::GenerateKeyword(
+ const GURL& url,
+ const std::string& accept_languages) {
DCHECK(url.is_valid());
// Strip "www." off the front of the keyword; otherwise the keyword won't work
// properly. See http://code.google.com/p/chromium/issues/detail?id=6984 .
+ // Since keyword is generated from hostname, it might be IDN-encoded.
+ // If so, decode it and convert to Unicode using user's accepted languages,
+ // making it look like Unicode hostname the user is used to seeing.
Peter Kasting 2015/07/21 17:34:09 Grammar issues. Try this: |url|'s hostname may b
alshabalin 2015/07/22 14:31:17 Done.
+ base::string16 keyword =
+ net::StripWWW(net::IDNToUnicode(url.host(), accept_languages));
// Special case: if the host was exactly "www." (not sure this can happen but
// perhaps with some weird intranet and custom DNS server?), ensure we at
// least don't return the empty string.
- base::string16 keyword(net::StripWWWFromHost(url));
return keyword.empty() ? base::ASCIIToUTF16("www") : keyword;
}
@@ -1485,7 +1491,8 @@ void TemplateURL::ResetKeywordIfNecessary(
DCHECK(GetType() != OMNIBOX_API_EXTENSION);
GURL url(GenerateSearchURL(search_terms_data));
if (url.is_valid())
- data_.SetKeyword(GenerateKeyword(url));
+ data_.SetKeyword(
+ GenerateKeyword(url, search_terms_data.GetAcceptLanguages()));
}
}
« no previous file with comments | « components/search_engines/template_url.h ('k') | components/search_engines/template_url_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698