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

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

Issue 2347973002: Enable Chrome to tweak search engines for some locales (Closed)
Patch Set: fix compile Created 4 years, 2 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 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 if (!post_params_.empty()) 1175 if (!post_params_.empty())
1176 EncodeFormData(post_params_, post_content); 1176 EncodeFormData(post_params_, post_content);
1177 1177
1178 return url; 1178 return url;
1179 } 1179 }
1180 1180
1181 1181
1182 // TemplateURL ---------------------------------------------------------------- 1182 // TemplateURL ----------------------------------------------------------------
1183 1183
1184 TemplateURL::AssociatedExtensionInfo::AssociatedExtensionInfo( 1184 TemplateURL::AssociatedExtensionInfo::AssociatedExtensionInfo(
1185 Type type,
1186 const std::string& extension_id) 1185 const std::string& extension_id)
1187 : type(type), 1186 : extension_id(extension_id), wants_to_be_default_engine(false) {}
1188 extension_id(extension_id),
1189 wants_to_be_default_engine(false) {
1190 DCHECK_NE(NORMAL, type);
1191 }
1192 1187
1193 TemplateURL::AssociatedExtensionInfo::~AssociatedExtensionInfo() { 1188 TemplateURL::AssociatedExtensionInfo::~AssociatedExtensionInfo() {
1194 } 1189 }
1195 1190
1196 TemplateURL::TemplateURL(const TemplateURLData& data) 1191 TemplateURL::TemplateURL(const TemplateURLData& data, Type type)
1197 : data_(data), 1192 : data_(data),
1198 url_ref_(nullptr), 1193 url_ref_(nullptr),
1199 suggestions_url_ref_(this, 1194 suggestions_url_ref_(this, TemplateURLRef::SUGGEST),
1200 TemplateURLRef::SUGGEST), 1195 instant_url_ref_(this, TemplateURLRef::INSTANT),
1201 instant_url_ref_(this,
1202 TemplateURLRef::INSTANT),
1203 image_url_ref_(this, TemplateURLRef::IMAGE), 1196 image_url_ref_(this, TemplateURLRef::IMAGE),
1204 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), 1197 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB),
1205 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH), 1198 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH),
1206 engine_type_(SEARCH_ENGINE_UNKNOWN) { 1199 engine_type_(SEARCH_ENGINE_UNKNOWN),
1200 type_(type) {
1207 ResizeURLRefVector(); 1201 ResizeURLRefVector();
1208 SetPrepopulateId(data_.prepopulate_id); 1202 SetPrepopulateId(data_.prepopulate_id);
1209 1203
1210 if (data_.search_terms_replacement_key == 1204 if (data_.search_terms_replacement_key ==
1211 "{google:instantExtendedEnabledKey}") { 1205 "{google:instantExtendedEnabledKey}") {
1212 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; 1206 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam;
1213 } 1207 }
1214 } 1208 }
1215 1209
1216 TemplateURL::~TemplateURL() { 1210 TemplateURL::~TemplateURL() {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 } 1294 }
1301 return suggestions_url_ref_.HasGoogleBaseURLs(search_terms_data) || 1295 return suggestions_url_ref_.HasGoogleBaseURLs(search_terms_data) ||
1302 instant_url_ref_.HasGoogleBaseURLs(search_terms_data) || 1296 instant_url_ref_.HasGoogleBaseURLs(search_terms_data) ||
1303 image_url_ref_.HasGoogleBaseURLs(search_terms_data) || 1297 image_url_ref_.HasGoogleBaseURLs(search_terms_data) ||
1304 new_tab_url_ref_.HasGoogleBaseURLs(search_terms_data) || 1298 new_tab_url_ref_.HasGoogleBaseURLs(search_terms_data) ||
1305 contextual_search_url_ref_.HasGoogleBaseURLs(search_terms_data); 1299 contextual_search_url_ref_.HasGoogleBaseURLs(search_terms_data);
1306 } 1300 }
1307 1301
1308 bool TemplateURL::IsGoogleSearchURLWithReplaceableKeyword( 1302 bool TemplateURL::IsGoogleSearchURLWithReplaceableKeyword(
1309 const SearchTermsData& search_terms_data) const { 1303 const SearchTermsData& search_terms_data) const {
1310 return (GetType() == NORMAL) && 1304 return (type_ == NORMAL) &&
1311 url_ref_->HasGoogleBaseURLs(search_terms_data) && 1305 url_ref_->HasGoogleBaseURLs(search_terms_data) &&
1312 google_util::IsGoogleHostname(base::UTF16ToUTF8(data_.keyword()), 1306 google_util::IsGoogleHostname(base::UTF16ToUTF8(data_.keyword()),
1313 google_util::DISALLOW_SUBDOMAIN); 1307 google_util::DISALLOW_SUBDOMAIN);
1314 } 1308 }
1315 1309
1316 bool TemplateURL::HasSameKeywordAs( 1310 bool TemplateURL::HasSameKeywordAs(
1317 const TemplateURLData& other, 1311 const TemplateURLData& other,
1318 const SearchTermsData& search_terms_data) const { 1312 const SearchTermsData& search_terms_data) const {
1319 return (data_.keyword() == other.keyword()) || 1313 return (data_.keyword() == other.keyword()) ||
1320 (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) && 1314 (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) &&
1321 TemplateURL(other).IsGoogleSearchURLWithReplaceableKeyword( 1315 TemplateURL(other).IsGoogleSearchURLWithReplaceableKeyword(
1322 search_terms_data)); 1316 search_terms_data));
1323 } 1317 }
1324 1318
1325 TemplateURL::Type TemplateURL::GetType() const {
1326 return extension_info_ ? extension_info_->type : NORMAL;
1327 }
1328
1329 std::string TemplateURL::GetExtensionId() const { 1319 std::string TemplateURL::GetExtensionId() const {
1330 DCHECK(extension_info_); 1320 DCHECK(extension_info_);
1331 return extension_info_->extension_id; 1321 return extension_info_->extension_id;
1332 } 1322 }
1333 1323
1334 SearchEngineType TemplateURL::GetEngineType( 1324 SearchEngineType TemplateURL::GetEngineType(
1335 const SearchTermsData& search_terms_data) const { 1325 const SearchTermsData& search_terms_data) const {
1336 if (engine_type_ == SEARCH_ENGINE_UNKNOWN) { 1326 if (engine_type_ == SEARCH_ENGINE_UNKNOWN) {
1337 const GURL url = GenerateSearchURL(search_terms_data); 1327 const GURL url = GenerateSearchURL(search_terms_data);
1338 engine_type_ = url.is_valid() ? 1328 engine_type_ = url.is_valid() ?
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 instant_url_ref_.prepopulated_ = prepopulated; 1482 instant_url_ref_.prepopulated_ = prepopulated;
1493 image_url_ref_.prepopulated_ = prepopulated; 1483 image_url_ref_.prepopulated_ = prepopulated;
1494 new_tab_url_ref_.prepopulated_ = prepopulated; 1484 new_tab_url_ref_.prepopulated_ = prepopulated;
1495 contextual_search_url_ref_.prepopulated_ = prepopulated; 1485 contextual_search_url_ref_.prepopulated_ = prepopulated;
1496 } 1486 }
1497 1487
1498 void TemplateURL::ResetKeywordIfNecessary( 1488 void TemplateURL::ResetKeywordIfNecessary(
1499 const SearchTermsData& search_terms_data, 1489 const SearchTermsData& search_terms_data,
1500 bool force) { 1490 bool force) {
1501 if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) { 1491 if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) {
1502 DCHECK(GetType() != OMNIBOX_API_EXTENSION); 1492 DCHECK(type_ != OMNIBOX_API_EXTENSION);
Peter Kasting 2016/09/21 21:45:08 Nit: DCHECK_NE(OMNIBOX_API_EXTENSION, type_)?
Ian Wen 2016/09/21 23:12:38 Done.
1503 GURL url(GenerateSearchURL(search_terms_data)); 1493 GURL url(GenerateSearchURL(search_terms_data));
1504 if (url.is_valid()) 1494 if (url.is_valid())
1505 data_.SetKeyword(GenerateKeyword(url)); 1495 data_.SetKeyword(GenerateKeyword(url));
1506 } 1496 }
1507 } 1497 }
1508 1498
1509 void TemplateURL::InvalidateCachedValues() const { 1499 void TemplateURL::InvalidateCachedValues() const {
1510 for (const TemplateURLRef& ref : url_refs_) 1500 for (const TemplateURLRef& ref : url_refs_)
1511 ref.InvalidateCachedValues(); 1501 ref.InvalidateCachedValues();
1512 suggestions_url_ref_.InvalidateCachedValues(); 1502 suggestions_url_ref_.InvalidateCachedValues();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 // patterns. This means that given patterns 1540 // patterns. This means that given patterns
1551 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1541 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1552 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1542 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1553 // return false. This is important for at least Google, where such URLs 1543 // return false. This is important for at least Google, where such URLs
1554 // are invalid. 1544 // are invalid.
1555 return !search_terms->empty(); 1545 return !search_terms->empty();
1556 } 1546 }
1557 } 1547 }
1558 return false; 1548 return false;
1559 } 1549 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698