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

Side by Side Diff: chrome/browser/autocomplete/extension_app_provider.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 "chrome/browser/autocomplete/extension_app_provider.h" 5 #include "chrome/browser/autocomplete/extension_app_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 11 matching lines...) Expand all
22 : AutocompleteProvider(listener, profile, "ExtensionApps") { 22 : AutocompleteProvider(listener, profile, "ExtensionApps") {
23 RegisterForNotifications(); 23 RegisterForNotifications();
24 RefreshAppList(); 24 RefreshAppList();
25 } 25 }
26 26
27 void ExtensionAppProvider::AddExtensionAppForTesting(const string16& app_name, 27 void ExtensionAppProvider::AddExtensionAppForTesting(const string16& app_name,
28 const string16& url) { 28 const string16& url) {
29 extension_apps_.push_back(std::make_pair(app_name, url)); 29 extension_apps_.push_back(std::make_pair(app_name, url));
30 } 30 }
31 31
32 AutocompleteMatch ExtensionAppProvider::CreateAutocompleteMatch(
33 const AutocompleteInput& input,
34 const string16& name,
35 const string16& url,
36 size_t name_match_index,
37 size_t url_match_index) {
38 // TODO(finnur): Figure out what type to return here, might want to have
39 // the extension icon/a generic icon show up in the Omnibox.
40 AutocompleteMatch match(this, 0, false,
41 AutocompleteMatch::EXTENSION_APP);
42 match.fill_into_edit = url;
43 match.destination_url = GURL(url);
44 match.inline_autocomplete_offset = string16::npos;
45 match.contents = AutocompleteMatch::SanitizeString(name);
46 AutocompleteMatch::ClassifyLocationInString(name_match_index,
47 input.text().length(),
48 name.length(),
49 ACMatchClassification::NONE,
50 &match.contents_class);
51 match.description = url;
52 AutocompleteMatch::ClassifyLocationInString(url_match_index,
53 input.text().length(),
54 url.length(),
55 ACMatchClassification::URL,
56 &match.description_class);
57 match.relevance = CalculateRelevance(input.type(),
58 input.text().length(),
59 name_match_index != string16::npos ?
60 name.length() : url.length(),
61 match.destination_url);
62 return match;
63 }
64
32 void ExtensionAppProvider::Start(const AutocompleteInput& input, 65 void ExtensionAppProvider::Start(const AutocompleteInput& input,
33 bool minimal_changes) { 66 bool minimal_changes) {
34 matches_.clear(); 67 matches_.clear();
35 68
36 if (input.type() == AutocompleteInput::INVALID) 69 if (input.type() == AutocompleteInput::INVALID)
37 return; 70 return;
38 71
39 if (!input.text().empty()) { 72 if (!input.text().empty()) {
40 for (ExtensionApps::const_iterator app = extension_apps_.begin(); 73 for (ExtensionApps::const_iterator app = extension_apps_.begin();
41 app != extension_apps_.end(); ++app) { 74 app != extension_apps_.end(); ++app) {
42 // See if the input matches this extension application. 75 // See if the input matches this extension application.
43 const string16& name = app->first; 76 const string16& name = app->first;
44 string16::const_iterator name_iter = std::search(name.begin(), name.end(), 77 string16::const_iterator name_iter = std::search(name.begin(), name.end(),
45 input.text().begin(), input.text().end(), 78 input.text().begin(), input.text().end(),
46 base::CaseInsensitiveCompare<char16>()); 79 base::CaseInsensitiveCompare<char16>());
47 bool matches_name = name_iter != name.end(); 80 bool matches_name = name_iter != name.end();
48 const string16& url = app->second; 81 const string16& url = app->second;
49 string16::const_iterator url_iter = std::search(url.begin(), url.end(), 82 string16::const_iterator url_iter = std::search(url.begin(), url.end(),
50 input.text().begin(), input.text().end(), 83 input.text().begin(), input.text().end(),
51 base::CaseInsensitiveCompare<char16>()); 84 base::CaseInsensitiveCompare<char16>());
52 bool matches_url = url_iter != url.end() && 85 bool matches_url = url_iter != url.end() &&
53 input.type() != AutocompleteInput::FORCED_QUERY; 86 input.type() != AutocompleteInput::FORCED_QUERY;
54 87
55 if (matches_name || matches_url) { 88 if (matches_name || matches_url) {
56 // We have a match, might be a partial match. 89 // We have a match, might be a partial match.
57 // TODO(finnur): Figure out what type to return here, might want to have 90 size_t name_match_index = matches_name ?
58 // the extension icon/a generic icon show up in the Omnibox. 91 static_cast<size_t>(name_iter - name.begin()) : string16::npos;
59 AutocompleteMatch match(this, 0, false, 92 size_t url_match_index = matches_url ?
60 AutocompleteMatch::EXTENSION_APP); 93 static_cast<size_t>(url_iter - url.begin()) : string16::npos;
61 match.fill_into_edit = url; 94 matches_.push_back(
62 match.destination_url = GURL(url); 95 CreateAutocompleteMatch(input, name, url, name_match_index,
63 match.inline_autocomplete_offset = string16::npos; 96 url_match_index));
64 match.contents = name;
65 AutocompleteMatch::ClassifyLocationInString(matches_name ?
66 static_cast<size_t>(name_iter - name.begin()) : string16::npos,
67 input.text().length(), name.length(), ACMatchClassification::NONE,
68 &match.contents_class);
69 match.description = url;
70 AutocompleteMatch::ClassifyLocationInString(matches_url ?
71 static_cast<size_t>(url_iter - url.begin()) : string16::npos,
72 input.text().length(), url.length(), ACMatchClassification::URL,
73 &match.description_class);
74 match.relevance = CalculateRelevance(input.type(),
75 input.text().length(), matches_name ? name.length() : url.length(),
76 match.destination_url);
77 matches_.push_back(match);
78 } 97 }
79 } 98 }
80 } 99 }
81 } 100 }
82 101
83 ExtensionAppProvider::~ExtensionAppProvider() { 102 ExtensionAppProvider::~ExtensionAppProvider() {
84 } 103 }
85 104
86 void ExtensionAppProvider::RefreshAppList() { 105 void ExtensionAppProvider::RefreshAppList() {
87 ExtensionService* extension_service = profile_->GetExtensionService(); 106 ExtensionService* extension_service = profile_->GetExtensionService();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 history::URLRow info; 167 history::URLRow info;
149 url_db->GetRowForURL(url, &info); 168 url_db->GetRowForURL(url, &info);
150 type_count_boost = 169 type_count_boost =
151 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); 170 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count())));
152 } 171 }
153 int relevance = 575 + static_cast<int>(type_count_boost) + 172 int relevance = 575 + static_cast<int>(type_count_boost) +
154 static_cast<int>(fraction_boost); 173 static_cast<int>(fraction_boost);
155 DCHECK_LE(relevance, kMaxRelevance); 174 DCHECK_LE(relevance, kMaxRelevance);
156 return relevance; 175 return relevance;
157 } 176 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698