Commit 457253d3 authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski

Android: Always offer a zero-suggest verbatim match for websites.

This is done so that the search-ready omnibox (SRO) will be shown
even in cases where there are currently no matches. Specifically,
in Incognito mode tabs.

SRO will be shown whenever the User focuses the Omnibox, or clears
the Omnibox content while visiting a Website, regardless of the
session type.

Bug: 1114125
Change-Id: I4446d10b341d55e9492fc128a4bf61a4edf6d0c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2350762Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798946}
parent 4baa9084
...@@ -200,6 +200,8 @@ static_library("browser") { ...@@ -200,6 +200,8 @@ static_library("browser") {
"verbatim_match.h", "verbatim_match.h",
"zero_suggest_provider.cc", "zero_suggest_provider.cc",
"zero_suggest_provider.h", "zero_suggest_provider.h",
"zero_suggest_verbatim_match_provider.cc",
"zero_suggest_verbatim_match_provider.h",
] ]
public_deps = [ public_deps = [
...@@ -507,6 +509,7 @@ source_set("unit_tests") { ...@@ -507,6 +509,7 @@ source_set("unit_tests") {
"titled_url_match_utils_unittest.cc", "titled_url_match_utils_unittest.cc",
"url_prefix_unittest.cc", "url_prefix_unittest.cc",
"zero_suggest_provider_unittest.cc", "zero_suggest_provider_unittest.cc",
"zero_suggest_verbatim_match_provider_unittest.cc",
] ]
deps = [ deps = [
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "components/omnibox/browser/search_provider.h" #include "components/omnibox/browser/search_provider.h"
#include "components/omnibox/browser/shortcuts_provider.h" #include "components/omnibox/browser/shortcuts_provider.h"
#include "components/omnibox/browser/zero_suggest_provider.h" #include "components/omnibox/browser/zero_suggest_provider.h"
#include "components/omnibox/browser/zero_suggest_verbatim_match_provider.h"
#include "components/omnibox/common/omnibox_features.h" #include "components/omnibox/common/omnibox_features.h"
#include "components/open_from_clipboard/clipboard_recent_content.h" #include "components/open_from_clipboard/clipboard_recent_content.h"
#include "components/search_engines/omnibox_focus_type.h" #include "components/search_engines/omnibox_focus_type.h"
...@@ -287,6 +288,18 @@ AutocompleteController::AutocompleteController( ...@@ -287,6 +288,18 @@ AutocompleteController::AutocompleteController(
ZeroSuggestProvider::Create(provider_client_.get(), this); ZeroSuggestProvider::Create(provider_client_.get(), this);
if (zero_suggest_provider_) if (zero_suggest_provider_)
providers_.push_back(zero_suggest_provider_); providers_.push_back(zero_suggest_provider_);
#if defined(OS_ANDROID)
// Note: the need for the always-present verbatim match originates from the
// OmniboxSearchReadyIncognito feature.
// The feature aims at showing SRO in an Incognito mode, where the
// ZeroSuggestProvider intentionally never gets invoked.
// The gating flag here should be removed when the SRO Incognito is
// launched.
if (base::FeatureList::IsEnabled(omnibox::kOmniboxSearchReadyIncognito)) {
providers_.push_back(
new ZeroSuggestVerbatimMatchProvider(provider_client_.get()));
}
#endif
} }
if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST_LOCAL_HISTORY) { if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST_LOCAL_HISTORY) {
providers_.push_back( providers_.push_back(
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/omnibox/browser/zero_suggest_verbatim_match_provider.h"
#include "components/omnibox/browser/autocomplete_provider_client.h"
#include "components/omnibox/browser/autocomplete_provider_listener.h"
#include "components/omnibox/browser/verbatim_match.h"
namespace {
// The relevance score for verbatim match.
// Must outrank the QueryTiles relevance score.
const int kVerbatimMatchRelevanceScore = 1600;
} // namespace
ZeroSuggestVerbatimMatchProvider::ZeroSuggestVerbatimMatchProvider(
AutocompleteProviderClient* client)
: AutocompleteProvider(TYPE_ZERO_SUGGEST), client_(client) {}
ZeroSuggestVerbatimMatchProvider::~ZeroSuggestVerbatimMatchProvider() = default;
void ZeroSuggestVerbatimMatchProvider::Start(const AutocompleteInput& input,
bool minimal_changes) {
Stop(true, false);
// Only offer verbatim match on a site visit (non-SRP, non-NTP).
if (input.current_page_classification() != metrics::OmniboxEventProto::OTHER)
return;
// Only offer verbatim match after the user just focused the Omnibox,
// or if the input field is empty.
if (!((input.focus_type() == OmniboxFocusType::ON_FOCUS) ||
(input.type() == metrics::OmniboxInputType::EMPTY))) {
return;
}
// Do not offer verbatim match, if the Omnibox does not contain a valid URL.
if (!input.current_url().is_valid())
return;
const auto& current_query = input.current_url().spec();
const auto& current_title = input.current_title();
AutocompleteInput verbatim_input = input;
verbatim_input.set_prevent_inline_autocomplete(true);
verbatim_input.set_allow_exact_keyword_match(false);
AutocompleteMatch match =
VerbatimMatchForURL(client_, verbatim_input, GURL(current_query),
current_title, nullptr, kVerbatimMatchRelevanceScore);
match.provider = this;
matches_.push_back(match);
}
void ZeroSuggestVerbatimMatchProvider::Stop(bool clear_cached_results,
bool due_to_user_inactivity) {
matches_.clear();
}
\ No newline at end of file
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_OMNIBOX_BROWSER_ZERO_SUGGEST_VERBATIM_MATCH_PROVIDER_H_
#define COMPONENTS_OMNIBOX_BROWSER_ZERO_SUGGEST_VERBATIM_MATCH_PROVIDER_H_
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_provider.h"
class AutocompleteProviderClient;
// An autocomplete provider that supplies the Verbatim Match for websites.
// The match is provided when the user focuses the omnibox, or if the user
// clears the contents of the Omnibox while visiting a website.
// This provider is intended for use on all platforms that always need the
// verbatim match on focus, like the Android Search Ready Omnibox.
// Note that the verbatim match may be also supplied by other providers,
// eg. ZeroSuggestProvider, but it will be deduplicated and the higher score
// from this provider will be used to boost it up to the top.
class ZeroSuggestVerbatimMatchProvider : public AutocompleteProvider {
public:
explicit ZeroSuggestVerbatimMatchProvider(AutocompleteProviderClient* client);
void Start(const AutocompleteInput& input, bool minimal_changes) override;
void Stop(bool clear_cached_results, bool due_to_user_inactivity) override;
private:
~ZeroSuggestVerbatimMatchProvider() override;
AutocompleteProviderClient* const client_{nullptr};
};
#endif // COMPONENTS_OMNIBOX_BROWSER_ZERO_SUGGEST_VERBATIM_MATCH_PROVIDER_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/omnibox/browser/zero_suggest_verbatim_match_provider.h"
#include <list>
#include <map>
#include <memory>
#include <string>
#include "base/strings/utf_string_conversions.h"
#include "components/omnibox/browser/mock_autocomplete_provider_client.h"
#include "components/omnibox/browser/test_scheme_classifier.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
class ZeroSuggestVerbatimMatchProviderTest : public testing::Test {
public:
ZeroSuggestVerbatimMatchProviderTest() = default;
void SetUp() override;
protected:
scoped_refptr<ZeroSuggestVerbatimMatchProvider> provider_;
MockAutocompleteProviderClient mock_client_;
};
void ZeroSuggestVerbatimMatchProviderTest::SetUp() {
provider_ = new ZeroSuggestVerbatimMatchProvider(&mock_client_);
}
TEST_F(ZeroSuggestVerbatimMatchProviderTest,
NoVerbatimMatchWhenOmniboxIsOnNTP) {
std::string url("chrome://newtab");
AutocompleteInput input(base::string16(), metrics::OmniboxEventProto::NTP,
TestSchemeClassifier());
input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::ON_FOCUS);
provider_->Start(input, false);
EXPECT_TRUE(provider_->matches().empty());
}
TEST_F(ZeroSuggestVerbatimMatchProviderTest,
NoVerbatimMatchForSearchResultsPage) {
std::string query("https://google.com/search?q=test");
AutocompleteInput input(
base::ASCIIToUTF16("test"),
metrics::OmniboxEventProto::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT,
TestSchemeClassifier());
input.set_current_url(GURL(query));
input.set_focus_type(OmniboxFocusType::ON_FOCUS);
provider_->Start(input, false);
EXPECT_TRUE(provider_->matches().empty());
}
TEST_F(ZeroSuggestVerbatimMatchProviderTest,
OffersVerbatimMatchInNonIncognito) {
std::string url("https://www.wired.com/");
AutocompleteInput input(base::ASCIIToUTF16(url),
metrics::OmniboxEventProto::OTHER,
TestSchemeClassifier());
input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::ON_FOCUS);
provider_->Start(input, false);
ASSERT_EQ(1U, provider_->matches().size());
// Note: we intentionally do not validate the match content here.
// The content is populated either by HistoryURLProvider or
// AutocompleteProviderClient both of which we would have to mock for this
// test. As a result, the test would validate what the mocks fill in.
}
TEST_F(ZeroSuggestVerbatimMatchProviderTest, OffersVerbatimMatchInIncognito) {
std::string url("https://www.theverge.com/");
AutocompleteInput input(base::ASCIIToUTF16(url),
metrics::OmniboxEventProto::OTHER,
TestSchemeClassifier());
input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::ON_FOCUS);
provider_->Start(input, false);
ASSERT_EQ(1U, provider_->matches().size());
// Note: we intentionally do not validate the match content here.
// The content is populated either by HistoryURLProvider or
// AutocompleteProviderClient both of which we would have to mock for this
// test. As a result, the test would validate what the mocks fill in.
}
TEST_F(ZeroSuggestVerbatimMatchProviderTest,
OffersVerbatimMatchNonIncognitoWithEmptyOmnibox) {
std::string url("https://www.wired.com/");
AutocompleteInput input(base::string16(), // Note: empty input.
metrics::OmniboxEventProto::OTHER,
TestSchemeClassifier());
input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::DEFAULT);
provider_->Start(input, false);
ASSERT_EQ(1U, provider_->matches().size());
// Note: we intentionally do not validate the match content here.
// The content is populated either by HistoryURLProvider or
// AutocompleteProviderClient both of which we would have to mock for this
// test. As a result, the test would validate what the mocks fill in.
}
TEST_F(ZeroSuggestVerbatimMatchProviderTest,
OffersVerbatimMatchInIncognitoWithEmptyOmnibox) {
std::string url("https://www.theverge.com/");
AutocompleteInput input(base::string16(), // Note: empty input.
metrics::OmniboxEventProto::OTHER,
TestSchemeClassifier());
input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::DEFAULT);
provider_->Start(input, false);
ASSERT_EQ(1U, provider_->matches().size());
// Note: we intentionally do not validate the match content here.
// The content is populated either by HistoryURLProvider or
// AutocompleteProviderClient both of which we would have to mock for this
// test. As a result, the test would validate what the mocks fill in.
}
\ No newline at end of file
...@@ -345,7 +345,7 @@ extern const base::Feature kDeferredKeyboardPopup{ ...@@ -345,7 +345,7 @@ extern const base::Feature kDeferredKeyboardPopup{
const base::Feature kRichAutocompletion{"OmniboxRichAutocompletion", const base::Feature kRichAutocompletion{"OmniboxRichAutocompletion",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
// Feature that enables Search Ready Omnibox in invognito. // Feature that enables Search Ready Omnibox in incognito.
const base::Feature kOmniboxSearchReadyIncognito{ const base::Feature kOmniboxSearchReadyIncognito{
"OmniboxSearchReadyIncognito", base::FEATURE_DISABLED_BY_DEFAULT}; "OmniboxSearchReadyIncognito", base::FEATURE_DISABLED_BY_DEFAULT};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment