OLD | NEW |
---|---|
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 Loading... | |
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()); |
1217 // Search engine's keyword is a user facing value and therefore | |
1218 // should be IDN-decoded using user's accepted languages. | |
Peter Kasting
2015/07/20 19:30:52
This rationale seems a bit inaccurate. How about
alshabalin
2015/07/21 08:44:19
Done.
But I worded it like this:
// Since keywo
| |
1219 base::string16 keyword = net::IDNToUnicode(url.host(), accept_languages); | |
Peter Kasting
2015/07/20 19:30:52
Nit: Combine this with the line below.
| |
1215 // Strip "www." off the front of the keyword; otherwise the keyword won't work | 1220 // 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 . | 1221 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . |
1217 // Special case: if the host was exactly "www." (not sure this can happen but | 1222 // Special case: if the host was exactly "www." (not sure this can happen but |
Peter Kasting
2015/07/20 19:30:52
Nit: Move this "Special case" comment below the St
| |
1218 // perhaps with some weird intranet and custom DNS server?), ensure we at | 1223 // perhaps with some weird intranet and custom DNS server?), ensure we at |
1219 // least don't return the empty string. | 1224 // least don't return the empty string. |
1220 base::string16 keyword(net::StripWWWFromHost(url)); | 1225 keyword = net::StripWWW(keyword); |
1221 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword; | 1226 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword; |
1222 } | 1227 } |
1223 | 1228 |
1224 // static | 1229 // static |
1225 GURL TemplateURL::GenerateFaviconURL(const GURL& url) { | 1230 GURL TemplateURL::GenerateFaviconURL(const GURL& url) { |
1226 DCHECK(url.is_valid()); | 1231 DCHECK(url.is_valid()); |
1227 GURL::Replacements rep; | 1232 GURL::Replacements rep; |
1228 | 1233 |
1229 const char favicon_path[] = "/favicon.ico"; | 1234 const char favicon_path[] = "/favicon.ico"; |
1230 int favicon_path_len = arraysize(favicon_path) - 1; | 1235 int favicon_path_len = arraysize(favicon_path) - 1; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1478 instant_url_ref_.prepopulated_ = prepopulated; | 1483 instant_url_ref_.prepopulated_ = prepopulated; |
1479 } | 1484 } |
1480 | 1485 |
1481 void TemplateURL::ResetKeywordIfNecessary( | 1486 void TemplateURL::ResetKeywordIfNecessary( |
1482 const SearchTermsData& search_terms_data, | 1487 const SearchTermsData& search_terms_data, |
1483 bool force) { | 1488 bool force) { |
1484 if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) { | 1489 if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) { |
1485 DCHECK(GetType() != OMNIBOX_API_EXTENSION); | 1490 DCHECK(GetType() != OMNIBOX_API_EXTENSION); |
1486 GURL url(GenerateSearchURL(search_terms_data)); | 1491 GURL url(GenerateSearchURL(search_terms_data)); |
1487 if (url.is_valid()) | 1492 if (url.is_valid()) |
1488 data_.SetKeyword(GenerateKeyword(url)); | 1493 data_.SetKeyword( |
1494 GenerateKeyword(url, search_terms_data.GetAcceptedLanguages())); | |
1489 } | 1495 } |
1490 } | 1496 } |
1491 | 1497 |
1492 bool TemplateURL::FindSearchTermsInURL( | 1498 bool TemplateURL::FindSearchTermsInURL( |
1493 const GURL& url, | 1499 const GURL& url, |
1494 const SearchTermsData& search_terms_data, | 1500 const SearchTermsData& search_terms_data, |
1495 base::string16* search_terms, | 1501 base::string16* search_terms, |
1496 url::Parsed::ComponentType* search_term_component, | 1502 url::Parsed::ComponentType* search_term_component, |
1497 url::Component* search_terms_position) const { | 1503 url::Component* search_terms_position) const { |
1498 DCHECK(search_terms); | 1504 DCHECK(search_terms); |
(...skipping 10 matching lines...) Expand all Loading... | |
1509 // patterns. This means that given patterns | 1515 // patterns. This means that given patterns |
1510 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1516 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1511 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1517 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1512 // return false. This is important for at least Google, where such URLs | 1518 // return false. This is important for at least Google, where such URLs |
1513 // are invalid. | 1519 // are invalid. |
1514 return !search_terms->empty(); | 1520 return !search_terms->empty(); |
1515 } | 1521 } |
1516 } | 1522 } |
1517 return false; | 1523 return false; |
1518 } | 1524 } |
OLD | NEW |