-
Notifications
You must be signed in to change notification settings - Fork 892
/
brave_main_delegate.cc
147 lines (131 loc) · 5.54 KB
/
brave_main_delegate.cc
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
135
136
137
138
139
140
141
142
143
144
145
146
147
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/app/brave_main_delegate.h"
#include <sstream>
#include "base/base_switches.h"
#include "base/lazy_instance.h"
#include "base/path_service.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "brave/browser/brave_content_browser_client.h"
#include "brave/common/brave_switches.h"
#include "brave/common/resource_bundle_helper.h"
#include "brave/components/brave_ads/browser/buildflags/buildflags.h"
#include "brave/renderer/brave_content_renderer_client.h"
#include "brave/utility/brave_content_utility_client.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/unified_consent/feature.h"
#include "content/public/common/content_features.h"
#include "extensions/common/extension_features.h"
#include "gpu/config/gpu_finch_features.h"
#include "ui/base/ui_base_features.h"
#if BUILDFLAG(BRAVE_ADS_ENABLED)
#include "components/dom_distiller/core/dom_distiller_switches.h"
#endif
#if !defined(CHROME_MULTIPLE_DLL_BROWSER)
base::LazyInstance<BraveContentRendererClient>::DestructorAtExit
g_brave_content_renderer_client = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<BraveContentUtilityClient>::DestructorAtExit
g_brave_content_utility_client = LAZY_INSTANCE_INITIALIZER;
#endif
#if !defined(CHROME_MULTIPLE_DLL_CHILD)
base::LazyInstance<BraveContentBrowserClient>::DestructorAtExit
g_brave_content_browser_client = LAZY_INSTANCE_INITIALIZER;
#endif
BraveMainDelegate::BraveMainDelegate()
: ChromeMainDelegate() {}
BraveMainDelegate::BraveMainDelegate(base::TimeTicks exe_entry_point_ticks)
: ChromeMainDelegate(exe_entry_point_ticks) {}
BraveMainDelegate::~BraveMainDelegate() {}
content::ContentBrowserClient*
BraveMainDelegate::CreateContentBrowserClient() {
#if defined(CHROME_MULTIPLE_DLL_CHILD)
return NULL;
#else
if (chrome_content_browser_client_ == nullptr) {
DCHECK(!chrome_feature_list_creator_);
chrome_feature_list_creator_ = std::make_unique<ChromeFeatureListCreator>();
chrome_content_browser_client_ =
std::make_unique<BraveContentBrowserClient>(
chrome_feature_list_creator_.get());
}
return chrome_content_browser_client_.get();
#endif
}
content::ContentRendererClient*
BraveMainDelegate::CreateContentRendererClient() {
#if defined(CHROME_MULTIPLE_DLL_BROWSER)
return NULL;
#else
return g_brave_content_renderer_client.Pointer();
#endif
}
content::ContentUtilityClient*
BraveMainDelegate::CreateContentUtilityClient() {
#if defined(CHROME_MULTIPLE_DLL_BROWSER)
return NULL;
#else
return g_brave_content_utility_client.Pointer();
#endif
}
void BraveMainDelegate::PreSandboxStartup() {
ChromeMainDelegate::PreSandboxStartup();
#if defined(OS_POSIX)
// Setup NativeMessagingHosts to point to the default Chrome locations
// because that's where native apps will create them
base::FilePath chrome_user_data_dir;
base::FilePath native_messaging_dir;
#if defined(OS_MACOSX)
base::PathService::Get(base::DIR_APP_DATA, &chrome_user_data_dir);
chrome_user_data_dir = chrome_user_data_dir.Append("Google/Chrome");
native_messaging_dir = base::FilePath(FILE_PATH_LITERAL(
"/Library/Google/Chrome/NativeMessagingHosts"));
#else
chrome::GetDefaultUserDataDirectory(&chrome_user_data_dir);
native_messaging_dir = base::FilePath(FILE_PATH_LITERAL(
"/etc/opt/chrome/native-messaging-hosts"));
#endif // defined(OS_MACOSX)
base::PathService::OverrideAndCreateIfNeeded(
chrome::DIR_USER_NATIVE_MESSAGING,
chrome_user_data_dir.Append(FILE_PATH_LITERAL("NativeMessagingHosts")),
false, true);
base::PathService::OverrideAndCreateIfNeeded(chrome::DIR_NATIVE_MESSAGING,
native_messaging_dir, false, true);
#endif // OS_POSIX
if (brave::SubprocessNeedsResourceBundle()) {
brave::InitializeResourceBundle();
}
}
bool BraveMainDelegate::BasicStartupComplete(int* exit_code) {
base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
#if BUILDFLAG(BRAVE_ADS_ENABLED)
command_line.AppendSwitch(switches::kEnableDomDistiller);
#endif
command_line.AppendSwitch(switches::kDisableDomainReliability);
command_line.AppendSwitch(switches::kDisableChromeGoogleURLTrackingClient);
command_line.AppendSwitch(switches::kNoPings);
std::stringstream enabled_features;
enabled_features << features::kEnableEmojiContextMenu.name
<< "," << features::kDesktopPWAWindowing.name
<< "," << password_manager::features::kFillOnAccountSelect.name
<< "," << extensions_features::kNewExtensionUpdaterService.name;
std::stringstream disabled_features;
disabled_features << features::kSharedArrayBuffer.name
<< "," << features::kDefaultEnableOopRasterization.name
<< "," << autofill::features::kAutofillSaveCardSignInAfterLocalSave.name
<< "," << features::kAudioServiceOutOfProcess.name
<< "," << autofill::features::kAutofillServerCommunication.name
<< "," << unified_consent::kUnifiedConsent.name;
command_line.AppendSwitchASCII(switches::kEnableFeatures,
enabled_features.str());
command_line.AppendSwitchASCII(switches::kDisableFeatures,
disabled_features.str());
return ChromeMainDelegate::BasicStartupComplete(exit_code);
}