首页 > 编程语言 >Chromium 屏蔽缺少 Google API 密钥,因此 Chromium 的部分功能将无法使用。c++

Chromium 屏蔽缺少 Google API 密钥,因此 Chromium 的部分功能将无法使用。c++

时间:2024-09-30 21:19:49浏览次数:3  
标签:google chrome GoogleApiKeysInfoBarDelegate startup c++ API browser Chromium Goog

新编译的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

标签:google,chrome,GoogleApiKeysInfoBarDelegate,startup,c++,API,browser,Chromium,Goog
From: https://blog.csdn.net/jangdong/article/details/142663685

相关文章

  • 【C++篇】启航——初识C++(下篇)
     接上篇【C++篇】启航——初识C++(上篇)目录一、引用1.引用的概念2.引用的基本语法3.引用的特点 3.1别名3.2不占用额外内存3.3必须初始化3.4 不能为NULL4.引用的使用 4.1 函数参数传递4.2 返回值4.3 常量引用5.引用和指针的关系 (1).基本定义(2).初......
  • vscode 运行 C++分文件显示 undefined reference to 问题解决
    一、问题无法关联到对应的方法。  二、结局方法1、第一步,查看.vsode文件夹里面的task.json文件;设置里面参数;${file}改成 ${fileDirname}\\*.cpp 2、第二步 2.1、打开coderunner的setting.json文件; 2.2、将 $fileName改成*.cpp 3.3、最后起哄一下vs......
  • c++泛型编程
    一、模板template1.1概念C++重模板可以让类或函数声明一种通用类型,使得函数或类中的某些成员变量或成员变量的参数、返回值在实际上的使用中可以是任何类型。模板可以让程序员写出与类型无关的代码,是泛型编程的基础。模板主要分为两种实现方式:函数模板类模板1.2函数......
  • 65结构体-结构体数组。在C++中,结构体的定义是什么呢?如何新建一个结构体呢?新建好的结构
    问题描述:根据下列代码和结果回答下列问题。//Createdby黑马程序员.#include"iostream"usingnamespacestd;#include<string>//结构体定义structstudent{//成员列表stringname;//姓名intage;//年龄intscore;//分数}stu3;/......
  • 如何解决Google AdSense 无效流量?一文教你提高AdSense点击率
     GoogleAdSense点击率低得可怜?广告收入少得可怜?想知道怎么才能让AdSense收入飙升吗?如果你正遭受无效流量的困扰,或者你正愁着怎么提高点击率,那么这篇文章就是你的救星!快和我一起往下看吧~一、什么是Adsense?AdSense就是Google提供的一个广告服务,它允许网站主在自......
  • C++ Data Member Pointers 和 Member Function Pointers
    https://itanium-cxx-abi.github.io/cxx-abi/abi.html#member-pointers2.3MemberPointers2.3.1DataMemberPointersThebasicABIpropertiesofdatamemberpointertypesarethoseofptrdiff_t.Adatamemberpointerisrepresentedasthedatamember's......
  • 【C++ STL】深入理解string类的底层实现
    string类的模拟实现一.string的构造与析构函数1.普通构造函数与析构函数2.拷贝构造的浅拷贝所带来的问题3.如何实现深拷贝二.运算符重载1.赋值运算符重载2.大小比较相关的运算符重载三.迭代器的实现四.string常用操作的实现1.静态const成员npos的定义2.插入操作3.查找......
  • 用C/C++构建自己的Redis——第五章、Redis中的AVL树实现
    用C/C++构建自己的Redis——第五章、Redis中的AVL树实现文章目录用C/C++构建自己的Redis——第五章、Redis中的AVL树实现前言一、键值对集查询概念1.1键值对集合查询1.2数据结构排序的复习排序数组(SortedArrays)树形数据结构(TreeDataStructures)通过随机性平衡(Balan......
  • 在Ubuntu下,为Vim配置C/C++代码补全
    1.安装vim-plugvim-plug是vim的一个插件管理器。(1)vim-plug的下载网址(2)新建目录~/.vim/autoload/(3)将 plug.vim文件放入该目录(4)添加vim-plug的代码到~/.vimrc文件,如下所示callplug#begin()"ListyourpluginsherePlug'tpope/vim-sensible'callplug#end......
  • vscode 配置 c/c++
    vscode配置c/c++[!CAUTION]使用本文的配置需要预装cmake,msvc,拥有cmake、CMakeTools插件工程目录D:.│CMakeLists.txt│├─.vscode│CMakePresets.json│c_cpp_properties.json│└─code│main.cpp│└─head......