< prev index next >

modules/web/src/main/native/Source/WebCore/loader/cache/CachedResourceLoader.cpp

Print this page




 273     case CachedResource::MainResource:
 274 #if ENABLE(LINK_PREFETCH)
 275     case CachedResource::LinkPrefetch:
 276     case CachedResource::LinkSubresource:
 277         // Prefetch cannot affect the current document.
 278 #endif
 279         break;
 280     }
 281     return true;
 282 }
 283 
 284 bool CachedResourceLoader::canRequest(CachedResource::Type type, const URL& url, const ResourceLoaderOptions& options, bool forPreload)
 285 {
 286     if (document() && !document()->securityOrigin()->canDisplay(url)) {
 287         if (!forPreload)
 288             FrameLoader::reportLocalLoadFailed(frame(), url.stringCenterEllipsizedToLength());
 289         LOG(ResourceLoading, "CachedResourceLoader::requestResource URL was not allowed by SecurityOrigin::canDisplay");
 290         return 0;
 291     }
 292 













 293     // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved.
 294     bool shouldBypassMainWorldContentSecurityPolicy = (frame() && frame()->script().shouldBypassMainWorldContentSecurityPolicy());
 295 
 296     // Some types of resources can be loaded only from the same origin.  Other
 297     // types of resources, like Images, Scripts, and CSS, can be loaded from
 298     // any URL.
 299     switch (type) {
 300     case CachedResource::MainResource:
 301     case CachedResource::ImageResource:
 302     case CachedResource::CSSStyleSheet:
 303     case CachedResource::Script:
 304     case CachedResource::FontResource:
 305     case CachedResource::RawResource:
 306 #if ENABLE(LINK_PREFETCH)
 307     case CachedResource::LinkPrefetch:
 308     case CachedResource::LinkSubresource:
 309 #endif
 310 #if ENABLE(VIDEO_TRACK)
 311     case CachedResource::TextTrackResource:
 312 #endif


 763 
 764 void CachedResourceLoader::garbageCollectDocumentResources()
 765 {
 766     typedef Vector<String, 10> StringVector;
 767     StringVector resourcesToDelete;
 768 
 769     for (DocumentResourceMap::iterator it = m_documentResources.begin(); it != m_documentResources.end(); ++it) {
 770         if (it->value->hasOneHandle()) {
 771             resourcesToDelete.append(it->key);
 772             it->value->setOwningCachedResourceLoader(0);
 773         }
 774     }
 775 
 776     for (StringVector::const_iterator it = resourcesToDelete.begin(); it != resourcesToDelete.end(); ++it)
 777         m_documentResources.remove(*it);
 778 }
 779 
 780 void CachedResourceLoader::performPostLoadActions()
 781 {
 782     checkForPendingPreloads();





 783 
 784     platformStrategies()->loaderStrategy()->resourceLoadScheduler()->servePendingRequests();
 785 }
 786 
 787 void CachedResourceLoader::incrementRequestCount(const CachedResource* res)
 788 {
 789     if (res->ignoreForRequestCount())
 790         return;
 791 
 792     ++m_requestCount;
 793 }
 794 
 795 void CachedResourceLoader::decrementRequestCount(const CachedResource* res)
 796 {
 797     if (res->ignoreForRequestCount())
 798         return;
 799 
 800     --m_requestCount;
 801     ASSERT(m_requestCount > -1);
 802 }




 273     case CachedResource::MainResource:
 274 #if ENABLE(LINK_PREFETCH)
 275     case CachedResource::LinkPrefetch:
 276     case CachedResource::LinkSubresource:
 277         // Prefetch cannot affect the current document.
 278 #endif
 279         break;
 280     }
 281     return true;
 282 }
 283 
 284 bool CachedResourceLoader::canRequest(CachedResource::Type type, const URL& url, const ResourceLoaderOptions& options, bool forPreload)
 285 {
 286     if (document() && !document()->securityOrigin()->canDisplay(url)) {
 287         if (!forPreload)
 288             FrameLoader::reportLocalLoadFailed(frame(), url.stringCenterEllipsizedToLength());
 289         LOG(ResourceLoading, "CachedResourceLoader::requestResource URL was not allowed by SecurityOrigin::canDisplay");
 290         return 0;
 291     }
 292 
 293     if (m_documentLoader) {
 294         // Don't load for user cancel or stop
 295         if (!m_documentLoader->mainDocumentError().isNull() && m_documentLoader->mainDocumentError().isCancellation())
 296             return false;
 297 
 298         // While navigating to new page and till the main resource is not received completly or
 299         // till the Provisional state the current frame is not detached. These will lead to
 300         // loading sub resource of previous page from either script runner, ResourceLoadScheduler,
 301         // HTMLScriptRunner.
 302         if (m_documentLoader->frame() && m_documentLoader->frame()->loader().state() == FrameState::FrameStateProvisional && type != CachedResource::Type::MainResource)
 303             return false;
 304     }
 305 
 306     // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved.
 307     bool shouldBypassMainWorldContentSecurityPolicy = (frame() && frame()->script().shouldBypassMainWorldContentSecurityPolicy());
 308 
 309     // Some types of resources can be loaded only from the same origin.  Other
 310     // types of resources, like Images, Scripts, and CSS, can be loaded from
 311     // any URL.
 312     switch (type) {
 313     case CachedResource::MainResource:
 314     case CachedResource::ImageResource:
 315     case CachedResource::CSSStyleSheet:
 316     case CachedResource::Script:
 317     case CachedResource::FontResource:
 318     case CachedResource::RawResource:
 319 #if ENABLE(LINK_PREFETCH)
 320     case CachedResource::LinkPrefetch:
 321     case CachedResource::LinkSubresource:
 322 #endif
 323 #if ENABLE(VIDEO_TRACK)
 324     case CachedResource::TextTrackResource:
 325 #endif


 776 
 777 void CachedResourceLoader::garbageCollectDocumentResources()
 778 {
 779     typedef Vector<String, 10> StringVector;
 780     StringVector resourcesToDelete;
 781 
 782     for (DocumentResourceMap::iterator it = m_documentResources.begin(); it != m_documentResources.end(); ++it) {
 783         if (it->value->hasOneHandle()) {
 784             resourcesToDelete.append(it->key);
 785             it->value->setOwningCachedResourceLoader(0);
 786         }
 787     }
 788 
 789     for (StringVector::const_iterator it = resourcesToDelete.begin(); it != resourcesToDelete.end(); ++it)
 790         m_documentResources.remove(*it);
 791 }
 792 
 793 void CachedResourceLoader::performPostLoadActions()
 794 {
 795     checkForPendingPreloads();
 796 
 797     // PostLoad might trigger async resource request which is not required for Canceled Main Document
 798     // caused by user cancel or stop
 799     if (m_documentLoader && !m_documentLoader->mainDocumentError().isNull() && m_documentLoader->mainDocumentError().isCancellation())
 800         return;
 801 
 802     platformStrategies()->loaderStrategy()->resourceLoadScheduler()->servePendingRequests();
 803 }
 804 
 805 void CachedResourceLoader::incrementRequestCount(const CachedResource* res)
 806 {
 807     if (res->ignoreForRequestCount())
 808         return;
 809 
 810     ++m_requestCount;
 811 }
 812 
 813 void CachedResourceLoader::decrementRequestCount(const CachedResource* res)
 814 {
 815     if (res->ignoreForRequestCount())
 816         return;
 817 
 818     --m_requestCount;
 819     ASSERT(m_requestCount > -1);
 820 }


< prev index next >