当前位置: 首页 > article >正文

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


http://www.kler.cn/a/326661.html

相关文章:

  • 单元测试(Junit)
  • uniapp在js方法中,获取当前用户的uid(uni-id-user)表中的用户id
  • AI开发-三方库-torch-torchvision
  • 408——计算机网络(持续更新)
  • 算法简介:K最近邻算法
  • 特殊矩阵的压缩存储
  • Conda 虚拟环境使用指南,python,anaconda,miniconda
  • MySQL InnoDB 事务commit逻辑分析
  • C++的new关键字
  • 如何在Android上运行Llama 3.2
  • 关于TrustedInstaller权限
  • c++-类和对象-设计立方体类
  • 每天学习一个技术栈 ——【Django Channels】篇(2)
  • ansible实现远程创建用户
  • [BUUCTF从零单排] Web方向 03.Web入门篇之sql注入-1(手工注入详解)
  • Java 编码系列:注解处理器详解与面试题解析
  • Uptime Kuma运维监控服务本地部署结合内网穿透实现远程在线监控
  • PostgreSQL的扩展Citus介绍
  • 非常全面的中考总复习资料-快速提升中考成绩!
  • 总结C/C++中内存区域划分
  • 点餐小程序实战教程14点餐功能
  • 心理咨询行业为何要有自己的知识付费小程序平台 心理咨询小程序搭建 集师saas知识付费小程序平台搭建
  • 遇到 Docker 镜像拉取失败的问题时该如何解决
  • 六、设计模式-6.3、责任链模式
  • WebAssembly 为什么能提升性能,怎么使用它 ?
  • 晶圆厂如何突破多网隔离实现安全稳定又快速的跨网域文件传输?