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

系统 1668 0
继续上一次的分析,这里开始把连接址和其它相关的信息传送 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.

# 007       m _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

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

#030  

#031       return false;

#032   }

在这个函数的第 29 行里,就会通过 ResourceHandle::create 函数创建一个资源消息,并把这个消息发送出去,到底它是怎么样实现的呢?下一次再来分析它。

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


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论