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

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

Issue 2659353002: Fix TemplateUrl::MatchesData comparison of search_terms_replacement_key (reland) (Closed)
Patch Set: Fixed deps Created 3 years, 10 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 parameter_position->begin = begin; 153 parameter_position->begin = begin;
154 parameter_position->len = arraysize(kSearchTermsParameterFullEscaped) - 1; 154 parameter_position->len = arraysize(kSearchTermsParameterFullEscaped) - 1;
155 return true; 155 return true;
156 } 156 }
157 157
158 bool IsTemplateParameterString(const std::string& param) { 158 bool IsTemplateParameterString(const std::string& param) {
159 return (param.length() > 2) && (*(param.begin()) == kStartParameter) && 159 return (param.length() > 2) && (*(param.begin()) == kStartParameter) &&
160 (*(param.rbegin()) == kEndParameter); 160 (*(param.rbegin()) == kEndParameter);
161 } 161 }
162 162
163 // Special case for search_terms_replacement_key comparison, because of
164 // its special initialization in TemplateUrl constructor.
165 bool SearchTermsReplacementKeysMatch(const std::string& key1,
166 const std::string& key2) {
167 const auto IsInstantExtended = [](const std::string& key) {
168 return (key == google_util::kInstantExtendedAPIParam) ||
169 (key == google_util::kGoogleInstantExtendedEnabledKeyFull);
170 };
171 return (key1 == key2) || (IsInstantExtended(key1) && IsInstantExtended(key2));
172 }
173
163 } // namespace 174 } // namespace
164 175
165
166 // TemplateURLRef::SearchTermsArgs -------------------------------------------- 176 // TemplateURLRef::SearchTermsArgs --------------------------------------------
167 177
168 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( 178 TemplateURLRef::SearchTermsArgs::SearchTermsArgs(
169 const base::string16& search_terms) 179 const base::string16& search_terms)
170 : search_terms(search_terms), 180 : search_terms(search_terms),
171 input_type(metrics::OmniboxInputType::INVALID), 181 input_type(metrics::OmniboxInputType::INVALID),
172 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE), 182 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE),
173 cursor_position(base::string16::npos), 183 cursor_position(base::string16::npos),
174 page_classification(metrics::OmniboxEventProto::INVALID_SPEC), 184 page_classification(metrics::OmniboxEventProto::INVALID_SPEC),
175 append_extra_query_params(false), 185 append_extra_query_params(false),
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start)); 608 Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start));
599 } else if (parameter == "google:imageURL") { 609 } else if (parameter == "google:imageURL") {
600 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL, 610 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL,
601 start)); 611 start));
602 } else if (parameter == "google:inputType") { 612 } else if (parameter == "google:inputType") {
603 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_INPUT_TYPE, 613 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_INPUT_TYPE,
604 start)); 614 start));
605 } else if (parameter == "google:instantExtendedEnabledParameter") { 615 } else if (parameter == "google:instantExtendedEnabledParameter") {
606 replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED, 616 replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED,
607 start)); 617 start));
608 } else if (parameter == "google:instantExtendedEnabledKey") { 618 } else if (parameter == google_util::kGoogleInstantExtendedEnabledKey) {
609 url->insert(start, google_util::kInstantExtendedAPIParam); 619 url->insert(start, google_util::kInstantExtendedAPIParam);
610 } else if (parameter == "google:iOSSearchLanguage") { 620 } else if (parameter == "google:iOSSearchLanguage") {
611 replacements->push_back(Replacement(GOOGLE_IOS_SEARCH_LANGUAGE, start)); 621 replacements->push_back(Replacement(GOOGLE_IOS_SEARCH_LANGUAGE, start));
612 } else if (parameter == "google:contextualSearchVersion") { 622 } else if (parameter == "google:contextualSearchVersion") {
613 replacements->push_back( 623 replacements->push_back(
614 Replacement(GOOGLE_CONTEXTUAL_SEARCH_VERSION, start)); 624 Replacement(GOOGLE_CONTEXTUAL_SEARCH_VERSION, start));
615 } else if (parameter == "google:contextualSearchContextData") { 625 } else if (parameter == "google:contextualSearchContextData") {
616 replacements->push_back( 626 replacements->push_back(
617 Replacement(GOOGLE_CONTEXTUAL_SEARCH_CONTEXT_DATA, start)); 627 Replacement(GOOGLE_CONTEXTUAL_SEARCH_CONTEXT_DATA, start));
618 } else if (parameter == "google:originalQueryForSuggestion") { 628 } else if (parameter == "google:originalQueryForSuggestion") {
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 instant_url_ref_(this, TemplateURLRef::INSTANT), 1162 instant_url_ref_(this, TemplateURLRef::INSTANT),
1153 image_url_ref_(this, TemplateURLRef::IMAGE), 1163 image_url_ref_(this, TemplateURLRef::IMAGE),
1154 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), 1164 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB),
1155 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH), 1165 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH),
1156 type_(type), 1166 type_(type),
1157 engine_type_(SEARCH_ENGINE_UNKNOWN) { 1167 engine_type_(SEARCH_ENGINE_UNKNOWN) {
1158 ResizeURLRefVector(); 1168 ResizeURLRefVector();
1159 SetPrepopulateId(data_.prepopulate_id); 1169 SetPrepopulateId(data_.prepopulate_id);
1160 1170
1161 if (data_.search_terms_replacement_key == 1171 if (data_.search_terms_replacement_key ==
1162 "{google:instantExtendedEnabledKey}") { 1172 google_util::kGoogleInstantExtendedEnabledKeyFull)
1163 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; 1173 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam;
1164 }
1165 } 1174 }
1166 1175
1167 TemplateURL::~TemplateURL() { 1176 TemplateURL::~TemplateURL() {
1168 } 1177 }
1169 1178
1170 // static 1179 // static
1171 base::string16 TemplateURL::GenerateKeyword(const GURL& url) { 1180 base::string16 TemplateURL::GenerateKeyword(const GURL& url) {
1172 DCHECK(url.is_valid()); 1181 DCHECK(url.is_valid());
1173 // Strip "www." off the front of the keyword; otherwise the keyword won't work 1182 // Strip "www." off the front of the keyword; otherwise the keyword won't work
1174 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . 1183 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 .
(...skipping 24 matching lines...) Expand all
1199 } 1208 }
1200 1209
1201 // static 1210 // static
1202 bool TemplateURL::MatchesData(const TemplateURL* t_url, 1211 bool TemplateURL::MatchesData(const TemplateURL* t_url,
1203 const TemplateURLData* data, 1212 const TemplateURLData* data,
1204 const SearchTermsData& search_terms_data) { 1213 const SearchTermsData& search_terms_data) {
1205 if (!t_url || !data) 1214 if (!t_url || !data)
1206 return !t_url && !data; 1215 return !t_url && !data;
1207 1216
1208 return (t_url->short_name() == data->short_name()) && 1217 return (t_url->short_name() == data->short_name()) &&
1209 t_url->HasSameKeywordAs(*data, search_terms_data) && 1218 t_url->HasSameKeywordAs(*data, search_terms_data) &&
1210 (t_url->url() == data->url()) && 1219 (t_url->url() == data->url()) &&
1211 (t_url->suggestions_url() == data->suggestions_url) && 1220 (t_url->suggestions_url() == data->suggestions_url) &&
1212 (t_url->instant_url() == data->instant_url) && 1221 (t_url->instant_url() == data->instant_url) &&
1213 (t_url->image_url() == data->image_url) && 1222 (t_url->image_url() == data->image_url) &&
1214 (t_url->new_tab_url() == data->new_tab_url) && 1223 (t_url->new_tab_url() == data->new_tab_url) &&
1215 (t_url->search_url_post_params() == data->search_url_post_params) && 1224 (t_url->search_url_post_params() == data->search_url_post_params) &&
1216 (t_url->suggestions_url_post_params() == 1225 (t_url->suggestions_url_post_params() ==
1217 data->suggestions_url_post_params) && 1226 data->suggestions_url_post_params) &&
1218 (t_url->instant_url_post_params() == data->instant_url_post_params) && 1227 (t_url->instant_url_post_params() == data->instant_url_post_params) &&
1219 (t_url->image_url_post_params() == data->image_url_post_params) && 1228 (t_url->image_url_post_params() == data->image_url_post_params) &&
1220 (t_url->favicon_url() == data->favicon_url) && 1229 (t_url->favicon_url() == data->favicon_url) &&
1221 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && 1230 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) &&
1222 (t_url->input_encodings() == data->input_encodings) && 1231 (t_url->input_encodings() == data->input_encodings) &&
1223 (t_url->alternate_urls() == data->alternate_urls) && 1232 (t_url->alternate_urls() == data->alternate_urls) &&
1224 (t_url->search_terms_replacement_key() == 1233 SearchTermsReplacementKeysMatch(t_url->search_terms_replacement_key(),
1225 data->search_terms_replacement_key); 1234 data->search_terms_replacement_key);
1226 } 1235 }
1227 1236
1228 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { 1237 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const {
1229 base::string16 bidi_safe_short_name = data_.short_name(); 1238 base::string16 bidi_safe_short_name = data_.short_name();
1230 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); 1239 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name);
1231 return bidi_safe_short_name; 1240 return bidi_safe_short_name;
1232 } 1241 }
1233 1242
1234 bool TemplateURL::SupportsReplacement( 1243 bool TemplateURL::SupportsReplacement(
1235 const SearchTermsData& search_terms_data) const { 1244 const SearchTermsData& search_terms_data) const {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 // patterns. This means that given patterns 1499 // patterns. This means that given patterns
1491 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1500 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1492 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1501 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1493 // return false. This is important for at least Google, where such URLs 1502 // return false. This is important for at least Google, where such URLs
1494 // are invalid. 1503 // are invalid.
1495 return !search_terms->empty(); 1504 return !search_terms->empty();
1496 } 1505 }
1497 } 1506 }
1498 return false; 1507 return false;
1499 } 1508 }
OLDNEW
« no previous file with comments | « components/search_engines/default_search_manager_unittest.cc ('k') | components/search_engines/template_url_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698