add-flag-for-search-engine-collection.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # Add flag to disable automatic search engine collection
  2. --- a/chrome/browser/ungoogled_flag_entries.h
  3. +++ b/chrome/browser/ungoogled_flag_entries.h
  4. @@ -12,4 +12,8 @@
  5. "Handling of extension MIME type requests",
  6. "Used when deciding how to handle a request for a CRX or User Script MIME type. ungoogled-chromium flag.",
  7. kOsAll, MULTI_VALUE_TYPE(kExtensionHandlingChoices)},
  8. + {"disable-search-engine-collection",
  9. + "Disable search engine collection",
  10. + "Prevents search engines from being added automatically. ungoogled-chromium flag.",
  11. + kOsAll, SINGLE_VALUE_TYPE("disable-search-engine-collection")},
  12. #endif // CHROME_BROWSER_UNGOOGLED_FLAG_ENTRIES_H_
  13. --- a/chrome/renderer/chrome_render_frame_observer.cc
  14. +++ b/chrome/renderer/chrome_render_frame_observer.cc
  15. @@ -139,9 +139,10 @@ ChromeRenderFrameObserver::ChromeRenderF
  16. if (!render_frame->IsMainFrame())
  17. return;
  18. -#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
  19. const base::CommandLine& command_line =
  20. *base::CommandLine::ForCurrentProcess();
  21. + should_autocollect_ = !command_line.HasSwitch("disable-search-engine-collection");
  22. +#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
  23. if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection))
  24. SetClientSidePhishingDetection();
  25. #endif
  26. @@ -201,14 +202,16 @@ void ChromeRenderFrameObserver::DidFinis
  27. if (frame->Parent())
  28. return;
  29. - GURL osdd_url = frame->GetDocument().OpenSearchDescriptionURL();
  30. - if (!osdd_url.is_empty()) {
  31. - mojo::AssociatedRemote<chrome::mojom::OpenSearchDescriptionDocumentHandler>
  32. - osdd_handler;
  33. - render_frame()->GetRemoteAssociatedInterfaces()->GetInterface(
  34. - &osdd_handler);
  35. - osdd_handler->PageHasOpenSearchDescriptionDocument(
  36. - frame->GetDocument().Url(), osdd_url);
  37. + if (should_autocollect_) {
  38. + GURL osdd_url = frame->GetDocument().OpenSearchDescriptionURL();
  39. + if (!osdd_url.is_empty()) {
  40. + mojo::AssociatedRemote<chrome::mojom::OpenSearchDescriptionDocumentHandler>
  41. + osdd_handler;
  42. + render_frame()->GetRemoteAssociatedInterfaces()->GetInterface(
  43. + &osdd_handler);
  44. + osdd_handler->PageHasOpenSearchDescriptionDocument(
  45. + frame->GetDocument().Url(), osdd_url);
  46. + }
  47. }
  48. }
  49. --- a/chrome/renderer/chrome_render_frame_observer.h
  50. +++ b/chrome/renderer/chrome_render_frame_observer.h
  51. @@ -139,6 +139,7 @@ class ChromeRenderFrameObserver : public
  52. #if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
  53. safe_browsing::PhishingClassifierDelegate* phishing_classifier_ = nullptr;
  54. #endif
  55. + bool should_autocollect_; // Whether to autocollect search engines
  56. // Owned by ChromeContentRendererClient and outlive us.
  57. web_cache::WebCacheImpl* web_cache_impl_;
  58. --- a/components/search_engines/template_url_service.cc
  59. +++ b/components/search_engines/template_url_service.cc
  60. @@ -12,6 +12,7 @@
  61. #include "base/bind.h"
  62. #include "base/callback.h"
  63. #include "base/callback_helpers.h"
  64. +#include "base/command_line.h"
  65. #include "base/containers/contains.h"
  66. #include "base/debug/crash_logging.h"
  67. #include "base/format_macros.h"
  68. @@ -197,6 +198,12 @@ bool IsCreatedByExtension(const Template
  69. template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION;
  70. }
  71. +bool ShouldAutocollect() {
  72. + const base::CommandLine& command_line =
  73. + *base::CommandLine::ForCurrentProcess();
  74. + return !command_line.HasSwitch("disable-search-engine-collection");
  75. +}
  76. +
  77. } // namespace
  78. // TemplateURLService::LessWithPrefix -----------------------------------------
  79. @@ -282,6 +289,7 @@ TemplateURLService::TemplateURLService(
  80. std::unique_ptr<TemplateURLServiceClient> client,
  81. const base::RepeatingClosure& dsp_change_callback)
  82. : prefs_(prefs),
  83. + should_autocollect_(true),
  84. search_terms_data_(std::move(search_terms_data)),
  85. web_data_service_(web_data_service),
  86. client_(std::move(client)),
  87. @@ -363,8 +371,8 @@ bool TemplateURLService::CanAddAutogener
  88. // that may interfere with search queries). An easy heuristic for this is
  89. // whether the user has a TemplateURL that has been manually modified (e.g.,
  90. // renamed) connected to the same host.
  91. - return !url.is_valid() || url.host().empty() ||
  92. - CanAddAutogeneratedKeywordForHost(url.host());
  93. + return should_autocollect_ && (!url.is_valid() || url.host().empty() ||
  94. + CanAddAutogeneratedKeywordForHost(url.host()));
  95. }
  96. bool TemplateURLService::IsPrepopulatedOrCreatedByPolicy(
  97. @@ -1500,6 +1508,8 @@ SyncDataMap TemplateURLService::CreateGU
  98. void TemplateURLService::Init(const Initializer* initializers,
  99. int num_initializers) {
  100. + should_autocollect_ = ShouldAutocollect();
  101. +
  102. if (client_)
  103. client_->SetOwner(this);
  104. @@ -1636,6 +1646,9 @@ void TemplateURLService::ChangeToLoadedS
  105. bool TemplateURLService::CanAddAutogeneratedKeywordForHost(
  106. const std::string& host) const {
  107. + if (!should_autocollect_)
  108. + return false;
  109. +
  110. const TemplateURLSet* urls = provider_map_->GetURLsForHost(host);
  111. if (!urls)
  112. return true;
  113. --- a/components/search_engines/template_url_service.h
  114. +++ b/components/search_engines/template_url_service.h
  115. @@ -706,6 +706,8 @@ class TemplateURLService : public WebDat
  116. // ---------- Browser state related members ---------------------------------
  117. PrefService* prefs_ = nullptr;
  118. + bool should_autocollect_; // Whether search engines should be auto-collected
  119. +
  120. std::unique_ptr<SearchTermsData> search_terms_data_ =
  121. std::make_unique<SearchTermsData>();