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

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 // 0x2028 = line separator; 0x2029 = paragraph separator.
165 const char16 kRemoveChars[] = { '\n', '\r', '\t',
166 0x2028, // Line separator
167 0x2029, // Paragraph separator
168 0 };
169 string16 result;
170 TrimWhitespace(text, TRIM_LEADING, &result);
171 RemoveChars(result, kRemoveChars, &result);
172 return result;
173 }
174
159 #ifndef NDEBUG 175 #ifndef NDEBUG
160 void AutocompleteMatch::Validate() const { 176 void AutocompleteMatch::Validate() const {
161 ValidateClassifications(contents, contents_class); 177 ValidateClassifications(contents, contents_class);
162 ValidateClassifications(description, description_class); 178 ValidateClassifications(description, description_class);
163 } 179 }
164 180
165 void AutocompleteMatch::ValidateClassifications( 181 void AutocompleteMatch::ValidateClassifications(
166 const string16& text, 182 const string16& text,
167 const ACMatchClassifications& classifications) const { 183 const ACMatchClassifications& classifications) const {
168 if (text.empty()) { 184 if (text.empty()) {
(...skipping 10 matching lines...) Expand all
179 // The classifications should always be sorted. 195 // The classifications should always be sorted.
180 size_t last_offset = classifications[0].offset; 196 size_t last_offset = classifications[0].offset;
181 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); 197 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1);
182 i != classifications.end(); ++i) { 198 i != classifications.end(); ++i) {
183 DCHECK(i->offset > last_offset) << "Classification unsorted"; 199 DCHECK(i->offset > last_offset) << "Classification unsorted";
184 DCHECK(i->offset < text.length()) << "Classification out of bounds"; 200 DCHECK(i->offset < text.length()) << "Classification out of bounds";
185 last_offset = i->offset; 201 last_offset = i->offset;
186 } 202 }
187 } 203 }
188 #endif 204 #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