Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: components/search_engines/template_url.cc

Issue 2524733008: Fix for google:instantExtendedEnabledKey replacement (Closed)
Patch Set: Added unittest Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/search_engines/template_url_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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[] =
71 "{google:instantExtendedEnabledKey}"; 73 "{google:instantExtendedEnabledKey}";
72 74
73 // Attempts to encode |terms| and |original_query| in |encoding| and escape 75 // Attempts to encode |terms| and |original_query| in |encoding| and escape
74 // them. |terms| may be escaped as path or query depending on |is_in_query|; 76 // them. |terms| may be escaped as path or query depending on |is_in_query|;
75 // |original_query| is always escaped as query. Returns whether the encoding 77 // |original_query| is always escaped as query. Returns whether the encoding
76 // process succeeded. 78 // process succeeded.
77 bool TryEncoding(const base::string16& terms, 79 bool TryEncoding(const base::string16& terms,
78 const base::string16& original_query, 80 const base::string16& original_query,
79 const char* encoding, 81 const char* encoding,
80 bool is_in_query, 82 bool is_in_query,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 166 }
165 167
166 // Special case for search_terms_replacement_key comparison, because of 168 // Special case for search_terms_replacement_key comparison, because of
167 // its special initialization in TemplateUrl constructor. 169 // its special initialization in TemplateUrl constructor.
168 bool SearchTermsReplacementKeysMatch( 170 bool SearchTermsReplacementKeysMatch(
169 const std::string& search_terms_replacement_key1, 171 const std::string& search_terms_replacement_key1,
170 const std::string& search_terms_replacement_key2) { 172 const std::string& search_terms_replacement_key2) {
171 if (search_terms_replacement_key1 == search_terms_replacement_key2) 173 if (search_terms_replacement_key1 == search_terms_replacement_key2)
172 return true; 174 return true;
173 if (search_terms_replacement_key1 == google_util::kInstantExtendedAPIParam && 175 if (search_terms_replacement_key1 == google_util::kInstantExtendedAPIParam &&
174 search_terms_replacement_key2 == kGoogleInstantExtendedEnabledKey) 176 search_terms_replacement_key2 == kGoogleInstantExtendedEnabledKeyFull)
175 return true; 177 return true;
176 if (search_terms_replacement_key2 == google_util::kInstantExtendedAPIParam && 178 if (search_terms_replacement_key2 == google_util::kInstantExtendedAPIParam &&
177 search_terms_replacement_key1 == kGoogleInstantExtendedEnabledKey) 179 search_terms_replacement_key1 == kGoogleInstantExtendedEnabledKeyFull)
178 return true; 180 return true;
179 return false; 181 return false;
180 } 182 }
181 183
182 } // namespace 184 } // namespace
183 185
184 186
185 // TemplateURLRef::SearchTermsArgs -------------------------------------------- 187 // TemplateURLRef::SearchTermsArgs --------------------------------------------
186 188
187 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( 189 TemplateURLRef::SearchTermsArgs::SearchTermsArgs(
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 suggestions_url_ref_(this, TemplateURLRef::SUGGEST), 1206 suggestions_url_ref_(this, TemplateURLRef::SUGGEST),
1205 instant_url_ref_(this, TemplateURLRef::INSTANT), 1207 instant_url_ref_(this, TemplateURLRef::INSTANT),
1206 image_url_ref_(this, TemplateURLRef::IMAGE), 1208 image_url_ref_(this, TemplateURLRef::IMAGE),
1207 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), 1209 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB),
1208 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH), 1210 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH),
1209 type_(type), 1211 type_(type),
1210 engine_type_(SEARCH_ENGINE_UNKNOWN) { 1212 engine_type_(SEARCH_ENGINE_UNKNOWN) {
1211 ResizeURLRefVector(); 1213 ResizeURLRefVector();
1212 SetPrepopulateId(data_.prepopulate_id); 1214 SetPrepopulateId(data_.prepopulate_id);
1213 1215
1214 if (data_.search_terms_replacement_key == kGoogleInstantExtendedEnabledKey) 1216 if (data_.search_terms_replacement_key ==
1217 kGoogleInstantExtendedEnabledKeyFull)
1215 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; 1218 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam;
1216 } 1219 }
1217 1220
1218 TemplateURL::~TemplateURL() { 1221 TemplateURL::~TemplateURL() {
1219 } 1222 }
1220 1223
1221 // static 1224 // static
1222 base::string16 TemplateURL::GenerateKeyword(const GURL& url) { 1225 base::string16 TemplateURL::GenerateKeyword(const GURL& url) {
1223 DCHECK(url.is_valid()); 1226 DCHECK(url.is_valid());
1224 // Strip "www." off the front of the keyword; otherwise the keyword won't work 1227 // 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
1541 // patterns. This means that given patterns 1544 // patterns. This means that given patterns
1542 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1545 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1543 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1546 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1544 // return false. This is important for at least Google, where such URLs 1547 // return false. This is important for at least Google, where such URLs
1545 // are invalid. 1548 // are invalid.
1546 return !search_terms->empty(); 1549 return !search_terms->empty();
1547 } 1550 }
1548 } 1551 }
1549 return false; 1552 return false;
1550 } 1553 }
OLDNEW
« no previous file with comments | « no previous file | components/search_engines/template_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698