Chromium 屏蔽“缺少 Google API 密钥,因此 Chromium 的部分功能将无法使用。”提示 c++
新编译的Chromium工程默认gn参数如下:
可以利用gn args --list out/debug >1.txt 导出默认参数
google_api_key
Current value (from the default) = ""
From //google_apis/BUILD.gn:43
Set these to bake the specified API keys and OAuth client
IDs/secrets into your build.
If you create a build without values baked in, you can instead
set environment variables to provide the keys at runtime (see
src/google_apis/google_api_keys.h for details). Features that
require server-side APIs may fail to work if no keys are
provided.
Note that if `use_official_google_api_keys` has been set to true
(explicitly or implicitly), these values will be ignored and the official
keys will be used instead.
google_default_client_id
Current value (from the default) = ""
From //google_apis/BUILD.gn:46
See google_api_key.
google_default_client_secret
Current value (from the default) = ""
From //google_apis/BUILD.gn:49
See google_api_key.
============================================================
第一次运行编译出来的谷歌浏览器效果会提示:
屏蔽缺少 Google API 密钥,因此 Chromium 的部分功能将无法使用。
那么如何屏蔽此功能呢?
一、先根据提示"屏蔽缺少 Google API 密钥,因此 Chromium 的部分功能将无法使用。"找到对应ID,那么如何查找呢?看下面介绍:
1、先去chrome\app\resources\chromium_strings_zh-CN.xtb文件里面搜索该字符串,
<translation id="328888136576916638">缺少 Google API 密钥,因此 Chromium 的部分功能将无法使用。</translation>
2、根据 id="328888136576916638" 去chrome\app\resources\chromium_strings_en-GB.xtb 搜索该ID对应的英文
<translation id="328888136576916638">Google API keys are missing. Some functionality of Chromium will be disabled.</translation>
3、根据标红的英文去搜索chrome\app\google_chrome_strings.grd文件,
<!-- Google API keys info bar -->
<message name="IDS_MISSING_GOOGLE_API_KEYS" desc="Message shown when Google API keys are missing. This message is followed by a 'Learn more' link.">
Google API keys are missing. Some functionality of Google Chrome will be disabled.
</message>
这样就可以搜到该文字对应的ID = IDS_MISSING_GOOGLE_API_KEYS
【注意字符查找对应关系,其他的内容也是如此查找】
二、内容对应IDS_MISSING_GOOGLE_API_KEYS已经找到,再根据此ID找到c++代码。
chrome\browser\ui\startup\google_api_keys_infobar_delegate.cc
// static
void GoogleApiKeysInfoBarDelegate::Create(
infobars::ContentInfoBarManager* infobar_manager) {
infobar_manager->AddInfoBar(
CreateConfirmInfoBar(std::unique_ptr<ConfirmInfoBarDelegate>(
new GoogleApiKeysInfoBarDelegate())));
}
GoogleApiKeysInfoBarDelegate::GoogleApiKeysInfoBarDelegate()
: ConfirmInfoBarDelegate() {
}
infobars::InfoBarDelegate::InfoBarIdentifier
GoogleApiKeysInfoBarDelegate::GetIdentifier() const {
return GOOGLE_API_KEYS_INFOBAR_DELEGATE;
}
std::u16string GoogleApiKeysInfoBarDelegate::GetLinkText() const {
return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
}
GURL GoogleApiKeysInfoBarDelegate::GetLinkURL() const {
return GURL(google_apis::kAPIKeysDevelopersHowToURL);
}
std::u16string GoogleApiKeysInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringUTF16(IDS_MISSING_GOOGLE_API_KEYS);
}
int GoogleApiKeysInfoBarDelegate::GetButtons() const {
return BUTTON_NONE;
}
三、已经找到了GoogleApiKeysInfoBarDelegate类是弹出提示的类。
四、调用的类在chrome\browser\ui\startup\infobar_utils.cc
if (!google_apis::HasAPIKeyConfigured())
GoogleApiKeysInfoBarDelegate::Create(infobar_manager); 处,直接看代码:
void AddInfoBarsIfNecessary(Browser* browser,
Profile* profile,
const base::CommandLine& startup_command_line,
chrome::startup::IsFirstRun is_first_run,
bool is_web_app) {
if (!browser || !profile || browser->tab_strip_model()->count() == 0)
return;
// Show the Automation info bar unless it has been disabled by policy.
bool show_bad_flags_security_warnings = ShouldShowBadFlagsSecurityWarnings();
content::WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
DCHECK(web_contents);
if (show_bad_flags_security_warnings) {
#if BUILDFLAG(CHROME_FOR_TESTING)
if (!IsGpuTest()) {
ChromeForTestingInfoBarDelegate::Create();
}
#endif
if (IsAutomationEnabled())
AutomationInfoBarDelegate::Create();
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kProtectedAudiencesConsentedDebugToken)) {
BiddingAndAuctionConsentedDebuggingDelegate::Create(web_contents);
}
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
network::switches::kTestThirdPartyCookiePhaseout)) {
TestThirdPartyCookiePhaseoutInfoBarDelegate::Create(web_contents);
}
}
// Do not show any other info bars in Kiosk mode, because it's unlikely that
// the viewer can act upon or dismiss them.
if (IsKioskModeEnabled())
return;
// Web apps should not display the session restore bubble (crbug.com/1264121)
if (!is_web_app && HasPendingUncleanExit(browser->profile()))
SessionCrashedBubble::ShowIfNotOffTheRecordProfile(
browser, /*skip_tab_checking=*/false);
// These info bars are not shown when the browser is being controlled by
// automated tests, so that they don't interfere with tests that assume no
// info bars.
if (!startup_command_line.HasSwitch(switches::kTestType) &&
!IsAutomationEnabled()) {
// The below info bars are only added to the first profile which is
// launched. Other profiles might be restoring the browsing sessions
// asynchronously, so we cannot add the info bars to the focused tabs here.
//
// We cannot use `chrome::startup::IsProcessStartup` to determine whether
// this is the first profile that launched: The browser may be started
// without a startup window (`kNoStartupWindow`), or open the profile
// picker, which means that `chrome::startup::IsProcessStartup` will already
// be `kNo` when the first browser window is opened.
static bool infobars_shown = false;
if (infobars_shown)
return;
infobars_shown = true;
if (show_bad_flags_security_warnings)
chrome::ShowBadFlagsPrompt(web_contents);
infobars::ContentInfoBarManager* infobar_manager =
infobars::ContentInfoBarManager::FromWebContents(web_contents);
if (!google_apis::HasAPIKeyConfigured())
GoogleApiKeysInfoBarDelegate::Create(infobar_manager);
if (ObsoleteSystem::IsObsoleteNowOrSoon()) {
PrefService* local_state = g_browser_process->local_state();
if (!local_state ||
!local_state->GetBoolean(prefs::kSuppressUnsupportedOSWarning))
ObsoleteSystemInfoBarDelegate::Create(infobar_manager);
}
#if !BUILDFLAG(IS_CHROMEOS_ASH)
if (!is_web_app &&
!startup_command_line.HasSwitch(switches::kNoDefaultBrowserCheck)) {
// The default browser prompt should only be shown after the first run.
if (is_first_run == chrome::startup::IsFirstRun::kNo)
ShowDefaultBrowserPrompt(profile);
}
#endif
}
}
总结:
那么直接把 if (!google_apis::HasAPIKeyConfigured())
GoogleApiKeysInfoBarDelegate::Create(infobar_manager);这段代码屏蔽掉即可。
重新编译运行OK 效果:
GoogleApi主要是谷歌的地图云等服务,可以直接屏蔽。
- Cloud Search API
- Geolocation API (requires enabling billing but is free to use; you can skip this one, in which case geolocation features of Chrome will not work)
- Google Drive API (enable this for Files.app on Chrome OS and SyncFileSystem API)
- Safe Browsing API
- Time Zone API
- Optional
- Admin SDK
- Cloud Translation API
- Geocoding API
- Google Assistant API
- Google Calendar API
- Nearby Messages API
其他更详细介绍请参考API Keys