summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc6
-rw-r--r--chrome/browser/autocomplete/autocomplete.h12
-rw-r--r--chrome/browser/autocomplete/autocomplete_browsertest.cc2
-rw-r--r--chrome/browser/autocomplete/autocomplete_classifier.cc4
-rw-r--r--chrome/browser/autocomplete/autocomplete_classifier.h16
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc6
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.cc2
-rw-r--r--chrome/browser/autocomplete/autocomplete_unittest.cc108
-rw-r--r--chrome/browser/autocomplete/history_contents_provider_unittest.cc15
-rw-r--r--chrome/browser/autocomplete/history_quick_provider_unittest.cc2
-rw-r--r--chrome/browser/autocomplete/history_url_provider_unittest.cc4
-rw-r--r--chrome/browser/autocomplete/keyword_provider.cc15
-rw-r--r--chrome/browser/autocomplete/keyword_provider.h5
-rw-r--r--chrome/browser/autocomplete/keyword_provider_unittest.cc2
-rw-r--r--chrome/browser/autocomplete/search_provider_unittest.cc2
-rw-r--r--chrome/browser/extensions/extension_omnibox_apitest.cc6
-rw-r--r--chrome/browser/gtk/gtk_util.cc20
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc2
-rw-r--r--chrome/browser/ui/views/frame/browser_root_view.cc2
19 files changed, 162 insertions, 69 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index 007fd2b..8c47a69 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -46,6 +46,7 @@ AutocompleteInput::AutocompleteInput()
: type_(INVALID),
prevent_inline_autocomplete_(false),
prefer_keyword_(false),
+ allow_exact_keyword_match_(true),
synchronous_only_(false) {
}
@@ -53,10 +54,12 @@ AutocompleteInput::AutocompleteInput(const std::wstring& text,
const std::wstring& desired_tld,
bool prevent_inline_autocomplete,
bool prefer_keyword,
+ bool allow_exact_keyword_match,
bool synchronous_only)
: desired_tld_(desired_tld),
prevent_inline_autocomplete_(prevent_inline_autocomplete),
prefer_keyword_(prefer_keyword),
+ allow_exact_keyword_match_(allow_exact_keyword_match),
synchronous_only_(synchronous_only) {
// Trim whitespace from edges of input; don't inline autocomplete if there
// was trailing whitespace.
@@ -671,11 +674,12 @@ void AutocompleteController::Start(const std::wstring& text,
const std::wstring& desired_tld,
bool prevent_inline_autocomplete,
bool prefer_keyword,
+ bool allow_exact_keyword_match,
bool synchronous_only) {
const std::wstring old_input_text(input_.text());
const bool old_synchronous_only = input_.synchronous_only();
input_ = AutocompleteInput(text, desired_tld, prevent_inline_autocomplete,
- prefer_keyword, synchronous_only);
+ prefer_keyword, allow_exact_keyword_match, synchronous_only);
// See if we can avoid rerunning autocomplete when the query hasn't changed
// much. When the user presses or releases the ctrl key, the desired_tld
diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h
index 4f24852..53fd392 100644
--- a/chrome/browser/autocomplete/autocomplete.h
+++ b/chrome/browser/autocomplete/autocomplete.h
@@ -183,6 +183,7 @@ class AutocompleteInput {
const std::wstring& desired_tld,
bool prevent_inline_autocomplete,
bool prefer_keyword,
+ bool allow_exact_keyword_match,
bool synchronous_only);
~AutocompleteInput();
@@ -252,6 +253,11 @@ class AutocompleteInput {
// keyword, we should score it like a non-substituting keyword.
bool prefer_keyword() const { return prefer_keyword_; }
+ // Returns whether this input is allowed to be treated as an exact
+ // keyword match. If not, the default result is guaranteed not to be a
+ // keyword search, even if the input is "<keyword> <search string>".
+ bool allow_exact_keyword_match() const { return allow_exact_keyword_match_; }
+
// Returns whether providers should avoid scheduling asynchronous work. If
// this is true, providers should stop after returning all the
// synchronously-available matches. This also means any in-progress
@@ -273,6 +279,7 @@ class AutocompleteInput {
GURL canonicalized_url_;
bool prevent_inline_autocomplete_;
bool prefer_keyword_;
+ bool allow_exact_keyword_match_;
bool synchronous_only_;
};
@@ -550,6 +557,10 @@ class AutocompleteController : public ACProviderListener {
// bias the autocomplete result set toward the keyword provider when the input
// string is a bare keyword.
//
+ // |allow_exact_keyword_match| should be false when triggering keyword mode on
+ // the input string would be surprising or wrong, e.g. when highlighting text
+ // in a page and telling the browser to search for it or navigate to it.
+
// If |synchronous_only| is true, the controller asks the providers to only
// return matches which are synchronously available, which should mean that
// all providers will be done immediately.
@@ -565,6 +576,7 @@ class AutocompleteController : public ACProviderListener {
const std::wstring& desired_tld,
bool prevent_inline_autocomplete,
bool prefer_keyword,
+ bool allow_exact_keyword_match,
bool synchronous_only);
// Cancels the current query, ensuring there will be no future notifications
diff --git a/chrome/browser/autocomplete/autocomplete_browsertest.cc b/chrome/browser/autocomplete/autocomplete_browsertest.cc
index 877fe7a..27f7d48 100644
--- a/chrome/browser/autocomplete/autocomplete_browsertest.cc
+++ b/chrome/browser/autocomplete/autocomplete_browsertest.cc
@@ -107,7 +107,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) {
{
autocomplete_controller->Start(L"chrome", std::wstring(),
- true, false, true);
+ true, false, true, true);
EXPECT_TRUE(autocomplete_controller->done());
EXPECT_EQ(std::wstring(), location_bar->GetInputString());
diff --git a/chrome/browser/autocomplete/autocomplete_classifier.cc b/chrome/browser/autocomplete/autocomplete_classifier.cc
index 88dc89c..45635e3 100644
--- a/chrome/browser/autocomplete/autocomplete_classifier.cc
+++ b/chrome/browser/autocomplete/autocomplete_classifier.cc
@@ -17,9 +17,11 @@ AutocompleteClassifier::~AutocompleteClassifier() {
void AutocompleteClassifier::Classify(const std::wstring& text,
const std::wstring& desired_tld,
+ bool allow_exact_keyword_match,
AutocompleteMatch* match,
GURL* alternate_nav_url) {
- controller_->Start(text, desired_tld, true, false, true);
+ controller_->Start(text, desired_tld, true, false, allow_exact_keyword_match,
+ true);
DCHECK(controller_->done());
const AutocompleteResult& result = controller_->result();
if (result.empty()) {
diff --git a/chrome/browser/autocomplete/autocomplete_classifier.h b/chrome/browser/autocomplete/autocomplete_classifier.h
index facdd34..ed59306 100644
--- a/chrome/browser/autocomplete/autocomplete_classifier.h
+++ b/chrome/browser/autocomplete/autocomplete_classifier.h
@@ -23,15 +23,19 @@ class AutocompleteClassifier {
// Given some string |text| that the user wants to use for navigation,
// determines how it should be interpreted. |desired_tld| is the user's
- // desired TLD, if any; see AutocompleteInput::desired_tld(). |match| should
- // be a non-NULL outparam that will be set to the default match for this
- // input, if any (for invalid input, there will be no default match, and
- // |match| will be left unchanged). |alternate_nav_url| is a possibly-NULL
- // outparam that, if non-NULL, will be set to the navigational URL (if any) in
- // case of an accidental search; see comments on
+ // desired TLD, if any; see AutocompleteInput::desired_tld().
+ // |allow_exact_keyword_match| should be true when treating the string as a
+ // potential keyword search is valid; see
+ // AutocompleteInput::allow_exact_keyword_match(). |match| should be a
+ // non-NULL outparam that will be set to the default match for this input, if
+ // any (for invalid input, there will be no default match, and |match| will be
+ // left unchanged). |alternate_nav_url| is a possibly-NULL outparam that, if
+ // non-NULL, will be set to the navigational URL (if any) in case of an
+ // accidental search; see comments on
// AutocompleteResult::alternate_nav_url_ in autocomplete.h.
void Classify(const std::wstring& text,
const std::wstring& desired_tld,
+ bool allow_exact_keyword_match,
AutocompleteMatch* match,
GURL* alternate_nav_url);
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index ed18232..25a59e4 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -296,7 +296,7 @@ bool AutocompleteEditModel::CanPasteAndGo(const std::wstring& text) const {
return false;
AutocompleteMatch match;
- profile_->GetAutocompleteClassifier()->Classify(text, std::wstring(),
+ profile_->GetAutocompleteClassifier()->Classify(text, std::wstring(), false,
&match, &paste_and_go_alternate_nav_url_);
paste_and_go_url_ = match.destination_url;
paste_and_go_transition_ = match.transition;
@@ -772,8 +772,8 @@ void AutocompleteEditModel::GetInfoForCurrentText(
popup_->InfoForCurrentSelection(match, alternate_nav_url);
} else {
profile_->GetAutocompleteClassifier()->Classify(
- UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), match,
- alternate_nav_url);
+ UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), true,
+ match, alternate_nav_url);
}
}
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc
index a14d19f..a857b3c 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_model.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc
@@ -54,7 +54,7 @@ void AutocompletePopupModel::StartAutocomplete(
manually_selected_match_.Clear();
controller_->Start(text, desired_tld, prevent_inline_autocomplete,
- prefer_keyword, false);
+ prefer_keyword, true, false);
}
void AutocompletePopupModel::StopAutocomplete() {
diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc
index d78611c..f6b165e 100644
--- a/chrome/browser/autocomplete/autocomplete_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_unittest.cc
@@ -9,9 +9,14 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
+#include "chrome/browser/autocomplete/keyword_provider.h"
+#include "chrome/browser/autocomplete/search_provider.h"
+#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_service.h"
+#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
// identifiers for known autocomplete providers
@@ -102,15 +107,15 @@ void TestProvider::AddResults(int start_at, int num) {
class AutocompleteProviderTest : public testing::Test,
public NotificationObserver {
protected:
- // testing::Test
- virtual void SetUp();
-
- void ResetController(bool same_destinations);
+ void ResetControllerWithTestProviders(bool same_destinations);
// Runs a query on the input "a", and makes sure both providers' input is
// properly collected.
void RunTest();
+ void ResetControllerWithTestProvidersWithKeywordAndSearchProviders();
+ void RunExactKeymatchTest(bool allow_exact_keyword_match);
+
// These providers are owned by the controller once it's created.
ACProviders providers_;
@@ -125,15 +130,11 @@ class AutocompleteProviderTest : public testing::Test,
MessageLoopForUI message_loop_;
scoped_ptr<AutocompleteController> controller_;
NotificationRegistrar registrar_;
+ TestingProfile profile_;
};
-void AutocompleteProviderTest::SetUp() {
- registrar_.Add(this, NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED,
- NotificationService::AllSources());
- ResetController(false);
-}
-
-void AutocompleteProviderTest::ResetController(bool same_destinations) {
+void AutocompleteProviderTest::ResetControllerWithTestProviders(
+ bool same_destinations) {
// Forget about any existing providers. The controller owns them and will
// Release() them below, when we delete it during the call to reset().
providers_.clear();
@@ -154,17 +155,77 @@ void AutocompleteProviderTest::ResetController(bool same_destinations) {
controller_.reset(controller);
providerA->set_listener(controller);
providerB->set_listener(controller);
+
+ // The providers don't complete synchronously, so listen for "result updated"
+ // notifications.
+ registrar_.Add(this, NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED,
+ NotificationService::AllSources());
+}
+
+void AutocompleteProviderTest::
+ ResetControllerWithTestProvidersWithKeywordAndSearchProviders() {
+ profile_.CreateTemplateURLModel();
+
+ // Reset the default TemplateURL.
+ TemplateURL* default_t_url = new TemplateURL();
+ default_t_url->SetURL("http://defaultturl/{searchTerms}", 0, 0);
+ TemplateURLModel* turl_model = profile_.GetTemplateURLModel();
+ turl_model->Add(default_t_url);
+ turl_model->SetDefaultSearchProvider(default_t_url);
+ TemplateURLID default_provider_id = default_t_url->id();
+ ASSERT_NE(0, default_provider_id);
+
+ // Create another TemplateURL for KeywordProvider.
+ TemplateURL* keyword_t_url = new TemplateURL();
+ keyword_t_url->set_short_name(L"k");
+ keyword_t_url->set_keyword(L"k");
+ keyword_t_url->SetURL("http://keyword/{searchTerms}", 0, 0);
+ profile_.GetTemplateURLModel()->Add(keyword_t_url);
+ ASSERT_NE(0, keyword_t_url->id());
+
+ // Forget about any existing providers. The controller owns them and will
+ // Release() them below, when we delete it during the call to reset().
+ providers_.clear();
+
+ // Create both a keyword and search provider, and add them in that order.
+ // (Order is important; see comments in RunExactKeymatchTest().)
+ AutocompleteProvider* keyword_provider = new KeywordProvider(NULL,
+ &profile_);
+ keyword_provider->AddRef();
+ providers_.push_back(keyword_provider);
+ AutocompleteProvider* search_provider = new SearchProvider(NULL, &profile_);
+ search_provider->AddRef();
+ providers_.push_back(search_provider);
+
+ AutocompleteController* controller = new AutocompleteController(providers_);
+ controller_.reset(controller);
}
void AutocompleteProviderTest::RunTest() {
result_.Reset();
- controller_->Start(L"a", std::wstring(), true, false, false);
+ controller_->Start(L"a", std::wstring(), true, false, true, false);
// The message loop will terminate when all autocomplete input has been
// collected.
MessageLoop::current()->Run();
}
+void AutocompleteProviderTest::RunExactKeymatchTest(
+ bool allow_exact_keyword_match) {
+ // Send the controller input which exactly matches the keyword provider we
+ // created in ResetControllerWithKeywordAndSearchProviders(). The default
+ // match should thus be a keyword match iff |allow_exact_keyword_match| is
+ // true.
+ controller_->Start(L"k test", std::wstring(), true, false,
+ allow_exact_keyword_match, true);
+ EXPECT_TRUE(controller_->done());
+ // ResetControllerWithKeywordAndSearchProviders() adds the keyword provider
+ // first, then the search provider. So if the default match is a keyword
+ // match, it will come from provider 0, otherwise from provider 1.
+ EXPECT_EQ(providers_[allow_exact_keyword_match ? 0 : 1],
+ controller_->result().default_match()->provider);
+}
+
void AutocompleteProviderTest::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -176,6 +237,7 @@ void AutocompleteProviderTest::Observe(NotificationType type,
// Tests that the default selection is set properly when updating results.
TEST_F(AutocompleteProviderTest, Query) {
+ ResetControllerWithTestProviders(false);
RunTest();
// Make sure the default match gets set to the highest relevance match. The
@@ -186,9 +248,7 @@ TEST_F(AutocompleteProviderTest, Query) {
}
TEST_F(AutocompleteProviderTest, RemoveDuplicates) {
- // Set up the providers to provide duplicate results.
- ResetController(true);
-
+ ResetControllerWithTestProviders(true);
RunTest();
// Make sure all the first provider's results were eliminated by the second
@@ -197,10 +257,12 @@ TEST_F(AutocompleteProviderTest, RemoveDuplicates) {
for (AutocompleteResult::const_iterator i(result_.begin());
i != result_.end(); ++i)
EXPECT_EQ(providers_[1], i->provider);
+}
- // Set things back to the default for the benefit of any tests that run after
- // us.
- ResetController(false);
+TEST_F(AutocompleteProviderTest, AllowExactKeywordMatch) {
+ ResetControllerWithTestProvidersWithKeywordAndSearchProviders();
+ RunExactKeymatchTest(true);
+ RunExactKeymatchTest(false);
}
TEST(AutocompleteTest, InputType) {
@@ -283,7 +345,7 @@ TEST(AutocompleteTest, InputType) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
AutocompleteInput input(input_cases[i].input, std::wstring(), true, false,
- false);
+ true, false);
EXPECT_EQ(input_cases[i].type, input.type()) << "Input: " <<
input_cases[i].input;
}
@@ -299,7 +361,8 @@ TEST(AutocompleteTest, InputTypeWithDesiredTLD) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
- AutocompleteInput input(input_cases[i].input, L"com", true, false, false);
+ AutocompleteInput input(input_cases[i].input, L"com", true, false, true,
+ false);
EXPECT_EQ(input_cases[i].type, input.type()) << "Input: " <<
input_cases[i].input;
}
@@ -308,7 +371,8 @@ TEST(AutocompleteTest, InputTypeWithDesiredTLD) {
// This tests for a regression where certain input in the omnibox caused us to
// crash. As long as the test completes without crashing, we're fine.
TEST(AutocompleteTest, InputCrash) {
- AutocompleteInput input(L"\uff65@s", std::wstring(), true, false, false);
+ AutocompleteInput input(L"\uff65@s", std::wstring(), true, false, true,
+ false);
}
// Test that we can properly compare matches' relevance when at least one is
@@ -372,7 +436,7 @@ TEST(AutocompleteInput, ParseForEmphasizeComponent) {
&scheme,
&host);
AutocompleteInput input(input_cases[i].input, std::wstring(), true, false,
- false);
+ true, false);
EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin) << "Input: " <<
input_cases[i].input;
EXPECT_EQ(input_cases[i].scheme.len, scheme.len) << "Input: " <<
diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
index 9f1119b..b6c3208 100644
--- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
@@ -105,7 +105,7 @@ class HistoryContentsProviderTest : public testing::Test,
};
TEST_F(HistoryContentsProviderTest, Body) {
- AutocompleteInput input(L"FOO", std::wstring(), true, false, false);
+ AutocompleteInput input(L"FOO", std::wstring(), true, false, true, false);
RunQuery(input, false);
// The results should be the first two pages, in decreasing order.
@@ -118,7 +118,7 @@ TEST_F(HistoryContentsProviderTest, Body) {
}
TEST_F(HistoryContentsProviderTest, Title) {
- AutocompleteInput input(L"PAGEONE", std::wstring(), true, false, false);
+ AutocompleteInput input(L"PAGEONE", std::wstring(), true, false, true, false);
RunQuery(input, false);
// The results should be the first two pages.
@@ -134,13 +134,15 @@ TEST_F(HistoryContentsProviderTest, Title) {
TEST_F(HistoryContentsProviderTest, MinimalChanges) {
// A minimal changes request when there have been no real queries should
// give us no results.
- AutocompleteInput sync_input(L"PAGEONE", std::wstring(), true, false, true);
+ AutocompleteInput sync_input(L"PAGEONE", std::wstring(), true, false, true,
+ true);
RunQuery(sync_input, true);
const ACMatches& m1 = matches();
EXPECT_EQ(0U, m1.size());
// Now do a "regular" query to get the results.
- AutocompleteInput async_input(L"PAGEONE", std::wstring(), true, false, false);
+ AutocompleteInput async_input(L"PAGEONE", std::wstring(), true, false, true,
+ false);
RunQuery(async_input, false);
const ACMatches& m2 = matches();
EXPECT_EQ(2U, m2.size());
@@ -163,7 +165,7 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) {
ASCIIToUTF16("bar"), true);
// Ask for synchronous. This should only get the bookmark.
- AutocompleteInput sync_input(L"bar", std::wstring(), true, false, true);
+ AutocompleteInput sync_input(L"bar", std::wstring(), true, false, true, true);
RunQuery(sync_input, false);
const ACMatches& m1 = matches();
ASSERT_EQ(1U, m1.size());
@@ -172,7 +174,8 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) {
EXPECT_TRUE(m1[0].starred);
// Ask for async. We should get the bookmark immediately.
- AutocompleteInput async_input(L"bar", std::wstring(), true, false, false);
+ AutocompleteInput async_input(L"bar", std::wstring(), true, false, true,
+ false);
provider()->Start(async_input, false);
const ACMatches& m2 = matches();
ASSERT_EQ(1U, m2.size());
diff --git a/chrome/browser/autocomplete/history_quick_provider_unittest.cc b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
index 6de941a..7dab5dc 100644
--- a/chrome/browser/autocomplete/history_quick_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
@@ -169,7 +169,7 @@ void HistoryQuickProviderTest::RunTest(const std::wstring text,
std::sort(expected_urls.begin(), expected_urls.end());
MessageLoop::current()->RunAllPending();
- AutocompleteInput input(text, std::wstring(), false, false, false);
+ AutocompleteInput input(text, std::wstring(), false, false, true, false);
provider_->Start(input, false);
EXPECT_TRUE(provider_->done());
diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc
index 19f3053..89ed06c 100644
--- a/chrome/browser/autocomplete/history_url_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc
@@ -189,7 +189,7 @@ void HistoryURLProviderTest::RunTest(const std::wstring text,
const std::string* expected_urls,
size_t num_results) {
AutocompleteInput input(text, desired_tld, prevent_inline_autocomplete,
- false, false);
+ false, true, false);
autocomplete_->Start(input, false);
if (!autocomplete_->done())
MessageLoop::current()->Run();
@@ -203,7 +203,7 @@ void HistoryURLProviderTest::RunTest(const std::wstring text,
void HistoryURLProviderTest::RunAdjustOffsetTest(const std::wstring text,
size_t expected_offset) {
- AutocompleteInput input(text, std::wstring(), false, false, false);
+ AutocompleteInput input(text, std::wstring(), false, false, true, false);
autocomplete_->Start(input, false);
if (!autocomplete_->done())
MessageLoop::current()->Run();
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc
index af9c125..64793d9 100644
--- a/chrome/browser/autocomplete/keyword_provider.cc
+++ b/chrome/browser/autocomplete/keyword_provider.cc
@@ -102,6 +102,9 @@ const TemplateURL* KeywordProvider::GetSubstitutingTemplateURLForInput(
Profile* profile,
const AutocompleteInput& input,
std::wstring* remaining_input) {
+ if (!input.allow_exact_keyword_match())
+ return NULL;
+
std::wstring keyword;
if (!ExtractKeywordFromInput(input, &keyword, remaining_input))
return NULL;
@@ -344,9 +347,12 @@ void KeywordProvider::FillInURLAndContents(
// static
int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type,
bool complete,
- bool no_query_text_needed) {
+ bool no_query_text_needed,
+ bool allow_exact_keyword_match) {
if (!complete)
return (type == AutocompleteInput::URL) ? 700 : 450;
+ if (!allow_exact_keyword_match)
+ return 1100;
if (no_query_text_needed)
return 1500;
return (type == AutocompleteInput::QUERY) ? 1450 : 1100;
@@ -375,7 +381,8 @@ AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
// When the user wants keyword matches to take
// preference, score them highly regardless of
// whether the input provides query text.
- input.prefer_keyword() || !supports_replacement);
+ input.prefer_keyword() || !supports_replacement,
+ input.allow_exact_keyword_match());
}
AutocompleteMatch result(this, relevance, false,
supports_replacement ? AutocompleteMatch::SEARCH_OTHER_ENGINE :
@@ -451,8 +458,8 @@ void KeywordProvider::Observe(NotificationType type,
// and subtract 1 for each subsequent suggestion from the extension.
// We know that |complete| is true, because we wouldn't get results from
// the extension unless the full keyword had been typed.
- int first_relevance =
- CalculateRelevance(input.type(), true, input.prefer_keyword());
+ int first_relevance = CalculateRelevance(input.type(), true,
+ input.prefer_keyword(), input.allow_exact_keyword_match());
extension_suggest_matches_.push_back(CreateAutocompleteMatch(
model, keyword, input, keyword.length(),
UTF16ToWide(suggestion.content), first_relevance - (i + 1)));
diff --git a/chrome/browser/autocomplete/keyword_provider.h b/chrome/browser/autocomplete/keyword_provider.h
index 711562a..e39b5b6 100644
--- a/chrome/browser/autocomplete/keyword_provider.h
+++ b/chrome/browser/autocomplete/keyword_provider.h
@@ -105,9 +105,12 @@ class KeywordProvider : public AutocompleteProvider,
// typed the complete keyword, and whether the keyword needs query text (true
// if the keyword supports replacement and the user isn't in "prefer keyword
// matches" mode).
+ // If |allow_exact_keyword_match| is false, the relevance for complete
+ // keywords is degraded.
static int CalculateRelevance(AutocompleteInput::Type type,
bool complete,
- bool no_query_text_needed);
+ bool no_query_text_needed,
+ bool allow_exact_keyword_match);
// Creates a fully marked-up AutocompleteMatch from the user's input.
// If |relevance| is negative, calculate a relevance based on heuristics.
diff --git a/chrome/browser/autocomplete/keyword_provider_unittest.cc b/chrome/browser/autocomplete/keyword_provider_unittest.cc
index e63d548..165662e 100644
--- a/chrome/browser/autocomplete/keyword_provider_unittest.cc
+++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc
@@ -64,7 +64,7 @@ void KeywordProviderTest::RunTest(
ACMatches matches;
for (int i = 0; i < num_cases; ++i) {
AutocompleteInput input(keyword_cases[i].input, std::wstring(), true,
- false, false);
+ false, true, false);
kw_provider_->Start(input, false);
EXPECT_TRUE(kw_provider_->done());
matches = kw_provider_->matches();
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc
index 43ae43b..7e268d1 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -165,7 +165,7 @@ void SearchProviderTest::RunTillProviderDone() {
void SearchProviderTest::QueryForInput(const string16& text) {
// Start a query.
AutocompleteInput input(UTF16ToWide(text), std::wstring(),
- false, false, false);
+ false, false, true, false);
provider_->Start(input, false);
// RunAllPending so that the task scheduled by SearchProvider to create the
diff --git a/chrome/browser/extensions/extension_omnibox_apitest.cc b/chrome/browser/extensions/extension_omnibox_apitest.cc
index 9f9c6a0..c5c54f0 100644
--- a/chrome/browser/extensions/extension_omnibox_apitest.cc
+++ b/chrome/browser/extensions/extension_omnibox_apitest.cc
@@ -93,7 +93,7 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) {
// it.
{
autocomplete_controller->Start(L"keywor", std::wstring(),
- true, false, false);
+ true, false, true, false);
WaitForAutocompleteDone(autocomplete_controller);
EXPECT_TRUE(autocomplete_controller->done());
@@ -118,7 +118,7 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) {
// Test that our extension can send suggestions back to us.
{
autocomplete_controller->Start(L"keyword suggestio", std::wstring(),
- true, false, false);
+ true, false, true, false);
WaitForAutocompleteDone(autocomplete_controller);
EXPECT_TRUE(autocomplete_controller->done());
@@ -167,7 +167,7 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) {
{
ResultCatcher catcher;
autocomplete_controller->Start(L"keyword command", std::wstring(),
- true, false, false);
+ true, false, true, false);
location_bar->AcceptInput();
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}
diff --git a/chrome/browser/gtk/gtk_util.cc b/chrome/browser/gtk/gtk_util.cc
index 74b7423..bb508b7 100644
--- a/chrome/browser/gtk/gtk_util.cc
+++ b/chrome/browser/gtk/gtk_util.cc
@@ -22,11 +22,13 @@
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/gtk/cairo_cached_surface.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
+#include "chrome/browser/profile.h"
#include "chrome/common/renderer_preferences.h"
#include "gfx/gtk_util.h"
#include "googleurl/src/gurl.h"
@@ -959,22 +961,14 @@ bool URLFromPrimarySelection(Profile* profile, GURL* url) {
// Use autocomplete to clean up the text, going so far as to turn it into
// a search query if necessary.
- AutocompleteController controller(profile);
- controller.Start(UTF8ToWide(selection_text),
- std::wstring(), // desired_tld
- true, // prevent_inline_autocomplete
- false, // prefer_keyword
- true); // synchronous_only
+ AutocompleteMatch match;
+ profile->GetAutocompleteClassifier()->Classify(UTF8ToWide(selection_text),
+ std::wstring(), false, &match, NULL);
g_free(selection_text);
- const AutocompleteResult& result = controller.result();
- AutocompleteResult::const_iterator it = result.default_match();
- if (it == result.end())
+ if (!match.destination_url.is_valid())
return false;
- if (!it->destination_url.is_valid())
- return false;
-
- *url = it->destination_url;
+ *url = match.destination_url;
return true;
}
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 989c6c9..20d77d3 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -585,7 +585,7 @@ void RenderViewContextMenu::AppendSearchProvider() {
AutocompleteMatch match;
profile_->GetAutocompleteClassifier()->Classify(params_.selection_text,
- std::wstring(), &match, NULL);
+ std::wstring(), false, &match, NULL);
selection_navigation_url_ = match.destination_url;
if (!selection_navigation_url_.is_valid())
return;
diff --git a/chrome/browser/ui/views/frame/browser_root_view.cc b/chrome/browser/ui/views/frame/browser_root_view.cc
index e423603..e99cccb 100644
--- a/chrome/browser/ui/views/frame/browser_root_view.cc
+++ b/chrome/browser/ui/views/frame/browser_root_view.cc
@@ -145,7 +145,7 @@ bool BrowserRootView::GetPasteAndGoURL(const OSExchangeData& data, GURL* url) {
AutocompleteMatch match;
browser_view_->browser()->profile()->GetAutocompleteClassifier()->Classify(
- text, std::wstring(), &match, NULL);
+ text, std::wstring(), false, &match, NULL);
if (!match.destination_url.is_valid())
return false;