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

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

Issue 2639153002: Make extensions DSE persistent in browser prefs (Reland) (Closed)
Patch Set: Fixed flakiness caused by extension reload while TemplateURLService is not loaded 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 parameter_position->begin = begin; 158 parameter_position->begin = begin;
159 parameter_position->len = arraysize(kSearchTermsParameterFullEscaped) - 1; 159 parameter_position->len = arraysize(kSearchTermsParameterFullEscaped) - 1;
160 return true; 160 return true;
161 } 161 }
162 162
163 bool IsTemplateParameterString(const std::string& param) { 163 bool IsTemplateParameterString(const std::string& param) {
164 return (param.length() > 2) && (*(param.begin()) == kStartParameter) && 164 return (param.length() > 2) && (*(param.begin()) == kStartParameter) &&
165 (*(param.rbegin()) == kEndParameter); 165 (*(param.rbegin()) == kEndParameter);
166 } 166 }
167 167
168 // Special case for search_terms_replacement_key comparison, because of
169 // its special initialization in TemplateUrl constructor.
170 bool SearchTermsReplacementKeysMatch(
171 const std::string& search_terms_replacement_key1,
172 const std::string& search_terms_replacement_key2) {
173 if (search_terms_replacement_key1 == search_terms_replacement_key2)
174 return true;
175 if (search_terms_replacement_key1 == google_util::kInstantExtendedAPIParam &&
176 search_terms_replacement_key2 == kGoogleInstantExtendedEnabledKeyFull)
177 return true;
178 if (search_terms_replacement_key2 == google_util::kInstantExtendedAPIParam &&
179 search_terms_replacement_key1 == kGoogleInstantExtendedEnabledKeyFull)
180 return true;
181 return false;
182 }
183
184 } // namespace 168 } // namespace
185 169
186 170
187 // TemplateURLRef::SearchTermsArgs -------------------------------------------- 171 // TemplateURLRef::SearchTermsArgs --------------------------------------------
188 172
189 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( 173 TemplateURLRef::SearchTermsArgs::SearchTermsArgs(
190 const base::string16& search_terms) 174 const base::string16& search_terms)
191 : search_terms(search_terms), 175 : search_terms(search_terms),
192 input_type(metrics::OmniboxInputType::INVALID), 176 input_type(metrics::OmniboxInputType::INVALID),
193 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE), 177 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE),
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 (t_url->instant_url_post_params() == data->instant_url_post_params) && 1222 (t_url->instant_url_post_params() == data->instant_url_post_params) &&
1239 (t_url->image_url_post_params() == data->image_url_post_params) && 1223 (t_url->image_url_post_params() == data->image_url_post_params) &&
1240 (t_url->favicon_url() == data->favicon_url) && 1224 (t_url->favicon_url() == data->favicon_url) &&
1241 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && 1225 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) &&
1242 (t_url->input_encodings() == data->input_encodings) && 1226 (t_url->input_encodings() == data->input_encodings) &&
1243 (t_url->alternate_urls() == data->alternate_urls) && 1227 (t_url->alternate_urls() == data->alternate_urls) &&
1244 SearchTermsReplacementKeysMatch(t_url->search_terms_replacement_key(), 1228 SearchTermsReplacementKeysMatch(t_url->search_terms_replacement_key(),
1245 data->search_terms_replacement_key); 1229 data->search_terms_replacement_key);
1246 } 1230 }
1247 1231
1232 // static
1233 bool TemplateURL::SearchTermsReplacementKeysMatch(
1234 const std::string& search_terms_replacement_key1,
1235 const std::string& search_terms_replacement_key2) {
1236 if (search_terms_replacement_key1 == google_util::kInstantExtendedAPIParam &&
1237 search_terms_replacement_key2 == kGoogleInstantExtendedEnabledKeyFull)
1238 return true;
1239 if (search_terms_replacement_key2 == google_util::kInstantExtendedAPIParam &&
1240 search_terms_replacement_key1 == kGoogleInstantExtendedEnabledKeyFull)
1241 return true;
1242 return search_terms_replacement_key1 == search_terms_replacement_key2;
1243 }
1244
1248 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { 1245 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const {
1249 base::string16 bidi_safe_short_name = data_.short_name(); 1246 base::string16 bidi_safe_short_name = data_.short_name();
1250 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); 1247 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name);
1251 return bidi_safe_short_name; 1248 return bidi_safe_short_name;
1252 } 1249 }
1253 1250
1254 bool TemplateURL::SupportsReplacement( 1251 bool TemplateURL::SupportsReplacement(
1255 const SearchTermsData& search_terms_data) const { 1252 const SearchTermsData& search_terms_data) const {
1256 return url_ref_->SupportsReplacement(search_terms_data); 1253 return url_ref_->SupportsReplacement(search_terms_data);
1257 } 1254 }
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 // patterns. This means that given patterns 1507 // patterns. This means that given patterns
1511 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1508 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1512 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1509 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1513 // return false. This is important for at least Google, where such URLs 1510 // return false. This is important for at least Google, where such URLs
1514 // are invalid. 1511 // are invalid.
1515 return !search_terms->empty(); 1512 return !search_terms->empty();
1516 } 1513 }
1517 } 1514 }
1518 return false; 1515 return false;
1519 } 1516 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698