chromium load url

browser的行为

先看调试堆栈:
	content_shell.exe!content::RenderViewHostImpl::Navigate(const ViewMsg_Navigate_Params & params)  行 296	C++
>	content_shell.exe!content::WebContentsImpl::NavigateToEntry(const content::NavigationEntryImpl & entry, content::NavigationController::ReloadType reload_type)  行 1805	C++
 	content_shell.exe!content::WebContentsImpl::NavigateToPendingEntry(content::NavigationController::ReloadType reload_type)  行 1739	C++
 	content_shell.exe!content::NavigationControllerImpl::NavigateToPendingEntry(content::NavigationController::ReloadType reload_type)  行 1540 + 0xf 字节	C++
 	content_shell.exe!content::NavigationControllerImpl::LoadEntry(content::NavigationEntryImpl * entry)  行 393	C++
 	content_shell.exe!content::NavigationControllerImpl::LoadURLWithParams(const content::NavigationController::LoadURLParams & params)  行 712	C++
 	content_shell.exe!content::Shell::LoadURLForFrame(const GURL & url, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & frame_name)  行 179 + 0x4f 字节	C++
 	content_shell.exe!content::Shell::LoadURL(const GURL & url)  行 171 + 0x15 字节	C++
 	content_shell.exe!content::Shell::CreateNewWindow(content::BrowserContext * browser_context, const GURL & url, content::SiteInstance * site_instance, int routing_id, const gfx::Size & initial_size)  行 167	C++
 	content_shell.exe!content::ShellBrowserMainParts::PreMainMessageLoopRun()  行 123 + 0x31 字节	C++
 	content_shell.exe!content::BrowserMainLoop::CreateThreads()  行 614 + 0x26 字节	C++
 	content_shell.exe!content::BrowserMainRunnerImpl::Initialize(const content::MainFunctionParams & parameters)  行 106	C++
 	content_shell.exe!ShellBrowserMain(const content::MainFunctionParams & parameters, const scoped_ptr<content::BrowserMainRunner,base::DefaultDeleter<content::BrowserMainRunner> > & main_runner)  行 131 + 0x27 字节	C++
 	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)  行 178 + 0xd 字节	C++
 	content_shell.exe!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)  行 421 + 0x17 字节	C++
 	content_shell.exe!content::ContentMainRunnerImpl::Run()  行 754 + 0x14 字节	C++
 	content_shell.exe!content::ContentMain(HINSTANCE__ * instance, sandbox::SandboxInterfaceInfo * sandbox_info, content::ContentMainDelegate * delegate)  行 35 + 0x1a 字节	C++

这里描述了从用户输入一个url地址开始,通过 NavigationControllerImpl、WebContentsImpl、RenderViewHostImpl把浏览器层(browser)的命令发送到渲染层,最后到达webkit;

webkit加载html文档

