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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 parameter_position->begin = begin; | 153 parameter_position->begin = begin; |
154 parameter_position->len = arraysize(kSearchTermsParameterFullEscaped) - 1; | 154 parameter_position->len = arraysize(kSearchTermsParameterFullEscaped) - 1; |
155 return true; | 155 return true; |
156 } | 156 } |
157 | 157 |
158 bool IsTemplateParameterString(const std::string& param) { | 158 bool IsTemplateParameterString(const std::string& param) { |
159 return (param.length() > 2) && (*(param.begin()) == kStartParameter) && | 159 return (param.length() > 2) && (*(param.begin()) == kStartParameter) && |
160 (*(param.rbegin()) == kEndParameter); | 160 (*(param.rbegin()) == kEndParameter); |
161 } | 161 } |
162 | 162 |
163 // Special case for search_terms_replacement_key comparison, because of | |
164 // its special initialization in TemplateUrl constructor. | |
165 bool SearchTermsReplacementKeysMatch(const std::string& key1, | |
166 const std::string& key2) { | |
167 const auto IsInstantExtended = [](const std::string& key) { | |
168 return (key == google_util::kInstantExtendedAPIParam) || | |
169 (key == google_util::kGoogleInstantExtendedEnabledKeyFull); | |
170 }; | |
171 return (key1 == key2) || (IsInstantExtended(key1) && IsInstantExtended(key2)); | |
172 } | |
173 | |
174 } // namespace | 163 } // namespace |
175 | 164 |
176 // TemplateURLRef::SearchTermsArgs -------------------------------------------- | 165 // TemplateURLRef::SearchTermsArgs -------------------------------------------- |
177 | 166 |
178 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( | 167 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( |
179 const base::string16& search_terms) | 168 const base::string16& search_terms) |
180 : search_terms(search_terms), | 169 : search_terms(search_terms), |
181 input_type(metrics::OmniboxInputType::INVALID), | 170 input_type(metrics::OmniboxInputType::INVALID), |
182 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE), | 171 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE), |
183 cursor_position(base::string16::npos), | 172 cursor_position(base::string16::npos), |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 (t_url->instant_url_post_params() == data->instant_url_post_params) && | 1216 (t_url->instant_url_post_params() == data->instant_url_post_params) && |
1228 (t_url->image_url_post_params() == data->image_url_post_params) && | 1217 (t_url->image_url_post_params() == data->image_url_post_params) && |
1229 (t_url->favicon_url() == data->favicon_url) && | 1218 (t_url->favicon_url() == data->favicon_url) && |
1230 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && | 1219 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && |
1231 (t_url->input_encodings() == data->input_encodings) && | 1220 (t_url->input_encodings() == data->input_encodings) && |
1232 (t_url->alternate_urls() == data->alternate_urls) && | 1221 (t_url->alternate_urls() == data->alternate_urls) && |
1233 SearchTermsReplacementKeysMatch(t_url->search_terms_replacement_key(), | 1222 SearchTermsReplacementKeysMatch(t_url->search_terms_replacement_key(), |
1234 data->search_terms_replacement_key); | 1223 data->search_terms_replacement_key); |
1235 } | 1224 } |
1236 | 1225 |
| 1226 // Special case for search_terms_replacement_key comparison, because of |
| 1227 // its special initialization in TemplateUrl constructor. |
| 1228 bool TemplateURL::SearchTermsReplacementKeysMatch(const std::string& key1, |
| 1229 const std::string& key2) { |
| 1230 const auto IsInstantExtended = [](const std::string& key) { |
| 1231 return (key == google_util::kInstantExtendedAPIParam) || |
| 1232 (key == google_util::kGoogleInstantExtendedEnabledKeyFull); |
| 1233 }; |
| 1234 return (key1 == key2) || (IsInstantExtended(key1) && IsInstantExtended(key2)); |
| 1235 } |
| 1236 |
1237 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { | 1237 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { |
1238 base::string16 bidi_safe_short_name = data_.short_name(); | 1238 base::string16 bidi_safe_short_name = data_.short_name(); |
1239 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); | 1239 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); |
1240 return bidi_safe_short_name; | 1240 return bidi_safe_short_name; |
1241 } | 1241 } |
1242 | 1242 |
1243 bool TemplateURL::SupportsReplacement( | 1243 bool TemplateURL::SupportsReplacement( |
1244 const SearchTermsData& search_terms_data) const { | 1244 const SearchTermsData& search_terms_data) const { |
1245 return url_ref_->SupportsReplacement(search_terms_data); | 1245 return url_ref_->SupportsReplacement(search_terms_data); |
1246 } | 1246 } |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 // patterns. This means that given patterns | 1499 // patterns. This means that given patterns |
1500 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1500 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1501 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1501 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1502 // return false. This is important for at least Google, where such URLs | 1502 // return false. This is important for at least Google, where such URLs |
1503 // are invalid. | 1503 // are invalid. |
1504 return !search_terms->empty(); | 1504 return !search_terms->empty(); |
1505 } | 1505 } |
1506 } | 1506 } |
1507 return false; | 1507 return false; |
1508 } | 1508 } |
OLD | NEW |