编译、定制chromium

编译、定制chromium

编译

按照官方文档走,基本没问题。

https://chromium.googlesource.com/chromium/src/+/main/docs/windows_build_instructions.md

https://chromium.googlesource.com/chromium/src/+/main/docs/mac_build_instructions.md

macOS上编译需要选择正确的Xcode版本(主要是SDK版本),intel x64 CPU可以交叉编译ARM版本。

获取源码

1
2
3
4
5
6
7
8
9
fetch chromium

# 切换到指定版本 138.0.7204.101
# https://chromiumdash.appspot.com/releases?platform=Windows (查询对应版本commit)

cd src
git checkout a2159ad9ab8037bd34a21b9903003e0964c2075b
cd ..
gclient sync --force --reset

错误解决

当设置了is_official_build = true时,需要修改.gclient

1
"custom_vars": {"checkout_pgo_profiles":True},

编译Release版本

1
gn args out/Release
1
2
3
4
5
6
7
8
9
is_debug = false
target_cpu = "x64"
is_official_build = true
symbol_level = 0
blink_symbol_level=0
v8_symbol_level = 0
enable_nacl = false
ffmpeg_branding = "Chrome"
proprietary_codecs = true

编译时间

i7-9700k+32G内存环境下编译时间:

Windows x64,约8小时

macOS x64, 约10个小时(黑苹果)

macOS arm64, 约17个小时(x64黑苹果交叉编译)

