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

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

Issue 2479113002: Make extensions DSE persistent in browser prefs (Closed)
Patch Set: Added DSE tests Created 4 years 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 parameter_position->begin = begin; 156 parameter_position->begin = begin;
157 parameter_position->len = arraysize(kSearchTermsParameterFullEscaped) - 1; 157 parameter_position->len = arraysize(kSearchTermsParameterFullEscaped) - 1;
158 return true; 158 return true;
159 } 159 }
160 160
161 bool IsTemplateParameterString(const std::string& param) { 161 bool IsTemplateParameterString(const std::string& param) {
162 return (param.length() > 2) && (*(param.begin()) == kStartParameter) && 162 return (param.length() > 2) && (*(param.begin()) == kStartParameter) &&
163 (*(param.rbegin()) == kEndParameter); 163 (*(param.rbegin()) == kEndParameter);
164 } 164 }
165 165
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 166 } // namespace
183 167
184 168
185 // TemplateURLRef::SearchTermsArgs -------------------------------------------- 169 // TemplateURLRef::SearchTermsArgs --------------------------------------------
186 170
187 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( 171 TemplateURLRef::SearchTermsArgs::SearchTermsArgs(
188 const base::string16& search_terms) 172 const base::string16& search_terms)
189 : search_terms(search_terms), 173 : search_terms(search_terms),
190 input_type(metrics::OmniboxInputType::INVALID), 174 input_type(metrics::OmniboxInputType::INVALID),
191 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE), 175 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE),
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 (t_url->instant_url_post_params() == data->instant_url_post_params) && 1253 (t_url->instant_url_post_params() == data->instant_url_post_params) &&
1270 (t_url->image_url_post_params() == data->image_url_post_params) && 1254 (t_url->image_url_post_params() == data->image_url_post_params) &&
1271 (t_url->favicon_url() == data->favicon_url) && 1255 (t_url->favicon_url() == data->favicon_url) &&
1272 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && 1256 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) &&
1273 (t_url->input_encodings() == data->input_encodings) && 1257 (t_url->input_encodings() == data->input_encodings) &&
1274 (t_url->alternate_urls() == data->alternate_urls) && 1258 (t_url->alternate_urls() == data->alternate_urls) &&
1275 SearchTermsReplacementKeysMatch(t_url->search_terms_replacement_key(), 1259 SearchTermsReplacementKeysMatch(t_url->search_terms_replacement_key(),
1276 data->search_terms_replacement_key); 1260 data->search_terms_replacement_key);
1277 } 1261 }
1278 1262
1263 // static
1264 // Special case for search_terms_replacement_key comparison, because of
1265 // its special initialization in TemplateUrl constructor.
vasilii 2016/11/30 14:00:03 Move the comment to the header.
Alexander Yashkin 2016/12/05 18:16:48 Done
1266 bool TemplateURL::SearchTermsReplacementKeysMatch(
1267 const std::string& search_terms_replacement_key1,
1268 const std::string& search_terms_replacement_key2) {
1269 if (search_terms_replacement_key1 == search_terms_replacement_key2)
1270 return true;
1271 if (search_terms_replacement_key1 == google_util::kInstantExtendedAPIParam &&
1272 search_terms_replacement_key2 == kGoogleInstantExtendedEnabledKey)
1273 return true;
1274 if (search_terms_replacement_key2 == google_util::kInstantExtendedAPIParam &&
1275 search_terms_replacement_key1 == kGoogleInstantExtendedEnabledKey)
1276 return true;
1277 return false;
1278 }
1279
1279 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { 1280 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const {
1280 base::string16 bidi_safe_short_name = data_.short_name(); 1281 base::string16 bidi_safe_short_name = data_.short_name();
1281 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); 1282 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name);
1282 return bidi_safe_short_name; 1283 return bidi_safe_short_name;
1283 } 1284 }
1284 1285
1285 bool TemplateURL::SupportsReplacement( 1286 bool TemplateURL::SupportsReplacement(
1286 const SearchTermsData& search_terms_data) const { 1287 const SearchTermsData& search_terms_data) const {
1287 return url_ref_->SupportsReplacement(search_terms_data); 1288 return url_ref_->SupportsReplacement(search_terms_data);
1288 } 1289 }
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 // patterns. This means that given patterns 1542 // patterns. This means that given patterns
1542 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1543 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1543 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1544 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1544 // return false. This is important for at least Google, where such URLs 1545 // return false. This is important for at least Google, where such URLs
1545 // are invalid. 1546 // are invalid.
1546 return !search_terms->empty(); 1547 return !search_terms->empty();
1547 } 1548 }
1548 } 1549 }
1549 return false; 1550 return false;
1550 } 1551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698