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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # Add flag to disable automatic search engine collection
  2. --- a/chrome/browser/about_flags.cc
  3. +++ b/chrome/browser/about_flags.cc
  4. @@ -1211,6 +1211,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. @@ -151,9 +151,10 @@ ChromeRenderFrameObserver::ChromeRenderF
  18. if (!render_frame->IsMainFrame())
  19. return;
  20. -#if defined(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 defined(SAFE_BROWSING_CSD)
  25. if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection))
  26. SetClientSidePhishingDetection(true);
  27. #endif
  28. @@ -340,14 +341,16 @@ void ChromeRenderFrameObserver::DidFinis
  29. if (frame->Parent())
  30. return;
  31. - GURL osdd_url = frame->GetDocument().OpenSearchDescriptionURL();
  32. - if (!osdd_url.is_empty()) {
  33. - chrome::mojom::OpenSearchDescriptionDocumentHandlerAssociatedPtr
  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. + chrome::mojom::OpenSearchDescriptionDocumentHandlerAssociatedPtr
  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. @@ -109,6 +109,7 @@ class ChromeRenderFrameObserver : public
  54. // Have the same lifetime as us.
  55. translate::TranslateHelper* translate_helper_;
  56. safe_browsing::PhishingClassifierDelegate* phishing_classifier_;
  57. + bool should_autocollect_; // Whether to autocollect search engines
  58. // Owned by ChromeContentRendererClient and outlive us.
  59. web_cache::WebCacheImpl* web_cache_impl_;
  60. --- a/components/search_engines/template_url_service.cc
  61. +++ b/components/search_engines/template_url_service.cc
  62. @@ -9,6 +9,7 @@
  63. #include "base/auto_reset.h"
  64. #include "base/bind.h"
  65. #include "base/callback.h"
  66. +#include "base/command_line.h"
  67. #include "base/debug/crash_logging.h"
  68. #include "base/format_macros.h"
  69. #include "base/metrics/histogram_macros.h"
  70. @@ -200,6 +201,12 @@ bool IsCreatedByExtension(const Template
  71. template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION;
  72. }
  73. +bool ShouldAutocollect() {
  74. + const base::CommandLine& command_line =
  75. + *base::CommandLine::ForCurrentProcess();
  76. + return !command_line.HasSwitch("disable-search-engine-collection");
  77. +}
  78. +
  79. } // namespace
  80. // TemplateURLService::LessWithPrefix -----------------------------------------
  81. @@ -286,6 +293,7 @@ TemplateURLService::TemplateURLService(
  82. rappor::RapporServiceImpl* rappor_service,
  83. const base::Closure& dsp_change_callback)
  84. : prefs_(prefs),
  85. + should_autocollect_(true),
  86. search_terms_data_(std::move(search_terms_data)),
  87. web_data_service_(web_data_service),
  88. client_(std::move(client)),
  89. @@ -351,7 +359,7 @@ bool TemplateURLService::CanAddAutogener
  90. if (existing_url) {
  91. // We already have a TemplateURL for this keyword. Only allow it to be
  92. // replaced if the TemplateURL can be replaced.
  93. - return CanReplace(existing_url);
  94. + return should_autocollect_ && CanReplace(existing_url);
  95. }
  96. // We don't have a TemplateURL with keyword. We still may not allow this
  97. @@ -360,8 +368,8 @@ bool TemplateURLService::CanAddAutogener
  98. // that may interfere with search queries). An easy heuristic for this is
  99. // whether the user has a TemplateURL that has been manually modified (e.g.,
  100. // renamed) connected to the same host.
  101. - return !url.is_valid() || url.host().empty() ||
  102. - CanAddAutogeneratedKeywordForHost(url.host());
  103. + return should_autocollect_ && (!url.is_valid() || url.host().empty() ||
  104. + CanAddAutogeneratedKeywordForHost(url.host()));
  105. }
  106. bool TemplateURLService::IsPrepopulatedOrCreatedByPolicy(
  107. @@ -1383,6 +1391,8 @@ SyncDataMap TemplateURLService::CreateGU
  108. void TemplateURLService::Init(const Initializer* initializers,
  109. int num_initializers) {
  110. + should_autocollect_ = ShouldAutocollect();
  111. +
  112. if (client_)
  113. client_->SetOwner(this);
  114. @@ -1618,6 +1628,9 @@ void TemplateURLService::ChangeToLoadedS
  115. bool TemplateURLService::CanAddAutogeneratedKeywordForHost(
  116. const std::string& host) const {
  117. + if (!should_autocollect_)
  118. + return false;
  119. +
  120. const TemplateURLSet* urls = provider_map_->GetURLsForHost(host);
  121. if (!urls)
  122. return true;
  123. @@ -1628,7 +1641,8 @@ bool TemplateURLService::CanAddAutogener
  124. }
  125. bool TemplateURLService::CanReplace(const TemplateURL* t_url) const {
  126. - return !ShowInDefaultList(t_url) && t_url->safe_for_autoreplace();
  127. + return should_autocollect_ && !ShowInDefaultList(t_url) &&
  128. + t_url->safe_for_autoreplace();
  129. }
  130. TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword(
  131. --- a/components/search_engines/template_url_service.h
  132. +++ b/components/search_engines/template_url_service.h
  133. @@ -733,6 +733,8 @@ class TemplateURLService : public WebDat
  134. // ---------- Browser state related members ---------------------------------
  135. PrefService* prefs_ = nullptr;
  136. + bool should_autocollect_; // Whether search engines should be auto-collected
  137. +
  138. std::unique_ptr<SearchTermsData> search_terms_data_ =
  139. std::make_unique<SearchTermsData>();