谷歌浏览器的源码分析 24

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

#001  void FrameLoader::load(constResourceRequest& request)

#002  {

#003      load(request,SubstituteData());

#004  }

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

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

#002  {

#003      if (m_inStopAllLoaders)

#004          return;

#005         

#006      // FIXME: is this theright place to reset loadType? Perhaps this should be done after loading isfinished 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 originalencoding override since it is not loaded by user

#014      // selecting encoding.

#015      if (m_documentLoader)

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

#017     

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

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

#020      // is appropriatelymaintained.

#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, constSubstituteData&  substituteData)

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

bool MainResourceLoader::loadNow(ResourceRequest& r)

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

#001  boolMainResourceLoader::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函数创建一个资源消息,并把这个消息发送出去,到底它是怎么样实现的呢?下一次再来分析它。

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/uytrrfg/article/details/86654309
24