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

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

Issue 2672653002: Revert of Fix TemplateUrl::MatchesData comparison of search_terms_replacement_key (patchset #2 id:2… (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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start)); 598 Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start));
618 } else if (parameter == "google:imageURL") { 599 } else if (parameter == "google:imageURL") {
619 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL, 600 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL,
620 start)); 601 start));
621 } else if (parameter == "google:inputType") { 602 } else if (parameter == "google:inputType") {
622 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_INPUT_TYPE, 603 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_INPUT_TYPE,
623 start)); 604 start));
624 } else if (parameter == "google:instantExtendedEnabledParameter") { 605 } else if (parameter == "google:instantExtendedEnabledParameter") {
625 replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED, 606 replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED,
626 start)); 607 start));
627 } else if (parameter == kGoogleInstantExtendedEnabledKey) { 608 } else if (parameter == "google:instantExtendedEnabledKey") {
628 url->insert(start, google_util::kInstantExtendedAPIParam); 609 url->insert(start, google_util::kInstantExtendedAPIParam);
629 } else if (parameter == "google:iOSSearchLanguage") { 610 } else if (parameter == "google:iOSSearchLanguage") {
630 replacements->push_back(Replacement(GOOGLE_IOS_SEARCH_LANGUAGE, start)); 611 replacements->push_back(Replacement(GOOGLE_IOS_SEARCH_LANGUAGE, start));
631 } else if (parameter == "google:contextualSearchVersion") { 612 } else if (parameter == "google:contextualSearchVersion") {
632 replacements->push_back( 613 replacements->push_back(
633 Replacement(GOOGLE_CONTEXTUAL_SEARCH_VERSION, start)); 614 Replacement(GOOGLE_CONTEXTUAL_SEARCH_VERSION, start));
634 } else if (parameter == "google:contextualSearchContextData") { 615 } else if (parameter == "google:contextualSearchContextData") {
635 replacements->push_back( 616 replacements->push_back(
636 Replacement(GOOGLE_CONTEXTUAL_SEARCH_CONTEXT_DATA, start)); 617 Replacement(GOOGLE_CONTEXTUAL_SEARCH_CONTEXT_DATA, start));
637 } else if (parameter == "google:originalQueryForSuggestion") { 618 } else if (parameter == "google:originalQueryForSuggestion") {
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 suggestions_url_ref_(this, TemplateURLRef::SUGGEST), 1151 suggestions_url_ref_(this, TemplateURLRef::SUGGEST),
1171 instant_url_ref_(this, TemplateURLRef::INSTANT), 1152 instant_url_ref_(this, TemplateURLRef::INSTANT),
1172 image_url_ref_(this, TemplateURLRef::IMAGE), 1153 image_url_ref_(this, TemplateURLRef::IMAGE),
1173 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), 1154 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB),
1174 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH), 1155 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH),
1175 type_(type), 1156 type_(type),
1176 engine_type_(SEARCH_ENGINE_UNKNOWN) { 1157 engine_type_(SEARCH_ENGINE_UNKNOWN) {
1177 ResizeURLRefVector(); 1158 ResizeURLRefVector();
1178 SetPrepopulateId(data_.prepopulate_id); 1159 SetPrepopulateId(data_.prepopulate_id);
1179 1160
1180 if (data_.search_terms_replacement_key == kGoogleInstantExtendedEnabledKey) 1161 if (data_.search_terms_replacement_key ==
1162 "{google:instantExtendedEnabledKey}") {
1181 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; 1163 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam;
1164 }
1182 } 1165 }
1183 1166
1184 TemplateURL::~TemplateURL() { 1167 TemplateURL::~TemplateURL() {
1185 } 1168 }
1186 1169
1187 // static 1170 // static
1188 base::string16 TemplateURL::GenerateKeyword(const GURL& url) { 1171 base::string16 TemplateURL::GenerateKeyword(const GURL& url) {
1189 DCHECK(url.is_valid()); 1172 DCHECK(url.is_valid());
1190 // Strip "www." off the front of the keyword; otherwise the keyword won't work 1173 // Strip "www." off the front of the keyword; otherwise the keyword won't work
1191 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . 1174 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 .
(...skipping 24 matching lines...) Expand all
1216 } 1199 }
1217 1200
1218 // static 1201 // static
1219 bool TemplateURL::MatchesData(const TemplateURL* t_url, 1202 bool TemplateURL::MatchesData(const TemplateURL* t_url,
1220 const TemplateURLData* data, 1203 const TemplateURLData* data,
1221 const SearchTermsData& search_terms_data) { 1204 const SearchTermsData& search_terms_data) {
1222 if (!t_url || !data) 1205 if (!t_url || !data)
1223 return !t_url && !data; 1206 return !t_url && !data;
1224 1207
1225 return (t_url->short_name() == data->short_name()) && 1208 return (t_url->short_name() == data->short_name()) &&
1226 t_url->HasSameKeywordAs(*data, search_terms_data) && 1209 t_url->HasSameKeywordAs(*data, search_terms_data) &&
1227 (t_url->url() == data->url()) && 1210 (t_url->url() == data->url()) &&
1228 (t_url->suggestions_url() == data->suggestions_url) && 1211 (t_url->suggestions_url() == data->suggestions_url) &&
1229 (t_url->instant_url() == data->instant_url) && 1212 (t_url->instant_url() == data->instant_url) &&
1230 (t_url->image_url() == data->image_url) && 1213 (t_url->image_url() == data->image_url) &&
1231 (t_url->new_tab_url() == data->new_tab_url) && 1214 (t_url->new_tab_url() == data->new_tab_url) &&
1232 (t_url->search_url_post_params() == data->search_url_post_params) && 1215 (t_url->search_url_post_params() == data->search_url_post_params) &&
1233 (t_url->suggestions_url_post_params() == 1216 (t_url->suggestions_url_post_params() ==
1234 data->suggestions_url_post_params) && 1217 data->suggestions_url_post_params) &&
1235 (t_url->instant_url_post_params() == data->instant_url_post_params) && 1218 (t_url->instant_url_post_params() == data->instant_url_post_params) &&
1236 (t_url->image_url_post_params() == data->image_url_post_params) && 1219 (t_url->image_url_post_params() == data->image_url_post_params) &&
1237 (t_url->favicon_url() == data->favicon_url) && 1220 (t_url->favicon_url() == data->favicon_url) &&
1238 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && 1221 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) &&
1239 (t_url->input_encodings() == data->input_encodings) && 1222 (t_url->input_encodings() == data->input_encodings) &&
1240 (t_url->alternate_urls() == data->alternate_urls) && 1223 (t_url->alternate_urls() == data->alternate_urls) &&
1241 SearchTermsReplacementKeysMatch(t_url->search_terms_replacement_key(), 1224 (t_url->search_terms_replacement_key() ==
1242 data->search_terms_replacement_key); 1225 data->search_terms_replacement_key);
1243 } 1226 }
1244 1227
1245 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { 1228 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const {
1246 base::string16 bidi_safe_short_name = data_.short_name(); 1229 base::string16 bidi_safe_short_name = data_.short_name();
1247 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); 1230 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name);
1248 return bidi_safe_short_name; 1231 return bidi_safe_short_name;
1249 } 1232 }
1250 1233
1251 bool TemplateURL::SupportsReplacement( 1234 bool TemplateURL::SupportsReplacement(
1252 const SearchTermsData& search_terms_data) const { 1235 const SearchTermsData& search_terms_data) const {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 // patterns. This means that given patterns 1490 // patterns. This means that given patterns
1508 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1491 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1509 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1492 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1510 // return false. This is important for at least Google, where such URLs 1493 // return false. This is important for at least Google, where such URLs
1511 // are invalid. 1494 // are invalid.
1512 return !search_terms->empty(); 1495 return !search_terms->empty();
1513 } 1496 }
1514 } 1497 }
1515 return false; 1498 return false;
1516 } 1499 }
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