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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 constexpr char kGoogleInstantExtendedEnabledKey[] = | 70 constexpr char kGoogleInstantExtendedEnabledKey[] = |
71 "google:instantExtendedEnabledKey"; | |
72 constexpr char kGoogleInstantExtendedEnabledKeyFull[] = | |
73 "{google:instantExtendedEnabledKey}"; | 71 "{google:instantExtendedEnabledKey}"; |
74 | 72 |
75 // Attempts to encode |terms| and |original_query| in |encoding| and escape | 73 // Attempts to encode |terms| and |original_query| in |encoding| and escape |
76 // 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|; |
77 // |original_query| is always escaped as query. Returns whether the encoding | 75 // |original_query| is always escaped as query. Returns whether the encoding |
78 // process succeeded. | 76 // process succeeded. |
79 bool TryEncoding(const base::string16& terms, | 77 bool TryEncoding(const base::string16& terms, |
80 const base::string16& original_query, | 78 const base::string16& original_query, |
81 const char* encoding, | 79 const char* encoding, |
82 bool is_in_query, | 80 bool is_in_query, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 164 } |
167 | 165 |
168 // Special case for search_terms_replacement_key comparison, because of | 166 // Special case for search_terms_replacement_key comparison, because of |
169 // its special initialization in TemplateUrl constructor. | 167 // its special initialization in TemplateUrl constructor. |
170 bool SearchTermsReplacementKeysMatch( | 168 bool SearchTermsReplacementKeysMatch( |
171 const std::string& search_terms_replacement_key1, | 169 const std::string& search_terms_replacement_key1, |
172 const std::string& search_terms_replacement_key2) { | 170 const std::string& search_terms_replacement_key2) { |
173 if (search_terms_replacement_key1 == search_terms_replacement_key2) | 171 if (search_terms_replacement_key1 == search_terms_replacement_key2) |
174 return true; | 172 return true; |
175 if (search_terms_replacement_key1 == google_util::kInstantExtendedAPIParam && | 173 if (search_terms_replacement_key1 == google_util::kInstantExtendedAPIParam && |
176 search_terms_replacement_key2 == kGoogleInstantExtendedEnabledKeyFull) | 174 search_terms_replacement_key2 == kGoogleInstantExtendedEnabledKey) |
177 return true; | 175 return true; |
178 if (search_terms_replacement_key2 == google_util::kInstantExtendedAPIParam && | 176 if (search_terms_replacement_key2 == google_util::kInstantExtendedAPIParam && |
179 search_terms_replacement_key1 == kGoogleInstantExtendedEnabledKeyFull) | 177 search_terms_replacement_key1 == kGoogleInstantExtendedEnabledKey) |
180 return true; | 178 return true; |
181 return false; | 179 return false; |
182 } | 180 } |
183 | 181 |
184 } // namespace | 182 } // namespace |
185 | 183 |
186 | 184 |
187 // TemplateURLRef::SearchTermsArgs -------------------------------------------- | 185 // TemplateURLRef::SearchTermsArgs -------------------------------------------- |
188 | 186 |
189 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( | 187 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( |
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 suggestions_url_ref_(this, TemplateURLRef::SUGGEST), | 1204 suggestions_url_ref_(this, TemplateURLRef::SUGGEST), |
1207 instant_url_ref_(this, TemplateURLRef::INSTANT), | 1205 instant_url_ref_(this, TemplateURLRef::INSTANT), |
1208 image_url_ref_(this, TemplateURLRef::IMAGE), | 1206 image_url_ref_(this, TemplateURLRef::IMAGE), |
1209 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), | 1207 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), |
1210 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH), | 1208 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH), |
1211 type_(type), | 1209 type_(type), |
1212 engine_type_(SEARCH_ENGINE_UNKNOWN) { | 1210 engine_type_(SEARCH_ENGINE_UNKNOWN) { |
1213 ResizeURLRefVector(); | 1211 ResizeURLRefVector(); |
1214 SetPrepopulateId(data_.prepopulate_id); | 1212 SetPrepopulateId(data_.prepopulate_id); |
1215 | 1213 |
1216 if (data_.search_terms_replacement_key == | 1214 if (data_.search_terms_replacement_key == kGoogleInstantExtendedEnabledKey) |
1217 kGoogleInstantExtendedEnabledKeyFull) | |
1218 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; | 1215 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; |
1219 } | 1216 } |
1220 | 1217 |
1221 TemplateURL::~TemplateURL() { | 1218 TemplateURL::~TemplateURL() { |
1222 } | 1219 } |
1223 | 1220 |
1224 // static | 1221 // static |
1225 base::string16 TemplateURL::GenerateKeyword(const GURL& url) { | 1222 base::string16 TemplateURL::GenerateKeyword(const GURL& url) { |
1226 DCHECK(url.is_valid()); | 1223 DCHECK(url.is_valid()); |
1227 // Strip "www." off the front of the keyword; otherwise the keyword won't work | 1224 // Strip "www." off the front of the keyword; otherwise the keyword won't work |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 // patterns. This means that given patterns | 1541 // patterns. This means that given patterns |
1545 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1542 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1546 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1543 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1547 // return false. This is important for at least Google, where such URLs | 1544 // return false. This is important for at least Google, where such URLs |
1548 // are invalid. | 1545 // are invalid. |
1549 return !search_terms->empty(); | 1546 return !search_terms->empty(); |
1550 } | 1547 } |
1551 } | 1548 } |
1552 return false; | 1549 return false; |
1553 } | 1550 } |
OLD | NEW |