Commit 5e88351d authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] Add OmniboxFocusType::DELETED_PERMANENT_TEXT = 2 value.

Add a new value to OmniboxFocusType called DELETED_PERMANENT_TEXT,
which corresponds to the Ctrl+L, and then Backspace case.

This CL also breaks OmniboxFocusType out of template_url.h, into its
own header file.

This is because we plan to use OmniboxFocusType within
AutocompleteInput in the next CL, to replace the from_omnibox_focus()
boolean with this multi-valued enum.

Bug: 1106096
Change-Id: I2ef25083845d272fd934adafa66624de85d84cb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2341399Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Tommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796048}
parent aef173a4
...@@ -233,8 +233,9 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input, ...@@ -233,8 +233,9 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input,
TemplateURLRef::SearchTermsArgs search_terms_args; TemplateURLRef::SearchTermsArgs search_terms_args;
search_terms_args.page_classification = current_page_classification_; search_terms_args.page_classification = current_page_classification_;
search_terms_args.omnibox_focus_type = // TODO(tommycli): Once AutocompleteInput supports tracking OmniboxFocusType,
TemplateURLRef::SearchTermsArgs::OmniboxFocusType::ON_FOCUS; // copy the value from there.
search_terms_args.focus_type = OmniboxFocusType::ON_FOCUS;
GURL suggest_url = RemoteSuggestionsService::EndpointUrl( GURL suggest_url = RemoteSuggestionsService::EndpointUrl(
search_terms_args, client()->GetTemplateURLService()); search_terms_args, client()->GetTemplateURLService());
if (!suggest_url.is_valid()) if (!suggest_url.is_valid())
......
...@@ -166,8 +166,7 @@ class ZeroSuggestProviderTest : public testing::Test, ...@@ -166,8 +166,7 @@ class ZeroSuggestProviderTest : public testing::Test,
metrics::OmniboxEventProto::PageClassification page_classification) { metrics::OmniboxEventProto::PageClassification page_classification) {
TemplateURLRef::SearchTermsArgs search_terms_args; TemplateURLRef::SearchTermsArgs search_terms_args;
search_terms_args.page_classification = page_classification; search_terms_args.page_classification = page_classification;
search_terms_args.omnibox_focus_type = search_terms_args.focus_type = OmniboxFocusType::ON_FOCUS;
TemplateURLRef::SearchTermsArgs::OmniboxFocusType::ON_FOCUS;
return RemoteSuggestionsService::EndpointUrl( return RemoteSuggestionsService::EndpointUrl(
search_terms_args, client_->GetTemplateURLService()); search_terms_args, client_->GetTemplateURLService());
} }
......
...@@ -19,6 +19,7 @@ static_library("search_engines") { ...@@ -19,6 +19,7 @@ static_library("search_engines") {
"keyword_table.h", "keyword_table.h",
"keyword_web_data_service.cc", "keyword_web_data_service.cc",
"keyword_web_data_service.h", "keyword_web_data_service.h",
"omnibox_focus_type.h",
"search_engines_pref_names.cc", "search_engines_pref_names.cc",
"search_engines_pref_names.h", "search_engines_pref_names.h",
"search_engines_switches.cc", "search_engines_switches.cc",
......
// 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.
#ifndef COMPONENTS_SEARCH_ENGINES_OMNIBOX_FOCUS_TYPE_H_
#define COMPONENTS_SEARCH_ENGINES_OMNIBOX_FOCUS_TYPE_H_
// For search requests, this enum specifies how the user last interacted with
// the UI control. This is used for both the omnibox and NTP realbox.
// It's called OmniboxFocusType so this enum matches the "oft" GET param.
//
// These values are used as HTTP GET parameter values. Entries should not be
// renumbered and numeric values should never be reused.
enum class OmniboxFocusType {
// The default value. This is used for any search requests without any
// special interaction annotation, including: normal omnibox searches,
// as-you-type omnibox suggestions, as well as non-omnibox searches.
DEFAULT = 0,
// This search request is triggered by the user focusing the omnibox.
ON_FOCUS = 1,
// This search request is triggered by the user deleting all of the
// omnibox permanent text at once, i.e. user is on "https://example.com",
// does Ctrl+L which selects the whole URL, then presses Backspace.
//
// This value does not apply in these circumstances:
// - User deletes their own typed text.
// - User deletes the permanent text one character at a time.
// - User uses Cut (Ctrl+X) to delete the permanent text.
DELETED_PERMANENT_TEXT = 2,
};
#endif // COMPONENTS_SEARCH_ENGINES_OMNIBOX_FOCUS_TYPE_H_
...@@ -1073,11 +1073,10 @@ std::string TemplateURLRef::HandleReplacements( ...@@ -1073,11 +1073,10 @@ std::string TemplateURLRef::HandleReplacements(
case GOOGLE_OMNIBOX_FOCUS_TYPE: case GOOGLE_OMNIBOX_FOCUS_TYPE:
DCHECK(!i->is_post_param); DCHECK(!i->is_post_param);
if (search_terms_args.omnibox_focus_type != if (search_terms_args.focus_type != OmniboxFocusType::DEFAULT) {
SearchTermsArgs::OmniboxFocusType::DEFAULT) {
HandleReplacement("oft", HandleReplacement("oft",
base::NumberToString(static_cast<int>( base::NumberToString(
search_terms_args.omnibox_focus_type)), static_cast<int>(search_terms_args.focus_type)),
*i, &url); *i, &url);
} }
break; break;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/search_engines/omnibox_focus_type.h"
#include "components/search_engines/search_engine_type.h" #include "components/search_engines/search_engine_type.h"
#include "components/search_engines/template_url_data.h" #include "components/search_engines/template_url_data.h"
#include "components/search_engines/template_url_id.h" #include "components/search_engines/template_url_id.h"
...@@ -76,21 +77,6 @@ class TemplateURLRef { ...@@ -76,21 +77,6 @@ class TemplateURLRef {
SearchTermsArgs(const SearchTermsArgs& other); SearchTermsArgs(const SearchTermsArgs& other);
~SearchTermsArgs(); ~SearchTermsArgs();
// If the search request is from the omnibox, this enum may specify details
// about how the user last interacted with the omnibox.
//
// These values are used as HTTP GET parameter values. Entries should not be
// renumbered and numeric values should never be reused.
enum class OmniboxFocusType {
// The default value. This is used for any search requests without any
// special interaction annotation, including: normal omnibox searches,
// as-you-type omnibox suggestions, as well as non-omnibox searches.
DEFAULT = 0,
// This search request is triggered by the user focusing the omnibox.
ON_FOCUS = 1,
};
struct ContextualSearchParams { struct ContextualSearchParams {
ContextualSearchParams(); ContextualSearchParams();
// Modern constructor, used when the content is sent in the HTTP header // Modern constructor, used when the content is sent in the HTTP header
...@@ -186,9 +172,8 @@ class TemplateURLRef { ...@@ -186,9 +172,8 @@ class TemplateURLRef {
// The type the original input query was identified as. // The type the original input query was identified as.
metrics::OmniboxInputType input_type = metrics::OmniboxInputType::EMPTY; metrics::OmniboxInputType input_type = metrics::OmniboxInputType::EMPTY;
// If the search request is from the omnibox, this may specify how the user // Specifies how the user last interacted with the searchbox UI element.
// last interacted with the omnibox. OmniboxFocusType focus_type = OmniboxFocusType::DEFAULT;
OmniboxFocusType omnibox_focus_type = OmniboxFocusType::DEFAULT;
// The optional assisted query stats, aka AQS, used for logging purposes. // The optional assisted query stats, aka AQS, used for logging purposes.
// This string contains impressions of all autocomplete matches shown // This string contains impressions of all autocomplete matches shown
......
...@@ -736,18 +736,19 @@ TEST_F(TemplateURLTest, ReplaceInputType) { ...@@ -736,18 +736,19 @@ TEST_F(TemplateURLTest, ReplaceInputType) {
TEST_F(TemplateURLTest, ReplaceOmniboxFocusType) { TEST_F(TemplateURLTest, ReplaceOmniboxFocusType) {
struct TestData { struct TestData {
const base::string16 search_term; const base::string16 search_term;
TemplateURLRef::SearchTermsArgs::OmniboxFocusType omnibox_focus_type; OmniboxFocusType focus_type;
const std::string url; const std::string url;
const std::string expected_result; const std::string expected_result;
} test_data[] = { } test_data[] = {
{ASCIIToUTF16("foo"), {ASCIIToUTF16("foo"), OmniboxFocusType::DEFAULT,
TemplateURLRef::SearchTermsArgs::OmniboxFocusType::DEFAULT,
"{google:baseURL}?{searchTerms}&{google:omniboxFocusType}", "{google:baseURL}?{searchTerms}&{google:omniboxFocusType}",
"http://www.google.com/?foo&"}, "http://www.google.com/?foo&"},
{ASCIIToUTF16("foo"), {ASCIIToUTF16("foo"), OmniboxFocusType::ON_FOCUS,
TemplateURLRef::SearchTermsArgs::OmniboxFocusType::ON_FOCUS,
"{google:baseURL}?{searchTerms}&{google:omniboxFocusType}", "{google:baseURL}?{searchTerms}&{google:omniboxFocusType}",
"http://www.google.com/?foo&oft=1&"}, "http://www.google.com/?foo&oft=1&"},
{ASCIIToUTF16("foo"), OmniboxFocusType::DELETED_PERMANENT_TEXT,
"{google:baseURL}?{searchTerms}&{google:omniboxFocusType}",
"http://www.google.com/?foo&oft=2&"},
}; };
TemplateURLData data; TemplateURLData data;
data.input_encodings.push_back("UTF-8"); data.input_encodings.push_back("UTF-8");
...@@ -757,7 +758,7 @@ TEST_F(TemplateURLTest, ReplaceOmniboxFocusType) { ...@@ -757,7 +758,7 @@ TEST_F(TemplateURLTest, ReplaceOmniboxFocusType) {
EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_)); EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_)); ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
search_terms_args.omnibox_focus_type = test_data[i].omnibox_focus_type; search_terms_args.focus_type = test_data[i].focus_type;
GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args, GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args,
search_terms_data_)); search_terms_data_));
ASSERT_TRUE(result.is_valid()); ASSERT_TRUE(result.is_valid());
......
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