summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autocomplete/autocomplete_match.cc1
-rw-r--r--chrome/browser/autocomplete/extension_app_provider.cc76
-rw-r--r--chrome/browser/autocomplete/extension_app_provider.h17
-rw-r--r--chrome/browser/autocomplete/extension_app_provider_unittest.cc11
4 files changed, 36 insertions, 69 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_match.cc b/chrome/browser/autocomplete/autocomplete_match.cc
index b68b514..59fa925 100644
--- a/chrome/browser/autocomplete/autocomplete_match.cc
+++ b/chrome/browser/autocomplete/autocomplete_match.cc
@@ -117,6 +117,7 @@ void AutocompleteMatch::ClassifyMatchInString(
text.length(), style, classification);
}
+// static
void AutocompleteMatch::ClassifyLocationInString(
size_t match_location,
size_t match_length,
diff --git a/chrome/browser/autocomplete/extension_app_provider.cc b/chrome/browser/autocomplete/extension_app_provider.cc
index 0abe36b..4a75ba0 100644
--- a/chrome/browser/autocomplete/extension_app_provider.cc
+++ b/chrome/browser/autocomplete/extension_app_provider.cc
@@ -23,9 +23,8 @@ ExtensionAppProvider::ExtensionAppProvider(ACProviderListener* listener,
RefreshAppList();
}
-void ExtensionAppProvider::AddExtensionAppForTesting(
- const std::string& app_name,
- const std::string url) {
+void ExtensionAppProvider::AddExtensionAppForTesting(const string16& app_name,
+ const string16& url) {
extension_apps_.push_back(std::make_pair(app_name, url));
}
@@ -37,46 +36,43 @@ void ExtensionAppProvider::Start(const AutocompleteInput& input,
return;
if (!input.text().empty()) {
- std::string input_utf8 = UTF16ToUTF8(input.text());
for (ExtensionApps::const_iterator app = extension_apps_.begin();
app != extension_apps_.end(); ++app) {
// See if the input matches this extension application.
- const std::string& name = app->first;
- const std::string& url = app->second;
- std::string::const_iterator name_iter =
- std::search(name.begin(),
- name.end(),
- input_utf8.begin(),
- input_utf8.end(),
- base::CaseInsensitiveCompare<char>());
- std::string::const_iterator url_iter =
- std::search(url.begin(),
- url.end(),
- input_utf8.begin(),
- input_utf8.end(),
- base::CaseInsensitiveCompare<char>());
-
+ const string16& name = app->first;
+ string16::const_iterator name_iter = std::search(name.begin(), name.end(),
+ input.text().begin(), input.text().end(),
+ base::CaseInsensitiveCompare<char16>());
bool matches_name = name_iter != name.end();
+ const string16& url = app->second;
+ string16::const_iterator url_iter = std::search(url.begin(), url.end(),
+ input.text().begin(), input.text().end(),
+ base::CaseInsensitiveCompare<char16>());
bool matches_url = url_iter != url.end() &&
input.type() != AutocompleteInput::FORCED_QUERY;
+
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 = UTF8ToUTF16(url);
+ match.fill_into_edit = url;
match.destination_url = GURL(url);
match.inline_autocomplete_offset = string16::npos;
- match.contents = UTF8ToUTF16(name);
- HighlightMatch(input, &match.contents_class, name_iter, name);
- match.description = UTF8ToUTF16(url);
- HighlightMatch(input, &match.description_class, url_iter, url);
+ match.contents = name;
+ AutocompleteMatch::ClassifyLocationInString(
+ matches_name ? (name_iter - name.begin()) : string16::npos,
+ input.text().length(), name.length(), ACMatchClassification::NONE,
+ &match.contents_class);
+ match.description = url;
+ AutocompleteMatch::ClassifyLocationInString(
+ matches_url ? (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(),
- GURL(url));
+ input.text().length(), matches_name ? name.length() : url.length(),
+ match.destination_url);
matches_.push_back(match);
}
}
@@ -100,8 +96,8 @@ void ExtensionAppProvider::RefreshAppList() {
continue;
extension_apps_.push_back(
- std::make_pair((*app)->name(),
- (*app)->GetFullLaunchURL().spec()));
+ std::make_pair(UTF8ToUTF16((*app)->name()),
+ UTF8ToUTF16((*app)->GetFullLaunchURL().spec())));
}
}
}
@@ -119,26 +115,6 @@ void ExtensionAppProvider::Observe(NotificationType type,
RefreshAppList();
}
-void ExtensionAppProvider::HighlightMatch(const AutocompleteInput& input,
- ACMatchClassifications* match_class,
- std::string::const_iterator iter,
- const std::string& match_string) {
- size_t pos = iter - match_string.begin();
- bool match_found = iter != match_string.end();
- if (!match_found || pos > 0) {
- match_class->push_back(
- ACMatchClassification(0, ACMatchClassification::DIM));
- }
- if (match_found) {
- match_class->push_back(
- ACMatchClassification(pos, ACMatchClassification::MATCH));
- if (pos + input.text().length() < match_string.length()) {
- match_class->push_back(ACMatchClassification(pos + input.text().length(),
- ACMatchClassification::DIM));
- }
- }
-}
-
int ExtensionAppProvider::CalculateRelevance(AutocompleteInput::Type type,
int input_length,
int target_length,
diff --git a/chrome/browser/autocomplete/extension_app_provider.h b/chrome/browser/autocomplete/extension_app_provider.h
index 4209ee9..ade0123 100644
--- a/chrome/browser/autocomplete/extension_app_provider.h
+++ b/chrome/browser/autocomplete/extension_app_provider.h
@@ -16,7 +16,6 @@
#define CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_
#pragma once
-#include <string>
#include <utility>
#include <vector>
@@ -34,8 +33,8 @@ class ExtensionAppProvider : public AutocompleteProvider,
ExtensionAppProvider(ACProviderListener* listener, Profile* profile);
// Only used for testing.
- void AddExtensionAppForTesting(const std::string& app_name,
- const std::string url);
+ void AddExtensionAppForTesting(const string16& app_name,
+ const string16& url);
// AutocompleteProvider implementation:
virtual void Start(const AutocompleteInput& input,
@@ -43,7 +42,7 @@ class ExtensionAppProvider : public AutocompleteProvider,
private:
// An ExtensionApp is a pair of Extension Name and the Launch URL.
- typedef std::pair<std::string, std::string> ExtensionApp;
+ typedef std::pair<string16, string16> ExtensionApp;
typedef std::vector<ExtensionApp> ExtensionApps;
virtual ~ExtensionAppProvider();
@@ -54,16 +53,6 @@ class ExtensionAppProvider : public AutocompleteProvider,
// Register for install/uninstall notification so we can update our cache.
void RegisterForNotifications();
- // Highlights a certain part of a match string within a certain match class.
- // |input| is the input we got from the user, |match_class| is the
- // AutoComplete match classification that keeps track of the highlighting
- // values, and |iter| is the location of the user input found within
- // |match_string|.
- void HighlightMatch(const AutocompleteInput& input,
- ACMatchClassifications* match_class,
- std::string::const_iterator iter,
- const std::string& match_string);
-
// Calculate the relevance of the match.
int CalculateRelevance(AutocompleteInput::Type type,
int input_length,
diff --git a/chrome/browser/autocomplete/extension_app_provider_unittest.cc b/chrome/browser/autocomplete/extension_app_provider_unittest.cc
index 578c4c7..97639e2 100644
--- a/chrome/browser/autocomplete/extension_app_provider_unittest.cc
+++ b/chrome/browser/autocomplete/extension_app_provider_unittest.cc
@@ -44,9 +44,9 @@ void ExtensionAppProviderTest::SetUp() {
app_provider_ = new ExtensionAppProvider(NULL, profile_.get());
struct ExtensionApps {
- std::string app_name;
- std::string url;
- std::string title;
+ const char* app_name;
+ const char* url;
+ const char* title;
int typed_count;
} kExtensionApps[] = {
{"COYB", "http://asdf/", "COYB", 7},
@@ -57,8 +57,9 @@ void ExtensionAppProviderTest::SetUp() {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kExtensionApps); ++i) {
// Populate the Extension Apps list.
- app_provider_->AddExtensionAppForTesting(kExtensionApps[i].app_name,
- kExtensionApps[i].url);
+ app_provider_->AddExtensionAppForTesting(
+ ASCIIToUTF16(kExtensionApps[i].app_name),
+ ASCIIToUTF16(kExtensionApps[i].url));
// Populate the InMemoryDatabase.
history::URLRow info(GURL(kExtensionApps[i].url));