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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_match.cc

Issue 8364001: Strip special characters in extension omnibox suggestions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/string_util.h"
6 #include "chrome/browser/autocomplete/autocomplete_match.h" 7 #include "chrome/browser/autocomplete/autocomplete_match.h"
7 #include "grit/theme_resources.h" 8 #include "grit/theme_resources.h"
8 9
9 // AutocompleteMatch ---------------------------------------------------------- 10 // AutocompleteMatch ----------------------------------------------------------
10 11
11 AutocompleteMatch::AutocompleteMatch() 12 AutocompleteMatch::AutocompleteMatch()
12 : provider(NULL), 13 : provider(NULL),
13 relevance(0), 14 relevance(0),
14 deletable(false), 15 deletable(false),
15 inline_autocomplete_offset(string16::npos), 16 inline_autocomplete_offset(string16::npos),
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 classification->push_back(ACMatchClassification(match_location, 150 classification->push_back(ACMatchClassification(match_location,
150 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM)); 151 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM));
151 152
152 // Mark post-match portion of string (if any). 153 // Mark post-match portion of string (if any).
153 const size_t after_match(match_location + match_length); 154 const size_t after_match(match_location + match_length);
154 if (after_match < overall_length) { 155 if (after_match < overall_length) {
155 classification->push_back(ACMatchClassification(after_match, style)); 156 classification->push_back(ACMatchClassification(after_match, style));
156 } 157 }
157 } 158 }
158 159
160 // static
161 string16 AutocompleteMatch::SanitizeString(const string16& text) {
162 // NOTE: This logic is mirrored by |sanitizeString()| in
163 // extension_process_bindings.js.
164 const char16 kRemoveChars[] = { '\n', '\r', '\t', 0x2028, 0x2029, 0 };
Scott Hess - ex-Googler 2011/10/26 21:08:00 Document the crazy code points so I don't have to
Alexei Svitkine (slow) 2011/10/27 13:30:53 Done.
165 string16 result;
166 TrimWhitespace(text, TRIM_LEADING, &result);
167 RemoveChars(result, kRemoveChars, &result);
Scott Hess - ex-Googler 2011/10/26 21:08:00 The potential for aliasing kinda frightens me, but
Alexei Svitkine (slow) 2011/10/27 13:30:53 Yeah, this is actually documented as safe to do fo
Scott Hess - ex-Googler 2011/10/27 18:28:37 Oh, cool, I embarrassingly went direct to the impl
168 return result;
169 }
170
159 #ifndef NDEBUG 171 #ifndef NDEBUG
160 void AutocompleteMatch::Validate() const { 172 void AutocompleteMatch::Validate() const {
161 ValidateClassifications(contents, contents_class); 173 ValidateClassifications(contents, contents_class);
162 ValidateClassifications(description, description_class); 174 ValidateClassifications(description, description_class);
163 } 175 }
164 176
165 void AutocompleteMatch::ValidateClassifications( 177 void AutocompleteMatch::ValidateClassifications(
166 const string16& text, 178 const string16& text,
167 const ACMatchClassifications& classifications) const { 179 const ACMatchClassifications& classifications) const {
168 if (text.empty()) { 180 if (text.empty()) {
(...skipping 10 matching lines...) Expand all
179 // The classifications should always be sorted. 191 // The classifications should always be sorted.
180 size_t last_offset = classifications[0].offset; 192 size_t last_offset = classifications[0].offset;
181 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); 193 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1);
182 i != classifications.end(); ++i) { 194 i != classifications.end(); ++i) {
183 DCHECK(i->offset > last_offset) << "Classification unsorted"; 195 DCHECK(i->offset > last_offset) << "Classification unsorted";
184 DCHECK(i->offset < text.length()) << "Classification out of bounds"; 196 DCHECK(i->offset < text.length()) << "Classification out of bounds";
185 last_offset = i->offset; 197 last_offset = i->offset;
186 } 198 }
187 } 199 }
188 #endif 200 #endif
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_match.h ('k') | chrome/browser/autocomplete/extension_app_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698