您的位置:首页 > 其它

谷歌浏览器的源码分析(24)

2008-10-12 13:54 323 查看
继续上一次的分析,这里开始把连接址和其它相关的信息传送frame_->loader()->load函数里面,那么在这个函数里面到底是怎么样处理的呢,只有去分析它的代码,我们才能找到它的答案,现在就来开始看吧,如下:

#001 void FrameLoader::load(const
ResourceRequest& request)

#002 {

#003 load(request,
SubstituteData());

#004 }

在这个函数也只是一个中间者,它又调用函数load函数的重载函数来实现了。

#001 void FrameLoader::load(const
ResourceRequest& request, const SubstituteData& substituteData)

#002 {

#003 if (m_inStopAllLoaders)

#004 return;

#005

#006 // FIXME: is this the
right place to reset loadType? Perhaps this should be done after loading is
finished or aborted.

#_loadType =
FrameLoadTypeStandard;

#008
load(m_client->createDocumentLoader(request, substituteData).get());

#009 }

#010

在这个函数里,第一个参数request是连接相关的信息,第二个参数substituteData是一些状态数据。然后在第7行里设置加载的类型,第8行里调用WebFrameLoaderClient::createDocumentLoader函数来创建WebDocumentLoaderImpl对象,然后再通过get函数返回来,这样就知道load函数又调用那个重载函数了,原来它是调用这个函数,如下:

#001 void FrameLoader::load(DocumentLoader*
newDocumentLoader)

#002 {

#003 ResourceRequest& r =
newDocumentLoader->request();

#004
addExtraFieldsToRequest(r, true, false);

#005 FrameLoadType type;

#006

#007 if
(shouldTreatURLAsSameAsCurrent(newDocumentLoader->originalRequest().url()))
{

#008
r.setCachePolicy(ReloadIgnoringCacheData);

#009 type =
FrameLoadTypeSame;

#010 } else

#011 type =
FrameLoadTypeStandard;

#012

#013 // Do not use original
encoding override since it is not loaded by user

#014 // selecting encoding.

#015 if (m_documentLoader)

#016
newDocumentLoader->setOverrideEncoding(String());

#017

#018 // When we loading
alternate content for an unreachable URL that we're

#019 // visiting in the b/f
list, we treat it as a reload so the b/f list

#020 // is appropriately
maintained.

#021 if
(shouldReloadToHandleUnreachableURL(newDocumentLoader)) {

#022 ASSERT(type ==
FrameLoadTypeStandard);

#023 type = FrameLoadTypeReload;

#024 }

#025

#026 load(newDocumentLoader,
type, 0);

#027 }

上面只对newDocumentLoader做一些准备工作,并没有真正地去加载任何东西,接着又调用函数:

void FrameLoader::load(DocumentLoader* loader, FrameLoadType type,
PassRefPtr<FormState> formState)

在上面这个函数进行安全策略的处理,然后再经过N个函数处理之后,就调用下面的函数:

void FrameLoader::continueLoadAfterWillSubmitForm(PolicyAction)

在这个函数开始使用类DocumentLoader来设置下载请求,主要通过函数

bool DocumentLoader::startLoadingMainResource(unsigned long identifier)

来实现的,紧跟后面调用加载函数:

bool MainResourceLoader::load(const ResourceRequest& r, const
SubstituteData& substituteData)

在这个函数里又开始分为两种情况处理,一种是延进加载数据,一种是立即加载数据,下面主要介绍立即加载数据函数:

bool MainResourceLoader::loadNow(ResourceRequest& r)

在类MainResourceLoader是主要资源下载的管理类,loadNow函数是把资源请求ResourceRequest变成一个IPC消息又发送给资源下载进程去处理。它的简略代码如下:

#001 bool
MainResourceLoader::loadNow(ResourceRequest& r)

#002 {

......

#011 willSendRequest(r,
ResourceResponse());

#012

......

#015 if (!frameLoader())

#016 return false;

#017

......

#023

#024 if
(m_substituteData.isValid())

#025
handleDataLoadSoon(r);

#026 else if (shouldLoadEmpty
|| frameLoader()->representationExistsForURLScheme(url.protocol()))

#027 handleEmptyLoad(url,
!shouldLoadEmpty);

#028 else

#_handle =
ResourceHandle::create(r, this, m_frame.get(), false, true, true);

#030

#031 return false;

#032 }

在这个函数的第29行里,就会通过ResourceHandle::create函数创建一个资源消息,并把这个消息发送出去,到底它是怎么样实现的呢?下一次再来分析它。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: