1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# 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
@@ -187,9 +187,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
@@ -248,14 +249,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
@@ -140,6 +140,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"
@@ -200,6 +201,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 -----------------------------------------
@@ -285,6 +292,7 @@ TemplateURLService::TemplateURLService(
std::unique_ptr<TemplateURLServiceClient> 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)),
@@ -366,8 +374,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(
@@ -1516,6 +1524,8 @@ SyncDataMap TemplateURLService::CreateGU
void TemplateURLService::Init(const Initializer* initializers,
int num_initializers) {
+ should_autocollect_ = ShouldAutocollect();
+
if (client_)
client_->SetOwner(this);
@@ -1654,6 +1664,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
@@ -716,6 +716,8 @@ class TemplateURLService : public WebDat
// ---------- Browser state related members ---------------------------------
raw_ptr<PrefService> prefs_ = nullptr;
+ bool should_autocollect_; // Whether search engines should be auto-collected
+
std::unique_ptr<SearchTermsData> search_terms_data_ =
std::make_unique<SearchTermsData>();
|