123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- # Add flag to disable automatic search engine collection
- --- a/chrome/browser/about_flags.cc
- +++ b/chrome/browser/about_flags.cc
- @@ -1770,6 +1770,10 @@ const FeatureEntry kFeatureEntries[] = {
- "Enable stacking in tab strip",
- "Forces tabs to be stacked in the tab strip. Otherwise, they follow default behavior.",
- kOsAll, SINGLE_VALUE_TYPE("enable-stacked-tab-strip")},
- + {"disable-search-engine-collection",
- + "Disable search engine collection",
- + "Prevents search engines from being added automatically.",
- + kOsAll, SINGLE_VALUE_TYPE("disable-search-engine-collection")},
- {"ignore-gpu-blacklist", flag_descriptions::kIgnoreGpuBlacklistName,
- flag_descriptions::kIgnoreGpuBlacklistDescription, kOsAll,
- SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist)},
- --- a/chrome/renderer/chrome_render_frame_observer.cc
- +++ b/chrome/renderer/chrome_render_frame_observer.cc
- @@ -129,9 +129,10 @@ ChromeRenderFrameObserver::ChromeRenderF
- if (!render_frame->IsMainFrame())
- return;
-
- -#if BUILDFLAG(SAFE_BROWSING_CSD)
- const base::CommandLine& command_line =
- *base::CommandLine::ForCurrentProcess();
- + should_autocollect_ = !command_line.HasSwitch("disable-search-engine-collection");
- +#if BUILDFLAG(SAFE_BROWSING_CSD)
- if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection))
- SetClientSidePhishingDetection(true);
- #endif
- @@ -365,14 +366,16 @@ void ChromeRenderFrameObserver::DidFinis
- if (frame->Parent())
- return;
-
- - GURL osdd_url = frame->GetDocument().OpenSearchDescriptionURL();
- - if (!osdd_url.is_empty()) {
- - mojo::AssociatedRemote<chrome::mojom::OpenSearchDescriptionDocumentHandler>
- - 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<chrome::mojom::OpenSearchDescriptionDocumentHandler>
- + 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
- @@ -133,6 +133,7 @@ class ChromeRenderFrameObserver : public
- #if BUILDFLAG(SAFE_BROWSING_CSD)
- 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_;
- @@ -150,4 +151,4 @@ class ChromeRenderFrameObserver : public
- DISALLOW_COPY_AND_ASSIGN(ChromeRenderFrameObserver);
- };
-
- -#endif // CHROME_RENDERER_CHROME_RENDER_FRAME_OBSERVER_H_
- \ No newline at end of file
- +#endif // CHROME_RENDERER_CHROME_RENDER_FRAME_OBSERVER_H_
- --- a/components/search_engines/template_url_service.cc
- +++ b/components/search_engines/template_url_service.cc
- @@ -9,6 +9,7 @@
- #include "base/auto_reset.h"
- #include "base/bind.h"
- #include "base/callback.h"
- +#include "base/command_line.h"
- #include "base/debug/crash_logging.h"
- #include "base/format_macros.h"
- #include "base/metrics/histogram_macros.h"
- @@ -199,6 +200,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 -----------------------------------------
- @@ -283,6 +290,7 @@ TemplateURLService::TemplateURLService(
- std::unique_ptr<TemplateURLServiceClient> client,
- const base::Closure& 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)),
- @@ -346,7 +354,7 @@ bool TemplateURLService::CanAddAutogener
- if (existing_url) {
- // We already have a TemplateURL for this keyword. Only allow it to be
- // replaced if the TemplateURL can be replaced.
- - return CanReplace(existing_url);
- + return should_autocollect_ && CanReplace(existing_url);
- }
-
- // We don't have a TemplateURL with keyword. We still may not allow this
- @@ -355,8 +363,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(
- @@ -1396,6 +1404,8 @@ SyncDataMap TemplateURLService::CreateGU
-
- void TemplateURLService::Init(const Initializer* initializers,
- int num_initializers) {
- + should_autocollect_ = ShouldAutocollect();
- +
- if (client_)
- client_->SetOwner(this);
-
- @@ -1617,6 +1627,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;
- @@ -1627,7 +1640,8 @@ bool TemplateURLService::CanAddAutogener
- }
-
- bool TemplateURLService::CanReplace(const TemplateURL* t_url) const {
- - return !ShowInDefaultList(t_url) && t_url->safe_for_autoreplace();
- + return should_autocollect_ && !ShowInDefaultList(t_url) &&
- + t_url->safe_for_autoreplace();
- }
-
- TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword(
- --- a/components/search_engines/template_url_service.h
- +++ b/components/search_engines/template_url_service.h
- @@ -728,6 +728,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<SearchTermsData> search_terms_data_ =
- std::make_unique<SearchTermsData>();
-
|