diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-28 17:29:18 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-28 17:29:18 +0000 |
commit | 5595f40d57179459f55aa9fe2ecad151d5d4d433 (patch) | |
tree | 8bbbc50ef5838a1b41f007c5a10868109c681506 /chrome/browser/autocomplete/extension_app_provider.cc | |
parent | a96cf921dee0b27d916b31d495b36165da7fc931 (diff) | |
download | chromium_src-5595f40d57179459f55aa9fe2ecad151d5d4d433.zip chromium_src-5595f40d57179459f55aa9fe2ecad151d5d4d433.tar.gz chromium_src-5595f40d57179459f55aa9fe2ecad151d5d4d433.tar.bz2 |
Strip special characters in extension omnibox suggestions.
This makes the drop downs on Mac and Linux match how Windows
currently renders these suggestions when they include newline,
tab and carriage return characters.
Removes invalid characters in matches coming from extension suggestions
and apps.
BUG=100564
TEST=Manual per bug and added ExtensionAppProviderTest.CreateMatchSanitize KeywordProviderTest.SuggestionMatchSanitize tests.
Review URL: http://codereview.chromium.org/8364001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107746 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/extension_app_provider.cc')
-rw-r--r-- | chrome/browser/autocomplete/extension_app_provider.cc | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/chrome/browser/autocomplete/extension_app_provider.cc b/chrome/browser/autocomplete/extension_app_provider.cc index d8c2a50..b3ceac1 100644 --- a/chrome/browser/autocomplete/extension_app_provider.cc +++ b/chrome/browser/autocomplete/extension_app_provider.cc @@ -29,6 +29,33 @@ void ExtensionAppProvider::AddExtensionAppForTesting(const string16& app_name, extension_apps_.push_back(std::make_pair(app_name, url)); } +AutocompleteMatch ExtensionAppProvider::CreateAutocompleteMatch( + const AutocompleteInput& input, + const string16& name, + const string16& url, + size_t name_match_index, + size_t url_match_index) { + // TODO(finnur): Figure out what type to return here, might want to have + // the extension icon/a generic icon show up in the Omnibox. + AutocompleteMatch match(this, 0, false, + AutocompleteMatch::EXTENSION_APP); + match.fill_into_edit = url; + match.destination_url = GURL(url); + match.inline_autocomplete_offset = string16::npos; + match.contents = AutocompleteMatch::SanitizeString(name); + AutocompleteMatch::ClassifyLocationInString(name_match_index, + input.text().length(), name.length(), ACMatchClassification::NONE, + &match.contents_class); + match.description = url; + AutocompleteMatch::ClassifyLocationInString(url_match_index, + input.text().length(), url.length(), ACMatchClassification::URL, + &match.description_class); + match.relevance = CalculateRelevance(input.type(), input.text().length(), + (name_match_index != string16::npos ? name.length() : url.length()), + match.destination_url); + return match; +} + void ExtensionAppProvider::Start(const AutocompleteInput& input, bool minimal_changes) { matches_.clear(); @@ -54,27 +81,11 @@ void ExtensionAppProvider::Start(const AutocompleteInput& input, if (matches_name || matches_url) { // We have a match, might be a partial match. - // TODO(finnur): Figure out what type to return here, might want to have - // the extension icon/a generic icon show up in the Omnibox. - AutocompleteMatch match(this, 0, false, - AutocompleteMatch::EXTENSION_APP); - match.fill_into_edit = url; - match.destination_url = GURL(url); - match.inline_autocomplete_offset = string16::npos; - match.contents = name; - AutocompleteMatch::ClassifyLocationInString(matches_name ? - static_cast<size_t>(name_iter - name.begin()) : string16::npos, - input.text().length(), name.length(), ACMatchClassification::NONE, - &match.contents_class); - match.description = url; - AutocompleteMatch::ClassifyLocationInString(matches_url ? - static_cast<size_t>(url_iter - url.begin()) : string16::npos, - input.text().length(), url.length(), ACMatchClassification::URL, - &match.description_class); - match.relevance = CalculateRelevance(input.type(), - input.text().length(), matches_name ? name.length() : url.length(), - match.destination_url); - matches_.push_back(match); + matches_.push_back(CreateAutocompleteMatch(input, name, url, + matches_name ? + static_cast<size_t>(name_iter - name.begin()) : string16::npos, + matches_url ? + static_cast<size_t>(url_iter - url.begin()) : string16::npos)); } } } |