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

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

Issue 2654093004: Revert of Fix TemplateUrl::MatchesData comparison of search_terms_replacement_key (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | components/search_engines/template_url_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // Display value for kGoogleUnescapedSearchTermsParameter. 60 // Display value for kGoogleUnescapedSearchTermsParameter.
61 const char kDisplayUnescapedSearchTerms[] = "%S"; 61 const char kDisplayUnescapedSearchTerms[] = "%S";
62 62
63 // Used if the count parameter is not optional. Indicates we want 10 search 63 // Used if the count parameter is not optional. Indicates we want 10 search
64 // results. 64 // results.
65 const char kDefaultCount[] = "10"; 65 const char kDefaultCount[] = "10";
66 66
67 // Used if the output encoding parameter is required. 67 // Used if the output encoding parameter is required.
68 const char kOutputEncodingType[] = "UTF-8"; 68 const char kOutputEncodingType[] = "UTF-8";
69 69
70 constexpr char kGoogleInstantExtendedEnabledKey[] =
71 "{google:instantExtendedEnabledKey}";
72
73 // Attempts to encode |terms| and |original_query| in |encoding| and escape 70 // Attempts to encode |terms| and |original_query| in |encoding| and escape
74 // them. |terms| may be escaped as path or query depending on |is_in_query|; 71 // them. |terms| may be escaped as path or query depending on |is_in_query|;
75 // |original_query| is always escaped as query. Returns whether the encoding 72 // |original_query| is always escaped as query. Returns whether the encoding
76 // process succeeded. 73 // process succeeded.
77 bool TryEncoding(const base::string16& terms, 74 bool TryEncoding(const base::string16& terms,
78 const base::string16& original_query, 75 const base::string16& original_query,
79 const char* encoding, 76 const char* encoding,
80 bool is_in_query, 77 bool is_in_query,
81 base::string16* escaped_terms, 78 base::string16* escaped_terms,
82 base::string16* escaped_original_query) { 79 base::string16* escaped_original_query) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 parameter_position->begin = begin; 153 parameter_position->begin = begin;
157 parameter_position->len = arraysize(kSearchTermsParameterFullEscaped) - 1; 154 parameter_position->len = arraysize(kSearchTermsParameterFullEscaped) - 1;
158 return true; 155 return true;
159 } 156 }
160 157
161 bool IsTemplateParameterString(const std::string& param) { 158 bool IsTemplateParameterString(const std::string& param) {
162 return (param.length() > 2) && (*(param.begin()) == kStartParameter) && 159 return (param.length() > 2) && (*(param.begin()) == kStartParameter) &&
163 (*(param.rbegin()) == kEndParameter); 160 (*(param.rbegin()) == kEndParameter);
164 } 161 }
165 162
166 // Special case for search_terms_replacement_key comparison, because of
167 // its special initialization in TemplateUrl constructor.
168 bool SearchTermsReplacementKeysMatch(
169 const std::string& search_terms_replacement_key1,
170 const std::string& search_terms_replacement_key2) {
171 if (search_terms_replacement_key1 == search_terms_replacement_key2)
172 return true;
173 if (search_terms_replacement_key1 == google_util::kInstantExtendedAPIParam &&
174 search_terms_replacement_key2 == kGoogleInstantExtendedEnabledKey)
175 return true;
176 if (search_terms_replacement_key2 == google_util::kInstantExtendedAPIParam &&
177 search_terms_replacement_key1 == kGoogleInstantExtendedEnabledKey)
178 return true;
179 return false;
180 }
181
182 } // namespace 163 } // namespace
183 164
184 165
185 // TemplateURLRef::SearchTermsArgs -------------------------------------------- 166 // TemplateURLRef::SearchTermsArgs --------------------------------------------
186 167
187 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( 168 TemplateURLRef::SearchTermsArgs::SearchTermsArgs(
188 const base::string16& search_terms) 169 const base::string16& search_terms)
189 : search_terms(search_terms), 170 : search_terms(search_terms),
190 input_type(metrics::OmniboxInputType::INVALID), 171 input_type(metrics::OmniboxInputType::INVALID),
191 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE), 172 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE),
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start)); 622 Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start));
642 } else if (parameter == "google:imageURL") { 623 } else if (parameter == "google:imageURL") {
643 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL, 624 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL,
644 start)); 625 start));
645 } else if (parameter == "google:inputType") { 626 } else if (parameter == "google:inputType") {
646 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_INPUT_TYPE, 627 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_INPUT_TYPE,
647 start)); 628 start));
648 } else if (parameter == "google:instantExtendedEnabledParameter") { 629 } else if (parameter == "google:instantExtendedEnabledParameter") {
649 replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED, 630 replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED,
650 start)); 631 start));
651 } else if (parameter == kGoogleInstantExtendedEnabledKey) { 632 } else if (parameter == "google:instantExtendedEnabledKey") {
652 url->insert(start, google_util::kInstantExtendedAPIParam); 633 url->insert(start, google_util::kInstantExtendedAPIParam);
653 } else if (parameter == "google:iOSSearchLanguage") { 634 } else if (parameter == "google:iOSSearchLanguage") {
654 replacements->push_back(Replacement(GOOGLE_IOS_SEARCH_LANGUAGE, start)); 635 replacements->push_back(Replacement(GOOGLE_IOS_SEARCH_LANGUAGE, start));
655 } else if (parameter == "google:contextualSearchVersion") { 636 } else if (parameter == "google:contextualSearchVersion") {
656 replacements->push_back( 637 replacements->push_back(
657 Replacement(GOOGLE_CONTEXTUAL_SEARCH_VERSION, start)); 638 Replacement(GOOGLE_CONTEXTUAL_SEARCH_VERSION, start));
658 } else if (parameter == "google:contextualSearchContextData") { 639 } else if (parameter == "google:contextualSearchContextData") {
659 replacements->push_back( 640 replacements->push_back(
660 Replacement(GOOGLE_CONTEXTUAL_SEARCH_CONTEXT_DATA, start)); 641 Replacement(GOOGLE_CONTEXTUAL_SEARCH_CONTEXT_DATA, start));
661 } else if (parameter == "google:originalQueryForSuggestion") { 642 } else if (parameter == "google:originalQueryForSuggestion") {
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 suggestions_url_ref_(this, TemplateURLRef::SUGGEST), 1185 suggestions_url_ref_(this, TemplateURLRef::SUGGEST),
1205 instant_url_ref_(this, TemplateURLRef::INSTANT), 1186 instant_url_ref_(this, TemplateURLRef::INSTANT),
1206 image_url_ref_(this, TemplateURLRef::IMAGE), 1187 image_url_ref_(this, TemplateURLRef::IMAGE),
1207 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), 1188 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB),
1208 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH), 1189 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH),
1209 type_(type), 1190 type_(type),
1210 engine_type_(SEARCH_ENGINE_UNKNOWN) { 1191 engine_type_(SEARCH_ENGINE_UNKNOWN) {
1211 ResizeURLRefVector(); 1192 ResizeURLRefVector();
1212 SetPrepopulateId(data_.prepopulate_id); 1193 SetPrepopulateId(data_.prepopulate_id);
1213 1194
1214 if (data_.search_terms_replacement_key == kGoogleInstantExtendedEnabledKey) 1195 if (data_.search_terms_replacement_key ==
1196 "{google:instantExtendedEnabledKey}") {
1215 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; 1197 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam;
1198 }
1216 } 1199 }
1217 1200
1218 TemplateURL::~TemplateURL() { 1201 TemplateURL::~TemplateURL() {
1219 } 1202 }
1220 1203
1221 // static 1204 // static
1222 base::string16 TemplateURL::GenerateKeyword(const GURL& url) { 1205 base::string16 TemplateURL::GenerateKeyword(const GURL& url) {
1223 DCHECK(url.is_valid()); 1206 DCHECK(url.is_valid());
1224 // Strip "www." off the front of the keyword; otherwise the keyword won't work 1207 // Strip "www." off the front of the keyword; otherwise the keyword won't work
1225 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . 1208 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 .
(...skipping 24 matching lines...) Expand all
1250 } 1233 }
1251 1234
1252 // static 1235 // static
1253 bool TemplateURL::MatchesData(const TemplateURL* t_url, 1236 bool TemplateURL::MatchesData(const TemplateURL* t_url,
1254 const TemplateURLData* data, 1237 const TemplateURLData* data,
1255 const SearchTermsData& search_terms_data) { 1238 const SearchTermsData& search_terms_data) {
1256 if (!t_url || !data) 1239 if (!t_url || !data)
1257 return !t_url && !data; 1240 return !t_url && !data;
1258 1241
1259 return (t_url->short_name() == data->short_name()) && 1242 return (t_url->short_name() == data->short_name()) &&
1260 t_url->HasSameKeywordAs(*data, search_terms_data) && 1243 t_url->HasSameKeywordAs(*data, search_terms_data) &&
1261 (t_url->url() == data->url()) && 1244 (t_url->url() == data->url()) &&
1262 (t_url->suggestions_url() == data->suggestions_url) && 1245 (t_url->suggestions_url() == data->suggestions_url) &&
1263 (t_url->instant_url() == data->instant_url) && 1246 (t_url->instant_url() == data->instant_url) &&
1264 (t_url->image_url() == data->image_url) && 1247 (t_url->image_url() == data->image_url) &&
1265 (t_url->new_tab_url() == data->new_tab_url) && 1248 (t_url->new_tab_url() == data->new_tab_url) &&
1266 (t_url->search_url_post_params() == data->search_url_post_params) && 1249 (t_url->search_url_post_params() == data->search_url_post_params) &&
1267 (t_url->suggestions_url_post_params() == 1250 (t_url->suggestions_url_post_params() ==
1268 data->suggestions_url_post_params) && 1251 data->suggestions_url_post_params) &&
1269 (t_url->instant_url_post_params() == data->instant_url_post_params) && 1252 (t_url->instant_url_post_params() == data->instant_url_post_params) &&
1270 (t_url->image_url_post_params() == data->image_url_post_params) && 1253 (t_url->image_url_post_params() == data->image_url_post_params) &&
1271 (t_url->favicon_url() == data->favicon_url) && 1254 (t_url->favicon_url() == data->favicon_url) &&
1272 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && 1255 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) &&
1273 (t_url->input_encodings() == data->input_encodings) && 1256 (t_url->input_encodings() == data->input_encodings) &&
1274 (t_url->alternate_urls() == data->alternate_urls) && 1257 (t_url->alternate_urls() == data->alternate_urls) &&
1275 SearchTermsReplacementKeysMatch(t_url->search_terms_replacement_key(), 1258 (t_url->search_terms_replacement_key() ==
1276 data->search_terms_replacement_key); 1259 data->search_terms_replacement_key);
1277 } 1260 }
1278 1261
1279 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { 1262 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const {
1280 base::string16 bidi_safe_short_name = data_.short_name(); 1263 base::string16 bidi_safe_short_name = data_.short_name();
1281 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); 1264 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name);
1282 return bidi_safe_short_name; 1265 return bidi_safe_short_name;
1283 } 1266 }
1284 1267
1285 bool TemplateURL::SupportsReplacement( 1268 bool TemplateURL::SupportsReplacement(
1286 const SearchTermsData& search_terms_data) const { 1269 const SearchTermsData& search_terms_data) const {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 // patterns. This means that given patterns 1524 // patterns. This means that given patterns
1542 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1525 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1543 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1526 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1544 // return false. This is important for at least Google, where such URLs 1527 // return false. This is important for at least Google, where such URLs
1545 // are invalid. 1528 // are invalid.
1546 return !search_terms->empty(); 1529 return !search_terms->empty();
1547 } 1530 }
1548 } 1531 }
1549 return false; 1532 return false;
1550 } 1533 }
OLDNEW
« no previous file with comments | « no previous file | components/search_engines/template_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698