>	content_shell.exe!webkit_glue::WebURLLoaderImpl::Context::Start(const WebKit::WebURLRequest & request, webkit_glue::ResourceLoaderBridge::SyncLoadResponse * sync_load_response, webkit_glue::WebKitPlatformSupportImpl * platform)  行 416	C++
 	content_shell.exe!webkit_glue::WebURLLoaderImpl::loadAsynchronously(const WebKit::WebURLRequest & request, WebKit::WebURLLoaderClient * client)  行 840	C++
 	content_shell.exe!WebCore::ResourceHandleInternal::start(WebCore::StoredCredentials storedCredentials)  行 72 + 0x28 字节	C++
 	content_shell.exe!WebCore::ResourceHandle::start(WebCore::StoredCredentials storedCredentials)  行 217	C++
 	content_shell.exe!WebCore::ResourceHandle::create(const WebCore::ResourceRequest & request, WebCore::ResourceHandleClient * client, bool defersLoading, bool shouldContentSniff, WebCore::StoredCredentials storedCredentials)  行 191	C++
 	content_shell.exe!WebCore::ResourceLoader::start()  行 157 + 0x3a 字节	C++
 	content_shell.exe!WebCore::ResourceLoader::create(WebCore::DocumentLoader * documentLoader, WebCore::CachedResource * resource, const WebCore::ResourceRequest & request, const WebCore::ResourceLoaderOptions & options)  行 65	C++
 	content_shell.exe!WebCore::CachedResource::load(WebCore::CachedResourceLoader * cachedResourceLoader, const WebCore::ResourceLoaderOptions & options)  行 197 + 0x24 字节	C++
 	content_shell.exe!WebCore::CachedResourceLoader::requestResource(WebCore::CachedResource::Type type, WebCore::CachedResourceRequest & request)  行 485 + 0x30 字节	C++
 	content_shell.exe!WebCore::CachedResourceLoader::requestMainResource(WebCore::CachedResourceRequest & request)  行 287 + 0x12 字节	C++
 	content_shell.exe!WebCore::DocumentLoader::startLoadingMainResource()  行 966 + 0x20 字节	C++
 	content_shell.exe!WebCore::FrameLoader::checkNavigationPolicyAndContinueLoad(WTF::PassRefPtr<WebCore::FormState> formState, WebCore::FrameLoadType type)  行 2086	C++
 	content_shell.exe!WebCore::FrameLoader::loadWithNavigationAction(const WebCore::ResourceRequest & request, const WebCore::NavigationAction & action, WebCore::FrameLoadType type, WTF::PassRefPtr<WebCore::FormState> formState, const WebCore::SubstituteData & substituteData, const WTF::String & overrideEncoding)  行 1098	C++
 	content_shell.exe!WebCore::FrameLoader::load(const WebCore::FrameLoadRequest & passedRequest)  行 1068 + 0x54 字节	C++
 	content_shell.exe!WebKit::WebFrameImpl::loadRequest(const WebKit::WebURLRequest & request)  行 950 + 0x41 字节	C++
 	content_shell.exe!content::RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params & params)  行 1439 + 0x19 字节	C++
 	content_shell.exe!DispatchToMethod<content::RenderViewImpl,void (__thiscall content::RenderViewImpl::*)(ViewMsg_Navigate_Params const &),ViewMsg_Navigate_Params>(content::RenderViewImpl * obj, void (const ViewMsg_Navigate_Params &)* method, const Tuple1<ViewMsg_Navigate_Params> & arg)  行 548 + 0x28 字节	C++
 	content_shell.exe!ViewMsg_Navigate::Dispatch<content::RenderViewImpl,content::RenderViewImpl,void (__thiscall content::RenderViewImpl::*)(ViewMsg_Navigate_Params const &)>(const IPC::Message * msg, content::RenderViewImpl * obj, content::RenderViewImpl * sender, void (const ViewMsg_Navigate_Params &)* func)  行 896 + 0x71 字节	C++
 	content_shell.exe!content::RenderViewImpl::OnMessageReceived(const IPC::Message & message)  行 1177 + 0x7d 字节	C++
 	content_shell.exe!content::MessageRouter::RouteMessage(const IPC::Message & msg)  行 49 + 0x12 字节	C++
 	content_shell.exe!content::MessageRouter::OnMessageReceived(const IPC::Message & msg)  行 41 + 0x13 字节	C++
 	content_shell.exe!content::ChildThread::OnMessageReceived(const IPC::Message & msg)  行 294 + 0x16 字节	C++
 	content_shell.exe!IPC::ChannelProxy::Context::OnDispatchMessage(const IPC::Message & message)  行 261 + 0x18 字节	C++
 	content_shell.exe!base::internal::RunnableAdapter<void (__thiscall IPC::ChannelProxy::Context::*)(IPC::Message const &)>::Run(IPC::ChannelProxy::Context * object, const IPC::Message & a1)  行 190 + 0x21 字节	C++
 	content_shell.exe!base::internal::InvokeHelper<0,void,base::internal::RunnableAdapter<void (__thiscall IPC::ChannelProxy::Context::*)(IPC::Message const &)>,void __cdecl(IPC::ChannelProxy::Context * const &,IPC::Message const &)>::MakeItSo(base::internal::RunnableAdapter<void (__thiscall IPC::ChannelProxy::Context::*)(IPC::Message const &)> runnable, IPC::ChannelProxy::Context * const & a1, const IPC::Message & a2)  行 899	C++
 	content_shell.exe!base::internal::Invoker<2,base::internal::BindState<base::internal::RunnableAdapter<void (__thiscall IPC::ChannelProxy::Context::*)(IPC::Message const &)>,void __cdecl(IPC::ChannelProxy::Context *,IPC::Message const &),void __cdecl(IPC::ChannelProxy::Context *,IPC::Message)>,void __cdecl(IPC::ChannelProxy::Context *,IPC::Message const &)>::Run(base::internal::BindStateBase * base)  行 1253 + 0x2a 字节	C++
 	content_shell.exe!base::Callback<void __cdecl(void)>::Run()  行 396 + 0xe 字节	C++
 	content_shell.exe!base::MessageLoop::RunTask(const base::PendingTask & pending_task)  行 486	C++
 	content_shell.exe!base::MessageLoop::DeferOrRunPendingTask(const base::PendingTask & pending_task)  行 499	C++
 	content_shell.exe!base::MessageLoop::DoWork()  行 688 + 0xc 字节	C++
 	content_shell.exe!base::MessagePumpForUI::DoRunLoop()  行 243 + 0x1d 字节	C++
 	content_shell.exe!base::MessagePumpWin::RunWithDispatcher(base::MessagePump::Delegate * delegate, base::MessagePumpDispatcher * dispatcher)  行 65 + 0xf 字节	C++
 	content_shell.exe!base::MessagePumpWin::Run(base::MessagePump::Delegate * delegate)  行 48 + 0x1c 字节	C++
 	content_shell.exe!base::MessageLoop::RunInternal()  行 441 + 0x29 字节	C++
 	content_shell.exe!base::MessageLoop::RunHandler()  行 415	C++
 	content_shell.exe!base::RunLoop::Run()  行 46	C++
 	content_shell.exe!base::MessageLoop::Run()  行 322	C++
 	content_shell.exe!base::Thread::Run(base::MessageLoop * message_loop)  行 159	C++
 	content_shell.exe!base::Thread::ThreadMain()  行 203 + 0x16 字节	C++
