📄 documentloader.cpp
字号:
} return frameLoader()->subframeIsLoading();}void DocumentLoader::addAllArchiveResources(Archive* archive){ if (!m_archiveResourceCollection) m_archiveResourceCollection.set(new ArchiveResourceCollection); ASSERT(archive); if (!archive) return; m_archiveResourceCollection->addAllResources(archive);}// FIXME: Adding a resource directly to a DocumentLoader/ArchiveResourceCollection seems like bad design, but is API some apps rely on.// Can we change the design in a manner that will let us deprecate that API without reducing functionality of those apps?void DocumentLoader::addArchiveResource(PassRefPtr<ArchiveResource> resource){ if (!m_archiveResourceCollection) m_archiveResourceCollection.set(new ArchiveResourceCollection); ASSERT(resource); if (!resource) return; m_archiveResourceCollection->addResource(resource);}ArchiveResource* DocumentLoader::archiveResourceForURL(const KURL& url) const{ if (!m_archiveResourceCollection) return 0; ArchiveResource* resource = m_archiveResourceCollection->archiveResourceForURL(url); return resource && !resource->shouldIgnoreWhenUnarchiving() ? resource : 0;}PassRefPtr<Archive> DocumentLoader::popArchiveForSubframe(const String& frameName){ return m_archiveResourceCollection ? m_archiveResourceCollection->popSubframeArchive(frameName) : 0;}void DocumentLoader::clearArchiveResources(){ m_archiveResourceCollection.clear(); m_substituteResourceDeliveryTimer.stop();}void DocumentLoader::setParsedArchiveData(PassRefPtr<SharedBuffer> data){ m_parsedArchiveData = data;}SharedBuffer* DocumentLoader::parsedArchiveData() const{ return m_parsedArchiveData.get();}PassRefPtr<ArchiveResource> DocumentLoader::mainResource() const{ const ResourceResponse& r = response(); RefPtr<SharedBuffer> mainResourceBuffer = mainResourceData(); if (!mainResourceBuffer) mainResourceBuffer = SharedBuffer::create(); return ArchiveResource::create(mainResourceBuffer, r.url(), r.mimeType(), r.textEncodingName(), frame()->tree()->name());}PassRefPtr<ArchiveResource> DocumentLoader::subresource(const KURL& url) const{ if (!isCommitted()) return 0; Document* doc = m_frame->document(); CachedResource* resource = doc->docLoader()->cachedResource(url); if (!resource || resource->preloadResult() == CachedResource::PreloadReferenced) return archiveResourceForURL(url); return ArchiveResource::create(resource->data(), url, resource->response());}void DocumentLoader::getSubresources(Vector<PassRefPtr<ArchiveResource> >& subresources) const{ if (!isCommitted()) return; Document* document = m_frame->document(); const DocLoader::DocumentResourceMap& allResources = document->docLoader()->allCachedResources(); DocLoader::DocumentResourceMap::const_iterator end = allResources.end(); for (DocLoader::DocumentResourceMap::const_iterator it = allResources.begin(); it != end; ++it) { RefPtr<ArchiveResource> subresource = this->subresource(KURL(it->second->url())); if (subresource) subresources.append(subresource.release()); } return;}void DocumentLoader::deliverSubstituteResourcesAfterDelay(){ if (m_pendingSubstituteResources.isEmpty()) return; ASSERT(m_frame && m_frame->page()); if (m_frame->page()->defersLoading()) return; if (!m_substituteResourceDeliveryTimer.isActive()) m_substituteResourceDeliveryTimer.startOneShot(0);}void DocumentLoader::substituteResourceDeliveryTimerFired(Timer<DocumentLoader>*){ if (m_pendingSubstituteResources.isEmpty()) return; ASSERT(m_frame && m_frame->page()); if (m_frame->page()->defersLoading()) return; SubstituteResourceMap copy; copy.swap(m_pendingSubstituteResources); SubstituteResourceMap::const_iterator end = copy.end(); for (SubstituteResourceMap::const_iterator it = copy.begin(); it != end; ++it) { RefPtr<ResourceLoader> loader = it->first; SubstituteResource* resource = it->second.get(); if (resource) { SharedBuffer* data = resource->data(); loader->didReceiveResponse(resource->response()); loader->didReceiveData(data->data(), data->size(), data->size(), true); loader->didFinishLoading(); } else { // A null resource means that we should fail the load. // FIXME: Maybe we should use another error here - something like "not in cache". loader->didFail(loader->cannotShowURLError()); } }}#ifndef NDEBUGbool DocumentLoader::isSubstituteLoadPending(ResourceLoader* loader) const{ return m_pendingSubstituteResources.contains(loader);}#endifvoid DocumentLoader::cancelPendingSubstituteLoad(ResourceLoader* loader){ if (m_pendingSubstituteResources.isEmpty()) return; m_pendingSubstituteResources.remove(loader); if (m_pendingSubstituteResources.isEmpty()) m_substituteResourceDeliveryTimer.stop();}bool DocumentLoader::scheduleArchiveLoad(ResourceLoader* loader, const ResourceRequest& request, const KURL& originalURL){ ArchiveResource* resource = 0; if (request.url() == originalURL) resource = archiveResourceForURL(originalURL); if (!resource) { // WebArchiveDebugMode means we fail loads instead of trying to fetch them from the network if they're not in the archive. bool shouldFailLoad = m_frame->settings()->webArchiveDebugModeEnabled() && ArchiveFactory::isArchiveMimeType(responseMIMEType()); if (!shouldFailLoad) return false; } m_pendingSubstituteResources.set(loader, resource); deliverSubstituteResourcesAfterDelay(); return true;}void DocumentLoader::addResponse(const ResourceResponse& r){ if (!m_stopRecordingResponses) m_responses.append(r);}void DocumentLoader::stopRecordingResponses(){ m_stopRecordingResponses = true;}void DocumentLoader::setTitle(const String& title){ if (title.isEmpty()) return; String trimmed = canonicalizedTitle(title, m_frame); if (!trimmed.isEmpty() && m_pageTitle != trimmed) { frameLoader()->willChangeTitle(this); m_pageTitle = trimmed; frameLoader()->didChangeTitle(this); }}KURL DocumentLoader::urlForHistory() const{ // Return the URL to be used for history and B/F list. // Returns nil for WebDataProtocol URLs that aren't alternates // for unreachable URLs, because these can't be stored in history. if (m_substituteData.isValid()) return unreachableURL(); return m_originalRequestCopy.url();}bool DocumentLoader::urlForHistoryReflectsFailure() const{ return m_substituteData.isValid() || m_response.httpStatusCode() >= 400;}void DocumentLoader::loadFromCachedPage(PassRefPtr<CachedPage> cachedPage){ LOG(PageCache, "WebCorePageCache: DocumentLoader %p loading from cached page %p", this, cachedPage.get()); prepareForLoadStart(); setLoadingFromCachedPage(true); setCommitted(true); frameLoader()->commitProvisionalLoad(cachedPage);}const KURL& DocumentLoader::originalURL() const{ return m_originalRequestCopy.url();}const KURL& DocumentLoader::requestURL() const{ return request().url();}const KURL& DocumentLoader::responseURL() const{ return m_response.url();}const String& DocumentLoader::responseMIMEType() const{ return m_response.mimeType();}const KURL& DocumentLoader::unreachableURL() const{ return m_substituteData.failingURL();}void DocumentLoader::setDefersLoading(bool defers){ if (m_mainResourceLoader) m_mainResourceLoader->setDefersLoading(defers); setAllDefersLoading(m_subresourceLoaders, defers); setAllDefersLoading(m_plugInStreamLoaders, defers); if (!defers) deliverSubstituteResourcesAfterDelay();}void DocumentLoader::stopLoadingPlugIns(){ cancelAll(m_plugInStreamLoaders);}void DocumentLoader::stopLoadingSubresources(){ cancelAll(m_subresourceLoaders);}void DocumentLoader::addSubresourceLoader(ResourceLoader* loader){ m_subresourceLoaders.add(loader); setLoading(true);}void DocumentLoader::removeSubresourceLoader(ResourceLoader* loader){ m_subresourceLoaders.remove(loader); updateLoading(); if (Frame* frame = m_frame) frame->loader()->checkLoadComplete();}void DocumentLoader::addPlugInStreamLoader(ResourceLoader* loader){ m_plugInStreamLoaders.add(loader); setLoading(true);}void DocumentLoader::removePlugInStreamLoader(ResourceLoader* loader){ m_plugInStreamLoaders.remove(loader); updateLoading();}bool DocumentLoader::isLoadingMainResource() const{ return !!m_mainResourceLoader;}bool DocumentLoader::isLoadingSubresources() const{ return !m_subresourceLoaders.isEmpty();}bool DocumentLoader::isLoadingPlugIns() const{ return !m_plugInStreamLoaders.isEmpty();}bool DocumentLoader::isLoadingMultipartContent() const{ return m_mainResourceLoader && m_mainResourceLoader->isLoadingMultipartContent();}bool DocumentLoader::startLoadingMainResource(unsigned long identifier){ ASSERT(!m_mainResourceLoader); m_mainResourceLoader = MainResourceLoader::create(m_frame); m_mainResourceLoader->setIdentifier(identifier); // FIXME: Is there any way the extra fields could have not been added by now? // If not, it would be great to remove this line of code. frameLoader()->addExtraFieldsToMainResourceRequest(m_request); if (!m_mainResourceLoader->load(m_request, m_substituteData)) { // FIXME: If this should really be caught, we should just ASSERT this doesn't happen; // should it be caught by other parts of WebKit or other parts of the app? LOG_ERROR("could not create WebResourceHandle for URL %s -- should be caught by policy handler level", m_request.url().string().ascii().data()); m_mainResourceLoader = 0; return false; } return true;}void DocumentLoader::cancelMainResourceLoad(const ResourceError& error){ m_mainResourceLoader->cancel(error);}void DocumentLoader::subresourceLoaderFinishedLoadingOnePart(ResourceLoader* loader){ m_multipartSubresourceLoaders.add(loader); m_subresourceLoaders.remove(loader); updateLoading(); if (Frame* frame = m_frame) frame->loader()->checkLoadComplete(); }void DocumentLoader::iconLoadDecisionAvailable(){ if (m_frame) m_frame->loader()->iconLoadDecisionAvailable();}#if ENABLE(OFFLINE_WEB_APPLICATIONS)void DocumentLoader::setCandidateApplicationCacheGroup(ApplicationCacheGroup* group){ ASSERT(!m_applicationCache); m_candidateApplicationCacheGroup = group;} void DocumentLoader::setApplicationCache(PassRefPtr<ApplicationCache> applicationCache){ if (m_candidateApplicationCacheGroup) { ASSERT(!m_applicationCache); m_candidateApplicationCacheGroup = 0; } m_applicationCache = applicationCache;}ApplicationCache* DocumentLoader::mainResourceApplicationCache() const{ if (m_mainResourceApplicationCache) return m_mainResourceApplicationCache.get(); if (m_mainResourceLoader) return m_mainResourceLoader->applicationCache(); return 0;}bool DocumentLoader::shouldLoadResourceFromApplicationCache(const ResourceRequest& request, ApplicationCacheResource*& resource){ ApplicationCache* cache = applicationCache(); if (!cache || !cache->isComplete()) return false; // If the resource is not a HTTP/HTTPS GET, then abort if (!ApplicationCache::requestIsHTTPOrHTTPSGet(request)) return false; // If the resource's URL is an master entry, the manifest, an explicit entry, a fallback entry, or a dynamic entry // in the application cache, then get the resource from the cache (instead of fetching it). resource = cache->resourceForURL(request.url()); // Resources that match fallback namespaces or online whitelist entries are fetched from the network, // unless they are also cached. if (!resource && (cache->urlMatchesFallbackNamespace(request.url()) || cache->isURLInOnlineWhitelist(request.url()))) return false; // Resources that are not present in the manifest will always fail to load (at least, after the // cache has been primed the first time), making the testing of offline applications simpler. return true;}bool DocumentLoader::getApplicationCacheFallbackResource(const ResourceRequest& request, ApplicationCacheResource*& resource, ApplicationCache* cache){ if (!cache) { cache = applicationCache(); if (!cache) return false; } if (!cache->isComplete()) return false; // If the resource is not a HTTP/HTTPS GET, then abort if (!ApplicationCache::requestIsHTTPOrHTTPSGet(request)) return false; KURL fallbackURL; if (!cache->urlMatchesFallbackNamespace(request.url(), &fallbackURL)) return false; resource = cache->resourceForURL(fallbackURL); ASSERT(resource); return true;}bool DocumentLoader::scheduleApplicationCacheLoad(ResourceLoader* loader, const ResourceRequest& request, const KURL& originalURL){ if (!frameLoader()->frame()->settings() || !frameLoader()->frame()->settings()->offlineWebApplicationCacheEnabled()) return false; if (request.url() != originalURL) return false; ApplicationCacheResource* resource; if (!shouldLoadResourceFromApplicationCache(request, resource)) return false; m_pendingSubstituteResources.set(loader, resource); deliverSubstituteResourcesAfterDelay(); return true;}bool DocumentLoader::scheduleLoadFallbackResourceFromApplicationCache(ResourceLoader* loader, const ResourceRequest& request, ApplicationCache* cache){ if (!frameLoader()->frame()->settings() || !frameLoader()->frame()->settings()->offlineWebApplicationCacheEnabled()) return false; ApplicationCacheResource* resource; if (!getApplicationCacheFallbackResource(request, resource, cache)) return false; m_pendingSubstituteResources.set(loader, resource); deliverSubstituteResourcesAfterDelay(); return true;}#endif // ENABLE(OFFLINE_WEB_APPLICATIONS)}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -