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

Side by Side Diff: components/search_engines/template_url.cc

Issue 1841653003: Drop |languages| from {Format,Elide}Url* and IDNToUnicode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased, most Android targets locally built successfully Created 4 years, 8 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/command_line.h" 10 #include "base/command_line.h"
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
1184 const GURL& url, 1184 const GURL& url) {
Peter Kasting 2016/04/05 02:42:33 Nit: Rewrap
jungshik at Google 2016/04/05 18:56:19 Done.
1185 const std::string& accept_languages) {
1186 DCHECK(url.is_valid()); 1185 DCHECK(url.is_valid());
1187 // Strip "www." off the front of the keyword; otherwise the keyword won't work 1186 // 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 . 1187 // 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, 1188 // |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 1189 // 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( 1190 base::string16 keyword = url_formatter::StripWWW(
1193 url_formatter::IDNToUnicode(url.host(), accept_languages)); 1191 url_formatter::IDNToUnicode(url.host()));
1194 // Special case: if the host was exactly "www." (not sure this can happen but 1192 // 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 1193 // perhaps with some weird intranet and custom DNS server?), ensure we at
1196 // least don't return the empty string. 1194 // least don't return the empty string.
1197 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword; 1195 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword;
1198 } 1196 }
1199 1197
1200 // static 1198 // static
1201 GURL TemplateURL::GenerateFaviconURL(const GURL& url) { 1199 GURL TemplateURL::GenerateFaviconURL(const GURL& url) {
1202 DCHECK(url.is_valid()); 1200 DCHECK(url.is_valid());
1203 GURL::Replacements rep; 1201 GURL::Replacements rep;
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 instant_url_ref_.prepopulated_ = prepopulated; 1443 instant_url_ref_.prepopulated_ = prepopulated;
1446 } 1444 }
1447 1445
1448 void TemplateURL::ResetKeywordIfNecessary( 1446 void TemplateURL::ResetKeywordIfNecessary(
1449 const SearchTermsData& search_terms_data, 1447 const SearchTermsData& search_terms_data,
1450 bool force) { 1448 bool force) {
1451 if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) { 1449 if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) {
1452 DCHECK(GetType() != OMNIBOX_API_EXTENSION); 1450 DCHECK(GetType() != OMNIBOX_API_EXTENSION);
1453 GURL url(GenerateSearchURL(search_terms_data)); 1451 GURL url(GenerateSearchURL(search_terms_data));
1454 if (url.is_valid()) 1452 if (url.is_valid())
1455 data_.SetKeyword( 1453 data_.SetKeyword(GenerateKeyword(url));
1456 GenerateKeyword(url, search_terms_data.GetAcceptLanguages()));
1457 } 1454 }
1458 } 1455 }
1459 1456
1460 void TemplateURL::InvalidateCachedValues() const { 1457 void TemplateURL::InvalidateCachedValues() const {
1461 for (const TemplateURLRef& ref : url_refs_) 1458 for (const TemplateURLRef& ref : url_refs_)
1462 ref.InvalidateCachedValues(); 1459 ref.InvalidateCachedValues();
1463 suggestions_url_ref_.InvalidateCachedValues(); 1460 suggestions_url_ref_.InvalidateCachedValues();
1464 instant_url_ref_.InvalidateCachedValues(); 1461 instant_url_ref_.InvalidateCachedValues();
1465 image_url_ref_.InvalidateCachedValues(); 1462 image_url_ref_.InvalidateCachedValues();
1466 new_tab_url_ref_.InvalidateCachedValues(); 1463 new_tab_url_ref_.InvalidateCachedValues();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 // patterns. This means that given patterns 1498 // patterns. This means that given patterns
1502 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1499 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1503 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1500 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1504 // return false. This is important for at least Google, where such URLs 1501 // return false. This is important for at least Google, where such URLs
1505 // are invalid. 1502 // are invalid.
1506 return !search_terms->empty(); 1503 return !search_terms->empty();
1507 } 1504 }
1508 } 1505 }
1509 return false; 1506 return false;
1510 } 1507 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698