From: Blaise Date: Sat, 22 Aug 2020 08:52:40 -0500 Subject: Add flag for omnibox autocomplete filtering Adds a flag that restricts whether search history, clipboard, bookmarks and internal chrome:// pages will be used for the autocomplete results. --- chrome/browser/about_flags.cc | 21 +++++++++++++++++++ .../browser/autocomplete_controller.cc | 10 +++++++++ .../omnibox/browser/history_url_provider.cc | 3 +++ components/omnibox/browser/search_provider.cc | 4 ++++ components/url_formatter/url_fixer.cc | 3 +++ 5 files changed, 41 insertions(+) diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -503,6 +503,22 @@ const FeatureEntry::FeatureVariation kAdaptiveButtonInTopToolbarVariations[] = { }; #endif // OS_ANDROID +const FeatureEntry::Choice kOmniboxAutocompleteFiltering[] = { + {flags_ui::kGenericExperimentChoiceDefault, "", ""}, + {"Search suggestions only", + "omnibox-autocomplete-filtering", + "search"}, + {"Search suggestions and bookmarks", + "omnibox-autocomplete-filtering", + "search-bookmarks"}, + {"Search suggestions and internal chrome pages", + "omnibox-autocomplete-filtering", + "search-chrome"}, + {"Search suggestions, bookmarks, and internal chrome pages", + "omnibox-autocomplete-filtering", + "search-bookmarks-chrome"}, +}; + #if defined(OS_ANDROID) const FeatureEntry::FeatureParam kHideDismissButton[] = { {"dismiss_button", "hide"}}; @@ -4769,6 +4785,11 @@ const FeatureEntry kFeatureEntries[] = { FEATURE_VALUE_TYPE(chrome::android::kReaderModeInCCT)}, #endif // !defined(OS_ANDROID) + {"omnibox-autocomplete-filtering", + "Omnibox Autocomplete Filtering", + "Restrict omnibox autocomplete results to a combination of search suggestions (if enabled), bookmarks, and internal chrome pages. ungoogled-chromium flag.", + kOsAll, MULTI_VALUE_TYPE(kOmniboxAutocompleteFiltering)}, + #if defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) || \ defined(OS_CHROMEOS) {"direct-manipulation-stylus", diff --git a/components/omnibox/browser/autocomplete_controller.cc b/components/omnibox/browser/autocomplete_controller.cc --- a/components/omnibox/browser/autocomplete_controller.cc +++ b/components/omnibox/browser/autocomplete_controller.cc @@ -15,6 +15,7 @@ #include "base/bind.h" #include "base/check_op.h" +#include "base/command_line.h" #include "base/feature_list.h" #include "base/format_macros.h" #include "base/metrics/histogram.h" @@ -275,6 +276,15 @@ AutocompleteController::AutocompleteController( search_service_worker_signal_sent_(false), template_url_service_(provider_client_->GetTemplateURLService()) { provider_types &= ~OmniboxFieldTrial::GetDisabledProviderTypes(); + if (base::CommandLine::ForCurrentProcess()->HasSwitch("omnibox-autocomplete-filtering")) { + const std::string flag_value = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("omnibox-autocomplete-filtering"); + provider_types &= AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH | + AutocompleteProvider::TYPE_HISTORY_URL | AutocompleteProvider::TYPE_BOOKMARK | AutocompleteProvider::TYPE_BUILTIN; + if (!base::Contains(flag_value, "bookmarks")) + provider_types &= ~AutocompleteProvider::TYPE_BOOKMARK; + if (!base::Contains(flag_value, "chrome")) + provider_types &= ~AutocompleteProvider::TYPE_BUILTIN; + } if (provider_types & AutocompleteProvider::TYPE_BOOKMARK) providers_.push_back(new BookmarkProvider(provider_client_.get())); if (provider_types & AutocompleteProvider::TYPE_BUILTIN) diff --git a/components/omnibox/browser/history_url_provider.cc b/components/omnibox/browser/history_url_provider.cc --- a/components/omnibox/browser/history_url_provider.cc +++ b/components/omnibox/browser/history_url_provider.cc @@ -553,6 +553,9 @@ void HistoryURLProvider::Start(const AutocompleteInput& input, if (fixed_up_input.type() != metrics::OmniboxInputType::QUERY) matches_.push_back(what_you_typed_match); + if (base::CommandLine::ForCurrentProcess()->HasSwitch("omnibox-autocomplete-filtering")) + return; + // We'll need the history service to run both passes, so try to obtain it. history::HistoryService* const history_service = client()->GetHistoryService(); diff --git a/components/omnibox/browser/search_provider.cc b/components/omnibox/browser/search_provider.cc --- a/components/omnibox/browser/search_provider.cc +++ b/components/omnibox/browser/search_provider.cc @@ -12,6 +12,7 @@ #include "base/base64.h" #include "base/bind.h" #include "base/callback.h" +#include "base/command_line.h" #include "base/feature_list.h" #include "base/i18n/break_iterator.h" #include "base/i18n/case_conversion.h" @@ -643,6 +644,9 @@ void SearchProvider::Run(bool query_is_private) { } void SearchProvider::DoHistoryQuery(bool minimal_changes) { + if (base::CommandLine::ForCurrentProcess()->HasSwitch("omnibox-autocomplete-filtering")) + return; + // The history query results are synchronous, so if minimal_changes is true, // we still have the last results and don't need to do anything. if (minimal_changes) diff --git a/components/url_formatter/url_fixer.cc b/components/url_formatter/url_fixer.cc --- a/components/url_formatter/url_fixer.cc +++ b/components/url_formatter/url_fixer.cc @@ -9,6 +9,7 @@ #include #include "base/check_op.h" +#include "base/command_line.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/ranges/algorithm.h" @@ -607,6 +608,8 @@ GURL FixupURL(const std::string& text, const std::string& desired_tld) { FixupHost(trimmed, parts.host, parts.scheme.is_valid(), desired_tld, &url); if (chrome_url && !parts.host.is_valid()) + if (!base::CommandLine::ForCurrentProcess()->HasSwitch("omnibox-autocomplete-filtering") || + base::Contains(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("omnibox-autocomplete-filtering"), "chrome")) url.append(kChromeUIDefaultHost); FixupPort(trimmed, parts.port, &url); FixupPath(trimmed, parts.path, &url); -- 2.17.1