OLD | NEW |
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 Loading... |
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 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 (t_url->instant_url_post_params() == data->instant_url_post_params) && | 1258 (t_url->instant_url_post_params() == data->instant_url_post_params) && |
1275 (t_url->image_url_post_params() == data->image_url_post_params) && | 1259 (t_url->image_url_post_params() == data->image_url_post_params) && |
1276 (t_url->favicon_url() == data->favicon_url) && | 1260 (t_url->favicon_url() == data->favicon_url) && |
1277 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && | 1261 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && |
1278 (t_url->input_encodings() == data->input_encodings) && | 1262 (t_url->input_encodings() == data->input_encodings) && |
1279 (t_url->alternate_urls() == data->alternate_urls) && | 1263 (t_url->alternate_urls() == data->alternate_urls) && |
1280 SearchTermsReplacementKeysMatch(t_url->search_terms_replacement_key(), | 1264 SearchTermsReplacementKeysMatch(t_url->search_terms_replacement_key(), |
1281 data->search_terms_replacement_key); | 1265 data->search_terms_replacement_key); |
1282 } | 1266 } |
1283 | 1267 |
| 1268 // static |
| 1269 bool TemplateURL::SearchTermsReplacementKeysMatch( |
| 1270 const std::string& search_terms_replacement_key1, |
| 1271 const std::string& search_terms_replacement_key2) { |
| 1272 if (search_terms_replacement_key1 == google_util::kInstantExtendedAPIParam && |
| 1273 search_terms_replacement_key2 == kGoogleInstantExtendedEnabledKeyFull) |
| 1274 return true; |
| 1275 if (search_terms_replacement_key2 == google_util::kInstantExtendedAPIParam && |
| 1276 search_terms_replacement_key1 == kGoogleInstantExtendedEnabledKeyFull) |
| 1277 return true; |
| 1278 return search_terms_replacement_key1 == search_terms_replacement_key2; |
| 1279 } |
| 1280 |
1284 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { | 1281 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { |
1285 base::string16 bidi_safe_short_name = data_.short_name(); | 1282 base::string16 bidi_safe_short_name = data_.short_name(); |
1286 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); | 1283 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); |
1287 return bidi_safe_short_name; | 1284 return bidi_safe_short_name; |
1288 } | 1285 } |
1289 | 1286 |
1290 bool TemplateURL::SupportsReplacement( | 1287 bool TemplateURL::SupportsReplacement( |
1291 const SearchTermsData& search_terms_data) const { | 1288 const SearchTermsData& search_terms_data) const { |
1292 return url_ref_->SupportsReplacement(search_terms_data); | 1289 return url_ref_->SupportsReplacement(search_terms_data); |
1293 } | 1290 } |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 // patterns. This means that given patterns | 1543 // patterns. This means that given patterns |
1547 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1544 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1548 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1545 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1549 // return false. This is important for at least Google, where such URLs | 1546 // return false. This is important for at least Google, where such URLs |
1550 // are invalid. | 1547 // are invalid. |
1551 return !search_terms->empty(); | 1548 return !search_terms->empty(); |
1552 } | 1549 } |
1553 } | 1550 } |
1554 return false; | 1551 return false; |
1555 } | 1552 } |
OLD | NEW |