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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. # Add flag to disable automatic search engine collection
  2. --- a/chrome/browser/about_flags.cc
  3. +++ b/chrome/browser/about_flags.cc
  4. @@ -1770,6 +1770,10 @@ const FeatureEntry kFeatureEntries[] = {
  5. "Enable stacking in tab strip",
  6. "Forces tabs to be stacked in the tab strip. Otherwise, they follow default behavior.",
  7. kOsAll, SINGLE_VALUE_TYPE("enable-stacked-tab-strip")},
  8. + {"disable-search-engine-collection",
  9. + "Disable search engine collection",
  10. + "Prevents search engines from being added automatically.",
  11. + kOsAll, SINGLE_VALUE_TYPE("disable-search-engine-collection")},
  12. {"ignore-gpu-blacklist", flag_descriptions::kIgnoreGpuBlacklistName,
  13. flag_descriptions::kIgnoreGpuBlacklistDescription, kOsAll,
  14. SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist)},
  15. --- a/chrome/renderer/chrome_render_frame_observer.cc
  16. +++ b/chrome/renderer/chrome_render_frame_observer.cc
  17. @@ -129,9 +129,10 @@ ChromeRenderFrameObserver::ChromeRenderF
  18. if (!render_frame->IsMainFrame())
  19. return;
  20. -#if BUILDFLAG(SAFE_BROWSING_CSD)
  21. const base::CommandLine& command_line =
  22. *base::CommandLine::ForCurrentProcess();
  23. + should_autocollect_ = !command_line.HasSwitch("disable-search-engine-collection");
  24. +#if BUILDFLAG(SAFE_BROWSING_CSD)
  25. if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection))
  26. SetClientSidePhishingDetection(true);
  27. #endif
  28. @@ -365,14 +366,16 @@ void ChromeRenderFrameObserver::DidFinis
  29. if (frame->Parent())
  30. return;
  31. - GURL osdd_url = frame->GetDocument().OpenSearchDescriptionURL();
  32. - if (!osdd_url.is_empty()) {
  33. - mojo::AssociatedRemote<chrome::mojom::OpenSearchDescriptionDocumentHandler>
  34. - osdd_handler;
  35. - render_frame()->GetRemoteAssociatedInterfaces()->GetInterface(
  36. - &osdd_handler);
  37. - osdd_handler->PageHasOpenSearchDescriptionDocument(
  38. - frame->GetDocument().Url(), osdd_url);
  39. + if (should_autocollect_) {
  40. + GURL osdd_url = frame->GetDocument().OpenSearchDescriptionURL();
  41. + if (!osdd_url.is_empty()) {
  42. + mojo::AssociatedRemote<chrome::mojom::OpenSearchDescriptionDocumentHandler>
  43. + osdd_handler;
  44. + render_frame()->GetRemoteAssociatedInterfaces()->GetInterface(
  45. + &osdd_handler);
  46. + osdd_handler->PageHasOpenSearchDescriptionDocument(
  47. + frame->GetDocument().Url(), osdd_url);
  48. + }
  49. }
  50. }
  51. --- a/chrome/renderer/chrome_render_frame_observer.h
  52. +++ b/chrome/renderer/chrome_render_frame_observer.h
  53. @@ -133,6 +133,7 @@ class ChromeRenderFrameObserver : public
  54. #if BUILDFLAG(SAFE_BROWSING_CSD)
  55. safe_browsing::PhishingClassifierDelegate* phishing_classifier_ = nullptr;
  56. #endif
  57. + bool should_autocollect_; // Whether to autocollect search engines
  58. // Owned by ChromeContentRendererClient and outlive us.
  59. web_cache::WebCacheImpl* web_cache_impl_;
  60. @@ -150,4 +151,4 @@ class ChromeRenderFrameObserver : public
  61. DISALLOW_COPY_AND_ASSIGN(ChromeRenderFrameObserver);
  62. };
  63. -#endif // CHROME_RENDERER_CHROME_RENDER_FRAME_OBSERVER_H_
  64. \ No newline at end of file
  65. +#endif // CHROME_RENDERER_CHROME_RENDER_FRAME_OBSERVER_H_
  66. --- a/components/search_engines/template_url_service.cc
  67. +++ b/components/search_engines/template_url_service.cc
  68. @@ -9,6 +9,7 @@
  69. #include "base/auto_reset.h"
  70. #include "base/bind.h"
  71. #include "base/callback.h"
  72. +#include "base/command_line.h"
  73. #include "base/debug/crash_logging.h"
  74. #include "base/format_macros.h"
  75. #include "base/metrics/histogram_macros.h"
  76. @@ -199,6 +200,12 @@ bool IsCreatedByExtension(const Template
  77. template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION;
  78. }
  79. +bool ShouldAutocollect() {
  80. + const base::CommandLine& command_line =
  81. + *base::CommandLine::ForCurrentProcess();
  82. + return !command_line.HasSwitch("disable-search-engine-collection");
  83. +}
  84. +
  85. } // namespace
  86. // TemplateURLService::LessWithPrefix -----------------------------------------
  87. @@ -283,6 +290,7 @@ TemplateURLService::TemplateURLService(
  88. std::unique_ptr<TemplateURLServiceClient> client,
  89. const base::Closure& dsp_change_callback)
  90. : prefs_(prefs),
  91. + should_autocollect_(true),
  92. search_terms_data_(std::move(search_terms_data)),
  93. web_data_service_(web_data_service),
  94. client_(std::move(client)),
  95. @@ -346,7 +354,7 @@ bool TemplateURLService::CanAddAutogener
  96. if (existing_url) {
  97. // We already have a TemplateURL for this keyword. Only allow it to be
  98. // replaced if the TemplateURL can be replaced.
  99. - return CanReplace(existing_url);
  100. + return should_autocollect_ && CanReplace(existing_url);
  101. }
  102. // We don't have a TemplateURL with keyword. We still may not allow this
  103. @@ -355,8 +363,8 @@ bool TemplateURLService::CanAddAutogener
  104. // that may interfere with search queries). An easy heuristic for this is
  105. // whether the user has a TemplateURL that has been manually modified (e.g.,
  106. // renamed) connected to the same host.
  107. - return !url.is_valid() || url.host().empty() ||
  108. - CanAddAutogeneratedKeywordForHost(url.host());
  109. + return should_autocollect_ && (!url.is_valid() || url.host().empty() ||
  110. + CanAddAutogeneratedKeywordForHost(url.host()));
  111. }
  112. bool TemplateURLService::IsPrepopulatedOrCreatedByPolicy(
  113. @@ -1396,6 +1404,8 @@ SyncDataMap TemplateURLService::CreateGU
  114. void TemplateURLService::Init(const Initializer* initializers,
  115. int num_initializers) {
  116. + should_autocollect_ = ShouldAutocollect();
  117. +
  118. if (client_)
  119. client_->SetOwner(this);
  120. @@ -1617,6 +1627,9 @@ void TemplateURLService::ChangeToLoadedS
  121. bool TemplateURLService::CanAddAutogeneratedKeywordForHost(
  122. const std::string& host) const {
  123. + if (!should_autocollect_)
  124. + return false;
  125. +
  126. const TemplateURLSet* urls = provider_map_->GetURLsForHost(host);
  127. if (!urls)
  128. return true;
  129. @@ -1627,7 +1640,8 @@ bool TemplateURLService::CanAddAutogener
  130. }
  131. bool TemplateURLService::CanReplace(const TemplateURL* t_url) const {
  132. - return !ShowInDefaultList(t_url) && t_url->safe_for_autoreplace();
  133. + return should_autocollect_ && !ShowInDefaultList(t_url) &&
  134. + t_url->safe_for_autoreplace();
  135. }
  136. TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword(
  137. --- a/components/search_engines/template_url_service.h
  138. +++ b/components/search_engines/template_url_service.h
  139. @@ -728,6 +728,8 @@ class TemplateURLService : public WebDat
  140. // ---------- Browser state related members ---------------------------------
  141. PrefService* prefs_ = nullptr;
  142. + bool should_autocollect_; // Whether search engines should be auto-collected
  143. +
  144. std::unique_ptr<SearchTermsData> search_terms_data_ =
  145. std::make_unique<SearchTermsData>();