定制

  • 修改浏览器名称
  • 内置插件
  • 将插件固定到工具栏
  • 默认显示书签栏
  • 添加一个书签(最终在插件实现)
  • 移除缺少Google API密钥提示
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
diff --git a/chrome/app/chromium_strings.grd b/chrome/app/chromium_strings.grd
index 04c8cab..7d670e5 100644
--- a/chrome/app/chromium_strings.grd
+++ b/chrome/app/chromium_strings.grd
@@ -294,10 +294,10 @@ If you update this file, be sure also to update google_chrome_strings.grd. -->
</then>
<else>
<message name="IDS_PRODUCT_NAME" desc="The Chrome application name" translateable="false">
- Chromium
+ MW方舟
</message>
<message name="IDS_SHORT_PRODUCT_NAME" desc="The Chrome application short name." translateable="false">
- Chromium
+ MW方舟
</message>
</else>
</if>
diff --git a/chrome/app/theme/chromium/BRANDING b/chrome/app/theme/chromium/BRANDING
index f8363d5..e9f9fa9 100644
--- a/chrome/app/theme/chromium/BRANDING
+++ b/chrome/app/theme/chromium/BRANDING
@@ -1,9 +1,9 @@
-COMPANY_FULLNAME=The Chromium Authors
-COMPANY_SHORTNAME=The Chromium Authors
-PRODUCT_FULLNAME=Chromium
-PRODUCT_SHORTNAME=Chromium
-PRODUCT_INSTALLER_FULLNAME=Chromium Installer
-PRODUCT_INSTALLER_SHORTNAME=Chromium Installer
+COMPANY_FULLNAME=MW_FANGZHOU
+COMPANY_SHORTNAME=MW_FANGZHOU
+PRODUCT_FULLNAME=MW
+PRODUCT_SHORTNAME=MW
+PRODUCT_INSTALLER_FULLNAME=MW_FANGZHOU Installer
+PRODUCT_INSTALLER_SHORTNAME=MW_FANGZHOU Installer
COPYRIGHT=Copyright @LASTCHANGE_YEAR@ The Chromium Authors. All rights reserved.
MAC_BUNDLE_ID=org.chromium.Chromium
MAC_CREATOR_CODE=Cr24
diff --git a/chrome/app/theme/chromium/mac/app.icns b/chrome/app/theme/chromium/mac/app.icns
index d2d7296..5f7e541 100644
Binary files a/chrome/app/theme/chromium/mac/app.icns and b/chrome/app/theme/chromium/mac/app.icns differ
diff --git a/chrome/app/theme/chromium/win/chromium.ico b/chrome/app/theme/chromium/win/chromium.ico
index d0aa0c2..cf83463 100644
Binary files a/chrome/app/theme/chromium/win/chromium.ico and b/chrome/app/theme/chromium/win/chromium.ico differ
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd
index 4cd8f9f..9e23c8d 100644
--- a/chrome/browser/browser_resources.grd
+++ b/chrome/browser/browser_resources.grd
@@ -43,6 +43,7 @@
<include name="IDR_ABOUT_CONFLICTS_WARNING_SVG" file="resources\conflicts\warning.svg" type="BINDATA" />
</if>
<include name="IDR_AD_NETWORK_HASHES" file="resources\ad_networks.dat" type="BINDATA" />
+ <include name="IDR_EXTENSION_MANIFEST" file="resources\AutoProxy\manifest.json" type="BINDATA" />
<if expr="chromeos_ash">
<include name="IDR_CHROME_APP_MANIFEST" file="resources\chrome_app\manifest.json" type="BINDATA" />
<include name="IDR_URL_MOJOM_LITE_JS" file="${root_gen_dir}\url\mojom\url.mojom-lite.js" use_base_dir="false" type="BINDATA" />
diff --git a/chrome/browser/extensions/component_extensions_allowlist/allowlist.cc b/chrome/browser/extensions/component_extensions_allowlist/allowlist.cc
index b818225..f1902fe 100644
--- a/chrome/browser/extensions/component_extensions_allowlist/allowlist.cc
+++ b/chrome/browser/extensions/component_extensions_allowlist/allowlist.cc
@@ -82,6 +82,7 @@ bool IsComponentExtensionAllowlisted(int manifest_resource_id) {
case IDR_HANGOUT_SERVICES_MANIFEST_V2:
case IDR_HANGOUT_SERVICES_MANIFEST_V3:
#endif
+ case IDR_EXTENSION_MANIFEST:
case IDR_NETWORK_SPEECH_SYNTHESIS_MANIFEST:
case IDR_NETWORK_SPEECH_SYNTHESIS_MANIFEST_MV3:
case IDR_READING_MODE_GDOCS_HELPER_MANIFEST:
diff --git a/chrome/browser/extensions/component_loader.cc b/chrome/browser/extensions/component_loader.cc
index 9e0447b..a248b3d 100644
--- a/chrome/browser/extensions/component_loader.cc
+++ b/chrome/browser/extensions/component_loader.cc
@@ -485,6 +485,7 @@ void ComponentLoader::AddDefaultComponentExtensions(
bool skip_session_components) {
// Do not add component extensions that have background pages here -- add them
// to AddDefaultComponentExtensionsWithBackgroundPages.
+ Add(IDR_EXTENSION_MANIFEST, base::FilePath(FILE_PATH_LITERAL("AutoProxy")));
#if BUILDFLAG(IS_CHROMEOS)

#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
diff --git a/chrome/browser/resources/component_extension_resources.grd b/chrome/browser/resources/component_extension_resources.grd
index 2e355c8..3b86dba 100644
--- a/chrome/browser/resources/component_extension_resources.grd
+++ b/chrome/browser/resources/component_extension_resources.grd
@@ -12,6 +12,22 @@
</outputs>
<release seq="1">
<includes>
+ <include name="IDR_AUTOPROXY_BACKGROUND_JS" file="AutoProxy/background.js" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_ICON_ACTIVE_ICON128" file="AutoProxy/icons/active_icon128.png" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_ICON_ACTIVE_ICON16" file="AutoProxy/icons/active_icon16.png" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_ICON_ACTIVE_ICON32" file="AutoProxy/icons/active_icon32.png" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_ICON_ACTIVE_ICON48" file="AutoProxy/icons/active_icon48.png" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_ICON_DEFAULT_ICON128" file="AutoProxy/icons/default_icon128.png" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_ICON_DEFAULT_ICON16" file="AutoProxy/icons/default_icon16.png" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_ICON_DEFAULT_ICON32" file="AutoProxy/icons/default_icon32.png" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_ICON_DEFAULT_ICON48" file="AutoProxy/icons/default_icon48.png" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_ICON_CACHE_ICON128" file="AutoProxy/icons/cache_icon128.png" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_ICON_CACHE_ICON16" file="AutoProxy/icons/cache_icon16.png" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_ICON_CACHE_ICON32" file="AutoProxy/icons/cache_icon32.png" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_ICON_CACHE_ICON48" file="AutoProxy/icons/cache_icon48.png" type="BINDATA" />
+ <include name="IDR_AUTOPROXY_POPUP" file="AutoProxy/popup.html" type="BINDATA" />
+
+
<include name="IDR_NETWORK_SPEECH_SYNTHESIS_JS" file="network_speech_synthesis/tts_extension.js" type="BINDATA" />

<include name="IDR_NETWORK_SPEECH_SYNTHESIS_MV3_AUDIO_HTML" file="network_speech_synthesis/mv3/audio.html" type="BINDATA" />
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index f79df46..b032ccf 100644
--- a/chrome/browser/ui/startup/infobar_utils.cc
+++ b/chrome/browser/ui/startup/infobar_utils.cc
@@ -171,9 +171,9 @@ void AddInfoBarsIfNecessary(Browser* browser,
infobars::ContentInfoBarManager* infobar_manager =
infobars::ContentInfoBarManager::FromWebContents(web_contents);

- if (!google_apis::HasAPIKeyConfigured()) {
- GoogleApiKeysInfoBarDelegate::Create(infobar_manager);
- }
+ // if (!google_apis::HasAPIKeyConfigured()) {
+ // GoogleApiKeysInfoBarDelegate::Create(infobar_manager);
+ // }

if (ObsoleteSystem::IsObsoleteNowOrSoon()) {
PrefService* local_state = g_browser_process->local_state();
diff --git a/components/bookmarks/browser/bookmark_utils.cc b/components/bookmarks/browser/bookmark_utils.cc
index abac9e4..9d0ce98 100644
--- a/components/bookmarks/browser/bookmark_utils.cc
+++ b/components/bookmarks/browser/bookmark_utils.cc
@@ -448,8 +448,9 @@ bool DoesBookmarkContainWords(const std::u16string& title,
}

void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
+ // zhighest
registry->RegisterBooleanPref(
- prefs::kShowBookmarkBar, false,
+ prefs::kShowBookmarkBar, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterBooleanPref(prefs::kEditBookmarksEnabled, true);
registry->RegisterBooleanPref(
diff --git a/extensions/browser/extension_prefs.cc b/extensions/browser/extension_prefs.cc
index 321617a..3b3b418 100644
--- a/extensions/browser/extension_prefs.cc
+++ b/extensions/browser/extension_prefs.cc
@@ -1456,15 +1456,18 @@ bool ExtensionPrefs::IsExtensionDisabled(const ExtensionId& id) const {

ExtensionIdList ExtensionPrefs::GetPinnedExtensions() const {
ExtensionIdList id_list_out;
- GetUserExtensionPrefIntoContainer(pref_names::kPinnedExtensions,
- &id_list_out);
+ GetUserExtensionPrefIntoContainer(pref_names::kPinnedExtensions, &id_list_out);
return id_list_out;
}

+
+
+
void ExtensionPrefs::SetPinnedExtensions(const ExtensionIdList& extension_ids) {
SetExtensionPrefFromContainer(pref_names::kPinnedExtensions, extension_ids);
}

+
void ExtensionPrefs::OnExtensionInstalled(
const Extension* extension,
const base::flat_set<int>& disable_reasons,
@@ -2119,6 +2122,15 @@ void ExtensionPrefs::InitPrefStore() {
InitExtensionControlledPrefs(extensions_info);

extension_pref_value_map_->NotifyInitializationCompleted();
+
+ // 首次启动时将插件固定到工具栏
+ auto stored_pinned_actions = GetPinnedExtensions();
+ if (stored_pinned_actions.empty()) {
+ const std::string kTargetId = "mbgaaepcempjaiaicindaobjnigjgdbc";
+ extensions::ExtensionIdList pinned_extension_list = {kTargetId};
+ SetPinnedExtensions(pinned_extension_list);
+ }
+
}

bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const {