经过几次调试,得到了以上堆栈,有点大迂回的感觉。。。。

其中 WebFrameImpl是webframe的实现类,WebFrameImpl架起了chromium的render process和webkit的桥梁,感兴趣的可以阅读源码接口;在FrameLoader的load函数中主要做了以下事情:
1、初始化相应的Request,比如FrameLoadRequest和ResourceRequest;以及相应的FrameLoadType;
2、调用loadWithNavigationAction函数

loadWithNavigationAction函数的功能:
1、通过m_client(FrameLoadClientImpl)的createDocumentLoader函数得到一个DocumentLoader,实际上是DocumentLoader的后代WebDataSourceImpl,它重写了部分DocumentLoader的接口功能,这样就把webkit的网络加载请求可以转化为对chromium的请求,我个人的猜测,具体要看了代码才知道
2、设置第一步得到的DocumentLoader的一些属性,并把该Loader赋给m_policyDocumentLoader,并做了相关的清除工作,见FrameLoader的setPolicyDocumentLoader函数
3、呼叫checkNavigationPolicyAndContinueLoad函数


checkNavigationPolicyAndContinueLoad的功能:
1、通过一系列的检查,看能否继续进行加载
2、如果能加载就呼叫setProvisionalDocumentLoader,把m_policyDocumentLoader赋给m_provisionalDocumentLoader,进入到FrameStateProvisional状态
3、呼叫prepareForLoadStart,在这个函数里呼叫RenderViewImpl的dispatchDidStartProvisionalLoad函数,一直到WebContentImpl的DidStartProvisionalLoadForFrame函数
4、加载前的相关准备工作,呼叫m_provisionalDocumentLoader->startLoadingMainResource开始加载,这里呼叫的是DocumentLoader的startLoadingMainResource函数,虽然是通过WebDataSourceImpl的对象进行呼叫的

