Changeset 36109 in webkit
- Timestamp:
- Sep 5, 2008 2:28:11 AM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 added
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r36108 r36109 1 2008-09-05 Antti Koivisto <antti@apple.com> 2 3 Reviewed by Darin. 4 5 Most of the implementation for https://bugs.webkit.org/show_bug.cgi?id=17998 6 When a resource is cached locally, WebKit should follow RFC 2616 "Specific end-to-end revalidation" instead of "Unspecified end-to-end revalidation" 7 8 Implement HTTP 1.1 "Specific end-to-end revalidation" for WebCore memory cache. This patch does 9 not yet enable it for the biggest use case, reloading. However it is good for general browsing as 10 well. Doing this in WebCore level as opposed to relying on disk cache has big benefit that 11 we avoid re-decoding resources, especially images. 12 13 To be exact the enabled case is not actually the "Specific end-to-end revalidation" since it does not include 14 CacheControl: max-age=0 header. That would be added in reload case. 15 16 The approach for revalidation is to kick the original resource out from the memory cache 17 and create a new CachedResource that represents the revalidation request. In case 18 we get 304 back for the request we put the original resource back to the cache, update 19 its expiration date and switch the clients registered to revalidation resource to be 20 clients of the original resource. 21 22 All heap allocated CachedImage pointers now use CachedResourceHandle<CachedImage> (and so on) instead. 23 This allows updating the handles to point to the original resource when the revalidation succeeds. It 24 also acts as refcounting smart pointer. 25 26 * WebCore.pro: 27 * WebCore.vcproj/WebCore.vcproj: 28 * WebCore.xcodeproj/project.pbxproj: 29 * css/CSSFontFaceSource.h: 30 * css/CSSImportRule.h: 31 * dom/Clipboard.h: 32 (WebCore::Clipboard::dragImage): 33 * dom/ProcessingInstruction.h: 34 * dom/ScriptElement.h: 35 * dom/XMLTokenizer.cpp: 36 (WebCore::XMLTokenizer::isWaitingForScripts): 37 * dom/XMLTokenizer.h: 38 * html/HTMLImageLoader.cpp: 39 (WebCore::HTMLImageLoader::setImage): 40 (WebCore::HTMLImageLoader::updateFromElement): 41 (WebCore::HTMLImageLoader::notifyFinished): 42 * html/HTMLImageLoader.h: 43 (WebCore::HTMLImageLoader::image): 44 * html/HTMLLinkElement.h: 45 * html/HTMLTokenizer.cpp: 46 (WebCore::HTMLTokenizer::reset): 47 (WebCore::HTMLTokenizer::scriptHandler): 48 (WebCore::HTMLTokenizer::notifyFinished): 49 * html/HTMLTokenizer.h: 50 * loader/Cache.cpp: 51 (WebCore::Cache::revalidateResource): 52 (WebCore::Cache::revalidationSucceeded): 53 (WebCore::Cache::revalidationFailed): 54 * loader/Cache.h: 55 * loader/CachedResource.cpp: 56 (WebCore::CachedResource::CachedResource): 57 (WebCore::CachedResource::~CachedResource): 58 (WebCore::CachedResource::isExpired): 59 (WebCore::CachedResource::setResponse): 60 (WebCore::CachedResource::deleteIfPossible): 61 (WebCore::CachedResource::setResourceToRevalidate): 62 (WebCore::CachedResource::clearResourceToRevalidate): 63 (WebCore::CachedResource::switchClientsToRevalidatedResource): 64 (WebCore::CachedResource::canUseCacheValidator): 65 (WebCore::CachedResource::mustRevalidate): 66 * loader/CachedResource.h: 67 (WebCore::CachedResource::canDelete): 68 (WebCore::CachedResource::registerHandle): 69 (WebCore::CachedResource::unregisterHandle): 70 (WebCore::CachedResource::isCacheValidator): 71 (WebCore::CachedResource::resourceToRevalidate): 72 (WebCore::CachedResource::setExpirationDate): 73 * loader/CachedResourceHandle.cpp: Added. 74 (WebCore::CachedResourceHandleBase::setResource): 75 * loader/CachedResourceHandle.h: Added. 76 (WebCore::CachedResourceHandleBase::~CachedResourceHandleBase): 77 (WebCore::CachedResourceHandleBase::get): 78 (WebCore::CachedResourceHandleBase::operator!): 79 (WebCore::CachedResourceHandleBase::operator UnspecifiedBoolType): 80 (WebCore::CachedResourceHandleBase::CachedResourceHandleBase): 81 (WebCore::CachedResourceHandleBase::operator=): 82 (WebCore::CachedResourceHandle::CachedResourceHandle): 83 (WebCore::CachedResourceHandle::get): 84 (WebCore::CachedResourceHandle::operator->): 85 (WebCore::CachedResourceHandle::operator=): 86 (WebCore::CachedResourceHandle::operator==): 87 (WebCore::CachedResourceHandle::operator!=): 88 (WebCore::operator==): 89 (WebCore::operator!=): 90 * loader/DocLoader.cpp: 91 (WebCore::DocLoader::checkForReload): 92 * loader/UserStyleSheetLoader.h: 93 * loader/loader.cpp: 94 (WebCore::Loader::Host::servePendingRequests): 95 (WebCore::Loader::Host::didFinishLoading): 96 (WebCore::Loader::Host::didFail): 97 (WebCore::Loader::Host::didReceiveResponse): 98 (WebCore::Loader::Host::didReceiveData): 99 * page/EventHandler.cpp: 100 (WebCore::EventHandler::selectCursor): 101 * rendering/RenderImage.cpp: 102 (WebCore::RenderImage::setCachedImage): 103 (WebCore::RenderImage::imageChanged): 104 * rendering/RenderImage.h: 105 (WebCore::RenderImage::cachedImage): 106 (WebCore::RenderImage::imagePtr): 107 * rendering/style/RenderStyle.h: 108 * rendering/style/StyleCachedImage.h: 109 (WebCore::StyleCachedImage::data): 110 (WebCore::StyleCachedImage::cachedImage): 111 * svg/SVGFEImageElement.h: 112 * svg/graphics/filters/SVGFEImage.h: 113 * xml/XSLImportRule.h: 114 1 115 2008-09-04 Brady Eidson <beidson@apple.com> 2 116 -
trunk/WebCore/WebCore.pro
r36089 r36109 702 702 loader/CachedImage.cpp \ 703 703 loader/CachedResourceClientWalker.cpp \ 704 loader/CachedResourceHandle.cpp \ 704 705 loader/CachedResource.cpp \ 705 706 loader/CachedScript.cpp \ -
trunk/WebCore/WebCore.vcproj/WebCore.vcproj
r36091 r36109 2789 2789 </File> 2790 2790 <File 2791 RelativePath="..\loader\CachedResourceHandle.cpp" 2792 > 2793 </File> 2794 <File 2795 RelativePath="..\loader\CachedResourceHandle.h" 2796 > 2797 </File> 2798 <File 2791 2799 RelativePath="..\loader\CachedScript.cpp" 2792 2800 > -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r36088 r36109 4086 4086 E44614510CD68A3500FADA75 /* RenderVideo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B41E330CBFB60900AF2ECE /* RenderVideo.cpp */; }; 4087 4087 E44614520CD68A3500FADA75 /* RenderVideo.h in Headers */ = {isa = PBXBuildFile; fileRef = E4B41E340CBFB60900AF2ECE /* RenderVideo.h */; }; 4088 E47B4BE80E71241600038854 /* CachedResourceHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = E47B4BE60E71241600038854 /* CachedResourceHandle.h */; }; 4089 E47B4BE90E71241600038854 /* CachedResourceHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47B4BE70E71241600038854 /* CachedResourceHandle.cpp */; }; 4088 4090 E49626C20D80D94800E3405C /* PreloadScanner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4D4ABE00D7542F000F96869 /* PreloadScanner.cpp */; }; 4089 4091 E49626C30D80D94900E3405C /* PreloadScanner.h in Headers */ = {isa = PBXBuildFile; fileRef = E4D4ABE10D7542F100F96869 /* PreloadScanner.h */; }; … … 8529 8531 E44614120CD6826900FADA75 /* JSTimeRanges.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTimeRanges.cpp; sourceTree = "<group>"; }; 8530 8532 E44614130CD6826900FADA75 /* JSTimeRanges.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTimeRanges.h; sourceTree = "<group>"; }; 8533 E472053A0E5A053A0006BB4D /* CachedResourceHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedResourceHandle.h; sourceTree = "<group>"; }; 8534 E47B4BE60E71241600038854 /* CachedResourceHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedResourceHandle.h; sourceTree = "<group>"; }; 8535 E47B4BE70E71241600038854 /* CachedResourceHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedResourceHandle.cpp; sourceTree = "<group>"; }; 8531 8536 E4AFCFA40DAF29A300F5F55C /* UnitBezier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnitBezier.h; sourceTree = "<group>"; }; 8532 8537 E4AFD0050DAF335400F5F55C /* SMILTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SMILTime.cpp; sourceTree = "<group>"; }; … … 12708 12713 BCB16C080979C3BD00467741 /* CachedResourceClientWalker.cpp */, 12709 12714 BCB16C090979C3BD00467741 /* CachedResourceClientWalker.h */, 12715 E47B4BE60E71241600038854 /* CachedResourceHandle.h */, 12716 E47B4BE70E71241600038854 /* CachedResourceHandle.cpp */, 12710 12717 BCB16C0A0979C3BD00467741 /* CachedScript.cpp */, 12711 12718 BCB16C0B0979C3BD00467741 /* CachedScript.h */, … … 12714 12721 BCB16C0E0979C3BD00467741 /* CachedXSLStyleSheet.cpp */, 12715 12722 BCB16C0F0979C3BD00467741 /* CachedXSLStyleSheet.h */, 12723 E472053A0E5A053A0006BB4D /* CachedResourceHandle.h */, 12716 12724 F587864902DE3A9A01EA4122 /* CachePolicy.h */, 12717 12725 BCB16C100979C3BD00467741 /* DocLoader.cpp */, … … 15550 15558 316FE0820E6CCC2800BF6088 /* DOMWebKitCSSKeyframesRuleInternal.h in Headers */, 15551 15559 7284ADDE0E6FEB31002EEFBD /* UserStyleSheetLoader.h in Headers */, 15560 E47B4BE80E71241600038854 /* CachedResourceHandle.h in Headers */, 15552 15561 ); 15553 15562 runOnlyForDeploymentPostprocessing = 0; … … 17349 17358 316FE0810E6CCC2800BF6088 /* DOMWebKitCSSKeyframesRule.mm in Sources */, 17350 17359 7284ADDD0E6FEB31002EEFBD /* UserStyleSheetLoader.cpp in Sources */, 17360 E47B4BE90E71241600038854 /* CachedResourceHandle.cpp in Sources */, 17351 17361 ); 17352 17362 runOnlyForDeploymentPostprocessing = 0; -
trunk/WebCore/css/CSSFontFaceSource.h
r34794 r36109 29 29 #include "AtomicString.h" 30 30 #include "CachedResourceClient.h" 31 #include "CachedResourceHandle.h" 31 32 #include <wtf/HashMap.h> 32 33 … … 68 69 private: 69 70 AtomicString m_string; // URI for remote, built-in font name for local. 70 Cached Font*m_font; // For remote fonts, a pointer to our cached resource.71 CachedResourceHandle<CachedFont> m_font; // For remote fonts, a pointer to our cached resource. 71 72 CSSFontFace* m_face; // Our owning font face. 72 73 HashMap<unsigned, SimpleFontData*> m_fontDataTable; // The hash key is composed of size synthetic styles. -
trunk/WebCore/css/CSSImportRule.h
r34627 r36109 25 25 #include "CSSRule.h" 26 26 #include "CachedResourceClient.h" 27 #include "CachedResourceHandle.h" 27 28 #include "MediaList.h" 28 29 #include "PlatformString.h" … … 66 67 RefPtr<MediaList> m_lstMedia; 67 68 RefPtr<CSSStyleSheet> m_styleSheet; 68 Cached CSSStyleSheet*m_cachedSheet;69 CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet; 69 70 bool m_loading; 70 71 }; -
trunk/WebCore/dom/Clipboard.h
r34432 r36109 25 25 #define Clipboard_h 26 26 27 #include "CachedResourceHandle.h" 27 28 #include "ClipboardAccessPolicy.h" 28 29 #include "DragActions.h" … … 55 56 56 57 IntPoint dragLocation() const { return m_dragLoc; } 57 CachedImage* dragImage() const { return m_dragImage ; }58 CachedImage* dragImage() const { return m_dragImage.get(); } 58 59 virtual void setDragImage(CachedImage*, const IntPoint&) = 0; 59 60 Node* dragImageElement() { return m_dragImageElement.get(); } … … 91 92 bool m_forDragging; 92 93 IntPoint m_dragLoc; 93 Cached Image*m_dragImage;94 CachedResourceHandle<CachedImage> m_dragImage; 94 95 RefPtr<Node> m_dragImageElement; 95 96 }; -
trunk/WebCore/dom/ProcessingInstruction.h
r35172 r36109 26 26 27 27 #include "CachedResourceClient.h" 28 #include "CachedResourceHandle.h" 28 29 #include "ContainerNode.h" 29 30 … … 85 86 String m_title; 86 87 String m_media; 87 CachedResource *m_cachedSheet;88 CachedResourceHandle<CachedResource> m_cachedSheet; 88 89 RefPtr<StyleSheet> m_sheet; 89 90 bool m_loading; -
trunk/WebCore/dom/ScriptElement.h
r35744 r36109 23 23 24 24 #include "CachedResourceClient.h" 25 #include "CachedResourceHandle.h" 25 26 26 27 namespace WebCore { … … 81 82 ScriptElement* m_scriptElement; 82 83 Element* m_element; 83 Cached Script*m_cachedScript;84 CachedResourceHandle<CachedScript> m_cachedScript; 84 85 bool m_createdByParser; 85 86 bool m_evaluated; -
trunk/WebCore/dom/XMLTokenizer.cpp
r36099 r36109 1542 1542 bool XMLTokenizer::isWaitingForScripts() const 1543 1543 { 1544 return m_pendingScript != 0;1544 return m_pendingScript; 1545 1545 } 1546 1546 -
trunk/WebCore/dom/XMLTokenizer.h
r31860 r36109 26 26 27 27 #include "CachedResourceClient.h" 28 #include "CachedResourceHandle.h" 28 29 #include "SegmentedString.h" 29 30 #include "StringHash.h" … … 155 156 String m_errorMessages; 156 157 157 Cached Script*m_pendingScript;158 CachedResourceHandle<CachedScript> m_pendingScript; 158 159 RefPtr<Element> m_scriptElement; 159 160 int m_scriptStartLine; -
trunk/WebCore/html/HTMLImageLoader.cpp
r34853 r36109 58 58 void HTMLImageLoader::setImage(CachedImage *newImage) 59 59 { 60 CachedImage *oldImage = m_image ;60 CachedImage *oldImage = m_image.get(); 61 61 if (newImage != oldImage) { 62 62 setLoadingImage(newImage); … … 108 108 } 109 109 110 CachedImage *oldImage = m_image ;110 CachedImage *oldImage = m_image.get(); 111 111 if (newImage != oldImage) { 112 112 #ifdef INSTRUMENT_LAYOUT_SCHEDULING … … 146 146 if (RenderObject* renderer = elem->renderer()) 147 147 if (renderer->isImage()) 148 static_cast<RenderImage*>(renderer)->setCachedImage(m_image );148 static_cast<RenderImage*>(renderer)->setCachedImage(m_image.get()); 149 149 150 150 if (image->errorOccurred() && elem->hasTagName(objectTag)) -
trunk/WebCore/html/HTMLImageLoader.h
r26992 r36109 27 27 28 28 #include "CachedResourceClient.h" 29 #include "CachedResourceHandle.h" 29 30 30 31 namespace WebCore { … … 44 45 bool imageComplete() const { return m_imageComplete; } 45 46 46 CachedImage* image() const { return m_image ; }47 CachedImage* image() const { return m_image.get(); } 47 48 void setImage(CachedImage*); 48 49 … … 60 61 private: 61 62 Element* m_element; 62 Cached Image*m_image;63 CachedResourceHandle<CachedImage> m_image; 63 64 bool m_firedLoad : 1; 64 65 bool m_imageComplete : 1; -
trunk/WebCore/html/HTMLLinkElement.h
r35172 r36109 26 26 #include "CSSStyleSheet.h" 27 27 #include "CachedResourceClient.h" 28 #include "CachedResourceHandle.h" 28 29 #include "HTMLElement.h" 29 30 … … 101 102 102 103 protected: 103 Cached CSSStyleSheet*m_cachedSheet;104 CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet; 104 105 RefPtr<CSSStyleSheet> m_sheet; 105 106 String m_url; -
trunk/WebCore/html/HTMLTokenizer.cpp
r35767 r36109 211 211 212 212 while (!pendingScripts.isEmpty()) { 213 CachedScript *cs = pendingScripts.dequeue(); 214 ASSERT(cache()->disabled() || cs->accessCount() > 0); 215 cs->removeClient(this); 213 CachedScript *cs = pendingScripts.first().get(); 214 pendingScripts.removeFirst(); 215 ASSERT(cache()->disabled() || cs->accessCount() > 0); 216 cs->removeClient(this); 216 217 } 217 218 … … 431 432 // If so, we don't want to load scripts. 432 433 if (!m_parserStopped && (cs = m_doc->docLoader()->requestScript(scriptSrc, scriptSrcCharset))) 433 pendingScripts. enqueue(cs);434 pendingScripts.append(cs); 434 435 else 435 436 scriptNode = 0; … … 1981 1982 1982 1983 bool finished = false; 1983 while (!finished && pendingScripts.head()->isLoaded()) { 1984 CachedScript* cs = pendingScripts.dequeue(); 1984 while (!finished && pendingScripts.first()->isLoaded()) { 1985 CachedScript *cs = pendingScripts.first().get(); 1986 pendingScripts.removeFirst(); 1985 1987 ASSERT(cache()->disabled() || cs->accessCount() > 0); 1986 1988 -
trunk/WebCore/html/HTMLTokenizer.h
r35767 r36109 25 25 #define HTMLTokenizer_h 26 26 27 #include "DeprecatedPtrQueue.h" 27 #include "CachedResourceClient.h" 28 #include "CachedResourceHandle.h" 28 29 #include "NamedMappedAttrMap.h" 29 30 #include "SegmentedString.h" 30 31 #include "Timer.h" 31 32 #include "Tokenizer.h" 32 #include "CachedResourceClient.h" 33 #include <wtf/Deque.h> 34 #include <wtf/OwnPtr.h> 33 35 #include <wtf/Vector.h> 34 #include <wtf/OwnPtr.h>35 36 36 37 namespace WebCore { … … 374 375 // the output of the script to be postponed until after the script has finished executing 375 376 int m_executingScript; 376 De precatedPtrQueue<CachedScript> pendingScripts;377 Deque<CachedResourceHandle<CachedScript> > pendingScripts; 377 378 RefPtr<Node> scriptNode; 378 379 -
trunk/WebCore/loader/Cache.cpp
r35921 r36109 187 187 188 188 return userSheet; 189 } 190 191 void Cache::revalidateResource(CachedResource* resource, DocLoader* docLoader) 192 { 193 ASSERT(resource); 194 ASSERT(!disabled()); 195 if (resource->resourceToRevalidate()) 196 return; 197 if (!resource->canUseCacheValidator()) { 198 remove(resource); 199 return; 200 } 201 const String& url = resource->url(); 202 CachedResource* newResource = createResource(resource->type(), KURL(url), resource->encoding()); 203 newResource->setResourceToRevalidate(resource); 204 remove(resource); 205 m_resources.set(url, newResource); 206 newResource->setInCache(true); 207 resourceAccessed(newResource); 208 newResource->load(docLoader); 209 } 210 211 void Cache::revalidationSucceeded(CachedResource* revalidatingResource, const ResourceResponse& response) 212 { 213 CachedResource* resource = revalidatingResource->resourceToRevalidate(); 214 ASSERT(resource); 215 ASSERT(!resource->inCache()); 216 ASSERT(resource->isLoaded()); 217 218 remove(revalidatingResource); 219 220 ASSERT(!m_resources.get(resource->url())); 221 m_resources.set(resource->url(), resource); 222 resource->setInCache(true); 223 resource->setExpirationDate(response.expirationDate()); 224 insertInLRUList(resource); 225 int delta = resource->size(); 226 if (resource->decodedSize() && resource->hasClients()) 227 insertInLiveDecodedResourcesList(resource); 228 if (delta) 229 adjustSize(resource->hasClients(), delta); 230 231 revalidatingResource->switchClientsToRevalidatedResource(); 232 // this deletes the revalidating resource 233 revalidatingResource->clearResourceToRevalidate(); 234 } 235 236 void Cache::revalidationFailed(CachedResource* revalidatingResource) 237 { 238 ASSERT(revalidatingResource->resourceToRevalidate()); 239 revalidatingResource->clearResourceToRevalidate(); 189 240 } 190 241 -
trunk/WebCore/loader/Cache.h
r31287 r36109 4 4 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 5 5 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> 6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.6 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 7 7 8 8 This library is free software; you can redistribute it and/or … … 100 100 CachedCSSStyleSheet* requestUserCSSStyleSheet(DocLoader*, const String& url, const String& charset); 101 101 102 void revalidateResource(CachedResource*, DocLoader*); 103 void revalidationSucceeded(CachedResource* revalidatingResource, const ResourceResponse&); 104 void revalidationFailed(CachedResource* revalidatingResource); 105 102 106 // Sets the cache's memory capacities, in bytes. These will hold only approximately, 103 107 // since the decoded cost of resources like scripts and stylesheets is not known. -
trunk/WebCore/loader/CachedResource.cpp
r36096 r36109 26 26 27 27 #include "Cache.h" 28 #include "CachedResourceHandle.h" 28 29 #include "DocLoader.h" 29 30 #include "Frame.h" … … 46 47 , m_loading(false) 47 48 , m_docLoader(0) 49 , m_handleCount(0) 50 , m_resourceToRevalidate(0) 51 , m_isBeingRevalidated(false) 52 , m_expirationDate(0) 48 53 { 49 54 m_type = type; … … 77 82 m_deleted = true; 78 83 #endif 79 84 85 ASSERT(cache()->resourceForURL(url()) != this); 86 87 if (m_resourceToRevalidate) 88 m_resourceToRevalidate->m_isBeingRevalidated = false; 89 80 90 if (m_docLoader) 81 91 m_docLoader->removeCachedResource(this); … … 96 106 bool CachedResource::isExpired() const 97 107 { 98 if (!m_ response.expirationDate())108 if (!m_expirationDate) 99 109 return false; 100 110 time_t now = time(0); 101 return (difftime(now, m_response.expirationDate()) >= 0); 102 } 103 111 return difftime(now, m_expirationDate) >= 0; 112 } 113 114 void CachedResource::setResponse(const ResourceResponse& response) 115 { 116 m_response = response; 117 m_expirationDate = response.expirationDate(); 118 } 119 104 120 void CachedResource::setRequest(Request* request) 105 121 { … … 140 156 } 141 157 158 void CachedResource::deleteIfPossible() 159 { 160 if (canDelete() && !inCache()) 161 delete this; 162 } 163 142 164 void CachedResource::setDecodedSize(unsigned size) 143 165 { … … 209 231 } 210 232 } 211 212 } 233 234 void CachedResource::setResourceToRevalidate(CachedResource* resource) 235 { 236 ASSERT(resource); 237 ASSERT(!m_resourceToRevalidate); 238 ASSERT(resource != this); 239 ASSERT(!resource->m_isBeingRevalidated); 240 ASSERT(m_handlesToRevalidate.isEmpty()); 241 ASSERT(resource->type() == type()); 242 resource->m_isBeingRevalidated = true; 243 m_resourceToRevalidate = resource; 244 } 245 246 void CachedResource::clearResourceToRevalidate() 247 { 248 ASSERT(m_resourceToRevalidate); 249 ASSERT(m_resourceToRevalidate->m_isBeingRevalidated); 250 m_resourceToRevalidate->m_isBeingRevalidated = false; 251 m_resourceToRevalidate->deleteIfPossible(); 252 m_handlesToRevalidate.clear(); 253 m_resourceToRevalidate = 0; 254 deleteIfPossible(); 255 } 256 257 void CachedResource::switchClientsToRevalidatedResource() 258 { 259 ASSERT(m_resourceToRevalidate); 260 ASSERT(!inCache()); 261 262 HashSet<CachedResourceHandleBase*>::iterator end = m_handlesToRevalidate.end(); 263 for (HashSet<CachedResourceHandleBase*>::iterator it = m_handlesToRevalidate.begin(); it != end; ++it) { 264 CachedResourceHandleBase* handle = *it; 265 handle->m_resource = m_resourceToRevalidate; 266 m_resourceToRevalidate->registerHandle(handle); 267 --m_handleCount; 268 } 269 ASSERT(!m_handleCount); 270 m_handlesToRevalidate.clear(); 271 272 Vector<CachedResourceClient*> clientsToMove; 273 HashCountedSet<CachedResourceClient*>::iterator end2 = m_clients.end(); 274 for (HashCountedSet<CachedResourceClient*>::iterator it = m_clients.begin(); it != end2; ++it) { 275 CachedResourceClient* client = it->first; 276 unsigned count = it->second; 277 while (count) { 278 clientsToMove.append(client); 279 --count; 280 } 281 } 282 // Equivalent of calling removeClient() for all clients 283 m_clients.clear(); 284 285 unsigned moveCount = clientsToMove.size(); 286 for (unsigned n = 0; n < moveCount; ++n) 287 m_resourceToRevalidate->addClient(clientsToMove[n]); 288 } 289 290 bool CachedResource::canUseCacheValidator() const 291 { 292 return !m_loading && (!m_response.httpHeaderField("Last-Modified").isEmpty() || !m_response.httpHeaderField("ETag").isEmpty()); 293 } 294 295 bool CachedResource::mustRevalidate(CachePolicy cachePolicy) const 296 { 297 if (m_loading) 298 return false; 299 String cacheControl = m_response.httpHeaderField("Cache-Control"); 300 // FIXME: It would be better to tokenize the field. 301 if (cachePolicy == CachePolicyCache) 302 return !cacheControl.isEmpty() && (cacheControl.contains("no-cache", false) || (isExpired() && cacheControl.contains("must-revalidate", false))); 303 return isExpired() || cacheControl.contains("no-cache", false); 304 } 305 306 } -
trunk/WebCore/loader/CachedResource.h
r36096 r36109 24 24 #define CachedResource_h 25 25 26 #include "CachePolicy.h" 26 27 #include "PlatformString.h" 27 28 #include "ResourceResponse.h" 28 29 #include "SharedBuffer.h" 29 30 #include <wtf/HashCountedSet.h> 31 #include <wtf/HashSet.h> 30 32 #include <wtf/Vector.h> 31 33 #include <time.h> … … 35 37 class Cache; 36 38 class CachedResourceClient; 37 class Cache HandleBase;39 class CachedResourceHandleBase; 38 40 class DocLoader; 39 41 class Request; … … 84 86 void removeClient(CachedResourceClient*); 85 87 bool hasClients() const { return !m_clients.isEmpty(); } 88 void deleteIfPossible(); 86 89 87 90 enum PreloadResult { … … 129 132 SharedBuffer* data() const { return m_data.get(); } 130 133 131 void setResponse(const ResourceResponse& response) { m_response = response; }134 void setResponse(const ResourceResponse&); 132 135 const ResourceResponse& response() const { return m_response; } 133 134 bool canDelete() const { return !hasClients() && !m_request && !m_preloadCount ; }136 137 bool canDelete() const { return !hasClients() && !m_request && !m_preloadCount && !m_handleCount && !m_resourceToRevalidate && !m_isBeingRevalidated; } 135 138 136 139 bool isExpired() const; … … 154 157 void decreasePreloadCount() { ASSERT(m_preloadCount); --m_preloadCount; } 155 158 159 void registerHandle(CachedResourceHandleBase* h) { ++m_handleCount; if (m_resourceToRevalidate) m_handlesToRevalidate.add(h); } 160 void unregisterHandle(CachedResourceHandleBase* h) { --m_handleCount; if (m_resourceToRevalidate) m_handlesToRevalidate.remove(h); if (!m_handleCount) deleteIfPossible(); } 161 162 bool canUseCacheValidator() const; 163 bool mustRevalidate(CachePolicy) const; 164 bool isCacheValidator() const { return m_resourceToRevalidate; } 165 CachedResource* resourceToRevalidate() const { return m_resourceToRevalidate; } 166 156 167 protected: 157 168 void setEncodedSize(unsigned); … … 174 185 175 186 private: 187 // These are called by the friendly Cache only 188 void setResourceToRevalidate(CachedResource*); 189 void switchClientsToRevalidatedResource(); 190 void clearResourceToRevalidate(); 191 void setExpirationDate(time_t expirationDate) { m_expirationDate = expirationDate; } 192 176 193 unsigned m_encodedSize; 177 194 unsigned m_decodedSize; … … 203 220 204 221 DocLoader* m_docLoader; // only non-0 for resources that are not in the cache 222 223 unsigned m_handleCount; 224 // If this field is non-null we are using the resource as a proxy for checking whether an existing resource is still up to date 225 // using HTTP If-Modified-Since/If-None-Match headers. If the response is 304 all clients of this resource are moved 226 // to to be clients of m_resourceToRevalidate and the resource is deleted. If not, the field is zeroed and this 227 // resources becomes normal resource load. 228 CachedResource* m_resourceToRevalidate; 229 bool m_isBeingRevalidated; 230 // These handles will need to be updated to point to the m_resourceToRevalidate in case we get 304 response. 231 HashSet<CachedResourceHandleBase*> m_handlesToRevalidate; 232 233 time_t m_expirationDate; 205 234 }; 206 235 -
trunk/WebCore/loader/DocLoader.cpp
r35801 r36109 81 81 return; 82 82 83 if (m_cachePolicy == CachePolicyVerify ) {83 if (m_cachePolicy == CachePolicyVerify || m_cachePolicy == CachePolicyCache) { 84 84 if (!m_reloadedURLs.contains(fullURL.string())) { 85 85 CachedResource* existing = cache()->resourceForURL(fullURL.string()); 86 if (existing && existing->isExpired() && !existing->isPreloaded()) {87 cache()->remove(existing);88 m_reloadedURLs.add(fullURL.string());86 if (existing && !existing->isPreloaded() && existing->mustRevalidate(m_cachePolicy)) { 87 cache()->revalidateResource(existing, this); 88 m_reloadedURLs.add(fullURL.string()); 89 89 } 90 90 } … … 93 93 CachedResource* existing = cache()->resourceForURL(fullURL.string()); 94 94 if (existing && !existing->isPreloaded()) { 95 // FIXME: Use revalidateResource() to implement HTTP 1.1 "Specific end-to-end revalidation" for regular reloading 95 96 cache()->remove(existing); 96 97 m_reloadedURLs.add(fullURL.string()); -
trunk/WebCore/loader/UserStyleSheetLoader.h
r36088 r36109 31 31 32 32 #include "CachedResourceClient.h" 33 #include "CachedResourceHandle.h" 33 34 34 35 #include "Document.h" … … 49 50 50 51 RefPtr<Document> m_document; 51 Cached CSSStyleSheet*m_cachedSheet;52 CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet; 52 53 }; 53 54 -
trunk/WebCore/loader/loader.cpp
r35801 r36109 219 219 Request* request = requestsPending.first(); 220 220 DocLoader* docLoader = request->docLoader(); 221 bool resourceIsCacheValidator = request->cachedResource()->isCacheValidator(); 221 222 // If the document is fully parsed and there are no pending stylesheets there won't be any more 222 223 // resources that we would want to push to the front of the queue. Just hand off the remaining resources 223 224 // to the networking layer. 224 225 bool parsedAndStylesheetsKnown = !docLoader->doc()->parsing() && docLoader->doc()->haveStylesheetsLoaded(); 225 if (!parsedAndStylesheetsKnown && m_requestsLoading.size() >= m_maxRequestsInFlight) {226 if (!parsedAndStylesheetsKnown && !resourceIsCacheValidator && m_requestsLoading.size() >= m_maxRequestsInFlight) { 226 227 serveLowerPriority = false; 227 228 return; … … 238 239 referrer.setPath("/"); 239 240 resourceRequest.setHTTPReferrer(referrer.string()); 241 242 if (resourceIsCacheValidator) { 243 CachedResource* resourceToRevalidate = request->cachedResource()->resourceToRevalidate(); 244 ASSERT(resourceToRevalidate->canUseCacheValidator()); 245 ASSERT(resourceToRevalidate->isLoaded()); 246 const String& lastModified = resourceToRevalidate->response().httpHeaderField("Last-Modified"); 247 const String& eTag = resourceToRevalidate->response().httpHeaderField("ETag"); 248 if (!lastModified.isEmpty() || !eTag.isEmpty()) { 249 if (docLoader->cachePolicy() == CachePolicyReload || docLoader->cachePolicy() == CachePolicyRefresh) 250 resourceRequest.setHTTPHeaderField("Cache-Control", "max-age=0"); 251 if (!lastModified.isEmpty()) 252 resourceRequest.setHTTPHeaderField("If-Modified-Since", lastModified); 253 if (!eTag.isEmpty()) 254 resourceRequest.setHTTPHeaderField("If-None-Match", eTag); 255 } 256 } 240 257 241 258 RefPtr<SubresourceLoader> loader = SubresourceLoader::create(docLoader->doc()->frame(), … … 270 287 271 288 CachedResource* resource = request->cachedResource(); 289 ASSERT(!resource->resourceToRevalidate()); 272 290 273 291 // If we got a 4xx response, we're pretending to have received a network … … 312 330 313 331 CachedResource* resource = request->cachedResource(); 332 333 if (resource->resourceToRevalidate()) 334 cache()->revalidationFailed(resource); 314 335 315 336 if (!cancelled) { … … 341 362 if (!request) 342 363 return; 343 request->cachedResource()->setResponse(response); 364 365 CachedResource* resource = request->cachedResource(); 366 367 if (resource->isCacheValidator()) { 368 if (response.httpStatusCode() == 304) { 369 // 304 Not modified / Use local copy 370 m_requestsLoading.remove(loader); 371 request->docLoader()->decrementRequestCount(); 372 373 // Existing resource is ok, just use it updating the expiration time. 374 cache()->revalidationSucceeded(resource, response); 375 delete request; 376 377 servePendingRequests(); 378 return; 379 } 380 // Did not get 304 response, continue as a regular resource load. 381 cache()->revalidationFailed(resource); 382 } 383 384 resource->setResponse(response); 344 385 345 386 String encoding = response.textEncodingName(); … … 372 413 373 414 CachedResource* resource = request->cachedResource(); 415 ASSERT(!resource->isCacheValidator()); 416 374 417 if (resource->errorOccurred()) 375 418 return; -
trunk/WebCore/page/EventHandler.cpp
r36000 r36109 840 840 const CursorList* cursors = style->cursors(); 841 841 for (unsigned i = 0; i < cursors->size(); ++i) { 842 CachedImage* cimage = (*cursors)[i].cursorImage ;842 CachedImage* cimage = (*cursors)[i].cursorImage.get(); 843 843 IntPoint hotSpot = (*cursors)[i].hotSpot; 844 844 if (!cimage) -
trunk/WebCore/rendering/RenderImage.cpp
r35828 r36109 197 197 m_cachedImage->addClient(this); 198 198 if (m_cachedImage->errorOccurred()) 199 imageChanged(m_cachedImage );199 imageChanged(m_cachedImage.get()); 200 200 } 201 201 } … … 260 260 // Set image dimensions, taking into account the size of the alt text. 261 261 if (errorOccurred()) 262 imageSizeChanged = setImageSizeForAltText(m_cachedImage );262 imageSizeChanged = setImageSizeForAltText(m_cachedImage.get()); 263 263 264 264 bool shouldRepaint = true; -
trunk/WebCore/rendering/RenderImage.h
r35828 r36109 27 27 28 28 #include "CachedImage.h" 29 #include "CachedResourceHandle.h" 29 30 #include "RenderReplaced.h" 30 31 … … 54 55 55 56 void setCachedImage(CachedImage*); 56 CachedImage* cachedImage() const { return m_cachedImage ; }57 CachedImage* cachedImage() const { return m_cachedImage.get(); } 57 58 58 59 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction); … … 79 80 virtual bool imageHasRelativeHeight() const { return m_cachedImage ? m_cachedImage->imageHasRelativeHeight() : false; } 80 81 virtual IntSize imageSize(float multiplier) const { return m_cachedImage ? m_cachedImage->imageSize(multiplier) : IntSize(); } 81 virtual WrappedImagePtr imagePtr() const { return m_cachedImage ; }82 virtual WrappedImagePtr imagePtr() const { return m_cachedImage.get(); } 82 83 83 84 virtual void intrinsicSizeChanged() { imageChanged(imagePtr()); } … … 92 93 protected: 93 94 // The image we are rendering. 94 Cached Image*m_cachedImage;95 CachedResourceHandle<CachedImage> m_cachedImage; 95 96 96 97 // Text to display as long as the image isn't available. -
trunk/WebCore/rendering/style/RenderStyle.h
r35996 r36109 41 41 #include "CSSReflectionDirection.h" 42 42 #include "CSSValueList.h" 43 #include "CachedImage.h" 44 #include "CachedResourceHandle.h" 43 45 #include "Color.h" 44 46 #include "DataRef.h" … … 1421 1423 1422 1424 IntPoint hotSpot; // for CSS3 support 1423 Cached Image* cursorImage; // weak pointer, the CSSValueImage takes care of deleting cursorImage1425 CachedResourceHandle<CachedImage> cursorImage; 1424 1426 }; 1425 1427 -
trunk/WebCore/rendering/style/StyleCachedImage.h
r35979 r36109 25 25 #define StyleCachedImage_h 26 26 27 #include "CachedResourceHandle.h" 27 28 #include "StyleImage.h" 28 29 … … 35 36 public: 36 37 static PassRefPtr<StyleCachedImage> create(CachedImage* image) { return adoptRef(new StyleCachedImage(image)); } 37 virtual WrappedImagePtr data() const { return m_image ; }38 virtual WrappedImagePtr data() const { return m_image.get(); } 38 39 39 40 virtual bool isCachedImage() const { return true; } … … 41 42 virtual PassRefPtr<CSSValue> cssValue(); 42 43 43 CachedImage* cachedImage() const { return m_image ; }44 CachedImage* cachedImage() const { return m_image.get(); } 44 45 45 46 virtual bool canRender(float multiplier) const; … … 61 62 } 62 63 63 Cached Image*m_image;64 CachedResourceHandle<CachedImage> m_image; 64 65 }; 65 66 -
trunk/WebCore/svg/SVGFEImageElement.h
r35248 r36109 25 25 26 26 #if ENABLE(SVG) && ENABLE(SVG_FILTERS) 27 #include "CachedResourceHandle.h" 27 28 #include "SVGFilterPrimitiveStandardAttributes.h" 28 29 #include "SVGURIReference.h" … … 56 57 ANIMATED_PROPERTY_DECLARATIONS(SVGFEImageElement, SVGNames::feImageTagString, SVGNames::preserveAspectRatioAttrString, SVGPreserveAspectRatio, PreserveAspectRatio, preserveAspectRatio) 57 58 58 Cached Image*m_cachedImage;59 CachedResourceHandle<CachedImage> m_cachedImage; 59 60 mutable RefPtr<FEImage> m_filterEffect; 60 61 }; -
trunk/WebCore/svg/graphics/filters/SVGFEImage.h
r35094 r36109 26 26 #include "CachedImage.h" 27 27 #include "CachedResourceClient.h" 28 #include "CachedResourceHandle.h" 28 29 #include "FilterEffect.h" 29 30 … … 48 49 FEImage(CachedImage*); 49 50 50 Cached Image*m_cachedImage;51 CachedResourceHandle<CachedImage> m_cachedImage; 51 52 }; 52 53 -
trunk/WebCore/xml/XSLImportRule.h
r34627 r36109 27 27 28 28 #include "CachedResourceClient.h" 29 #include "CachedResourceHandle.h" 29 30 #include "StyleBase.h" 30 31 #include "XSLStyleSheet.h" … … 61 62 String m_strHref; 62 63 RefPtr<XSLStyleSheet> m_styleSheet; 63 Cached XSLStyleSheet*m_cachedSheet;64 CachedResourceHandle<CachedXSLStyleSheet> m_cachedSheet; 64 65 bool m_loading; 65 66 };
Note: See TracChangeset
for help on using the changeset viewer.