# Add flag to disable automatic search engine collection --- a/chrome/browser/ungoogled_flag_entries.h +++ b/chrome/browser/ungoogled_flag_entries.h @@ -12,4 +12,8 @@ "Handling of extension MIME type requests", "Used when deciding how to handle a request for a CRX or User Script MIME type. ungoogled-chromium flag.", kOsAll, MULTI_VALUE_TYPE(kExtensionHandlingChoices)}, + {"disable-search-engine-collection", + "Disable search engine collection", + "Prevents search engines from being added automatically. ungoogled-chromium flag.", + kOsAll, SINGLE_VALUE_TYPE("disable-search-engine-collection")}, #endif // CHROME_BROWSER_UNGOOGLED_FLAG_ENTRIES_H_ --- a/chrome/renderer/chrome_render_frame_observer.cc +++ b/chrome/renderer/chrome_render_frame_observer.cc @@ -139,9 +139,10 @@ ChromeRenderFrameObserver::ChromeRenderF if (!render_frame->IsMainFrame()) return; -#if BUILDFLAG(SAFE_BROWSING_AVAILABLE) const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); + should_autocollect_ = !command_line.HasSwitch("disable-search-engine-collection"); +#if BUILDFLAG(SAFE_BROWSING_AVAILABLE) if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) SetClientSidePhishingDetection(); #endif @@ -201,14 +202,16 @@ void ChromeRenderFrameObserver::DidFinis if (frame->Parent()) return; - GURL osdd_url = frame->GetDocument().OpenSearchDescriptionURL(); - if (!osdd_url.is_empty()) { - mojo::AssociatedRemote - osdd_handler; - render_frame()->GetRemoteAssociatedInterfaces()->GetInterface( - &osdd_handler); - osdd_handler->PageHasOpenSearchDescriptionDocument( - frame->GetDocument().Url(), osdd_url); + if (should_autocollect_) { + GURL osdd_url = frame->GetDocument().OpenSearchDescriptionURL(); + if (!osdd_url.is_empty()) { + mojo::AssociatedRemote + osdd_handler; + render_frame()->GetRemoteAssociatedInterfaces()->GetInterface( + &osdd_handler); + osdd_handler->PageHasOpenSearchDescriptionDocument( + frame->GetDocument().Url(), osdd_url); + } } } --- a/chrome/renderer/chrome_render_frame_observer.h +++ b/chrome/renderer/chrome_render_frame_observer.h @@ -139,6 +139,7 @@ class ChromeRenderFrameObserver : public #if BUILDFLAG(SAFE_BROWSING_AVAILABLE) safe_browsing::PhishingClassifierDelegate* phishing_classifier_ = nullptr; #endif + bool should_autocollect_; // Whether to autocollect search engines // Owned by ChromeContentRendererClient and outlive us. web_cache::WebCacheImpl* web_cache_impl_; --- a/components/search_engines/template_url_service.cc +++ b/components/search_engines/template_url_service.cc @@ -12,6 +12,7 @@ #include "base/bind.h" #include "base/callback.h" #include "base/callback_helpers.h" +#include "base/command_line.h" #include "base/containers/contains.h" #include "base/debug/crash_logging.h" #include "base/format_macros.h" @@ -197,6 +198,12 @@ bool IsCreatedByExtension(const Template template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION; } +bool ShouldAutocollect() { + const base::CommandLine& command_line = + *base::CommandLine::ForCurrentProcess(); + return !command_line.HasSwitch("disable-search-engine-collection"); +} + } // namespace // TemplateURLService::LessWithPrefix ----------------------------------------- @@ -282,6 +289,7 @@ TemplateURLService::TemplateURLService( std::unique_ptr client, const base::RepeatingClosure& dsp_change_callback) : prefs_(prefs), + should_autocollect_(true), search_terms_data_(std::move(search_terms_data)), web_data_service_(web_data_service), client_(std::move(client)), @@ -363,8 +371,8 @@ bool TemplateURLService::CanAddAutogener // that may interfere with search queries). An easy heuristic for this is // whether the user has a TemplateURL that has been manually modified (e.g., // renamed) connected to the same host. - return !url.is_valid() || url.host().empty() || - CanAddAutogeneratedKeywordForHost(url.host()); + return should_autocollect_ && (!url.is_valid() || url.host().empty() || + CanAddAutogeneratedKeywordForHost(url.host())); } bool TemplateURLService::IsPrepopulatedOrCreatedByPolicy( @@ -1500,6 +1508,8 @@ SyncDataMap TemplateURLService::CreateGU void TemplateURLService::Init(const Initializer* initializers, int num_initializers) { + should_autocollect_ = ShouldAutocollect(); + if (client_) client_->SetOwner(this); @@ -1636,6 +1646,9 @@ void TemplateURLService::ChangeToLoadedS bool TemplateURLService::CanAddAutogeneratedKeywordForHost( const std::string& host) const { + if (!should_autocollect_) + return false; + const TemplateURLSet* urls = provider_map_->GetURLsForHost(host); if (!urls) return true; --- a/components/search_engines/template_url_service.h +++ b/components/search_engines/template_url_service.h @@ -706,6 +706,8 @@ class TemplateURLService : public WebDat // ---------- Browser state related members --------------------------------- PrefService* prefs_ = nullptr; + bool should_autocollect_; // Whether search engines should be auto-collected + std::unique_ptr search_terms_data_ = std::make_unique();