startLoadingMainResource,正式开始加载
1、呼叫willSendRequest函数,处理redirection等情况,处理空网页情况
2、发送请求前的准备工作
3、调用CachedResourceLoader的requestMainResource函数,发送加载网页请求给浏览器(browser);

个人觉得要注意的是有一下几点:
1、ResourceHandleInternal和WebUrlLoader的关系;
2、Platform类起的作用,有一点是肯定的,ResourceHandleInternal和WebUrlLoader的实现者(WebUrlLoaderImpl)联系是靠Platform的current函数联系起来的
3、ResourceHandleInternal、WebUrlLoader、Platform、WebUrlLoaderImpl、WebkitPlatformSupportImpl这几个类之间的关系,还有其他的中间类吗,个人感觉应该有
4、单进程中child_thread和resource_dispatcher的关系
5、platform的初始化工作,单进程中RenderThreadImpl::EnsureWebKitInitialized的作用
6、chromium在这一块的处理,单进程和多进程有何区别

至此,网页加载在渲染层和webkit,告一段落。

webkit 获取html网页数据

content_shell.exe!WebCore::Document::createParser()  行 2080	C++
 	content_shell.exe!WebCore::Document::implicitOpen()  行 2170 + 0x16 字节	C++
 	content_shell.exe!WebCore::DocumentWriter::DocumentWriter(WebCore::Document * document, const WTF::String & mimeType, const WTF::String & encoding, bool encodingUserChoosen)  行 60 + 0x68 字节	C++
 	content_shell.exe!WebCore::DocumentWriter::create(WebCore::Document * document, const WTF::String & mimeType, const WTF::String & encoding, bool encodingUserChoosen)  行 49 + 0x2c 字节	C++
 	content_shell.exe!WebCore::DocumentLoader::createWriterFor(WebCore::Frame * frame, const WebCore::Document * ownerDocument, const WebCore::KURL & url, const WTF::String & mimeType, const WTF::String & encoding, bool userChosen, bool dispatch)  行 1062 + 0x1f 字节	C++
 	content_shell.exe!WebCore::DocumentLoader::ensureWriter(const WTF::String & mimeType, const WebCore::KURL & overridingURL)  行 623 + 0x2b 字节	C++
 	content_shell.exe!WebCore::DocumentLoader::ensureWriter()  行 613 + 0x27 字节	C++
 	content_shell.exe!WebCore::DocumentLoader::commitData(const char * bytes, unsigned int length)  行 640	C++
 	content_shell.exe!WebCore::DocumentLoader::dataReceived(WebCore::CachedResource * resource, const char * data, int length)  行 693	C++
 	content_shell.exe!WebCore::CachedRawResource::appendData(const char * data, int length)  行 50 + 0x1b 字节	C++
 	content_shell.exe!WebCore::ResourceLoader::didReceiveData(WebCore::ResourceHandle * __formal, const char * data, int length, int encodedDataLength)  行 367 + 0x23 字节	C++
 	content_shell.exe!WebCore::ResourceHandleInternal::didReceiveData(WebKit::WebURLLoader * __formal, const char * data, int dataLength, int encodedDataLength)  行 139 + 0x33 字节	C++
 	content_shell.exe!webkit_glue::WebURLLoaderImpl::Context::OnReceivedData(const char * data, int data_length, int encoded_data_length)  行 694 + 0x28 字节	C++
 	content_shell.exe!content::ResourceDispatcher::OnReceivedData(const IPC::Message & message, int request_id, int data_offset, int data_length, int encoded_data_length)  行 417 + 0x22 字节	C++
 	content_shell.exe!ResourceMsg_DataReceived::Dispatch<content::ResourceDispatcher,content::ResourceDispatcher,int,int,int,int>(const IPC::Message * msg, content::ResourceDispatcher * obj, content::ResourceDispatcher * sender, void (const IPC::Message &, int, int, int, int)* func)  行 253 + 0x59 字节	C++
 	content_shell.exe!content::ResourceDispatcher::DispatchMessageW(const IPC::Message & message)  行 613 + 0x3f 字节	C++
 	content_shell.exe!content::ResourceDispatcher::OnMessageReceived(const IPC::Message & message)  行 306	C++
 	content_shell.exe!content::ChildThread::OnMessageReceived(const IPC::Message & msg)  行 261 + 0x2c 字节	C++
 	content_shell.exe!IPC::ChannelProxy::Context::OnDispatchMessage(const IPC::Message & message)  行 261 + 0x18 字节	C++
 	content_shell.exe!base::internal::RunnableAdapter<void (__thiscall IPC::ChannelProxy::Context::*)(IPC::Message const &)>::Run(IPC::ChannelProxy::Context * object, const IPC::Message & a1)  行 190 + 0x21 字节	C++
 	content_shell.exe!base::internal::InvokeHelper<0,void,base::internal::RunnableAdapter<void (__thiscall IPC::ChannelProxy::Context::*)(IPC::Message const &)>,void __cdecl(IPC::ChannelProxy::Context * const &,IPC::Message const &)>::MakeItSo(base::internal::RunnableAdapter<void (__thiscall IPC::ChannelProxy::Context::*)(IPC::Message const &)> runnable, IPC::ChannelProxy::Context * const & a1, const IPC::Message & a2)  行 899	C++
 	content_shell.exe!base::internal::Invoker<2,base::internal::BindState<base::internal::RunnableAdapter<void (__thiscall IPC::ChannelProxy::Context::*)(IPC::Message const &)>,void __cdecl(IPC::ChannelProxy::Context *,IPC::Message const &),void __cdecl(IPC::ChannelProxy::Context *,IPC::Message)>,void __cdecl(IPC::ChannelProxy::Context *,IPC::Message const &)>::Run(base::internal::BindStateBase * base)  行 1253 + 0x2a 字节	C++
 	content_shell.exe!base::Callback<void __cdecl(void)>::Run()  行 396 + 0xe 字节	C++
 	content_shell.exe!base::MessageLoop::RunTask(const base::PendingTask & pending_task)  行 486	C++
 	content_shell.exe!base::MessageLoop::DeferOrRunPendingTask(const base::PendingTask & pending_task)  行 499	C++
 	content_shell.exe!base::MessageLoop::DoWork()  行 688 + 0xc 字节	C++
 	content_shell.exe!base::MessagePumpForUI::DoRunLoop()  行 243 + 0x1d 字节	C++
 	content_shell.exe!base::MessagePumpWin::RunWithDispatcher(base::MessagePump::Delegate * delegate, base::MessagePumpDispatcher * dispatcher)  行 65 + 0xf 字节	C++
 	content_shell.exe!base::MessagePumpWin::Run(base::MessagePump::Delegate * delegate)  行 48 + 0x1c 字节	C++
 	content_shell.exe!base::MessageLoop::RunInternal()  行 441 + 0x29 字节	C++
 	content_shell.exe!base::MessageLoop::RunHandler()  行 415	C++
 	content_shell.exe!base::RunLoop::Run()  行 46	C++
 	content_shell.exe!base::MessageLoop::Run()  行 322	C++
 	content_shell.exe!base::Thread::Run(base::MessageLoop * message_loop)  行 159	C++
 	content_shell.exe!base::Thread::ThreadMain()  行 203 + 0x16 字节	C++

具体的框架分析,待续
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值