chromium启动流程和消息处理是怎么关联起来

本文深入探讨Chromium的启动流程,从ContentMain开始,介绍ContentMainRunnerImpl的初始化,包括ContentClient的设置,以及BrowserMain过程。在BrowserMain中,详细阐述了MessageLoop的创建、主线程的建立,以及窗口创建的过程,涉及到的关键对象包括Browser、BrowserWindow和HWNDMessageHandler,揭示了Chromium如何建立并处理消息的机制。
摘要由CSDN通过智能技术生成
..\chrome\app\chrome_main.cc
该函数是首先进入的主函数
#if defined(OS_WIN)
DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
                                 sandbox::SandboxInterfaceInfo* sandbox_info) {
#elif defined(OS_POSIX)
int ChromeMain(int argc, const char** argv) {
#endif
#if defined(OS_WIN) && defined(ARCH_CPU_X86_64)
  // VS2013 only checks the existence of FMA3 instructions, not the enabled-ness
  // of them at the OS level (this is fixed in VS2015). We force off usage of
  // FMA3 instructions in the CRT to avoid using that path and hitting illegal
  // instructions when running on CPUs that support FMA3, but OSs that don't.
  // See http://crbug.com/436603.
  _set_FMA3_enable(0);
#endif  // WIN && ARCH_CPU_X86_64


  ChromeMainDelegate chrome_main_delegate;
  content::ContentMainParams params(&chrome_main_delegate);


#if defined(OS_WIN)
  // The process should crash when going through abnormal termination.
  base::win::SetShouldCrashOnProcessDetach(true);
  base::win::SetAbortBehaviorForCrashReporting();
  params.instance = instance;
  params.sandbox_info = sandbox_info;


  // SetDumpWithoutCrashingFunction must be passed the DumpProcess function
  // from the EXE and not from the DLL in order for DumpWithoutCrashing to
  // function correctly.
  typedef void (__cdecl *DumpProcessFunction)();
  DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>(
      ::GetProcAddress(::GetModuleHandle(chrome::kBrowserProcessExecutableName),
          "DumpProcessWithoutCrash"));
  base::debug::SetDumpWithoutCrashingFunction(DumpProcess);
#else
  params.argc = argc;
  params.argv = argv;
#endif


#if BUILDFLAG(ENABLE_PACKAGE_MASH_SERVICES)
#if !defined(OS_WIN)
  base::CommandLine::Init(params.argc, params.argv);
#endif
  const base::CommandLine& command_line =
      *base::CommandLine::ForCurrentProcess();
  // TODO(sky): only do this for dev builds and if on canary channel.
  if (command_line.HasSwitch("mash"))
    return MashMain();
#endif


  int rv = content::ContentMain(params);


#if defined(OS_WIN)
  base::win::SetShouldCrashOnProcessDetach(false);
#endif


  return rv;
}

其次通过int rv = content::ContentMain(params);创建并初始化ContentMainRunnerImpl

该类是实现者,负责ContentClient的初始化和必要的对象关联,例如ContentClient内部指针对象

 // The embedder API for participating in browser logic.
  ContentBrowserClient* browser_;
  // The embedder API for participating in gpu logic.
  ContentGpuClient* gpu_;
  // The embedder API for participating in plugin logic.
  ContentPluginClient* plugin_;
  // The embedder API for participating in renderer logic.
  ContentRendererClient* renderer_;
  // The embedder API for participating in utility logic.
  ContentUtilityClient* utility_;

详细初始化位置如下:

在content::ContentMain内部调用

ContentMainRunnerImpl::Initialize()

而在ContentMainRunnerImpl::Initialize()调用

重要的delegate_->BasicStartupComplete 进行Content::SetContentClient初始化,这个函数会初始化一个全局对象。

而后调用ContentClientInitializer::Set(process_type, delegate_);在该函数里面,会初始化上面提及红色字体等内部对象指针。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值