| 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 == search_terms_replacement_key2) | 
 |  1273     return true; | 
 |  1274   if (search_terms_replacement_key1 == google_util::kInstantExtendedAPIParam && | 
 |  1275       search_terms_replacement_key2 == kGoogleInstantExtendedEnabledKeyFull) | 
 |  1276     return true; | 
 |  1277   if (search_terms_replacement_key2 == google_util::kInstantExtendedAPIParam && | 
 |  1278       search_terms_replacement_key1 == kGoogleInstantExtendedEnabledKeyFull) | 
 |  1279     return true; | 
 |  1280   return false; | 
 |  1281 } | 
 |  1282  | 
|  1284 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { |  1283 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { | 
|  1285   base::string16 bidi_safe_short_name = data_.short_name(); |  1284   base::string16 bidi_safe_short_name = data_.short_name(); | 
|  1286   base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); |  1285   base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); | 
|  1287   return bidi_safe_short_name; |  1286   return bidi_safe_short_name; | 
|  1288 } |  1287 } | 
|  1289  |  1288  | 
|  1290 bool TemplateURL::SupportsReplacement( |  1289 bool TemplateURL::SupportsReplacement( | 
|  1291     const SearchTermsData& search_terms_data) const { |  1290     const SearchTermsData& search_terms_data) const { | 
|  1292   return url_ref_->SupportsReplacement(search_terms_data); |  1291   return url_ref_->SupportsReplacement(search_terms_data); | 
|  1293 } |  1292 } | 
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1546       // patterns. This means that given patterns |  1545       // patterns. This means that given patterns | 
|  1547       //    [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |  1546       //    [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 
|  1548       // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |  1547       // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 
|  1549       // return false. This is important for at least Google, where such URLs |  1548       // return false. This is important for at least Google, where such URLs | 
|  1550       // are invalid. |  1549       // are invalid. | 
|  1551       return !search_terms->empty(); |  1550       return !search_terms->empty(); | 
|  1552     } |  1551     } | 
|  1553   } |  1552   } | 
|  1554   return false; |  1553   return false; | 
|  1555 } |  1554 } | 
| OLD | NEW |