C++博客 联系 聚合 管理  

Blog Stats

文章分类(17)

收藏夹(2)

文章档案(18)

相册

Blogs

citywanderer


1、下载回调接口
Source/WebCore/loader/DocumentLoader.cpp  798
798     if (!m_mainResourceLoader->load(m_request, m_substituteData))
Source/WebCore/loader/MainResourceLoader.cpp  590
590 bool MainResourceLoader::load(const ResourceRequest& r, const SubstituteData& substituteData)
612         if (loadNow(request)) {
557 bool MainResourceLoader::loadNow(ResourceRequest& r)
586         m_handle = ResourceHandle::create(m_frame->loader()->networkingContext(), r, thisfalsetrue);
Source/WebCore/platform/network/ResourceHandle.cpp  56 //与附件js下载同
 56 PassRefPtr<ResourceHandle> ResourceHandle::create(NetworkingContext* context, const ResourceRequest& request,
    ResourceHandleClient
* client, bool defersLoading, bool shouldContentSniff)//client即为上面的MainResourceLoader类对象,如下
//Source/WebCore/loader/MainResourceLoader.h
 48     class MainResourceLoader : public ResourceLoader {
//Source/WebCore/loader/ResourceLoader.h
 51     class ResourceLoader : public RefCounted<ResourceLoader>protected ResourceHandleClient {
 66     RefPtr<ResourceHandle> newHandle(adoptRef(new ResourceHandle(request, client, defersLoading, shouldContentSniff)));
 
71     if (newHandle->start(context))
Source/WebCore/platform/network/qt/ResourceHandleQt.cpp  82 
   qt等接口必须实现‘Source/WebCore/platform/network/ResourceHandle.h  216’文件中的‘216     bool start(NetworkingContext*);’  
 82 bool ResourceHandle::start(NetworkingContext* context)//从这里看this为此类对象
100     d->m_job = new QNetworkReplyHandler(this, QNetworkReplyHandler::AsynchronousLoad, d->m_defersLoading);
Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp  373
373 QNetworkReplyHandler::QNetworkReplyHandler(ResourceHandle* handle, LoadType loadType, bool deferred)
401     m_queue.push(&QNetworkReplyHandler::start);
161 void QNetworkReplyHandlerCallQueue::push(EnqueuedCall method)
// 49     typedef void (QNetworkReplyHandler::*EnqueuedCall)();
162 {
163     m_enqueuedCalls.append(method);
164     flush();//从头开始取出enque队列中的所有函数元素(这里第一个为为method,即start函数),并调用函数
165 }
//建立连接、发送html请求
659 void QNetworkReplyHandler::start()
660 {
661     ResourceHandleInternal* d = m_resourceHandle->getInternal();
665     QNetworkReply* reply = sendNetworkRequest(d->m_context->networkAccessManager(), d->m_firstRequest);//连接http服务器,由QNetworkAccessManager管理下载
669     m_replyWrapper = new QNetworkReplyWrapper(&m_queue, reply, m_resourceHandle->shouldContentSniff() && d->m_context->mimeSniffingEnabled(), this); 
             
208 QNetworkReplyWrapper::QNetworkReplyWrapper(QNetworkReplyHandlerCallQueue* queue, QNetworkReply* reply, bool sniffMIMETypes,
    QObject
* parent)
209     : QObject(parent)
210     , m_reply(reply)
211     , m_queue(queue)
212     , m_responseContainsData(false)
213     , m_sniffMIMETypes(sniffMIMETypes)
214 {
215     Q_ASSERT(m_reply);
216         
217     // setFinished() must be the first that we connect, so isFinished() is updated when running other slots.
//QT通过此种方式异步回调(yes, 信号、槽机制,http://www.ibm.com/developerworks/cn/linux/guitoolkit/qt/signal-slot/ ),当下载完毕时QNetworkReply对象将emit finish()信号(./WebKitBuild/Debug/WebCore/moc_QNetworkReplyHandler.cpp),将调用本对象的setFinished()等函数
218     connect(m_reply, SIGNAL(finished()), this, SLOT(setFinished()));
219     connect(m_reply, SIGNAL(finished()), this, SLOT(receiveMetaData()));
220     connect(m_reply, SIGNAL(readyRead()), this, SLOT(receiveMetaData()));
221 }
   

671     if (m_loadType == SynchronousLoad) {
673         // If supported, a synchronous request will be finished at this point, no need to hook up the signals.
672         m_replyWrapper->synchronousLoad();//支持同步下载??(不支持)
674         return;
675     }

679 }
下载完毕之后 (setFinished(), receiveMetaData())
261 void QNetworkReplyWrapper::receiveMetaData()
262 {
263     // This slot is only used to receive the first signal from the QNetworkReply object.
//断开下载器的所有信号
264     resetConnections();
288     m_sniffer = new QtMIMETypeSniffer(m_reply, m_advertisedMIMEType, isSupportedImageType);
289 
290     if (m_sniffer->isFinished()) {
291         receiveSniffedMIMEType();
--->
298 void QNetworkReplyWrapper::receiveSniffedMIMEType()
299 {
305     emitMetaDataChanged();
306 }
       --->
318 void QNetworkReplyWrapper::emitMetaDataChanged()
319 {
320     QueueLocker lock(m_queue);
//反馈给上层:MainResourceLoader;checkContentPolicy
321     m_queue->push(&QNetworkReplyHandler::sendResponseIfNeeded);
322 
323     if (m_reply->bytesAvailable()) {
324         m_responseContainsData = true;
//将下载到的数据传递给上层处理:ResourceLoader::didReceiveData->MainResourceLoader::didReceiveData->ResourceLoader::didReceiveData
325         m_queue->push(&QNetworkReplyHandler::forwardData);
326     }

327 
328     if (isFinished()) {
//判断是否重定向,是的话再start();否则调用上层的didFinishLoading:ResourceLoader::didFinishLoading->MainResourceLoader::didFinishLoading->FrameLoader::finishedLoading
329         m_queue->push(&QNetworkReplyHandler::finish);
330         return;
332 
333     // If not finished, connect to the slots that will be used from this point on.
        
//附件js的下载将会执行到这一步:QNetworkReplyWrapper::didReceiveFinished->QNetworkReplyHandler::finish->client->didFinishLoading(m_cachedResourceLoader->decrementRequestCount、m_cachedResourceLoader->loadDone)
334     connect(m_reply, SIGNAL(readyRead()), this, SLOT(didReceiveReadyRead()));
335     connect(m_reply, SIGNAL(finished()), this, SLOT(didReceiveFinished()));
331     }

336 }


292         return;
293     }

296 }

Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp :264


修改原始代码,使之以同步的方式下载网页(不会用到qt复杂的信号处理机制)——无效,客户端无反应
Source/WebCore/platform/network/qt/ResourceHandleQt.cpp  100
100     d->m_job = new QNetworkReplyHandler(this, QNetworkReplyHandler::AsynchronousLoad, d->m_defersLoading);
——>
100     d->m_job = new QNetworkReplyHandler(this, QNetworkReplyHandler::SynchronousLoad, d->m_defersLoading);

修改代码
Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp
947         client->didReceiveData(m_resourceHandle, data.constData(), data.length(), -1);
948         client->didFinishLoading(m_resourceHandle, 0);

2、js附件资源回调接口
Source/WebCore/dom/ScriptElement.cpp:255
245 bool ScriptElement::requestScript(const String& sourceUrl)
255     m_cachedScript = m_element->document()->cachedResourceLoader()->requestScript(sourceUrl, scriptCharset());
Source/WebCore/loader/cache/CachedResourceLoader.cpp  178
178 CachedScript* CachedResourceLoader::requestScript(const String& url, const String& charset)
179 {
180     return static_cast<CachedScript*>(requestResource(CachedResource::Script, url, charset));
181 }
 
300 CachedResource* CachedResourceLoader::requestResource(CachedResource::Type type, const String& resourceURL, const String&    charset, ResourceLoadPriority priority, bool forPreload)
324     CachedResource* resource = memoryCache()->resourceForURL(url);
328         resource = loadResource(type, url, charset, priority);
377 CachedResource* CachedResourceLoader::loadResource(CachedResource::Type type, const KURL& url, const String& charset,    ResourceLoadPriority priority)
383     CachedResource* resource = createResource(type, url, charset);
385     bool inCache = memoryCache()->add(resource);
393     resource->load(this);
Source/WebCore/loader/cache/CachedResource.h  84
 84     virtual void load(CachedResourceLoader* cachedResourceLoader)  { load(cachedResourceLoader, false, DoSecurityCheck, true); }
Source/WebCore/loader/cache/CachedResource.cpp  130
130 void CachedResource::load(CachedResourceLoader* cachedResourceLoader, bool incremental, SecurityCheckPolicy securityCheck, bool  sendResourceLoadCallbacks)
131 {
132     m_sendResourceLoadCallbacks = sendResourceLoadCallbacks;
133     cachedResourceLoader->load(this, incremental, securityCheck, sendResource
537 void CachedResourceLoader::load(CachedResource* resource, bool incremental, SecurityCheckPolicy securityCheck, bool sendResourceLoadCallbacks)
538 {   
539     incrementRequestCount(resource);
541     RefPtr<CachedResourceRequest> request = CachedResourceRequest::load(this, resource, incremental, securityCheck, sendResourceLoadCallbacks);
LoadCallbacks);
//this指向script类型的CachedResource
Source/WebCore/loader/cache/CachedResourceLoader.cpp  537
537 void CachedResourceLoader::load(CachedResource* resource, bool incremental, SecurityCheckPolicy securityCheck, bool sendResourceLoadCallbacks)
538 {   
539     incrementRequestCount(resource);
541     RefPtr<CachedResourceRequest> request = CachedResourceRequest::load(this, resource, incremental, securityCheck, sendResourceLoadCallbacks);
Source/WebCore/loader/cache/CachedResourceRequest.cpp  89
89 PassRefPtr<CachedResourceRequest> CachedResourceRequest::load(CachedResourceLoader* cachedResourceLoader, CachedResource*  resource, bool incremental, SecurityCheckPolicy securityCheck, bool sendResourceLoadCallbacks)
 
90 {
 
91     RefPtr<CachedResourceRequest> request = adoptRef(new CachedResourceRequest(cachedResourceLoader, resource, incremental));
 
92 
 
93     ResourceRequest resourceRequest(resource->url());
124     RefPtr<SubresourceLoader> loader = resourceLoadScheduler()->scheduleSubresourceLoad(cachedResourceLoader->document()->frame(),
125         request.get(), resourceRequest, priority, securityCheck, sendResourceLoadCallbacks);
126     if (!loader || loader->reachedTerminalState()) {
127         // FIXME: What if resources in other frames were waiting for this revalidation?
128         LOG(ResourceLoading, "Cannot start loading '%s'", resource->url().latin1().data());//出错
Source/WebCore/loader/ResourceLoadScheduler.cpp  86
86 PassRefPtr<SubresourceLoader> ResourceLoadScheduler::scheduleSubresourceLoad(Frame* frame, SubresourceLoaderClient* client, const ResourceRequest& request, ResourceLoadPriority priority, SecurityCheckPolicy securityCheck, 
 
87                                                                              bool sendResourceLoadCallbacks, bool shouldContentSniff, const String& optionalOutgoingReferrer)
 
88 {
 
89     RefPtr<SubresourceLoader> loader = SubresourceLoader::create(frame, client, request, securityCheck, sendResourceLoadCallbacks, shouldContentSniff, optionalOutgoingReferrer);
 
90     if (loader)
 
91         scheduleLoad(loader.get(), priority);
108 void ResourceLoadScheduler::scheduleLoad(ResourceLoader* resourceLoader, ResourceLoadPriority priority)
117     HostInformation* host = hostForURL(resourceLoader->url(), CreateIfNotFound);
123         servePendingRequests(host, priority);
181 void ResourceLoadScheduler::servePendingRequests(HostInformation* host, ResourceLoadPriority minimumPriority)
186         HostInformation::RequestQueue& requestsPending = host->requestsPending(ResourceLoadPriority(priority));
187 
188         while (!requestsPending.isEmpty()) {
189             RefPtr<ResourceLoader> resourceLoader = requestsPending.first();
201             resourceLoader->start();
Source/WebCore/loader/ResourceLoader.cpp  142
142 void ResourceLoader::start()
164         m_handle = ResourceHandle::create(m_frame->loader()->networkingContext(), m_request, this, m_defersLoading, m_shouldContentSniff);
Source/WebCore/platform/network/ResourceHandle.cpp  56 //与上同 

3、图片资源回调接口
同2

4、重定向
location重定向
posted on 2013-08-22 14:25 citywanderer 阅读(1139) 评论(0)  编辑 收藏 引用 所属分类: webkit

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理