http://blog.csdn.net/chromium_webkit/article/details/8666005

上一篇介绍到了Shell_browser_main.cc的中调用的BrowserMainRunnerImpl的Initialize和Run函数,现在来介绍具体的过程和特点;在BrowserMainRunnerImpl的Initialize中会看到如下代码:


[cpp]  view plain copy
  1. main_loop_.reset(new BrowserMainLoop(parameters));  
  2.   
  3.    main_loop_->Init();  
  4.   
  5.    main_loop_->EarlyInitialization();  
  6.   
  7.    // Must happen before we try to use a message loop or display any UI.  
  8.    main_loop_->InitializeToolkit();  
  9.   
  10.    main_loop_->MainMessageLoopStart();  

BrowserMainLoop的Init在上一篇我们介绍过了,下面来看看EarlyInitialization:

[cpp]  view plain copy
  1. if (parts_.get())  
  2.    parts_->PreEarlyInitialization();  

[cpp]  view plain copy
  1. if (parts_.get())  
  2.     parts_->PostEarlyInitialization();  

parts_是在Init中初始化的,通过上一篇的分析我们得知是由ShellContentBrowserClient的CreateBrowserMainParts函数得到结果,其代码如下:

[cpp]  view plain copy
  1. shell_browser_main_parts_ = new ShellBrowserMainParts(parameters);  
  2.   return shell_browser_main_parts_;  

从代码中我们可以知道,ShellBrowserMainParts的这连个函数在windows平台下,什么都没做;

看看BrowserMainLoop的InitializeToolkit函数,该函数主要是平台界面系统的初始化工作;

BrowserMainLoop的MainMessageLoopStart函数:初始化main_message_loop_和主线程CrBrowserMain


接下来BrowserMainRunnerImpl的Initialize函数调用BrowserMainLoop的CreateThreads函数:初始化DB thread、IO thread、File thread、Cache thread等


call stack:

[cpp]  view plain copy
  1. >    content.dll!content::WebContentsImpl::GetNativeView()  行 1113 + 0x20 字节 C++  
  2.     content_shell.exe!content::Shell::GetContentView()  行 201 + 0x20 字节 C++  
  3.     content_shell.exe!content::Shell::PlatformResizeSubViews()  行 168 + 0x1b 字节 C++  
  4.     content_shell.exe!content::Shell::CreateShell(content::WebContents * web_contents)  行 93    C++  
  5.     content_shell.exe!content::Shell::CreateNewWindow(content::BrowserContext * browser_context, const GURL & url, content::SiteInstance * site_instance, int routing_id, content::WebContents * base_web_contents)  行 134 + 0x9 字节 C++  
  6.     content_shell.exe!content::ShellBrowserMainParts::PreMainMessageLoopRun()  行 137 + 0x46 字节  C++  
  7.     content.dll!content::BrowserMainLoop::CreateThreads()  行 469 + 0x26 字节  C++  
  8.     content.dll!content::BrowserMainRunnerImpl::Initialize(const content::MainFunctionParams & parameters)  行 106   C++  
  9.     content_shell.exe!ShellBrowserMain(const content::MainFunctionParams & parameters)  行 111 + 0x2a 字节 C++  
  10.     content_shell.exe!content::ShellMainDelegate::RunProcess(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & process_type, const content::MainFunctionParams & main_function_params)  行 134 + 0x9 字节 C++  
  11.     content.dll!content::RunNamedProcessTypeMain(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & process_type, const content::MainFunctionParams & main_function_params, content::ContentMainDelegate * delegate)  行 438 + 0x17 字节   C++  
  12.     content.dll!content::ContentMainRunnerImpl::Run()  行 754 + 0x14 字节  C++  
  13.     content.dll!content::ContentMain(HINSTANCE__ * instance, sandbox::SandboxInterfaceInfo * sandbox_info, content::ContentMainDelegate * delegate)  行 35 + 0x1a 字节 C++  
  14.     content_shell.exe!wWinMain(HINSTANCE__ * instance, HINSTANCE__ * __formal, HINSTANCE__ * __formal, HINSTANCE__ * __formal)  行 24 + 0x14 字节  C++  
  15.     content_shell.exe!__tmainCRTStartup()  行 547 + 0x2c 字节  C  
  16.     content_shell.exe!wWinMainCRTStartup()  行 371   C  

到这里就创建了浏览器的主窗口,进入了主要的事件循环了。
Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