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/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 if (data_.search_terms_replacement_key == | 1173 if (data_.search_terms_replacement_key == |
1174 "{google:instantExtendedEnabledKey}") { | 1174 "{google:instantExtendedEnabledKey}") { |
1175 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; | 1175 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; |
1176 } | 1176 } |
1177 } | 1177 } |
1178 | 1178 |
1179 TemplateURL::~TemplateURL() { | 1179 TemplateURL::~TemplateURL() { |
1180 } | 1180 } |
1181 | 1181 |
1182 // static | 1182 // static |
1183 base::string16 TemplateURL::GenerateKeyword( | 1183 base::string16 TemplateURL::GenerateKeyword(const GURL& url) { |
1184 const GURL& url, | |
1185 const std::string& accept_languages) { | |
1186 DCHECK(url.is_valid()); | 1184 DCHECK(url.is_valid()); |
1187 // Strip "www." off the front of the keyword; otherwise the keyword won't work | 1185 // Strip "www." off the front of the keyword; otherwise the keyword won't work |
1188 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . | 1186 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . |
1189 // |url|'s hostname may be IDN-encoded. Before generating |keyword| from it, | 1187 // |url|'s hostname may be IDN-encoded. Before generating |keyword| from it, |
1190 // convert to Unicode using the user's accept-languages, so it won't look like | 1188 // convert to Unicode, so it won't look like a confusing punycode string. |
1191 // a confusing punycode string. | |
1192 base::string16 keyword = url_formatter::StripWWW( | 1189 base::string16 keyword = url_formatter::StripWWW( |
1193 url_formatter::IDNToUnicode(url.host(), accept_languages)); | 1190 url_formatter::IDNToUnicode(url.host())); |
1194 // Special case: if the host was exactly "www." (not sure this can happen but | 1191 // Special case: if the host was exactly "www." (not sure this can happen but |
1195 // perhaps with some weird intranet and custom DNS server?), ensure we at | 1192 // perhaps with some weird intranet and custom DNS server?), ensure we at |
1196 // least don't return the empty string. | 1193 // least don't return the empty string. |
1197 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword; | 1194 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword; |
1198 } | 1195 } |
1199 | 1196 |
1200 // static | 1197 // static |
1201 GURL TemplateURL::GenerateFaviconURL(const GURL& url) { | 1198 GURL TemplateURL::GenerateFaviconURL(const GURL& url) { |
1202 DCHECK(url.is_valid()); | 1199 DCHECK(url.is_valid()); |
1203 GURL::Replacements rep; | 1200 GURL::Replacements rep; |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 instant_url_ref_.prepopulated_ = prepopulated; | 1442 instant_url_ref_.prepopulated_ = prepopulated; |
1446 } | 1443 } |
1447 | 1444 |
1448 void TemplateURL::ResetKeywordIfNecessary( | 1445 void TemplateURL::ResetKeywordIfNecessary( |
1449 const SearchTermsData& search_terms_data, | 1446 const SearchTermsData& search_terms_data, |
1450 bool force) { | 1447 bool force) { |
1451 if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) { | 1448 if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) { |
1452 DCHECK(GetType() != OMNIBOX_API_EXTENSION); | 1449 DCHECK(GetType() != OMNIBOX_API_EXTENSION); |
1453 GURL url(GenerateSearchURL(search_terms_data)); | 1450 GURL url(GenerateSearchURL(search_terms_data)); |
1454 if (url.is_valid()) | 1451 if (url.is_valid()) |
1455 data_.SetKeyword( | 1452 data_.SetKeyword(GenerateKeyword(url)); |
1456 GenerateKeyword(url, search_terms_data.GetAcceptLanguages())); | |
1457 } | 1453 } |
1458 } | 1454 } |
1459 | 1455 |
1460 void TemplateURL::InvalidateCachedValues() const { | 1456 void TemplateURL::InvalidateCachedValues() const { |
1461 for (const TemplateURLRef& ref : url_refs_) | 1457 for (const TemplateURLRef& ref : url_refs_) |
1462 ref.InvalidateCachedValues(); | 1458 ref.InvalidateCachedValues(); |
1463 suggestions_url_ref_.InvalidateCachedValues(); | 1459 suggestions_url_ref_.InvalidateCachedValues(); |
1464 instant_url_ref_.InvalidateCachedValues(); | 1460 instant_url_ref_.InvalidateCachedValues(); |
1465 image_url_ref_.InvalidateCachedValues(); | 1461 image_url_ref_.InvalidateCachedValues(); |
1466 new_tab_url_ref_.InvalidateCachedValues(); | 1462 new_tab_url_ref_.InvalidateCachedValues(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 // patterns. This means that given patterns | 1497 // patterns. This means that given patterns |
1502 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1498 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1503 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1499 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1504 // return false. This is important for at least Google, where such URLs | 1500 // return false. This is important for at least Google, where such URLs |
1505 // are invalid. | 1501 // are invalid. |
1506 return !search_terms->empty(); | 1502 return !search_terms->empty(); |
1507 } | 1503 } |
1508 } | 1504 } |
1509 return false; | 1505 return false; |
1510 } | 1506 } |
OLD | NEW |