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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 // Display value for kGoogleUnescapedSearchTermsParameter. | 60 // Display value for kGoogleUnescapedSearchTermsParameter. |
61 const char kDisplayUnescapedSearchTerms[] = "%S"; | 61 const char kDisplayUnescapedSearchTerms[] = "%S"; |
62 | 62 |
63 // Used if the count parameter is not optional. Indicates we want 10 search | 63 // Used if the count parameter is not optional. Indicates we want 10 search |
64 // results. | 64 // results. |
65 const char kDefaultCount[] = "10"; | 65 const char kDefaultCount[] = "10"; |
66 | 66 |
67 // Used if the output encoding parameter is required. | 67 // Used if the output encoding parameter is required. |
68 const char kOutputEncodingType[] = "UTF-8"; | 68 const char kOutputEncodingType[] = "UTF-8"; |
69 | 69 |
70 const char kGoogleInstantExtendedEnabledKey[] = | |
Peter Kasting
2016/11/21 02:24:50
Nit: constexpr (the rest of these here can be cons
| |
71 "{google:instantExtendedEnabledKey}"; | |
72 | |
70 // Attempts to encode |terms| and |original_query| in |encoding| and escape | 73 // Attempts to encode |terms| and |original_query| in |encoding| and escape |
71 // them. |terms| may be escaped as path or query depending on |is_in_query|; | 74 // them. |terms| may be escaped as path or query depending on |is_in_query|; |
72 // |original_query| is always escaped as query. Returns whether the encoding | 75 // |original_query| is always escaped as query. Returns whether the encoding |
73 // process succeeded. | 76 // process succeeded. |
74 bool TryEncoding(const base::string16& terms, | 77 bool TryEncoding(const base::string16& terms, |
75 const base::string16& original_query, | 78 const base::string16& original_query, |
76 const char* encoding, | 79 const char* encoding, |
77 bool is_in_query, | 80 bool is_in_query, |
78 base::string16* escaped_terms, | 81 base::string16* escaped_terms, |
79 base::string16* escaped_original_query) { | 82 base::string16* escaped_original_query) { |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start)); | 625 Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start)); |
623 } else if (parameter == "google:imageURL") { | 626 } else if (parameter == "google:imageURL") { |
624 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL, | 627 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL, |
625 start)); | 628 start)); |
626 } else if (parameter == "google:inputType") { | 629 } else if (parameter == "google:inputType") { |
627 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_INPUT_TYPE, | 630 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_INPUT_TYPE, |
628 start)); | 631 start)); |
629 } else if (parameter == "google:instantExtendedEnabledParameter") { | 632 } else if (parameter == "google:instantExtendedEnabledParameter") { |
630 replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED, | 633 replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED, |
631 start)); | 634 start)); |
632 } else if (parameter == "google:instantExtendedEnabledKey") { | 635 } else if (parameter == kGoogleInstantExtendedEnabledKey) { |
633 url->insert(start, google_util::kInstantExtendedAPIParam); | 636 url->insert(start, google_util::kInstantExtendedAPIParam); |
634 } else if (parameter == "google:iOSSearchLanguage") { | 637 } else if (parameter == "google:iOSSearchLanguage") { |
635 replacements->push_back(Replacement(GOOGLE_IOS_SEARCH_LANGUAGE, start)); | 638 replacements->push_back(Replacement(GOOGLE_IOS_SEARCH_LANGUAGE, start)); |
636 } else if (parameter == "google:contextualSearchVersion") { | 639 } else if (parameter == "google:contextualSearchVersion") { |
637 replacements->push_back( | 640 replacements->push_back( |
638 Replacement(GOOGLE_CONTEXTUAL_SEARCH_VERSION, start)); | 641 Replacement(GOOGLE_CONTEXTUAL_SEARCH_VERSION, start)); |
639 } else if (parameter == "google:contextualSearchContextData") { | 642 } else if (parameter == "google:contextualSearchContextData") { |
640 replacements->push_back( | 643 replacements->push_back( |
641 Replacement(GOOGLE_CONTEXTUAL_SEARCH_CONTEXT_DATA, start)); | 644 Replacement(GOOGLE_CONTEXTUAL_SEARCH_CONTEXT_DATA, start)); |
642 } else if (parameter == "google:originalQueryForSuggestion") { | 645 } else if (parameter == "google:originalQueryForSuggestion") { |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 suggestions_url_ref_(this, TemplateURLRef::SUGGEST), | 1188 suggestions_url_ref_(this, TemplateURLRef::SUGGEST), |
1186 instant_url_ref_(this, TemplateURLRef::INSTANT), | 1189 instant_url_ref_(this, TemplateURLRef::INSTANT), |
1187 image_url_ref_(this, TemplateURLRef::IMAGE), | 1190 image_url_ref_(this, TemplateURLRef::IMAGE), |
1188 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), | 1191 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), |
1189 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH), | 1192 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH), |
1190 type_(type), | 1193 type_(type), |
1191 engine_type_(SEARCH_ENGINE_UNKNOWN) { | 1194 engine_type_(SEARCH_ENGINE_UNKNOWN) { |
1192 ResizeURLRefVector(); | 1195 ResizeURLRefVector(); |
1193 SetPrepopulateId(data_.prepopulate_id); | 1196 SetPrepopulateId(data_.prepopulate_id); |
1194 | 1197 |
1195 if (data_.search_terms_replacement_key == | 1198 if (data_.search_terms_replacement_key == kGoogleInstantExtendedEnabledKey) { |
Peter Kasting
2016/11/21 02:24:50
Nit: {} no longer needed
| |
1196 "{google:instantExtendedEnabledKey}") { | |
1197 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; | 1199 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; |
1198 } | 1200 } |
1199 } | 1201 } |
1200 | 1202 |
1201 TemplateURL::~TemplateURL() { | 1203 TemplateURL::~TemplateURL() { |
1202 } | 1204 } |
1203 | 1205 |
1204 // static | 1206 // static |
1205 base::string16 TemplateURL::GenerateKeyword(const GURL& url) { | 1207 base::string16 TemplateURL::GenerateKeyword(const GURL& url) { |
1206 DCHECK(url.is_valid()); | 1208 DCHECK(url.is_valid()); |
(...skipping 25 matching lines...) Expand all Loading... | |
1232 return url.ReplaceComponents(rep); | 1234 return url.ReplaceComponents(rep); |
1233 } | 1235 } |
1234 | 1236 |
1235 // static | 1237 // static |
1236 bool TemplateURL::MatchesData(const TemplateURL* t_url, | 1238 bool TemplateURL::MatchesData(const TemplateURL* t_url, |
1237 const TemplateURLData* data, | 1239 const TemplateURLData* data, |
1238 const SearchTermsData& search_terms_data) { | 1240 const SearchTermsData& search_terms_data) { |
1239 if (!t_url || !data) | 1241 if (!t_url || !data) |
1240 return !t_url && !data; | 1242 return !t_url && !data; |
1241 | 1243 |
1242 return (t_url->short_name() == data->short_name()) && | 1244 if ((t_url->short_name() == data->short_name()) && |
1243 t_url->HasSameKeywordAs(*data, search_terms_data) && | 1245 t_url->HasSameKeywordAs(*data, search_terms_data) && |
1244 (t_url->url() == data->url()) && | 1246 (t_url->url() == data->url()) && |
1245 (t_url->suggestions_url() == data->suggestions_url) && | 1247 (t_url->suggestions_url() == data->suggestions_url) && |
1246 (t_url->instant_url() == data->instant_url) && | 1248 (t_url->instant_url() == data->instant_url) && |
1247 (t_url->image_url() == data->image_url) && | 1249 (t_url->image_url() == data->image_url) && |
1248 (t_url->new_tab_url() == data->new_tab_url) && | 1250 (t_url->new_tab_url() == data->new_tab_url) && |
1249 (t_url->search_url_post_params() == data->search_url_post_params) && | 1251 (t_url->search_url_post_params() == data->search_url_post_params) && |
1250 (t_url->suggestions_url_post_params() == | 1252 (t_url->suggestions_url_post_params() == |
1251 data->suggestions_url_post_params) && | 1253 data->suggestions_url_post_params) && |
1252 (t_url->instant_url_post_params() == data->instant_url_post_params) && | 1254 (t_url->instant_url_post_params() == data->instant_url_post_params) && |
1253 (t_url->image_url_post_params() == data->image_url_post_params) && | 1255 (t_url->image_url_post_params() == data->image_url_post_params) && |
1254 (t_url->favicon_url() == data->favicon_url) && | 1256 (t_url->favicon_url() == data->favicon_url) && |
1255 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && | 1257 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && |
1256 (t_url->input_encodings() == data->input_encodings) && | 1258 (t_url->input_encodings() == data->input_encodings) && |
1257 (t_url->alternate_urls() == data->alternate_urls) && | 1259 (t_url->alternate_urls() == data->alternate_urls)) { |
1258 (t_url->search_terms_replacement_key() == | 1260 // Special case for search_terms_replacement_key comparison, because of |
1259 data->search_terms_replacement_key); | 1261 // its special initialization in TemplateUrl constructor. |
Peter Kasting
2016/11/21 02:24:50
Nit: Might be more readable to add a local helper
| |
1262 if (t_url->search_terms_replacement_key() == | |
1263 data->search_terms_replacement_key) | |
Peter Kasting
2016/11/21 02:24:50
Nit: I don't think this indentation is what git cl
| |
1264 return true; | |
1265 return (t_url->search_terms_replacement_key() == | |
1266 google_util::kInstantExtendedAPIParam) && | |
1267 (data->search_terms_replacement_key == | |
1268 kGoogleInstantExtendedEnabledKey); | |
1269 } | |
1270 return false; | |
1260 } | 1271 } |
1261 | 1272 |
1262 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { | 1273 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { |
1263 base::string16 bidi_safe_short_name = data_.short_name(); | 1274 base::string16 bidi_safe_short_name = data_.short_name(); |
1264 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); | 1275 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); |
1265 return bidi_safe_short_name; | 1276 return bidi_safe_short_name; |
1266 } | 1277 } |
1267 | 1278 |
1268 bool TemplateURL::SupportsReplacement( | 1279 bool TemplateURL::SupportsReplacement( |
1269 const SearchTermsData& search_terms_data) const { | 1280 const SearchTermsData& search_terms_data) const { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1524 // patterns. This means that given patterns | 1535 // patterns. This means that given patterns |
1525 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1536 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1526 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1537 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1527 // return false. This is important for at least Google, where such URLs | 1538 // return false. This is important for at least Google, where such URLs |
1528 // are invalid. | 1539 // are invalid. |
1529 return !search_terms->empty(); | 1540 return !search_terms->empty(); |
1530 } | 1541 } |
1531 } | 1542 } |
1532 return false; | 1543 return false; |
1533 } | 1544 } |
OLD | NEW |