add-flag-for-omnibox-autocomplete-filtering.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. --- a/chrome/browser/ungoogled_flag_choices.h
  2. +++ b/chrome/browser/ungoogled_flag_choices.h
  3. @@ -45,4 +45,19 @@ const FeatureEntry::Choice kBookmarkBarN
  4. "bookmark-bar-ntp",
  5. "never"},
  6. };
  7. +const FeatureEntry::Choice kOmniboxAutocompleteFiltering[] = {
  8. + {flags_ui::kGenericExperimentChoiceDefault, "", ""},
  9. + {"Search suggestions only",
  10. + "omnibox-autocomplete-filtering",
  11. + "search"},
  12. + {"Search suggestions and bookmarks",
  13. + "omnibox-autocomplete-filtering",
  14. + "search-bookmarks"},
  15. + {"Search suggestions and internal chrome pages",
  16. + "omnibox-autocomplete-filtering",
  17. + "search-chrome"},
  18. + {"Search suggestions, bookmarks, and internal chrome pages",
  19. + "omnibox-autocomplete-filtering",
  20. + "search-bookmarks-chrome"},
  21. +};
  22. #endif // CHROME_BROWSER_UNGOOGLED_FLAG_CHOICES_H_
  23. --- a/chrome/browser/ungoogled_flag_entries.h
  24. +++ b/chrome/browser/ungoogled_flag_entries.h
  25. @@ -44,4 +44,8 @@
  26. "Bookmark Bar on New-Tab-Page",
  27. "Disable the Bookmark Bar on the New-Tab-Page. ungoogled-chromium flag.",
  28. kOsDesktop, MULTI_VALUE_TYPE(kBookmarkBarNewTab)},
  29. + {"omnibox-autocomplete-filtering",
  30. + "Omnibox Autocomplete Filtering",
  31. + "Restrict omnibox autocomplete results to a combination of search suggestions (if enabled), bookmarks, and internal chrome pages. ungoogled-chromium flag.",
  32. + kOsAll, MULTI_VALUE_TYPE(kOmniboxAutocompleteFiltering)},
  33. #endif // CHROME_BROWSER_UNGOOGLED_FLAG_ENTRIES_H_
  34. --- a/components/omnibox/browser/autocomplete_controller.cc
  35. +++ b/components/omnibox/browser/autocomplete_controller.cc
  36. @@ -15,6 +15,8 @@
  37. #include "base/bind.h"
  38. #include "base/check_op.h"
  39. +#include "base/containers/contains.h"
  40. +#include "base/command_line.h"
  41. #include "base/feature_list.h"
  42. #include "base/format_macros.h"
  43. #include "base/metrics/histogram.h"
  44. @@ -276,6 +278,15 @@ AutocompleteController::AutocompleteCont
  45. search_service_worker_signal_sent_(false),
  46. template_url_service_(provider_client_->GetTemplateURLService()) {
  47. provider_types &= ~OmniboxFieldTrial::GetDisabledProviderTypes();
  48. + if (base::CommandLine::ForCurrentProcess()->HasSwitch("omnibox-autocomplete-filtering")) {
  49. + const std::string flag_value = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("omnibox-autocomplete-filtering");
  50. + provider_types &= AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH |
  51. + AutocompleteProvider::TYPE_HISTORY_URL | AutocompleteProvider::TYPE_BOOKMARK | AutocompleteProvider::TYPE_BUILTIN;
  52. + if (!base::Contains(flag_value, "bookmarks"))
  53. + provider_types &= ~AutocompleteProvider::TYPE_BOOKMARK;
  54. + if (!base::Contains(flag_value, "chrome"))
  55. + provider_types &= ~AutocompleteProvider::TYPE_BUILTIN;
  56. + }
  57. if (provider_types & AutocompleteProvider::TYPE_BOOKMARK)
  58. providers_.push_back(new BookmarkProvider(provider_client_.get()));
  59. if (provider_types & AutocompleteProvider::TYPE_BUILTIN)
  60. --- a/components/omnibox/browser/history_url_provider.cc
  61. +++ b/components/omnibox/browser/history_url_provider.cc
  62. @@ -551,6 +551,9 @@ void HistoryURLProvider::Start(const Aut
  63. if (fixed_up_input.type() != metrics::OmniboxInputType::QUERY)
  64. matches_.push_back(what_you_typed_match);
  65. + if (base::CommandLine::ForCurrentProcess()->HasSwitch("omnibox-autocomplete-filtering"))
  66. + return;
  67. +
  68. // We'll need the history service to run both passes, so try to obtain it.
  69. history::HistoryService* const history_service =
  70. client()->GetHistoryService();
  71. --- a/components/omnibox/browser/search_provider.cc
  72. +++ b/components/omnibox/browser/search_provider.cc
  73. @@ -12,6 +12,7 @@
  74. #include "base/base64.h"
  75. #include "base/bind.h"
  76. #include "base/callback.h"
  77. +#include "base/command_line.h"
  78. #include "base/feature_list.h"
  79. #include "base/i18n/break_iterator.h"
  80. #include "base/i18n/case_conversion.h"
  81. @@ -646,6 +647,9 @@ void SearchProvider::Run(bool query_is_p
  82. }
  83. void SearchProvider::DoHistoryQuery(bool minimal_changes) {
  84. + if (base::CommandLine::ForCurrentProcess()->HasSwitch("omnibox-autocomplete-filtering"))
  85. + return;
  86. +
  87. // The history query results are synchronous, so if minimal_changes is true,
  88. // we still have the last results and don't need to do anything.
  89. if (minimal_changes)
  90. --- a/components/url_formatter/url_fixer.cc
  91. +++ b/components/url_formatter/url_fixer.cc
  92. @@ -9,6 +9,8 @@
  93. #include <algorithm>
  94. #include "base/check_op.h"
  95. +#include "base/containers/contains.h"
  96. +#include "base/command_line.h"
  97. #include "base/files/file_path.h"
  98. #include "base/files/file_util.h"
  99. #include "base/ranges/algorithm.h"
  100. @@ -607,6 +609,8 @@ GURL FixupURL(const std::string& text, c
  101. FixupHost(trimmed, parts.host, parts.scheme.is_valid(), desired_tld, &url);
  102. if (chrome_url && !parts.host.is_valid())
  103. + if (!base::CommandLine::ForCurrentProcess()->HasSwitch("omnibox-autocomplete-filtering") ||
  104. + base::Contains(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("omnibox-autocomplete-filtering"), "chrome"))
  105. url.append(kChromeUIDefaultHost);
  106. FixupPort(trimmed, parts.port, &url);
  107. FixupPath(trimmed, parts.path, &url);