📄 mainresourceloader.cpp
字号:
void MainResourceLoader::continueAfterContentPolicy(PolicyAction policy){ ASSERT(m_waitingForContentPolicy); m_waitingForContentPolicy = false; if (frameLoader() && !frameLoader()->isStopping()) continueAfterContentPolicy(policy, m_response); deref(); // balances ref in didReceiveResponse}void MainResourceLoader::didReceiveResponse(const ResourceResponse& r){#if ENABLE(OFFLINE_WEB_APPLICATIONS) if (r.httpStatusCode() / 100 == 4 || r.httpStatusCode() / 100 == 5) { ASSERT(!m_applicationCache); if (m_frame->settings() && m_frame->settings()->offlineWebApplicationCacheEnabled()) { m_applicationCache = ApplicationCacheGroup::fallbackCacheForMainRequest(request(), documentLoader()); if (scheduleLoadFallbackResourceFromApplicationCache(m_applicationCache.get())) return; } }#endif // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred. // See <rdar://problem/6304600> for more details.#if !PLATFORM(CF) ASSERT(shouldLoadAsEmptyDocument(r.url()) || !defersLoading());#endif if (m_loadingMultipartContent) { frameLoader()->setupForReplaceByMIMEType(r.mimeType()); clearResourceData(); } if (r.isMultipart()) m_loadingMultipartContent = true; // The additional processing can do anything including possibly removing the last // reference to this object; one example of this is 3266216. RefPtr<MainResourceLoader> protect(this); m_documentLoader->setResponse(r); m_response = r; ASSERT(!m_waitingForContentPolicy); m_waitingForContentPolicy = true; ref(); // balanced by deref in continueAfterContentPolicy and didCancel frameLoader()->checkContentPolicy(m_response.mimeType(), callContinueAfterContentPolicy, this);}void MainResourceLoader::didReceiveData(const char* data, int length, long long lengthReceived, bool allAtOnce){ ASSERT(data); ASSERT(length != 0); ASSERT(!m_response.isNull());#if USE(CFNETWORK) || (PLATFORM(MAC) && !defined(BUILDING_ON_TIGER)) // Workaround for <rdar://problem/6060782> if (m_response.isNull()) { m_response = ResourceResponse(KURL(), "text/html", 0, String(), String()); if (DocumentLoader* documentLoader = frameLoader()->activeDocumentLoader()) documentLoader->setResponse(m_response); }#endif // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred. // See <rdar://problem/6304600> for more details.#if !PLATFORM(CF) ASSERT(!defersLoading());#endif // The additional processing can do anything including possibly removing the last // reference to this object; one example of this is 3266216. RefPtr<MainResourceLoader> protect(this); ResourceLoader::didReceiveData(data, length, lengthReceived, allAtOnce);}void MainResourceLoader::didFinishLoading(){ // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred. // See <rdar://problem/6304600> for more details.#if !PLATFORM(CF) ASSERT(shouldLoadAsEmptyDocument(frameLoader()->activeDocumentLoader()->url()) || !defersLoading());#endif // The additional processing can do anything including possibly removing the last // reference to this object. RefPtr<MainResourceLoader> protect(this);#if ENABLE(OFFLINE_WEB_APPLICATIONS) RefPtr<DocumentLoader> dl = documentLoader();#endif frameLoader()->finishedLoading(); ResourceLoader::didFinishLoading(); #if ENABLE(OFFLINE_WEB_APPLICATIONS) ApplicationCacheGroup* group = dl->candidateApplicationCacheGroup(); if (!group && dl->applicationCache() && !dl->mainResourceApplicationCache()) group = dl->applicationCache()->group(); if (group) group->finishedLoadingMainResource(dl.get());#endif}void MainResourceLoader::didFail(const ResourceError& error){#if ENABLE(OFFLINE_WEB_APPLICATIONS) if (!error.isCancellation()) { ASSERT(!m_applicationCache); if (m_frame->settings() && m_frame->settings()->offlineWebApplicationCacheEnabled()) { m_applicationCache = ApplicationCacheGroup::fallbackCacheForMainRequest(request(), documentLoader()); if (scheduleLoadFallbackResourceFromApplicationCache(m_applicationCache.get())) return; } }#endif // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred. // See <rdar://problem/6304600> for more details.#if !PLATFORM(CF) ASSERT(!defersLoading());#endif receivedError(error);}void MainResourceLoader::handleEmptyLoad(const KURL& url, bool forURLScheme){ String mimeType; if (forURLScheme) mimeType = frameLoader()->generatedMIMETypeForURLScheme(url.protocol()); else mimeType = "text/html"; ResourceResponse response(url, mimeType, 0, String(), String()); didReceiveResponse(response);}void MainResourceLoader::handleDataLoadNow(Timer<MainResourceLoader>*){ RefPtr<MainResourceLoader> protect(this); KURL url = m_substituteData.responseURL(); if (url.isEmpty()) url = m_initialRequest.url(); ResourceResponse response(url, m_substituteData.mimeType(), m_substituteData.content()->size(), m_substituteData.textEncoding(), ""); didReceiveResponse(response);}void MainResourceLoader::handleDataLoadSoon(ResourceRequest& r){ m_initialRequest = r; if (m_documentLoader->deferMainResourceDataLoad()) m_dataLoadTimer.startOneShot(0); else handleDataLoadNow(0);}bool MainResourceLoader::loadNow(ResourceRequest& r){ bool shouldLoadEmptyBeforeRedirect = shouldLoadAsEmptyDocument(r.url()); ASSERT(!m_handle); ASSERT(shouldLoadEmptyBeforeRedirect || !defersLoading()); // Send this synthetic delegate callback since clients expect it, and // we no longer send the callback from within NSURLConnection for // initial requests. willSendRequest(r, ResourceResponse()); // <rdar://problem/4801066> // willSendRequest() is liable to make the call to frameLoader() return NULL, so we need to check that here if (!frameLoader()) return false; const KURL& url = r.url(); bool shouldLoadEmpty = shouldLoadAsEmptyDocument(url) && !m_substituteData.isValid(); if (shouldLoadEmptyBeforeRedirect && !shouldLoadEmpty && defersLoading()) return true; if (m_substituteData.isValid()) handleDataLoadSoon(r); else if (shouldLoadEmpty || frameLoader()->representationExistsForURLScheme(url.protocol())) handleEmptyLoad(url, !shouldLoadEmpty); else m_handle = ResourceHandle::create(r, this, m_frame.get(), false, true, true); return false;}bool MainResourceLoader::load(const ResourceRequest& r, const SubstituteData& substituteData){ ASSERT(!m_handle); m_substituteData = substituteData;#if ENABLE(OFFLINE_WEB_APPLICATIONS) // Check if this request should be loaded from the application cache if (!m_substituteData.isValid() && frameLoader()->frame()->settings() && frameLoader()->frame()->settings()->offlineWebApplicationCacheEnabled()) { ASSERT(!m_applicationCache); m_applicationCache = ApplicationCacheGroup::cacheForMainRequest(r, m_documentLoader.get()); if (m_applicationCache) { // Get the resource from the application cache. By definition, cacheForMainRequest() returns a cache that contains the resource. ApplicationCacheResource* resource = m_applicationCache->resourceForRequest(r); m_substituteData = SubstituteData(resource->data(), resource->response().mimeType(), resource->response().textEncodingName(), KURL()); } }#endif ResourceRequest request(r); bool defer = defersLoading(); if (defer) { bool shouldLoadEmpty = shouldLoadAsEmptyDocument(r.url()); if (shouldLoadEmpty) defer = false; } if (!defer) { if (loadNow(request)) { // Started as an empty document, but was redirected to something non-empty. ASSERT(defersLoading()); defer = true; } } if (defer) m_initialRequest = request; return true;}void MainResourceLoader::setDefersLoading(bool defers){ ResourceLoader::setDefersLoading(defers); if (defers) { if (m_dataLoadTimer.isActive()) m_dataLoadTimer.stop(); } else { if (m_initialRequest.isNull()) return; if (m_substituteData.isValid() && m_documentLoader->deferMainResourceDataLoad()) m_dataLoadTimer.startOneShot(0); else { ResourceRequest r(m_initialRequest); m_initialRequest = ResourceRequest(); loadNow(r); } }}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -