Changeset 195770 in webkit
- Timestamp:
- Jan 28, 2016 11:52:57 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r195769 r195770 1 2016-01-27 Jer Noble <jer.noble@apple.com> 2 3 Allow CachedResourceLoader clients to opt out of the MemoryCache. 4 https://bugs.webkit.org/show_bug.cgi?id=153549 5 6 Reviewed by Darin Adler. 7 8 Add a flag to ResourceLoaderOptions which allow loader clients to opt out of having 9 resources stored in the MemoryCache. 10 11 * loader/ResourceLoaderOptions.h: 12 (WebCore::ResourceLoaderOptions::ResourceLoaderOptions): 13 (WebCore::ResourceLoaderOptions::cachingPolicy): 14 15 Existing clients will have to add the (default) AllowCaching flag when they create a 16 ResourceLoaderOptions object. 17 18 * loader/DocumentLoader.cpp: 19 (WebCore::DocumentLoader::startLoadingMainResource): 20 * loader/MediaResourceLoader.cpp: 21 (WebCore::MediaResourceLoader::start): 22 * loader/NetscapePlugInStreamLoader.cpp: 23 (WebCore::NetscapePlugInStreamLoader::NetscapePlugInStreamLoader): 24 (WebCore::ResourceLoaderOptions::setCachingPolicy): 25 * loader/icon/IconLoader.cpp: 26 (WebCore::IconLoader::startLoading): 27 * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: 28 (WebCore::WebCoreAVFResourceLoader::startLoading): 29 30 Every time the CachedResource or CachedResourceLoader accesses the MemoryCache, check 31 to see whether the resource or the request have allowed caching before adding resources 32 to, removing resources from, or sourcing resource data from the MemoryCache. 33 34 * loader/cache/CachedResource.cpp: 35 (WebCore::CachedResource::~CachedResource): 36 (WebCore::CachedResource::failBeforeStarting): 37 (WebCore::CachedResource::addClientToSet): 38 (WebCore::CachedResource::removeClient): 39 (WebCore::CachedResource::setDecodedSize): 40 (WebCore::CachedResource::setEncodedSize): 41 (WebCore::CachedResource::didAccessDecodedData): 42 * loader/cache/CachedResource.h: 43 (WebCore::CachedResource::allowsCaching): 44 * loader/cache/CachedResourceLoader.cpp: 45 (WebCore::CachedResourceLoader::requestUserCSSStyleSheet): 46 (WebCore::CachedResourceLoader::requestResource): 47 (WebCore::CachedResourceLoader::revalidateResource): 48 (WebCore::CachedResourceLoader::loadResource): 49 (WebCore::CachedResourceLoader::printPreloadStats): 50 (WebCore::CachedResourceLoader::defaultCachedResourceOptions): 51 * loader/cache/CachedResourceRequest.h: 52 (WebCore::CachedResourceRequest::allowsCaching): 53 1 54 2016-01-28 Enrica Casucci <enrica@apple.com> 2 55 -
trunk/Source/WebCore/loader/DocumentLoader.cpp
r195452 r195770 1476 1476 request.makeUnconditional(); 1477 1477 1478 static NeverDestroyed<ResourceLoaderOptions> mainResourceLoadOptions(SendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForAllCredentials, ClientRequestedCredentials, SkipSecurityCheck, UseDefaultOriginRestrictionsForType, IncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading );1478 static NeverDestroyed<ResourceLoaderOptions> mainResourceLoadOptions(SendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForAllCredentials, ClientRequestedCredentials, SkipSecurityCheck, UseDefaultOriginRestrictionsForType, IncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading, CachingPolicy::AllowCaching); 1479 1479 CachedResourceRequest cachedResourceRequest(request, mainResourceLoadOptions); 1480 1480 cachedResourceRequest.setInitiator(*this); -
trunk/Source/WebCore/loader/MediaResourceLoader.cpp
r195452 r195770 62 62 63 63 // ContentSecurityPolicyImposition::DoPolicyCheck is a placeholder value. It does not affect the request since Content Security Policy does not apply to raw resources. 64 CachedResourceRequest cacheRequest(request, ResourceLoaderOptions(SendCallbacks, DoNotSniffContent, bufferingPolicy, allowCredentials, DoNotAskClientForCrossOriginCredentials, ClientDidNotRequestCredentials, DoSecurityCheck, corsPolicy, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading ));64 CachedResourceRequest cacheRequest(request, ResourceLoaderOptions(SendCallbacks, DoNotSniffContent, bufferingPolicy, allowCredentials, DoNotAskClientForCrossOriginCredentials, ClientDidNotRequestCredentials, DoSecurityCheck, corsPolicy, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading, CachingPolicy::AllowCaching)); 65 65 66 66 if (!m_crossOriginMode.isNull()) -
trunk/Source/WebCore/loader/NetscapePlugInStreamLoader.cpp
r195010 r195770 44 44 // See <https://bugs.webkit.org/show_bug.cgi?id=146663>. 45 45 NetscapePlugInStreamLoader::NetscapePlugInStreamLoader(Frame* frame, NetscapePlugInStreamLoaderClient* client) 46 : ResourceLoader(frame, ResourceLoaderOptions(SendCallbacks, SniffContent, DoNotBufferData, AllowStoredCredentials, AskClientForAllCredentials, ClientRequestedCredentials, SkipSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading ))46 : ResourceLoader(frame, ResourceLoaderOptions(SendCallbacks, SniffContent, DoNotBufferData, AllowStoredCredentials, AskClientForAllCredentials, ClientRequestedCredentials, SkipSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading, CachingPolicy::AllowCaching)) 47 47 , m_client(client) 48 48 { -
trunk/Source/WebCore/loader/ResourceLoaderOptions.h
r195010 r195770 77 77 }; 78 78 79 enum class CachingPolicy : uint8_t { 80 AllowCaching, 81 DisallowCaching 82 }; 83 79 84 struct ResourceLoaderOptions { 80 85 ResourceLoaderOptions() … … 91 96 } 92 97 93 ResourceLoaderOptions(SendCallbackPolicy sendLoadCallbacks, ContentSniffingPolicy sniffContent, DataBufferingPolicy dataBufferingPolicy, StoredCredentials allowCredentials, ClientCredentialPolicy credentialPolicy, CredentialRequest credentialRequest, SecurityCheckPolicy securityCheck, RequestOriginPolicy requestOriginPolicy, CertificateInfoPolicy certificateInfoPolicy, ContentSecurityPolicyImposition contentSecurityPolicyImposition, DefersLoadingPolicy defersLoadingPolicy )98 ResourceLoaderOptions(SendCallbackPolicy sendLoadCallbacks, ContentSniffingPolicy sniffContent, DataBufferingPolicy dataBufferingPolicy, StoredCredentials allowCredentials, ClientCredentialPolicy credentialPolicy, CredentialRequest credentialRequest, SecurityCheckPolicy securityCheck, RequestOriginPolicy requestOriginPolicy, CertificateInfoPolicy certificateInfoPolicy, ContentSecurityPolicyImposition contentSecurityPolicyImposition, DefersLoadingPolicy defersLoadingPolicy, CachingPolicy cachingPolicy) 94 99 : m_sendLoadCallbacks(sendLoadCallbacks) 95 100 , m_sniffContent(sniffContent) … … 103 108 , m_contentSecurityPolicyImposition(contentSecurityPolicyImposition) 104 109 , m_defersLoadingPolicy(defersLoadingPolicy) 110 , m_cachingPolicy(cachingPolicy) 105 111 { 106 112 } … … 128 134 DefersLoadingPolicy defersLoadingPolicy() const { return m_defersLoadingPolicy; } 129 135 void setDefersLoadingPolicy(DefersLoadingPolicy defersLoadingPolicy) { m_defersLoadingPolicy = defersLoadingPolicy; } 136 CachingPolicy cachingPolicy() const { return m_cachingPolicy; } 137 void setCachingPolicy(CachingPolicy cachingPolicy) { m_cachingPolicy = cachingPolicy; } 130 138 131 139 unsigned m_sendLoadCallbacks : 1; … … 140 148 ContentSecurityPolicyImposition m_contentSecurityPolicyImposition { ContentSecurityPolicyImposition::DoPolicyCheck }; 141 149 DefersLoadingPolicy m_defersLoadingPolicy { DefersLoadingPolicy::AllowDefersLoading }; 150 CachingPolicy m_cachingPolicy { CachingPolicy::AllowCaching }; 142 151 }; 143 152 -
trunk/Source/WebCore/loader/cache/CachedResource.cpp
r195452 r195770 160 160 ASSERT(!inCache()); 161 161 ASSERT(!m_deleted); 162 ASSERT(url().isNull() || MemoryCache::singleton().resourceForRequest(resourceRequest(), sessionID()) != this);162 ASSERT(url().isNull() || !allowsCaching() || MemoryCache::singleton().resourceForRequest(resourceRequest(), sessionID()) != this); 163 163 164 164 #ifndef NDEBUG … … 175 175 // FIXME: What if resources in other frames were waiting for this revalidation? 176 176 LOG(ResourceLoading, "Cannot start loading '%s'", url().string().latin1().data()); 177 if ( m_resourceToRevalidate)177 if (allowsCaching() && m_resourceToRevalidate) 178 178 MemoryCache::singleton().revalidationFailed(*this); 179 179 error(CachedResource::LoadError); … … 453 453 m_preloadResult = PreloadReferenced; 454 454 } 455 if ( !hasClients() && inCache())455 if (allowsCaching() && !hasClients() && inCache()) 456 456 MemoryCache::singleton().addToLiveResourcesSize(*this); 457 457 … … 484 484 485 485 bool deleted = deleteIfPossible(); 486 if ( !deleted && !hasClients()) {486 if (allowsCaching() && !deleted && !hasClients()) { 487 487 auto& memoryCache = MemoryCache::singleton(); 488 488 if (inCache()) { … … 542 542 // The object must be moved to a different queue, since its size has been changed. 543 543 // Remove before updating m_decodedSize, so we find the resource in the correct LRU list. 544 if ( inCache())544 if (allowsCaching() && inCache()) 545 545 MemoryCache::singleton().removeFromLRUList(*this); 546 546 547 547 m_decodedSize = size; 548 548 549 if ( inCache()) {549 if (allowsCaching() && inCache()) { 550 550 auto& memoryCache = MemoryCache::singleton(); 551 551 // Now insert into the new LRU list. … … 579 579 // The object must be moved to a different queue, since its size has been changed. 580 580 // Remove before updating m_encodedSize, so we find the resource in the correct LRU list. 581 if ( inCache())581 if (allowsCaching() && inCache()) 582 582 MemoryCache::singleton().removeFromLRUList(*this); 583 583 584 584 m_encodedSize = size; 585 585 586 if ( inCache()) {586 if (allowsCaching() && inCache()) { 587 587 auto& memoryCache = MemoryCache::singleton(); 588 588 memoryCache.insertInLRUList(*this); … … 595 595 m_lastDecodedAccessTime = timeStamp; 596 596 597 if ( inCache()) {597 if (allowsCaching() && inCache()) { 598 598 auto& memoryCache = MemoryCache::singleton(); 599 599 if (memoryCache.inLiveDecodedResourcesList(*this)) { -
trunk/Source/WebCore/loader/cache/CachedResource.h
r195430 r195770 219 219 bool shouldSendResourceLoadCallbacks() const { return m_options.sendLoadCallbacks() == SendCallbacks; } 220 220 DataBufferingPolicy dataBufferingPolicy() const { return m_options.dataBufferingPolicy(); } 221 222 bool allowsCaching() const { return m_options.cachingPolicy() == CachingPolicy::AllowCaching; } 221 223 222 224 virtual void destroyDecodedData() { } -
trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp
r195010 r195770 222 222 223 223 auto& memoryCache = MemoryCache::singleton(); 224 if (CachedResource* existing = memoryCache.resourceForRequest(request.resourceRequest(), sessionID())) { 225 if (is<CachedCSSStyleSheet>(*existing)) 226 return downcast<CachedCSSStyleSheet>(existing); 227 memoryCache.remove(*existing); 228 } 224 if (request.allowsCaching()) { 225 if (CachedResource* existing = memoryCache.resourceForRequest(request.resourceRequest(), sessionID())) { 226 if (is<CachedCSSStyleSheet>(*existing)) 227 return downcast<CachedCSSStyleSheet>(existing); 228 memoryCache.remove(*existing); 229 } 230 } 231 229 232 if (url.string() != request.resourceRequest().url()) 230 233 request.mutableResourceRequest().setURL(url); … … 232 235 CachedResourceHandle<CachedCSSStyleSheet> userSheet = new CachedCSSStyleSheet(request.resourceRequest(), request.charset(), sessionID()); 233 236 234 memoryCache.add(*userSheet); 237 if (request.allowsCaching()) 238 memoryCache.add(*userSheet); 235 239 // FIXME: loadResource calls setOwningCachedResourceLoader() if the resource couldn't be added to cache. Does this function need to call it, too? 236 240 237 userSheet->load(*this, ResourceLoaderOptions(DoNotSendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForAllCredentials, ClientRequestedCredentials, SkipSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::SkipPolicyCheck, DefersLoadingPolicy::AllowDefersLoading ));241 userSheet->load(*this, ResourceLoaderOptions(DoNotSendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForAllCredentials, ClientRequestedCredentials, SkipSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::SkipPolicyCheck, DefersLoadingPolicy::AllowDefersLoading, CachingPolicy::AllowCaching)); 238 242 239 243 return userSheet; … … 556 560 557 561 auto& memoryCache = MemoryCache::singleton(); 558 if ( memoryCache.disabled()) {562 if (request.allowsCaching() && memoryCache.disabled()) { 559 563 DocumentResourceMap::iterator it = m_documentResources.find(url.string()); 560 564 if (it != m_documentResources.end()) { … … 571 575 #endif 572 576 573 resource = memoryCache.resourceForRequest(request.resourceRequest(), sessionID()); 577 if (request.allowsCaching()) 578 resource = memoryCache.resourceForRequest(request.resourceRequest(), sessionID()); 574 579 575 580 logMemoryCacheResourceRequest(frame(), resource ? DiagnosticLoggingKeys::inMemoryCacheKey() : DiagnosticLoggingKeys::notInMemoryCacheKey()); … … 609 614 // We don't support immediate loads, but we do support immediate failure. 610 615 if (resource->errorOccurred()) { 611 if (resource-> inCache())616 if (resource->allowsCaching() && resource->inCache()) 612 617 memoryCache.remove(*resource); 613 618 return nullptr; … … 637 642 ASSERT(!resource->resourceToRevalidate()); 638 643 ASSERT(resource->sessionID() == sessionID()); 644 ASSERT(resource->allowsCaching()); 639 645 640 646 CachedResourceHandle<CachedResource> newResource = createResource(resource->type(), resource->resourceRequest(), resource->encoding(), resource->sessionID()); … … 662 668 CachedResourceHandle<CachedResource> resource = createResource(type, request.mutableResourceRequest(), request.charset(), sessionID()); 663 669 664 if ( !memoryCache.add(*resource))670 if (request.allowsCaching() && !memoryCache.add(*resource)) 665 671 resource->setOwningCachedResourceLoader(this); 666 672 #if ENABLE(RESOURCE_TIMING) … … 1152 1158 } 1153 1159 1154 if (resource->errorOccurred() )1160 if (resource->errorOccurred() && resource->preloadResult() == CachedResource::PreloadNotReferenced) 1155 1161 MemoryCache::singleton().remove(resource); 1156 1162 … … 1170 1176 const ResourceLoaderOptions& CachedResourceLoader::defaultCachedResourceOptions() 1171 1177 { 1172 static ResourceLoaderOptions options(SendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForAllCredentials, ClientRequestedCredentials, DoSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading );1178 static ResourceLoaderOptions options(SendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForAllCredentials, ClientRequestedCredentials, DoSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading, CachingPolicy::AllowCaching); 1173 1179 return options; 1174 1180 } -
trunk/Source/WebCore/loader/cache/CachedResourceRequest.h
r186390 r195770 61 61 void setInitiator(const AtomicString& name); 62 62 const AtomicString& initiatorName() const; 63 bool allowsCaching() const { return m_options.cachingPolicy() == CachingPolicy::AllowCaching; } 63 64 64 65 void setInitiator(DocumentLoader&); -
trunk/Source/WebCore/loader/icon/IconLoader.cpp
r195010 r195770 60 60 61 61 // ContentSecurityPolicyImposition::DoPolicyCheck is a placeholder value. It does not affect the request since Content Security Policy does not apply to raw resources. 62 CachedResourceRequest request(ResourceRequest(m_frame.loader().icon().url()), ResourceLoaderOptions(SendCallbacks, SniffContent, BufferData, DoNotAllowStoredCredentials, DoNotAskClientForAnyCredentials, ClientDidNotRequestCredentials, DoSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading ));62 CachedResourceRequest request(ResourceRequest(m_frame.loader().icon().url()), ResourceLoaderOptions(SendCallbacks, SniffContent, BufferData, DoNotAllowStoredCredentials, DoNotAskClientForAnyCredentials, ClientDidNotRequestCredentials, DoSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading, CachingPolicy::AllowCaching)); 63 63 64 64 request.mutableResourceRequest().setPriority(ResourceLoadPriority::Low); -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm
r195764 r195770 69 69 70 70 // ContentSecurityPolicyImposition::DoPolicyCheck is a placeholder value. It does not affect the request since Content Security Policy does not apply to raw resources. 71 CachedResourceRequest request(nsRequest, ResourceLoaderOptions(SendCallbacks, DoNotSniffContent, BufferData, DoNotAllowStoredCredentials, DoNotAskClientForCrossOriginCredentials, ClientDidNotRequestCredentials, DoSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading ));71 CachedResourceRequest request(nsRequest, ResourceLoaderOptions(SendCallbacks, DoNotSniffContent, BufferData, DoNotAllowStoredCredentials, DoNotAskClientForCrossOriginCredentials, ClientDidNotRequestCredentials, DoSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading, CachingPolicy::DisallowCaching)); 72 72 73 73 request.mutableResourceRequest().setPriority(ResourceLoadPriority::Low);
Note: See TracChangeset
for help on using the changeset viewer.