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

Side by Side 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 grammar. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/search_engines/template_url.h" 5 #include "components/search_engines/template_url.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 if (data_.search_terms_replacement_key == 1203 if (data_.search_terms_replacement_key ==
1204 "{google:instantExtendedEnabledKey}") { 1204 "{google:instantExtendedEnabledKey}") {
1205 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; 1205 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam;
1206 } 1206 }
1207 } 1207 }
1208 1208
1209 TemplateURL::~TemplateURL() { 1209 TemplateURL::~TemplateURL() {
1210 } 1210 }
1211 1211
1212 // static 1212 // static
1213 base::string16 TemplateURL::GenerateKeyword(const GURL& url) { 1213 base::string16 TemplateURL::GenerateKeyword(
1214 const GURL& url,
1215 const std::string& accept_languages) {
1214 DCHECK(url.is_valid()); 1216 DCHECK(url.is_valid());
1215 // Strip "www." off the front of the keyword; otherwise the keyword won't work 1217 // Strip "www." off the front of the keyword; otherwise the keyword won't work
1216 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . 1218 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 .
1219 // |url|'s hostname may be IDN-encoded. Before generating |keyword| from it,
1220 // convert to Unicode using the user's accept-languages, so it won't look like
1221 // a confusing punycode string.
1222 base::string16 keyword =
1223 net::StripWWW(net::IDNToUnicode(url.host(), accept_languages));
1217 // Special case: if the host was exactly "www." (not sure this can happen but 1224 // Special case: if the host was exactly "www." (not sure this can happen but
1218 // perhaps with some weird intranet and custom DNS server?), ensure we at 1225 // perhaps with some weird intranet and custom DNS server?), ensure we at
1219 // least don't return the empty string. 1226 // least don't return the empty string.
1220 base::string16 keyword(net::StripWWWFromHost(url));
1221 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword; 1227 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword;
1222 } 1228 }
1223 1229
1224 // static 1230 // static
1225 GURL TemplateURL::GenerateFaviconURL(const GURL& url) { 1231 GURL TemplateURL::GenerateFaviconURL(const GURL& url) {
1226 DCHECK(url.is_valid()); 1232 DCHECK(url.is_valid());
1227 GURL::Replacements rep; 1233 GURL::Replacements rep;
1228 1234
1229 const char favicon_path[] = "/favicon.ico"; 1235 const char favicon_path[] = "/favicon.ico";
1230 int favicon_path_len = arraysize(favicon_path) - 1; 1236 int favicon_path_len = arraysize(favicon_path) - 1;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 instant_url_ref_.prepopulated_ = prepopulated; 1484 instant_url_ref_.prepopulated_ = prepopulated;
1479 } 1485 }
1480 1486
1481 void TemplateURL::ResetKeywordIfNecessary( 1487 void TemplateURL::ResetKeywordIfNecessary(
1482 const SearchTermsData& search_terms_data, 1488 const SearchTermsData& search_terms_data,
1483 bool force) { 1489 bool force) {
1484 if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) { 1490 if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) {
1485 DCHECK(GetType() != OMNIBOX_API_EXTENSION); 1491 DCHECK(GetType() != OMNIBOX_API_EXTENSION);
1486 GURL url(GenerateSearchURL(search_terms_data)); 1492 GURL url(GenerateSearchURL(search_terms_data));
1487 if (url.is_valid()) 1493 if (url.is_valid())
1488 data_.SetKeyword(GenerateKeyword(url)); 1494 data_.SetKeyword(
1495 GenerateKeyword(url, search_terms_data.GetAcceptLanguages()));
1489 } 1496 }
1490 } 1497 }
1491 1498
1492 bool TemplateURL::FindSearchTermsInURL( 1499 bool TemplateURL::FindSearchTermsInURL(
1493 const GURL& url, 1500 const GURL& url,
1494 const SearchTermsData& search_terms_data, 1501 const SearchTermsData& search_terms_data,
1495 base::string16* search_terms, 1502 base::string16* search_terms,
1496 url::Parsed::ComponentType* search_term_component, 1503 url::Parsed::ComponentType* search_term_component,
1497 url::Component* search_terms_position) const { 1504 url::Component* search_terms_position) const {
1498 DCHECK(search_terms); 1505 DCHECK(search_terms);
(...skipping 10 matching lines...) Expand all
1509 // patterns. This means that given patterns 1516 // patterns. This means that given patterns
1510 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1517 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1511 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1518 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1512 // return false. This is important for at least Google, where such URLs 1519 // return false. This is important for at least Google, where such URLs
1513 // are invalid. 1520 // are invalid.
1514 return !search_terms->empty(); 1521 return !search_terms->empty();
1515 } 1522 }
1516 } 1523 }
1517 return false; 1524 return false;
1518 } 1525 }
OLDNEW
« 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