Rewrite of the WebCore memory cache. The following changes have been made...
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Oct 2006 09:21:54 +0000 (09:21 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Oct 2006 09:21:54 +0000 (09:21 +0000)
        (1) Referenced objects are now also cached.

        (2) Pruning of the cache will occur once the cache is both full and in addition
        more than half full with unreferenced objects.

        (3) The prune is much more aggressive now, since referenced objects are counted when
        pruning.  The cache will therefore often prune out every unreferenced object if lots of
        windows/tabs are open.

        (4) Consolidated the request methods for various types of resources to go through a single
        requestResource bottleneck function.

        (5) deref on CachedResource is no longer virtual, since the implementation in every subclass was
        identical.

        (6) Changed "object" to "resource" everywhere.

        (7) The Cache is now an actual object, obtained via cache().

        (8) Fixed bugs with the autoload images preference so that it would really work properly when disabled
        and enabled.

        (9) Tweaked ImageDocuments to set up the status properly for the CachedResource that they use.

        (10) Fixed the LRU-SP algorithm so that the LRU aspect really kicks in (by leaving the live objects
        in the LRU lists).  Also fixed a bug with the "-SP" part of the algorithm where the access count was
        being incorrectly weighted too much due to a math error.

        (11) Fixed a bug where the old cache could grow without bound because it didn't know anything about
        the size of referenced resources.

        Reviewed by Maciej, bradee-oh

        * bridge/mac/WebCoreCache.mm:
        (+[WebCoreCache statistics]):
        (+[WebCoreCache empty]):
        (+[WebCoreCache setDisabled:]):
        * bridge/mac/WebCoreFrameBridge.mm:
        (-[WebCoreFrameBridge initMainFrameWithPage:]):
        (-[WebCoreFrameBridge getData:andResponse:forURL:]):
        (-[WebCoreFrameBridge getAllResourceDatas:andResponses:]):
        * css/CSSImageValue.cpp:
        (WebCore::CSSImageValue::image):
        * dom/XMLTokenizer.cpp:
        (WebCore::openFunc):
        * html/HTMLImageLoader.cpp:
        (WebCore::HTMLImageLoader::updateFromElement):
        * loader/Cache.cpp:
        (WebCore::cache):
        (WebCore::Cache::Cache):
        (WebCore::createResource):
        (WebCore::Cache::requestResource):
        (WebCore::Cache::resourceForURL):
        (WebCore::Cache::prune):
        (WebCore::Cache::setMaximumSize):
        (WebCore::Cache::remove):
        (WebCore::Cache::addDocLoader):
        (WebCore::Cache::removeDocLoader):
        (WebCore::fastLog2):
        (WebCore::Cache::lruListFor):
        (WebCore::Cache::removeFromLRUList):
        (WebCore::Cache::insertInLRUList):
        (WebCore::Cache::resourceAccessed):
        (WebCore::Cache::adjustSize):
        (WebCore::Cache::getStatistics):
        (WebCore::Cache::setDisabled):
        * loader/Cache.h:
        (WebCore::LRUList::LRUList):
        (WebCore::Cache::loader):
        (WebCore::Cache::maximumSize):
        (WebCore::Cache::disabled):
        (WebCore::Cache::addToLiveObjectSize):
        (WebCore::Cache::removeFromLiveObjectSize):
        (WebCore::Cache::TypeStatistic::TypeStatistic):
        * loader/CachedCSSStyleSheet.cpp:
        (WebCore::CachedCSSStyleSheet::CachedCSSStyleSheet):
        * loader/CachedCSSStyleSheet.h:
        * loader/CachedImage.cpp:
        (WebCore::CachedImage::CachedImage):
        (WebCore::CachedImage::~CachedImage):
        (WebCore::brokenImage):
        (WebCore::nullImage):
        (WebCore::CachedImage::image):
        (WebCore::CachedImage::data):
        * loader/CachedImage.h:
        (WebCore::CachedImage::stillNeedsLoad):
        * loader/CachedResource.cpp:
        (WebCore::CachedResource::CachedResource):
        (WebCore::CachedResource::~CachedResource):
        (WebCore::CachedResource::finish):
        (WebCore::CachedResource::setExpireDate):
        (WebCore::CachedResource::isExpired):
        (WebCore::CachedResource::setRequest):
        (WebCore::CachedResource::ref):
        (WebCore::CachedResource::deref):
        (WebCore::CachedResource::setSize):
        * loader/CachedResource.h:
        (WebCore::CachedResource::):
        (WebCore::CachedResource::setCharset):
        (WebCore::CachedResource::url):
        (WebCore::CachedResource::type):
        (WebCore::CachedResource::referenced):
        (WebCore::CachedResource::count):
        (WebCore::CachedResource::status):
        (WebCore::CachedResource::size):
        (WebCore::CachedResource::isLoaded):
        (WebCore::CachedResource::setLoading):
        (WebCore::CachedResource::isImage):
        (WebCore::CachedResource::accessCount):
        (WebCore::CachedResource::increaseAccessCount):
        (WebCore::CachedResource::setInCache):
        (WebCore::CachedResource::inCache):
        (WebCore::CachedResource::cachePolicy):
        (WebCore::CachedResource::response):
        (WebCore::CachedResource::allData):
        (WebCore::CachedResource::canDelete):
        (WebCore::CachedResource::schedule):
        (WebCore::CachedResource::accept):
        (WebCore::CachedResource::setAccept):
        * loader/CachedScript.cpp:
        (WebCore::CachedScript::CachedScript):
        * loader/CachedScript.h:
        * loader/CachedXBLDocument.cpp:
        * loader/CachedXBLDocument.h:
        * loader/CachedXSLStyleSheet.cpp:
        (WebCore::CachedXSLStyleSheet::CachedXSLStyleSheet):
        * loader/CachedXSLStyleSheet.h:
        * loader/DocLoader.cpp:
        (WebCore::DocLoader::DocLoader):
        (WebCore::DocLoader::~DocLoader):
        (WebCore::DocLoader::checkForReload):
        (WebCore::DocLoader::requestImage):
        (WebCore::DocLoader::requestCSSStyleSheet):
        (WebCore::DocLoader::requestScript):
        (WebCore::DocLoader::requestXSLStyleSheet):
        (WebCore::DocLoader::requestXBLDocument):
        (WebCore::DocLoader::requestResource):
        (WebCore::DocLoader::setAutoLoadImages):
        (WebCore::DocLoader::removeCachedResource):
        * loader/DocLoader.h:
        (WebCore::DocLoader::cachedResource):
        (WebCore::DocLoader::allCachedResources):
        (WebCore::DocLoader::autoLoadImages):
        (WebCore::DocLoader::cachePolicy):
        (WebCore::DocLoader::expireDate):
        (WebCore::DocLoader::frame):
        (WebCore::DocLoader::doc):
        (WebCore::DocLoader::loadInProgress):
        * loader/ImageDocument.cpp:
        (WebCore::ImageTokenizer::finish):
        * loader/loader.cpp:
        (WebCore::Loader::receivedAllData):
        (WebCore::Loader::cancelRequests):
        * loader/mac/LoaderFunctionsMac.mm:
        (WebCore::NumberOfPendingOrLoadingRequests):
        (WebCore::CheckCacheObjectStatus):
        * page/Frame.cpp:
        (WebCore::UserStyleSheetLoader::UserStyleSheetLoader):
        (WebCore::Frame::Frame):
        (WebCore::Frame::stopLoading):
        (WebCore::Frame::setAutoLoadImages):
        (WebCore::Frame::autoLoadImages):
        (WebCore::Frame::begin):
        (WebCore::Frame::checkCompleted):
        (WebCore::Frame::reparseConfiguration):
        * page/Frame.h:
        * xml/XSLTProcessor.cpp:
        (WebCore::docLoaderFunc):
        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::send):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17131 268f45cc-cd09-0410-ab3c-d52691b4dbfc

29 files changed:
WebCore/ChangeLog
WebCore/bridge/mac/WebCoreCache.mm
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebCore/css/CSSImageValue.cpp
WebCore/dom/XMLTokenizer.cpp
WebCore/html/HTMLImageLoader.cpp
WebCore/loader/Cache.cpp
WebCore/loader/Cache.h
WebCore/loader/CachedCSSStyleSheet.cpp
WebCore/loader/CachedCSSStyleSheet.h
WebCore/loader/CachedImage.cpp
WebCore/loader/CachedImage.h
WebCore/loader/CachedResource.cpp
WebCore/loader/CachedResource.h
WebCore/loader/CachedScript.cpp
WebCore/loader/CachedScript.h
WebCore/loader/CachedXBLDocument.cpp
WebCore/loader/CachedXBLDocument.h
WebCore/loader/CachedXSLStyleSheet.cpp
WebCore/loader/CachedXSLStyleSheet.h
WebCore/loader/DocLoader.cpp
WebCore/loader/DocLoader.h
WebCore/loader/ImageDocument.cpp
WebCore/loader/loader.cpp
WebCore/loader/mac/LoaderFunctionsMac.mm
WebCore/page/Frame.cpp
WebCore/page/Frame.h
WebCore/xml/XSLTProcessor.cpp
WebCore/xml/xmlhttprequest.cpp

index dfeca4979c91ee90377f13ea03708c91b9ff3413..8885bd8f2dcad370fee83fdd54c12a9af6143765 100644 (file)
@@ -1,3 +1,178 @@
+2006-10-19  David Hyatt  <hyatt@apple.com>
+
+        Rewrite of the WebCore memory cache.  The following changes have been made (along with many more):
+
+        (1) Referenced objects are now also cached.
+
+        (2) Pruning of the cache will occur once the cache is both full and in addition
+        more than half full with unreferenced objects.
+
+        (3) The prune is much more aggressive now, since referenced objects are counted when
+        pruning.  The cache will therefore often prune out every unreferenced object if lots of
+        windows/tabs are open.
+
+        (4) Consolidated the request methods for various types of resources to go through a single
+        requestResource bottleneck function.
+
+        (5) deref on CachedResource is no longer virtual, since the implementation in every subclass was
+        identical.
+
+        (6) Changed "object" to "resource" everywhere.
+
+        (7) The Cache is now an actual object, obtained via cache().
+
+        (8) Fixed bugs with the autoload images preference so that it would really work properly when disabled
+        and enabled.
+
+        (9) Tweaked ImageDocuments to set up the status properly for the CachedResource that they use.
+
+        (10) Fixed the LRU-SP algorithm so that the LRU aspect really kicks in (by leaving the live objects
+        in the LRU lists).  Also fixed a bug with the "-SP" part of the algorithm where the access count was
+        being incorrectly weighted too much due to a math error.
+
+        (11) Fixed a bug where the old cache could grow without bound because it didn't know anything about
+        the size of referenced resources.
+
+        Reviewed by Maciej, bradee-oh
+
+        * bridge/mac/WebCoreCache.mm:
+        (+[WebCoreCache statistics]):
+        (+[WebCoreCache empty]):
+        (+[WebCoreCache setDisabled:]):
+        * bridge/mac/WebCoreFrameBridge.mm:
+        (-[WebCoreFrameBridge initMainFrameWithPage:]):
+        (-[WebCoreFrameBridge getData:andResponse:forURL:]):
+        (-[WebCoreFrameBridge getAllResourceDatas:andResponses:]):
+        * css/CSSImageValue.cpp:
+        (WebCore::CSSImageValue::image):
+        * dom/XMLTokenizer.cpp:
+        (WebCore::openFunc):
+        * html/HTMLImageLoader.cpp:
+        (WebCore::HTMLImageLoader::updateFromElement):
+        * loader/Cache.cpp:
+        (WebCore::cache):
+        (WebCore::Cache::Cache):
+        (WebCore::createResource):
+        (WebCore::Cache::requestResource):
+        (WebCore::Cache::resourceForURL):
+        (WebCore::Cache::prune):
+        (WebCore::Cache::setMaximumSize):
+        (WebCore::Cache::remove):
+        (WebCore::Cache::addDocLoader):
+        (WebCore::Cache::removeDocLoader):
+        (WebCore::fastLog2):
+        (WebCore::Cache::lruListFor):
+        (WebCore::Cache::removeFromLRUList):
+        (WebCore::Cache::insertInLRUList):
+        (WebCore::Cache::resourceAccessed):
+        (WebCore::Cache::adjustSize):
+        (WebCore::Cache::getStatistics):
+        (WebCore::Cache::setDisabled):
+        * loader/Cache.h:
+        (WebCore::LRUList::LRUList):
+        (WebCore::Cache::loader):
+        (WebCore::Cache::maximumSize):
+        (WebCore::Cache::disabled):
+        (WebCore::Cache::addToLiveObjectSize):
+        (WebCore::Cache::removeFromLiveObjectSize):
+        (WebCore::Cache::TypeStatistic::TypeStatistic):
+        * loader/CachedCSSStyleSheet.cpp:
+        (WebCore::CachedCSSStyleSheet::CachedCSSStyleSheet):
+        * loader/CachedCSSStyleSheet.h:
+        * loader/CachedImage.cpp:
+        (WebCore::CachedImage::CachedImage):
+        (WebCore::CachedImage::~CachedImage):
+        (WebCore::brokenImage):
+        (WebCore::nullImage):
+        (WebCore::CachedImage::image):
+        (WebCore::CachedImage::data):
+        * loader/CachedImage.h:
+        (WebCore::CachedImage::stillNeedsLoad):
+        * loader/CachedResource.cpp:
+        (WebCore::CachedResource::CachedResource):
+        (WebCore::CachedResource::~CachedResource):
+        (WebCore::CachedResource::finish):
+        (WebCore::CachedResource::setExpireDate):
+        (WebCore::CachedResource::isExpired):
+        (WebCore::CachedResource::setRequest):
+        (WebCore::CachedResource::ref):
+        (WebCore::CachedResource::deref):
+        (WebCore::CachedResource::setSize):
+        * loader/CachedResource.h:
+        (WebCore::CachedResource::):
+        (WebCore::CachedResource::setCharset):
+        (WebCore::CachedResource::url):
+        (WebCore::CachedResource::type):
+        (WebCore::CachedResource::referenced):
+        (WebCore::CachedResource::count):
+        (WebCore::CachedResource::status):
+        (WebCore::CachedResource::size):
+        (WebCore::CachedResource::isLoaded):
+        (WebCore::CachedResource::setLoading):
+        (WebCore::CachedResource::isImage):
+        (WebCore::CachedResource::accessCount):
+        (WebCore::CachedResource::increaseAccessCount):
+        (WebCore::CachedResource::setInCache):
+        (WebCore::CachedResource::inCache):
+        (WebCore::CachedResource::cachePolicy):
+        (WebCore::CachedResource::response):
+        (WebCore::CachedResource::allData):
+        (WebCore::CachedResource::canDelete):
+        (WebCore::CachedResource::schedule):
+        (WebCore::CachedResource::accept):
+        (WebCore::CachedResource::setAccept):
+        * loader/CachedScript.cpp:
+        (WebCore::CachedScript::CachedScript):
+        * loader/CachedScript.h:
+        * loader/CachedXBLDocument.cpp:
+        * loader/CachedXBLDocument.h:
+        * loader/CachedXSLStyleSheet.cpp:
+        (WebCore::CachedXSLStyleSheet::CachedXSLStyleSheet):
+        * loader/CachedXSLStyleSheet.h:
+        * loader/DocLoader.cpp:
+        (WebCore::DocLoader::DocLoader):
+        (WebCore::DocLoader::~DocLoader):
+        (WebCore::DocLoader::checkForReload):
+        (WebCore::DocLoader::requestImage):
+        (WebCore::DocLoader::requestCSSStyleSheet):
+        (WebCore::DocLoader::requestScript):
+        (WebCore::DocLoader::requestXSLStyleSheet):
+        (WebCore::DocLoader::requestXBLDocument):
+        (WebCore::DocLoader::requestResource):
+        (WebCore::DocLoader::setAutoLoadImages):
+        (WebCore::DocLoader::removeCachedResource):
+        * loader/DocLoader.h:
+        (WebCore::DocLoader::cachedResource):
+        (WebCore::DocLoader::allCachedResources):
+        (WebCore::DocLoader::autoLoadImages):
+        (WebCore::DocLoader::cachePolicy):
+        (WebCore::DocLoader::expireDate):
+        (WebCore::DocLoader::frame):
+        (WebCore::DocLoader::doc):
+        (WebCore::DocLoader::loadInProgress):
+        * loader/ImageDocument.cpp:
+        (WebCore::ImageTokenizer::finish):
+        * loader/loader.cpp:
+        (WebCore::Loader::receivedAllData):
+        (WebCore::Loader::cancelRequests):
+        * loader/mac/LoaderFunctionsMac.mm:
+        (WebCore::NumberOfPendingOrLoadingRequests):
+        (WebCore::CheckCacheObjectStatus):
+        * page/Frame.cpp:
+        (WebCore::UserStyleSheetLoader::UserStyleSheetLoader):
+        (WebCore::Frame::Frame):
+        (WebCore::Frame::stopLoading):
+        (WebCore::Frame::setAutoLoadImages):
+        (WebCore::Frame::autoLoadImages):
+        (WebCore::Frame::begin):
+        (WebCore::Frame::checkCompleted):
+        (WebCore::Frame::reparseConfiguration):
+        * page/Frame.h:
+        * xml/XSLTProcessor.cpp:
+        (WebCore::docLoaderFunc):
+        * xml/xmlhttprequest.cpp:
+        (WebCore::XMLHttpRequest::send):
+
 2006-10-18  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Geoff.
index 9bd8e6da41af610c30c999380ce77e0805ac4b1d..e3e9af95a645c62b77ec82b4fe08a13995d3bcaa 100644 (file)
 
 + (NSArray *)statistics
 {
-    WebCore::Cache::Statistics s = WebCore::Cache::getStatistics();
+    WebCore::Cache::Statistics s = WebCore::cache()->getStatistics();
 
     return [NSArray arrayWithObjects:
         [NSDictionary dictionaryWithObjectsAndKeys:
             [NSNumber numberWithInt:s.images.count], @"images",
-            [NSNumber numberWithInt:s.movies.count], @"movies",
-            [NSNumber numberWithInt:s.styleSheets.count], @"style sheets",
+            [NSNumber numberWithInt:s.cssStyleSheets.count], @"style sheets",
             [NSNumber numberWithInt:s.scripts.count], @"scripts",
-            [NSNumber numberWithInt:s.other.count], @"other",
             nil],
         [NSDictionary dictionaryWithObjectsAndKeys:
             [NSNumber numberWithInt:s.images.size], @"images",
-            [NSNumber numberWithInt:s.movies.size], @"movies",
-            [NSNumber numberWithInt:s.styleSheets.size] ,@"style sheets",
+            [NSNumber numberWithInt:s.cssStyleSheets.size] ,@"style sheets",
             [NSNumber numberWithInt:s.scripts.size], @"scripts",
-            [NSNumber numberWithInt:s.other.size], @"other",
             nil],
         nil];
 }
 
 + (void)empty
 {
-    WebCore::Cache::flushAll();
+    if (WebCore::cache()->disabled())
+        return;
+    WebCore::cache()->setDisabled(YES);
+    WebCore::cache()->setDisabled(NO);
 }
 
 + (void)setDisabled:(BOOL)disabled
 {
-    WebCore::Cache::setCacheDisabled(disabled);
+    WebCore::cache()->setDisabled(disabled);
 }
 
 @end
index 46f66db903b9929b6ce8cf35068d50f3488be923..9ec2f0be42e9ad21dfe5d6dedc808678dad13ce0 100644 (file)
@@ -489,7 +489,7 @@ static inline WebCoreFrameBridge *bridge(Frame *frame)
     // FIXME: This is one-time initialization, but it gets the value of the setting from the
     // current WebView. That's a mismatch and not good!
     if (!initializedObjectCacheSize) {
-        WebCore::Cache::setSize([self getObjectCacheSize]);
+        WebCore::cache()->setMaximumSize([self getObjectCacheSize]);
         initializedObjectCacheSize = true;
     }
 
@@ -2542,12 +2542,12 @@ static NSCharacterSet *_getPostSmartSet(void)
     if (!doc)
         return NO;
 
-    CachedResource* o = doc->docLoader()->cachedObject([URL absoluteString]);
-    if (!o)
+    CachedResource* resource = doc->docLoader()->cachedResource([URL absoluteString]);
+    if (!resource)
         return NO;
 
-    *data = o->allData();
-    *response = o->response();
+    *data = resource->allData();
+    *response = resource->response();
     return YES;
 }
 
@@ -2561,7 +2561,7 @@ static NSCharacterSet *_getPostSmartSet(void)
         return;
     }
 
-    const HashMap<String, CachedResource*>& allResources = doc->docLoader()->allCachedObjects();
+    const HashMap<String, CachedResource*>& allResources = doc->docLoader()->allCachedResources();
 
     NSMutableArray *d = [[NSMutableArray alloc] initWithCapacity:allResources.size()];
     NSMutableArray *r = [[NSMutableArray alloc] initWithCapacity:allResources.size()];
index b5d57319d934b1ecb3b5481aba784a68b111c0c0..7a748496f0d617c887592e71fe7f9b14616975b5 100644 (file)
@@ -57,8 +57,9 @@ CachedImage* CSSImageValue::image(DocLoader* loader)
         if (loader)
             m_image = loader->requestImage(getStringValue());
         else
-            m_image = Cache::requestImage(0, getStringValue());
-        
+            // FIXME: Should find a way to make these images sit in their own memory partition, since they are user agent images.
+            m_image = static_cast<CachedImage*>(cache()->requestResource(0, CachedResource::ImageResource, KURL(getStringValue().deprecatedString()), 0, 0));
+
         if (m_image)
             m_image->ref(this);
     }
index 1a9c33e836fda9475c79f3e954a9c8d17394f674..15c870ab5b8aecbb1fb33e0ca5fecb3c5c536e6d 100644 (file)
@@ -460,7 +460,7 @@ static void* openFunc(const char* uri)
     KURL finalURL;
     RefPtr<ResourceLoader> loader = ResourceLoader::create(0, "GET", uri);
     DeprecatedString headers;
-    Vector<char> data = ServeSynchronousRequest(Cache::loader(), globalDocLoader, loader.get(), finalURL, headers);
+    Vector<char> data = ServeSynchronousRequest(cache()->loader(), globalDocLoader, loader.get(), finalURL, headers);
     
     return new OffsetBuffer(data);
 }
index a1419a00c929cb29b068d2402bda9a5bb943c88e..842926ce10a0bf0b58290ed77b6ff69731cf39bf 100644 (file)
@@ -77,8 +77,10 @@ void HTMLImageLoader::updateFromElement()
     CachedImage *newImage = 0;
     if (!attr.isEmpty()) {
         if (m_loadManually) {
+            doc->docLoader()->setAutoLoadImages(false);
             newImage = new CachedImage(doc->docLoader(), parseURL(attr), CachePolicyVerify, 0);
-            doc->docLoader()->m_docObjects.set(newImage->url(), newImage);
+            newImage->setLoading(true);
+            doc->docLoader()->m_docResources.set(newImage->url(), newImage);
         } else
             newImage = doc->docLoader()->requestImage(parseURL(attr));
     }
index dccaaefec17040bb4f3b46a305afc846cd0fabc4..f9874763bf2376c01d09ecc84a9267948ec4fc24 100644 (file)
@@ -42,402 +42,163 @@ using namespace std;
 
 namespace WebCore {
 
-const int defaultCacheSize = 8192 * 1024;
+const int cDefaultCacheSize = 8192 * 1024;
+const int cDefaultLargeResourceSize = 80 * 1024;
 
-// maxCacheableObjectSize is cache size divided by 128, but with this as a minimum
-const int minMaxCacheableObjectSize = 80 * 1024;
-
-const int maxLRULists = 20;
-    
-struct LRUList {
-    CachedResource* m_head;
-    CachedResource* m_tail;
-    LRUList() : m_head(0), m_tail(0) { }
-};
-
-static bool cacheDisabled;
-
-typedef HashMap<String, CachedResource*> CacheMap;
-
-static CacheMap* cache = 0;
-
-HashSet<DocLoader*>* Cache::docloaders = 0;
-Loader *Cache::m_loader = 0;
-
-int Cache::maxSize = defaultCacheSize;
-int Cache::maxCacheable = minMaxCacheableObjectSize;
-int Cache::flushCount = 0;
-
-Image *Cache::nullImage = 0;
-Image *Cache::brokenImage = 0;
-
-CachedResource *Cache::m_headOfUncacheableList = 0;
-int Cache::m_totalSizeOfLRULists = 0;
-int Cache::m_countOfLRUAndUncacheableLists;
-LRUList *Cache::m_LRULists = 0;
-
-void Cache::init()
-{
-    if (!cache)
-        cache = new CacheMap;
-
-    if (!docloaders)
-        docloaders = new HashSet<DocLoader*>;
-
-    if (!nullImage)
-        nullImage = new Image;
-
-    if (!brokenImage)
-        brokenImage = Image::loadPlatformResource("missingImage");
-
-    if (!m_loader)
-        m_loader = new Loader();
-}
-
-void Cache::clear()
-{
-    if (!cache)
-        return;
-
-    deleteAllValues(*cache);
-
-    delete cache; cache = 0;
-    delete nullImage; nullImage = 0;
-    delete brokenImage; brokenImage = 0;
-    delete m_loader; m_loader = 0;
-    ASSERT(docloaders->isEmpty());
-    delete docloaders; docloaders = 0;
-}
-
-void Cache::updateCacheStatus(DocLoader* dl, CachedResource* o)
+Cache* cache()
 {
-    moveToHeadOfLRUList(o);
-    if (dl) {
-        ASSERT(!o->url().isNull());
-        if (cacheDisabled)
-            dl->m_docObjects.remove(o->url());
-        else
-            dl->m_docObjects.set(o->url(), o);
-    }
+    static Cache cache;
+    return &cache;
 }
 
-CachedImage* Cache::requestImage(DocLoader* dl, const String& url, bool reload, time_t expireDate)
+Cache::Cache()
+: m_disabled(false)
+, m_maximumSize(cDefaultCacheSize)
+, m_currentSize(0)
+, m_liveResourcesSize(0)
 {
-    // this brings the _url to a standard form...
-    KURL kurl;
-    if (dl)
-        kurl = dl->m_doc->completeURL(url.deprecatedString());
-    else
-        kurl = url.deprecatedString();
-    return requestImage(dl, kurl, reload, expireDate);
 }
 
-CachedImage* Cache::requestImage(DocLoader* dl, const KURL& url, bool reload, time_t expireDate)
+static CachedResource* createResource(CachedResource::Type type, DocLoader* docLoader, const KURL& url, time_t expireDate, const String* charset)
 {
-    CachePolicy cachePolicy;
-    if (dl)
-        cachePolicy = dl->cachePolicy();
-    else
-        cachePolicy = CachePolicyVerify;
-
-    // Checking if the URL is malformed is lots of extra work for little benefit.
-
-    if (!dl->doc()->shouldCreateRenderers())
-        return 0;
-
-    CachedResource *o = 0;
-    if (!reload)
-        o = cache->get(url.url());
-    if (!o) {
-#ifdef CACHE_DEBUG
-        kdDebug(6060) << "Cache: new: " << url.url() << endl;
+    switch (type) {
+    case CachedResource::ImageResource:
+        // User agent images need to null check the docloader.  No other resources need to.
+        return new CachedImage(docLoader, url.url(), docLoader ? docLoader->cachePolicy() : CachePolicyCache, expireDate);
+    case CachedResource::CSSStyleSheet:
+        return new CachedCSSStyleSheet(docLoader, url.url(), docLoader->cachePolicy(), expireDate, *charset);
+    case CachedResource::Script:
+        return new CachedScript(docLoader, url.url(), docLoader->cachePolicy(), expireDate, *charset);
+#ifdef XSLT_SUPPORT
+    case CachedResource::XSLStyleSheet:
+        return new CachedXSLStyleSheet(docLoader, url.url(), docLoader->cachePolicy(), expireDate);
 #endif
-        CachedImage *im = new CachedImage(dl, url.url(), cachePolicy, expireDate);
-        if (dl && dl->autoloadImages()) Cache::loader()->load(dl, im, true);
-        if (cacheDisabled)
-            im->setFree(true);
-        else {
-            cache->set(url.url(), im);
-            moveToHeadOfLRUList(im);
-        }
-        o = im;
-    }
-
-    
-    if (o->type() != CachedResource::ImageResource)
-        return 0;
-
-#ifdef CACHE_DEBUG
-    if (o->status() == CachedResource::Pending)
-        kdDebug(6060) << "Cache: loading in progress: " << kurl.url() << endl;
-    else
-        kdDebug(6060) << "Cache: using cached: " << kurl.url() << ", status " << o->status() << endl;
+#ifdef XBL_SUPPORT
+    case CachedResource::XBLStyleSheet:
+        return new CachedXBLDocument(docLoader, url.url(), docLoader->cachePolicy(), expireDate);
 #endif
+    default:
+        break;
+    }
 
-    updateCacheStatus(dl, o);
-    return static_cast<CachedImage *>(o);
+    return 0;
 }
 
-CachedCSSStyleSheet* Cache::requestCSSStyleSheet(DocLoader* dl, const String& url, bool reload, time_t expireDate, const String& charset)
+CachedResource* Cache::requestResource(DocLoader* docLoader, CachedResource::Type type, const KURL& url, time_t expireDate, const String* charset)
 {
-    // this brings the _url to a standard form...
-    KURL kurl;
-    CachePolicy cachePolicy;
-    if (dl) {
-        kurl = dl->m_doc->completeURL(url.deprecatedString());
-        cachePolicy = dl->cachePolicy();
-    } else {
-        kurl = url.deprecatedString();
-        cachePolicy = CachePolicyVerify;
+    // Look up the resource in our map.
+    CachedResource* resource = m_resources.get(url.url());
+
+    if (!resource) {
+        // The resource does not exist.  Create it.
+        resource = createResource(type, docLoader, url.url(), expireDate, charset);
+        ASSERT(resource);
+        resource->setInCache(!disabled());
+        if (!disabled())
+            m_resources.set(url.url(), resource);  // The size will be added in later once the resource is loaded and calls back to us with the new size.
     }
 
-    // Checking if the URL is malformed is lots of extra work for little benefit.
-
-    CachedResource *o = cache->get(kurl.url());
-    if (!o) {
-#ifdef CACHE_DEBUG
-        kdDebug(6060) << "Cache: new: " << kurl.url() << endl;
-#endif
-        CachedCSSStyleSheet *sheet = new CachedCSSStyleSheet(dl, kurl.url(), cachePolicy, expireDate, charset);
-        if (cacheDisabled)
-            sheet->setFree(true);
-        else {
-            cache->set(kurl.url(), sheet);
-            moveToHeadOfLRUList(sheet);
-        }
-        o = sheet;
-    }
+    // This will move the resource to the front of its LRU list and increase its access count.
+    resourceAccessed(resource);
 
-    
-    if (o->type() != CachedResource::CSSStyleSheet)
-    {
-#ifdef CACHE_DEBUG
-        kdDebug(6060) << "Cache::Internal Error in requestCSSStyleSheet url=" << kurl.url() << "!" << endl;
-#endif
+    if (resource->type() != type)
         return 0;
-    }
 
-#ifdef CACHE_DEBUG
-    if (o->status() == CachedResource::Pending)
-        kdDebug(6060) << "Cache: loading in progress: " << kurl.url() << endl;
-    else
-        kdDebug(6060) << "Cache: using cached: " << kurl.url() << endl;
-#endif
+    return resource;
+}
 
-    updateCacheStatus(dl, o);
-    return static_cast<CachedCSSStyleSheet *>(o);
+CachedResource* Cache::resourceForURL(const String& url)
+{
+    return m_resources.get(url);
 }
 
-CachedScript* Cache::requestScript(DocLoader* dl, const String& url, bool reload, time_t expireDate, const String& charset)
+void Cache::prune()
 {
-    // this brings the _url to a standard form...
-    KURL kurl;
-    CachePolicy cachePolicy;
-    if (dl) {
-        kurl = dl->m_doc->completeURL(url.deprecatedString());
-        cachePolicy = dl->cachePolicy();
-    } else {
-        kurl = url.deprecatedString();
-        cachePolicy = CachePolicyVerify;
-    }
+    // No need to prune if all of our objects fit.
+    if (m_currentSize <= m_maximumSize)
+        return;
 
-    // Checking if the URL is malformed is lots of extra work for little benefit.
+    // We allow the cache to get as big as the # of live objects + half the maximum cache size
+    // before we do a prune.  Once we do decide to prune though, we are aggressive about it.
+    // We will include the live objects as part of the overall cache size when pruneing, so will often
+    // kill every last object that isn't referenced by a Web page.
+    unsigned unreferencedResourcesSize = m_currentSize - m_liveResourcesSize;
+    if (unreferencedResourcesSize < m_maximumSize / 2U)
+        return;
 
-    CachedResource *o = cache->get(kurl.url());
-    if (!o)
-    {
-#ifdef CACHE_DEBUG
-        kdDebug(6060) << "Cache: new: " << kurl.url() << endl;
-#endif
-        CachedScript *script = new CachedScript(dl, kurl.url(), cachePolicy, expireDate, charset);
-        if (cacheDisabled)
-            script->setFree(true);
-        else {
-            cache->set(kurl.url(), script);
-            moveToHeadOfLRUList(script);
+    bool canShrinkLRULists = true;
+    unsigned size = m_lruLists.size();
+    for (int i = size - 1; i >= 0; i--) {
+        // Remove from the tail, since this is the least frequently accessed of the objects.
+        CachedResource* current = m_lruLists[i].m_tail;
+        while (current) {
+            CachedResource* prev = current->m_prevInLRUList;
+            if (!current->referenced()) {
+                remove(current);
+                
+                // Stop pruneing if our total cache size is back under the maximum or if every
+                // remaining object in the cache is live (meaning there is nothing left we are able
+                // to prune).
+                if (m_currentSize <= m_maximumSize || m_currentSize == m_liveResourcesSize)
+                    return;
+            }
+            current = prev;
         }
-        o = script;
-    }
-
-    
-    if (!(o->type() == CachedResource::Script)) {
-#ifdef CACHE_DEBUG
-        kdDebug(6060) << "Cache::Internal Error in requestScript url=" << kurl.url() << "!" << endl;
-#endif
-        return 0;
+            
+        // Shrink the vector back down so we don't waste time inspecting
+        // empty LRU lists on future prunees.
+        if (m_lruLists[i].m_head)
+            canShrinkLRULists = false;
+        else if (canShrinkLRULists)
+            m_lruLists.resize(i);
     }
-    
-    
-#ifdef CACHE_DEBUG
-    if (o->status() == CachedResource::Pending)
-        kdDebug(6060) << "Cache: loading in progress: " << kurl.url() << endl;
-    else
-        kdDebug(6060) << "Cache: using cached: " << kurl.url() << endl;
-#endif
-
-    updateCacheStatus(dl, o);
-    return static_cast<CachedScript *>(o);
 }
 
-#ifdef XSLT_SUPPORT
-CachedXSLStyleSheet* Cache::requestXSLStyleSheet(DocLoader* dl, const String& url, bool reload, time_t expireDate)
+void Cache::setMaximumSize(int bytes)
 {
-    // this brings the _url to a standard form...
-    KURL kurl;
-    CachePolicy cachePolicy;
-    if (dl) {
-        kurl = dl->m_doc->completeURL(url.deprecatedString());
-        cachePolicy = dl->cachePolicy();
-    }
-    else {
-        kurl = url.deprecatedString();
-        cachePolicy = CachePolicyVerify;
-    }
-    
-    // Checking if the URL is malformed is lots of extra work for little benefit.
-    
-    CachedResource *o = cache->get(kurl.url());
-    if (!o) {
-#ifdef CACHE_DEBUG
-        kdDebug(6060) << "Cache: new: " << kurl.url() << endl;
-#endif
-        CachedXSLStyleSheet* doc = new CachedXSLStyleSheet(dl, kurl.url(), cachePolicy, expireDate);
-        if (cacheDisabled)
-            doc->setFree(true);
-        else {
-            cache->set(kurl.url(), doc);
-            moveToHeadOfLRUList(doc);
-        }
-        o = doc;
-    }
-    
-    
-    if (o->type() != CachedResource::XSLStyleSheet) {
-#ifdef CACHE_DEBUG
-        kdDebug(6060) << "Cache::Internal Error in requestXSLStyleSheet url=" << kurl.url() << "!" << endl;
-#endif
-        return 0;
-    }
-    
-#ifdef CACHE_DEBUG
-    if (o->status() == CachedResource::Pending)
-        kdDebug(6060) << "Cache: loading in progress: " << kurl.url() << endl;
-    else
-        kdDebug(6060) << "Cache: using cached: " << kurl.url() << endl;
-#endif
-    
-    updateCacheStatus(dl, o);
-    return static_cast<CachedXSLStyleSheet*>(o);
+    m_maximumSize = bytes;
+    prune();
 }
-#endif
 
-#ifdef XBL_SUPPORT
-CachedXBLDocument* Cache::requestXBLDocument(DocLoader* dl, const String& url, bool reload, 
-                                             time_t expireDate)
+void Cache::remove(CachedResource* resource)
 {
-    // this brings the _url to a standard form...
-    KURL kurl;
-    CachePolicy cachePolicy;
-    if (dl) {
-        kurl = dl->m_doc->completeURL(url.deprecatedString());
-        cachePolicy = dl->cachePolicy();
-    } else {
-        kurl = url.deprecatedString();
-        cachePolicy = CachePolicyVerify;
-    }
-    
-    // Checking if the URL is malformed is lots of extra work for little benefit.
-    
-    CachedResource *o = cache->get(kurl.url());
-    if (!o) {
-#ifdef CACHE_DEBUG
-        kdDebug(6060) << "Cache: new: " << kurl.url() << endl;
-#endif
-        CachedXBLDocument* doc = new CachedXBLDocument(dl, kurl.url(), cachePolicy, expireDate);
-        if (cacheDisabled)
-            doc->setFree(true);
-        else {
-            cache->set(kurl.url(), doc);
-            moveToHeadOfLRUList(doc);
-        }
-        o = doc;
-    }
-    
-    
-    if (o->type() != CachedResource::XBL) {
-#ifdef CACHE_DEBUG
-        kdDebug(6060) << "Cache::Internal Error in requestXBLDocument url=" << kurl.url() << "!" << endl;
-#endif
-        return 0;
-    }
-    
-#ifdef CACHE_DEBUG
-    if (o->status() == CachedResource::Pending)
-        kdDebug(6060) << "Cache: loading in progress: " << kurl.url() << endl;
-    else
-        kdDebug(6060) << "Cache: using cached: " << kurl.url() << endl;
-#endif
-    
-    updateCacheStatus(dl, o);
-    return static_cast<CachedXBLDocument*>(o);
-}
-#endif
+    ASSERT(resource->inCache());
 
-void Cache::flush(bool force)
-{
-    if (force)
-       flushCount = 0;
-    // Don't flush for every image.
-    if (m_countOfLRUAndUncacheableLists < flushCount)
-       return;
+    // Remove from the resource map.
+    m_resources.remove(resource->url());
+    resource->setInCache(false);
 
-    init();
+    // Remove from the appropriate LRU list.
+    removeFromLRUList(resource);
 
-    while (m_headOfUncacheableList)
-        remove(m_headOfUncacheableList);
+    // Notify all doc loaders that might be observing this object still that it has been
+    // extracted from the set of resources.
+    HashSet<DocLoader*>::iterator end = m_docLoaders.end();
+    for (HashSet<DocLoader*>::iterator itr = m_docLoaders.begin(); itr != end; ++itr)
+        (*itr)->removeCachedResource(resource);
 
-    for (int i = maxLRULists-1; i>=0; i--) {
-        if (m_totalSizeOfLRULists <= maxSize)
-            break;
-            
-        while (m_totalSizeOfLRULists > maxSize && m_LRULists[i].m_tail)
-            remove(m_LRULists[i].m_tail);
-    }
+    // Subtract from our size totals.
+    m_currentSize -= resource->size();
+    if (resource->referenced())
+        m_liveResourcesSize -= resource->size();
 
-    flushCount = m_countOfLRUAndUncacheableLists+10; // Flush again when the cache has grown.
+    if (resource->canDelete())
+        delete resource;
 }
 
-
-void Cache::setSize(int bytes)
+void Cache::addDocLoader(DocLoader* docLoader)
 {
-    maxSize = bytes;
-    maxCacheable = max(maxSize / 128, minMaxCacheableObjectSize);
-
-    // may be we need to clear parts of the cache
-    flushCount = 0;
-    flush(true);
+    m_docLoaders.add(docLoader);
 }
 
-void Cache::remove(CachedResource *object)
+void Cache::removeDocLoader(DocLoader* docLoader)
 {
-  // this indicates the deref() method of CachedResource to delete itself when the reference counter
-  // drops down to zero
-  object->setFree(true);
-
-  cache->remove(object->url());
-  removeFromLRUList(object);
-
-  HashSet<DocLoader*>::iterator end = docloaders->end();
-  for (HashSet<DocLoader*>::iterator itr = docloaders->begin(); itr != end; ++itr)
-      (*itr)->removeCachedObject(object);
-
-  if (object->canDelete())
-     delete object;
+    m_docLoaders.remove(docLoader);
 }
 
-static inline int FastLog2(uint32_t i)
+static inline unsigned fastLog2(unsigned i)
 {
-    int log2 = 0;
+    unsigned log2 = 0;
     if (i & (i - 1))
         log2 += 1;
     if (i >> 16)
@@ -453,110 +214,124 @@ static inline int FastLog2(uint32_t i)
     return log2;
 }
 
-LRUList* Cache::getLRUListFor(CachedResource* o)
+LRUList* Cache::lruListFor(CachedResource* resource)
 {
-    int accessCount = o->accessCount();
-    int queueIndex;
-    if (accessCount == 0) {
-        queueIndex = 0;
-    } else {
-        int sizeLog = FastLog2(o->size());
-        queueIndex = sizeLog / o->accessCount() - 1;
-        if (queueIndex < 0)
-            queueIndex = 0;
-        if (queueIndex >= maxLRULists)
-            queueIndex = maxLRULists-1;
-    }
-    if (!m_LRULists)
-        m_LRULists = new LRUList [maxLRULists];
-    return &m_LRULists[queueIndex];
+    unsigned accessCount = max(resource->accessCount(), 1U);
+    unsigned queueIndex = fastLog2(resource->size() / accessCount);
+#ifndef NDEBUG
+    resource->m_lruIndex = queueIndex;
+#endif
+    if (m_lruLists.size() <= queueIndex)
+        m_lruLists.resize(queueIndex + 1);
+    return &m_lruLists[queueIndex];
 }
 
-void Cache::removeFromLRUList(CachedResource *object)
+void Cache::removeFromLRUList(CachedResource* resource)
 {
-    CachedResource *next = object->m_nextInLRUList;
-    CachedResource *prev = object->m_prevInLRUList;
-    bool uncacheable = object->status() == CachedResource::Uncacheable;
-    
-    LRUList* list = uncacheable ? 0 : getLRUListFor(object);
-    CachedResource *&head = uncacheable ? m_headOfUncacheableList : list->m_head;
-    
-    if (next == 0 && prev == 0 && head != object) {
+    // If we've never been accessed, then we're brand new and not in any list.
+    if (resource->accessCount() == 0)
         return;
+
+#ifndef NDEBUG
+    unsigned oldListIndex = resource->m_lruIndex;
+#endif
+
+    LRUList* list = lruListFor(resource);
+
+#ifndef NDEBUG
+    // Verify that the list we got is the list we want.
+    ASSERT(resource->m_lruIndex == oldListIndex);
+
+    // Verify that we are in fact in this list.
+    bool found = false;
+    for (CachedResource* current = list->m_head; current; current = current->m_nextInLRUList) {
+        if (current == resource) {
+            found = true;
+            break;
+        }
     }
+    ASSERT(found);
+#endif
+
+    CachedResource* next = resource->m_nextInLRUList;
+    CachedResource* prev = resource->m_prevInLRUList;
     
-    object->m_nextInLRUList = 0;
-    object->m_prevInLRUList = 0;
+    if (next == 0 && prev == 0 && list->m_head != resource)
+        return;
+    
+    resource->m_nextInLRUList = 0;
+    resource->m_prevInLRUList = 0;
     
     if (next)
         next->m_prevInLRUList = prev;
-    else if (!uncacheable && list->m_tail == object)
+    else if (list->m_tail == resource)
         list->m_tail = prev;
 
     if (prev)
         prev->m_nextInLRUList = next;
-    else if (head == object)
-        head = next;
-    
-    --m_countOfLRUAndUncacheableLists;
-    
-    if (!uncacheable)
-        m_totalSizeOfLRULists -= object->size();
+    else if (list->m_head == resource)
+        list->m_head = next;
 }
 
-void Cache::moveToHeadOfLRUList(CachedResource *object)
+void Cache::insertInLRUList(CachedResource* resource)
 {
-    insertInLRUList(object);
+    // Make sure we aren't in some list already.
+    ASSERT(!resource->m_nextInLRUList && !resource->m_prevInLRUList);
+
+    LRUList* list = lruListFor(resource);
+
+    resource->m_nextInLRUList = list->m_head;
+    if (list->m_head)
+        list->m_head->m_prevInLRUList = resource;
+    list->m_head = resource;
+    
+    if (!resource->m_nextInLRUList)
+        list->m_tail = resource;
+        
+#ifndef NDEBUG
+    // Verify that we are in now in the list like we should be.
+    list = lruListFor(resource);
+    bool found = false;
+    for (CachedResource* current = list->m_head; current; current = current->m_nextInLRUList) {
+        if (current == resource) {
+            found = true;
+            break;
+        }
+    }
+    ASSERT(found);
+#endif
+
 }
 
-void Cache::insertInLRUList(CachedResource *object)
+void Cache::resourceAccessed(CachedResource* resource)
 {
-    removeFromLRUList(object);
+    // Need to make sure to remove before we increase the access count, since
+    // the queue will possibly change.
+    removeFromLRUList(resource);
     
-    if (!object->allowInLRUList())
-        return;
-    
-    LRUList* list = getLRUListFor(object);
-    
-    bool uncacheable = object->status() == CachedResource::Uncacheable;
-    CachedResource *&head = uncacheable ? m_headOfUncacheableList : list->m_head;
-
-    object->m_nextInLRUList = head;
-    if (head)
-        head->m_prevInLRUList = object;
-    head = object;
-    
-    if (object->m_nextInLRUList == 0 && !uncacheable)
-        list->m_tail = object;
+    // Add to our access count.
+    resource->increaseAccessCount();
     
-    ++m_countOfLRUAndUncacheableLists;
-    
-    if (!uncacheable)
-        m_totalSizeOfLRULists += object->size();
+    // Now insert into the new queue.
+    insertInLRUList(resource);
 }
 
-bool Cache::adjustSize(CachedResource *object, int delta)
+void Cache::adjustSize(bool live, unsigned oldResourceSize, unsigned newResourceSize)
 {
-    if (object->status() == CachedResource::Uncacheable)
-        return false;
-
-    if (object->m_nextInLRUList == 0 && object->m_prevInLRUList == 0 &&
-        getLRUListFor(object)->m_head != object)
-        return false;
-    
-    m_totalSizeOfLRULists += delta;
-    return delta != 0;
+    m_currentSize -= oldResourceSize;
+    if (live)
+        m_liveResourcesSize -= oldResourceSize;
+        
+    m_currentSize += newResourceSize;
+    if (live)
+        m_liveResourcesSize += newResourceSize;
 }
 
 Cache::Statistics Cache::getStatistics()
 {
     Statistics stats;
-
-    if (!cache)
-        return stats;
-
-    CacheMap::iterator e = cache->end();
-    for (CacheMap::iterator i = cache->begin(); i != e; ++i) {
+    CachedResourceMap::iterator e = m_resources.end();
+    for (CachedResourceMap::iterator i = m_resources.begin(); i != e; ++i) {
         CachedResource *o = i->second;
         switch (o->type()) {
             case CachedResource::ImageResource:
@@ -565,8 +340,8 @@ Cache::Statistics Cache::getStatistics()
                 break;
 
             case CachedResource::CSSStyleSheet:
-                stats.styleSheets.count++;
-                stats.styleSheets.size += o->size();
+                stats.cssStyleSheets.count++;
+                stats.cssStyleSheets.size += o->size();
                 break;
 
             case CachedResource::Script:
@@ -586,37 +361,25 @@ Cache::Statistics Cache::getStatistics()
                 break;
 #endif
             default:
-                stats.other.count++;
-                stats.other.size += o->size();
+                break;
         }
     }
     
     return stats;
 }
 
-void Cache::flushAll()
+void Cache::setDisabled(bool disabled)
 {
-    if (!cache)
+    m_disabled = disabled;
+    if (!m_disabled)
         return;
 
     for (;;) {
-        CacheMap::iterator i = cache->begin();
-        if (i == cache->end())
+        CachedResourceMap::iterator i = m_resources.begin();
+        if (i == m_resources.end())
             break;
         remove(i->second);
     }
 }
 
-void Cache::setCacheDisabled(bool disabled)
-{
-    cacheDisabled = disabled;
-    if (disabled)
-        flushAll();
-}
-
-CachedResource* Cache::get(const String& s)
-{
-    return (cache && s.impl()) ? cache->get(s) : 0;
-}
-
 }
index 2054c6521c6bd1ac2514187ab02e3d206c915b59..6cd844f71a15c461d87dacb0c6dbe68281ef9baa 100644 (file)
 #define Cache_h
 
 #include "CachePolicy.h"
+#include "CachedResource.h"
+#include "Loader.h"
 #include "PlatformString.h"
+#include "StringHash.h"
+#include <wtf/Vector.h>
 #include <wtf/HashSet.h>
+#include <wtf/HashMap.h>
 
 namespace WebCore  {
 
-    class CachedCSSStyleSheet;
-    class CachedImage;
-    class CachedResource;
-    class CachedScript;
-    class CachedXSLStyleSheet;
-    class DocLoader;
-    class Image;
-    class KURL;
-    class Loader;
-    struct LRUList;
+class CachedCSSStyleSheet;
+class CachedImage;
+class CachedResource;
+class CachedScript;
+class CachedXSLStyleSheet;
+class DocLoader;
+class Image;
+class KURL;
+
+struct LRUList {
+    CachedResource* m_head;
+    CachedResource* m_tail;
+    LRUList() : m_head(0), m_tail(0) { }
+};
+
+typedef HashMap<String, CachedResource*> CachedResourceMap;
+
+// This cache hold subresources used by Web pages.  These resources consist of images, scripts and stylesheets.
+class Cache {
+public:
+    Cache();
+       
+    // The loader that fetches resources.
+    Loader* loader() { return &m_loader; }
+
+    // Request resources from the cache.  A load will be initiated and a cache object created if the object is not
+    // found in the cache.
+    CachedResource* requestResource(DocLoader*, CachedResource::Type, const KURL& url, time_t expireDate = 0, const String* charset = 0);
+
+    // Set/retreive the size of the cache. This will only hold approximately, since the size some 
+    // cached objects (like stylesheets) take up in memory is not exactly known.
+    void setMaximumSize(int bytes);
+    int maximumSize() const { return m_maximumSize; };
+
+    // Turn the cache on and off.  Disabling the cache will remove all resources from the cache.  They may
+    // still live on if they are referenced by some Web page though.
+    void setDisabled(bool);
+    bool disabled() const { return m_disabled; }
     
-    /**
-     * Provides a cache/loader for objects needed for displaying the html page.
-     */
-    class Cache {
-        friend class DocLoader;
-    public:
-        /**
-         * Initialize the cache in case it's not already.
-         * This needs to get called once before using it.
-         */
-        static void init();
-        
-        /**
-         * Ask the cache for some URL.
-         * If the DocLoader is zero, the URL must be fully-qualified. Otherwise, it is automatically base-URL expanded
-         */
-        static CachedImage* requestImage(DocLoader*, const String& URL, bool reload = false, time_t expireDate = 0);
-        static CachedImage* requestImage(DocLoader*, const KURL& URL, bool reload, time_t expireDate);
-        static CachedCSSStyleSheet* requestCSSStyleSheet(DocLoader*, const String& URL, bool reload, time_t expireDate, const String& charset);
-        static CachedScript* requestScript(DocLoader*, const String& URL, bool reload, time_t expireDate, const String& charset);
+    // Remove an existing cache entry from both the resource map and from the LRU list.
+    void remove(CachedResource*);
 
-#ifdef XSLT_SUPPORT
-        static CachedXSLStyleSheet* requestXSLStyleSheet(DocLoader*, const String& URL, bool reload, time_t expireDate);
-#endif
+    // Flush the cache.  Any resources still referenced by Web pages will not be removed by this call.
+    void prune();
 
-#ifdef XBL_SUPPORT
-        static CachedXBLDocument* requestXBLDocument(DocLoader*, const String& URL, bool reload, time_t expireDate);
-#endif
+    void addDocLoader(DocLoader*);
+    void removeDocLoader(DocLoader*);
+
+    CachedResource* resourceForURL(const String&);
+
+    // Calls to put the cached resource into and out of LRU lists.
+    void insertInLRUList(CachedResource*);
+    void removeFromLRUList(CachedResource*);
 
-        /**
-         * Sets the size of the cache. This will only hold approximately, since the size some
-         * cached objects (like stylesheets) take up in memory is not exactly known.
-         */
-        static void setSize(int bytes);
-
-        /**
-         * returns the size of the cache
-         */
-        static int size() { return maxSize; };
-
-        static int maxCacheableObjectSize() { return maxCacheable; }
-
-        // Get an existing cache entry by URL.
-        static CachedResource* get(const String& URL);
-
-        // Remove an existing cache entry.
-        static void remove(CachedResource*);
-
-        /**
-         * clean up cache
-         */
-        static void flush(bool force = false);
-
-        /**
-         * clears the cache
-         * Warning: call this only at the end of your program, to clean up memory
-         * (useful for finding memory leaks).
-         */
-        static void clear();
-
-        static Loader* loader() { return m_loader; }
-
-        static Image* nullImage;
-        static Image* brokenImage;
-
-        struct TypeStatistic {
-            int count;
-            int size;
-            TypeStatistic() : count(0), size(0) { }
-        };
-        
-        struct Statistics {
-            TypeStatistic images;
-            TypeStatistic movies;
-            TypeStatistic styleSheets;
-            TypeStatistic scripts;
+    // Called to adjust the cache totals when a resource changes size.
+    void adjustSize(bool live, unsigned oldResourceSize, unsigned newResourceSize);
+
+    // Track the size of all resources that are in the cache and still referenced by a Web page. 
+    void addToLiveObjectSize(unsigned s) { m_liveResourcesSize += s; }
+    void removeFromLiveObjectSize(unsigned s) { m_liveResourcesSize -= s; }
+
+    // Functions to collect cache statistics for the caches window in the Safari Debug menu.
+    struct TypeStatistic {
+        int count;
+        int size;
+        TypeStatistic() : count(0), size(0) { }
+    };
+    
+    struct Statistics {
+        TypeStatistic images;
+        TypeStatistic cssStyleSheets;
+        TypeStatistic scripts;
 #ifdef XSLT_SUPPORT
-            TypeStatistic xslStyleSheets;
+        TypeStatistic xslStyleSheets;
 #endif
 #ifdef XBL_SUPPORT
-            TypeStatistic xblDocs;
+        TypeStatistic xblDocs;
 #endif
-            TypeStatistic other;
-        };
-
-        static Statistics getStatistics();
-        static void flushAll();
-        static void setCacheDisabled(bool);
-
-        static void insertInLRUList(CachedResource*);
-        static void removeFromLRUList(CachedResource*);
-        static bool adjustSize(CachedResource*, int sizeDelta);
-        
-        static LRUList* getLRUListFor(CachedResource*);
-        
-        static void checkLRUAndUncacheableListIntegrity();
-
-    private:
-        static HashSet<DocLoader*>* docloaders;
-    
-        static int maxSize;
-        static int maxCacheable;
-        static int flushCount;
-    
-        static Loader* m_loader;
+    };
+
+    Statistics getStatistics();
+
+private:
+    LRUList* lruListFor(CachedResource*);
     
-        static void moveToHeadOfLRUList(CachedResource*);
-        static void updateCacheStatus(DocLoader*, CachedResource*);
+    void resourceAccessed(CachedResource*);
+
+private:
+    // Member variables.
+    HashSet<DocLoader*> m_docLoaders;
+    Loader m_loader;
+
+    bool m_disabled;  // Whether or not the cache is enabled.
+
+    int m_maximumSize;  // The maximum size in bytes that the global cache can consume.
+    int m_currentSize;  // The current size of the global cache in bytes.
+    int m_liveResourcesSize; // The current size of "live" resources that cannot be flushed.
+
+    // Size-adjusted and popularity-aware LRU list collection for cache objects.  This collection can hold
+    // more resources than the cached resource map, since it can also hold "stale" muiltiple versions of objects that are
+    // waiting to die when the clients referencing them go away.
+    Vector<LRUList, 32> m_lruLists;
     
-        static LRUList* m_LRULists;
-        static int m_totalSizeOfLRULists;
-            
-        static CachedResource* m_headOfUncacheableList;
-            
-        static int m_countOfLRUAndUncacheableLists;
-    };
+    // A URL-based map of all resources that are in the cache (including the freshest version of objects that are currently being 
+    // referenced by a Web page).
+    HashMap<String, CachedResource*> m_resources;
+};
+
+// Function to obtain the global cache.
+Cache* cache();
 
 }
 
index 3860f370b8a50f5714a559fb6e8432147c69462f..1366ffb4205a133b3702cf727228abfa26add08a 100644 (file)
@@ -47,7 +47,7 @@ CachedCSSStyleSheet::CachedCSSStyleSheet(DocLoader* dl, const String& url, Cache
     // It's css we want.
     setAccept("text/css");
     // load the file
-    Cache::loader()->load(dl, this, false);
+    cache()->loader()->load(dl, this, false);
     m_loading = true;
 }
 
@@ -63,14 +63,6 @@ void CachedCSSStyleSheet::ref(CachedResourceClient *c)
         c->setCSSStyleSheet(m_url, m_decoder->encoding().name(), m_sheet);
 }
 
-void CachedCSSStyleSheet::deref(CachedResourceClient *c)
-{
-    Cache::flush();
-    CachedResource::deref(c);
-    if (canDelete() && m_free)
-        delete this;
-}
-
 void CachedCSSStyleSheet::setCharset(const String& chs)
 {
     m_decoder->setEncoding(chs, Decoder::EncodingFromHTTPHeader);
index 3876c0efbc38ab53fe9f49791b897f96bf40740b..118ba9d962738640e6cd2133261c3480eb070951 100644 (file)
@@ -45,8 +45,7 @@ namespace WebCore {
         const String& sheet() const { return m_sheet; }
 
         virtual void ref(CachedResourceClient*);
-        virtual void deref(CachedResourceClient*);
-
         virtual void setCharset(const String&);
         virtual void data(Vector<char>&, bool allDataReceived);
         virtual void error();
index 66f39b92c5f1a5f85265df9141f75f611c7dee18..0badd3cb4ccba2d0e86a96e7699a6afda5df1665 100644 (file)
@@ -42,19 +42,23 @@ using std::max;
 
 namespace WebCore {
 
-CachedImage::CachedImage(DocLoader* dl, const String &url, CachePolicy cachePolicy, time_t _expireDate)
+CachedImage::CachedImage(DocLoader* docLoader, const String& url, CachePolicy cachePolicy, time_t _expireDate)
     : CachedResource(url, ImageResource, cachePolicy, _expireDate)
     , m_dataSize(0)
 {
     m_image = 0;
     m_errorOccurred = false;
     m_status = Unknown;
-    m_loading = true;
+    if (!docLoader || docLoader->autoLoadImages())  {
+        m_loading = true;
+        cache()->loader()->load(docLoader, this, true);
+    } else
+        m_loading = false;
 }
 
 CachedImage::~CachedImage()
 {
-    clear();
+    delete m_image;
 }
 
 void CachedImage::ref(CachedResourceClient* c)
@@ -68,23 +72,29 @@ void CachedImage::ref(CachedResourceClient* c)
         c->notifyFinished(this);
 }
 
-void CachedImage::deref(CachedResourceClient *c)
+static Image* brokenImage()
+{
+    static Image* brokenImage;
+    if (!brokenImage)
+        brokenImage = Image::loadPlatformResource("missingImage");
+    return brokenImage;
+}
+
+static Image* nullImage()
 {
-    Cache::flush();
-    CachedResource::deref(c);
-    if (canDelete() && m_free)
-        delete this;
+    static Image nullImage;
+    return &nullImage;
 }
 
 Image* CachedImage::image() const
 {
     if (m_errorOccurred)
-        return Cache::brokenImage;
+        return brokenImage();
 
     if (m_image)
         return m_image;
 
-    return Cache::nullImage;
+    return nullImage();
 }
 
 IntSize CachedImage::imageSize() const
@@ -153,14 +163,15 @@ void CachedImage::data(Vector<char>& data, bool allDataReceived)
         if (m_image->isNull()) {
             m_errorOccurred = true;
             notifyObservers();
-            Cache::remove(this);
+            if (inCache())
+                cache()->remove(this);
         } else
             notifyObservers();
 
         // FIXME: An animated GIF with a huge frame count can't have its size properly estimated.  The reason is that we don't
         // want to decode the image to determine the frame count, so what we do instead is max the projected size of a single
         // RGBA32 buffer (width*height*4) with the data size.  This will help ensure that large animated GIFs with thousands of
-        // frames are properly designated as uncacheable.
+        // frames are at least given a reasonably large size.
         IntSize s = imageSize();
         setSize(max(s.width() * s.height() * 4, m_dataSize));
     }
index d392bf099221291638f09f35320feea01b30636a..7985295dac63f94b11c2336d44af601ba0ab681d 100644 (file)
@@ -52,7 +52,6 @@ public:
     IntRect imageRect() const;  // The size of the image.
 
     virtual void ref(CachedResourceClient*);
-    virtual void deref(CachedResourceClient*);
 
     virtual Vector<char>& bufferData(const char* bytes, int addedSize, Request*);
     virtual void data(Vector<char>&, bool allDataReceived);
@@ -71,6 +70,9 @@ public:
     virtual bool shouldStopAnimation(const Image* image);
     virtual void animationAdvanced(const Image* image);
 
+    bool stillNeedsLoad() const { return !m_errorOccurred && m_status == Unknown && m_loading == false; }
+    void load();
+
 private:
     void createImage();
     void notifyObservers();
index 24f2ea85a665eccb4d45dd85b4aedf87edfc4dee..4a69e98f10228cda4a6d964aea52569cf48d52be 100644 (file)
 
 namespace WebCore {
 
+CachedResource::CachedResource(const String& URL, Type type, CachePolicy cachePolicy, time_t expireDate, unsigned size)
+{
+    m_url = URL;
+    m_type = type;
+    m_status = Pending;
+    m_size = size;
+    m_inCache = false;
+    m_cachePolicy = cachePolicy;
+    m_request = 0;
+    m_response = 0;
+    m_allData = 0;
+    m_expireDate = expireDate;
+    m_expireDateChanged = false;
+    m_accessCount = 0;
+    m_nextInLRUList = 0;
+    m_prevInLRUList = 0;
+#ifndef NDEBUG
+    m_deleted = false;
+    m_lruIndex = 0;
+#endif
+}
+
 CachedResource::~CachedResource()
 {
-    if (m_deleted)
-        abort();
-    Cache::removeFromLRUList(this);
+    ASSERT(!inCache());
+    ASSERT(!m_deleted);
+#ifndef NDEBUG
     m_deleted = true;
+#endif
     setResponse(0);
     setAllData(0);
 }
@@ -60,10 +83,7 @@ Vector<char>& CachedResource::bufferData(const char* bytes, int addedSize, Reque
 
 void CachedResource::finish()
 {
-    if (m_size > Cache::maxCacheableObjectSize())
-        m_status = Uncacheable;
-    else
-        m_status = Cached;
+    m_status = Cached;
     KURL url(m_url.deprecatedString());
     if (m_expireDateChanged && url.protocol().startsWith("http"))
         m_expireDateChanged = false;
@@ -74,7 +94,7 @@ void CachedResource::setExpireDate(time_t expireDate, bool changeHttpCache)
     if (expireDate == m_expireDate)
         return;
 
-    if (m_status == Uncacheable || m_status == Cached)
+    if (m_status == Cached)
         finish();
 
     m_expireDate = expireDate;
@@ -84,48 +104,61 @@ void CachedResource::setExpireDate(time_t expireDate, bool changeHttpCache)
 
 bool CachedResource::isExpired() const
 {
-    if (!m_expireDate) return false;
+    if (!m_expireDate)
+        return false;
     time_t now = time(0);
     return (difftime(now, m_expireDate) >= 0);
 }
 
-void CachedResource::setRequest(Request *_request)
+void CachedResource::setRequest(Requestrequest)
 {
-    if ( _request && !m_request )
+    if (request && !m_request)
         m_status = Pending;
-    m_request = _request;
-    if (canDelete() && m_free)
+    m_request = request;
+    if (canDelete() && !inCache())
         delete this;
-    else if (allowInLRUList())
-        Cache::insertInLRUList(this);
 }
 
 void CachedResource::ref(CachedResourceClient *c)
 {
+    if (!referenced() && inCache())
+        cache()->addToLiveObjectSize(size());
     m_clients.add(c);
-    Cache::removeFromLRUList(this);
-    increaseAccessCount();
 }
 
 void CachedResource::deref(CachedResourceClient *c)
 {
     m_clients.remove(c);
-    if (allowInLRUList())
-        Cache::insertInLRUList(this);
+    if (canDelete() && !inCache())
+        delete this;
+    else if (!referenced() && inCache()) {
+        cache()->removeFromLiveObjectSize(size());
+        cache()->prune();
+    }
 }
 
-void CachedResource::setSize(int size)
+void CachedResource::setSize(unsigned size)
 {
-    bool sizeChanged = Cache::adjustSize(this, size - m_size);
+    if (size == m_size)
+        return;
 
-    // The object must now be moved to a different queue, since its size has been changed.
-    if (sizeChanged && allowInLRUList())
-        Cache::removeFromLRUList(this);
+    unsigned oldSize = m_size;
 
-    m_size = size;
+    // The object must now be moved to a different queue, since its size has been changed.
+    // We have to remove explicitly before updating m_size, so that we find the correct previous
+    // queue.
+    if (inCache())
+        cache()->removeFromLRUList(this);
     
-    if (sizeChanged && allowInLRUList())
-        Cache::insertInLRUList(this);
+    m_size = size;
+   
+    if (inCache()) { 
+        // Now insert into the new LRU list.
+        cache()->insertInLRUList(this);
+        
+        // Update the cache's size totals.
+        cache()->adjustSize(referenced(), oldSize, size);
+    }
 }
 
 }
index 9590b6a17d3e994701a2005245e08202d15acb82..1e94d26e2c542de6d7b79b94231e271b11e8b497 100644 (file)
 #include <time.h>
 
 namespace WebCore {
-    class CachedResourceClient;
-    class Request;
-    
-    /**
-     *
-     * A cached object. Classes who want to use this object should derive
-     * from CachedResourceClient, to get the function calls in case the requested data has arrived.
-     *
-     * This class also does the actual communication with kio and loads the file.
-     */
-    class CachedResource {
-    public:
-        enum Type {
-            ImageResource,
-            CSSStyleSheet,
-            Script
+
+class Cache;
+class CachedResourceClient;
+class Request;
+
+// A resource that is held in the cache. Classes who want to use this object should derive
+// from CachedResourceClient, to get the function calls in case the requested data has arrived.
+// This class also does the actual communication with the loader to obtain the resource from the network.
+class CachedResource {
+public:
+    enum Type {
+        ImageResource,
+        CSSStyleSheet,
+        Script
 #ifdef XSLT_SUPPORT
-            , XSLStyleSheet
+        , XSLStyleSheet
 #endif
 #ifdef XBL_SUPPORT
-            , XBL
+        , XBL
 #endif
-        };
-
-        enum Status {
-            NotCached,    // this URL is not cached
-            Unknown,      // let cache decide what to do with it
-            New,          // inserting new item
-            Pending,      // only partially loaded
-            Persistent,   // never delete this
-            Cached,       // regular case
-            Uncacheable   // too big to be cached, will be destroyed as soon as possible
-        };
-
-        CachedResource(const String& URL, Type type, CachePolicy cachePolicy, time_t expireDate, int size = 0)
-        {
-            m_url = URL;
-            m_type = type;
-            m_status = Pending;
-            m_size = size;
-            m_free = false;
-            m_cachePolicy = cachePolicy;
-            m_request = 0;
-            m_response = 0;
-            m_allData = 0;
-            m_expireDate = expireDate;
-            m_deleted = false;
-            m_expireDateChanged = false;
-            
-            m_accessCount = 0;
-            
-            m_nextInLRUList = 0;
-            m_prevInLRUList = 0;
-        }
-        virtual ~CachedResource();
-
-        virtual void setCharset(const String&) { }
-        virtual Vector<char>& bufferData(const char* bytes, int addedSize, Request*);
-        virtual void data(Vector<char>&, bool allDataReceived) = 0;
-        virtual void error() = 0;
-
-        const String &url() const { return m_url; }
-        Type type() const { return m_type; }
-
-        virtual void ref(CachedResourceClient*);
-        virtual void deref(CachedResourceClient*);
-
-        int count() const { return m_clients.size(); }
-
-        Status status() const { return m_status; }
-
-        int size() const { return m_size; }
-
-        bool isLoaded() const { return !m_loading; }
-
-        virtual bool isImage() const { return false; }
-
-        int accessCount() const { return m_accessCount; }
-        void increaseAccessCount() { m_accessCount++; }
+    };
+
+    enum Status {
+        NotCached,    // this URL is not cached
+        Unknown,      // let cache decide what to do with it
+        New,          // inserting new item
+        Pending,      // only partially loaded
+        Cached       // regular case
+    };
+
+    CachedResource(const String& URL, Type type, CachePolicy cachePolicy, time_t expireDate, unsigned size = 0);
+    virtual ~CachedResource();
+
+    virtual void setCharset(const String&) { }
+    virtual Vector<char>& bufferData(const char* bytes, int addedSize, Request*);
+    virtual void data(Vector<char>&, bool allDataReceived) = 0;
+    virtual void error() = 0;
+
+    const String &url() const { return m_url; }
+    Type type() const { return m_type; }
+
+    virtual void ref(CachedResourceClient*);
+    void deref(CachedResourceClient*);
+    bool referenced() const { return !m_clients.isEmpty(); }
+
+    unsigned count() const { return m_clients.size(); }
+
+    Status status() const { return m_status; }
+
+    unsigned size() const { return m_size; }
+
+    bool isLoaded() const { return !m_loading; }
+    void setLoading(bool b) { m_loading = b; }
+
+    virtual bool isImage() const { return false; }
+
+    unsigned accessCount() const { return m_accessCount; }
+    void increaseAccessCount() { m_accessCount++; }
+
+    // Computes the status of an object after loading.  
+    // Updates the expire date on the cache entry file
+    void finish();
+
+    // Called by the cache if the object has been removed from the cache
+    // while still being referenced. This means the object should delete itself
+    // if the number of clients observing it ever drops to 0.
+    void setInCache(bool b) { m_inCache = b; }
+    bool inCache() const { return m_inCache; }
     
-        /**
-         * computes the status of an object after loading.
-         * the result depends on the objects size and the size of the cache
-         * also updates the expire date on the cache entry file
-         */
-        void finish();
+    CachePolicy cachePolicy() const { return m_cachePolicy; }
 
-        /**
-         * Called by the cache if the object has been removed from the cache dict
-         * while still being referenced. This means the object should kill itself
-         * if its reference counter drops down to zero.
-         */
-        void setFree(bool b) { m_free = b; }
+    void setRequest(Request*);
 
-        CachePolicy cachePolicy() const { return m_cachePolicy; }
+    PlatformResponse response() const { return m_response; }
+    void setResponse(PlatformResponse);
+    PlatformData allData() const { return m_allData; }
+    void setAllData(PlatformData);
 
-        void setRequest(Request*);
+    bool canDelete() const { return !referenced() && !m_request; }
 
-        PlatformResponse response() const { return m_response; }
-        void setResponse(PlatformResponse);
-        PlatformData allData() const { return m_allData; }
-        void setAllData(PlatformData);
+    void setExpireDate(time_t expireDate, bool changeHttpCache);
 
-        bool canDelete() const { return m_clients.isEmpty() && !m_request; }
+    bool isExpired() const;
 
-        void setExpireDate(time_t expireDate, bool changeHttpCache);
+    virtual bool schedule() const { return false; }
 
-        bool isExpired() const;
+    // List of acceptable MIME types seperated by ",".
+    // A MIME type may contain a wildcard, e.g. "text/*".
+    String accept() const { return m_accept; }
+    void setAccept(const String& accept) { m_accept = accept; }
 
-        virtual bool schedule() const { return false; }
+protected:
+    void setSize(unsigned size);
 
-        // List of acceptable MIME types seperated by ",".
-        // A MIME type may contain a wildcard, e.g. "text/*".
-        String accept() const { return m_accept; }
-        void setAccept(const String& accept) { m_accept = accept; }
+    HashSet<CachedResourceClient*> m_clients;
 
-    protected:
-        void setSize(int size);
+    String m_url;
+    String m_accept;
+    Request* m_request;
 
-        HashSet<CachedResourceClient*> m_clients;
+    PlatformResponse m_response;
+    PlatformData m_allData;
 
-        String m_url;
-        String m_accept;
-        Request* m_request;
+    Type m_type;
+    Status m_status;
 
-        PlatformResponse m_response;
-        PlatformData m_allData;
+private:
+    unsigned m_size;
+    unsigned m_accessCount;
 
-        Type m_type;
-        Status m_status;
+protected:
+    time_t m_expireDate;
+    CachePolicy m_cachePolicy;
+    bool m_inCache;
+    bool m_loading;
+    bool m_expireDateChanged;
+#ifndef NDEBUG
+    bool m_deleted;
+    unsigned m_lruIndex;
+#endif
 
-    private:
-        int m_size;
-        int m_accessCount;
-    
-    protected:
-        time_t m_expireDate;
-        CachePolicy m_cachePolicy;
-        bool m_free : 1;
-        bool m_deleted : 1;
-        bool m_loading : 1;
-        bool m_expireDateChanged : 1;
-
-    private:
-        bool allowInLRUList() const { return canDelete() && status() != Persistent; }
-
-        CachedResource* m_nextInLRUList;
-        CachedResource* m_prevInLRUList;
-        friend class Cache;
-    };
+private:
+    CachedResource* m_nextInLRUList;
+    CachedResource* m_prevInLRUList;
+    friend class Cache;
+};
 
 }
 
index 5303912415d7ef40b1040ab4ed19b6b2913aebe2..ed91afaf7aef3a80c86a1cf769353515ba92ef77 100644 (file)
@@ -47,21 +47,12 @@ CachedScript::CachedScript(DocLoader* dl, const String& url, CachePolicy cachePo
     setAccept("*/*");
     m_errorOccurred = false;
     // load the file
-    Cache::loader()->load(dl, this, false);
+    cache()->loader()->load(dl, this, false);
     m_loading = true;
     if (!m_encoding.isValid())
         m_encoding = Latin1Encoding();
 }
 
-CachedScript::CachedScript(const String& url, const String& scriptData)
-    : CachedResource(url, Script, CachePolicyVerify, 0, scriptData.length())
-{
-    m_errorOccurred = false;
-    m_loading = false;
-    m_status = Persistent;
-    m_script = scriptData;
-}
-
 CachedScript::~CachedScript()
 {
 }
@@ -73,14 +64,6 @@ void CachedScript::ref(CachedResourceClient* c)
         c->notifyFinished(this);
 }
 
-void CachedScript::deref(CachedResourceClient* c)
-{
-    Cache::flush();
-    CachedResource::deref(c);
-    if (canDelete() && m_free)
-        delete this;
-}
-
 void CachedScript::setCharset(const String& chs)
 {
     TextEncoding encoding(chs);
index 1a391c6f4793294f4c3646060033000934cd7fec..92bac1f55d9d166c0c0de4738065d703389d935d 100644 (file)
@@ -38,13 +38,11 @@ namespace WebCore {
     class CachedScript : public CachedResource {
     public:
         CachedScript(DocLoader*, const String& URL, CachePolicy, time_t expireDate, const String& charset);
-        CachedScript(const String& URL, const String& scriptData);
         virtual ~CachedScript();
 
         const String& script() const { return m_script; }
 
         virtual void ref(CachedResourceClient*);
-        virtual void deref(CachedResourceClient*);
 
         virtual void setCharset(const String&);
         virtual void data(Vector<char>&, bool allDataReceived);
index 33a74567b4b3e29fa3d4d8011729fc57308be4f5..1c540511bf7ad3081003929025aa53b52581af00 100644 (file)
@@ -65,14 +65,6 @@ void CachedXBLDocument::ref(CachedResourceClient *c)
         c->setXBLDocument(m_url, m_document);
 }
 
-void CachedXBLDocument::deref(CachedResourceClient *c)
-{
-    Cache::flush();
-    CachedResource::deref(c);
-    if (canDelete() && m_free)
-        delete this;
-}
-
 void CachedXBLDocument::setCharset(const String& chs)
 {
     m_decoder->setEncoding(chs, Decoder::EncodingFromHTTPHeader);
index 146c080b8e50645c52dcd74661225f435864950d..cc8e22417f91c0afe3f8027ff5d075cee51ed7be 100644 (file)
@@ -47,7 +47,6 @@ namespace WebCore {
         XBL::XBLDocument* document() const { return m_document; }
         
         virtual void ref(CachedResourceClient*);
-        virtual void deref(CachedResourceClient*);
         
         virtual void setCharset(const String&);
         virtual void data(Vector<char>&, bool allDataReceived);
index c1be3f9ee71527ac69e8e402762f9154be227b1c..7917d2bbbd71c3ab0c981b5c9786cfc228e47c28 100644 (file)
@@ -49,7 +49,7 @@ CachedXSLStyleSheet::CachedXSLStyleSheet(DocLoader* dl, const String &url, Cache
     setAccept("text/xml, application/xml, application/xhtml+xml, text/xsl, application/rss+xml, application/atom+xml");
     
     // load the file
-    Cache::loader()->load(dl, this, false);
+    cache()->loader()->load(dl, this, false);
     m_loading = true;
 }
 
@@ -61,14 +61,6 @@ void CachedXSLStyleSheet::ref(CachedResourceClient *c)
         c->setXSLStyleSheet(m_url, m_sheet);
 }
 
-void CachedXSLStyleSheet::deref(CachedResourceClient *c)
-{
-    Cache::flush();
-    CachedResource::deref(c);
-    if (canDelete() && m_free)
-        delete this;
-}
-
 void CachedXSLStyleSheet::setCharset(const String& chs)
 {
     m_decoder->setEncoding(chs, Decoder::EncodingFromHTTPHeader);
index 19d5c3a4844fe8909034ca3ca5f40ab5b6c6bb5c..7a80fc64a3e41a7f16ef474b0e541abdce7c8ca8 100644 (file)
@@ -44,7 +44,6 @@ namespace WebCore {
         const String& sheet() const { return m_sheet; }
         
         virtual void ref(CachedResourceClient*);
-        virtual void deref(CachedResourceClient*);
         
         virtual void setCharset(const String&);
         virtual void data(Vector<char>&, bool allDataReceived);
index cc8c5698a8687454ae0c7f73a516aed9c6935bb1..a835698d79c959fd94e2f0e234e8e7e280a7d845 100644 (file)
 namespace WebCore {
 
 DocLoader::DocLoader(Frame *frame, Document* doc)
+: m_cache(cache())
 {
     m_cachePolicy = CachePolicyVerify;
     m_expireDate = 0;
-    m_bautoloadImages = true;
+    m_autoLoadImages = true;
     m_frame = frame;
     m_doc = doc;
     m_loadInProgress = false;
 
-    Cache::init();
-    Cache::docloaders->add(this);
+    m_cache->addDocLoader(this);
 }
 
 DocLoader::~DocLoader()
 {
-    Cache::docloaders->remove(this);
+    m_cache->removeDocLoader(this);
 }
 
 void DocLoader::setExpireDate(time_t _expireDate)
@@ -63,128 +63,97 @@ void DocLoader::setExpireDate(time_t _expireDate)
     m_expireDate = _expireDate;
 }
 
-bool DocLoader::needReload(const KURL& fullURL)
+void DocLoader::checkForReload(const KURL& fullURL)
 {
-    bool reload = false;
     if (m_cachePolicy == CachePolicyVerify) {
        if (!m_reloadedURLs.contains(fullURL.url())) {
-          CachedResource* existing = Cache::get(fullURL.url());
+          CachedResource* existing = cache()->resourceForURL(fullURL.url());
           if (existing && existing->isExpired()) {
-             Cache::remove(existing);
+             cache()->remove(existing);
              m_reloadedURLs.add(fullURL.url());
-             reload = true;
           }
        }
     } else if ((m_cachePolicy == CachePolicyReload) || (m_cachePolicy == CachePolicyRefresh)) {
        if (!m_reloadedURLs.contains(fullURL.url())) {
-          CachedResource* existing = Cache::get(fullURL.url());
+          CachedResource* existing = cache()->resourceForURL(fullURL.url());
           if (existing)
-             Cache::remove(existing);
+             cache()->remove(existing);
           m_reloadedURLs.add(fullURL.url());
-          reload = true;
        }
     }
-    return reload;
 }
 
-CachedImage *DocLoader::requestImage(const String& url)
+CachedImageDocLoader::requestImage(const String& url)
 {
-    KURL fullURL = m_doc->completeURL(url.deprecatedString());
-
-    if (CheckIfReloading(this))
-        setCachePolicy(CachePolicyReload);
-
-    bool reload = needReload(fullURL);
-
-    CachedImage *cachedObject = Cache::requestImage(this, fullURL, reload, m_expireDate);
-    CheckCacheObjectStatus(this, cachedObject);
-    return cachedObject;
+    CachedImage* resource = static_cast<CachedImage*>(requestResource(CachedResource::ImageResource, url));
+    if (autoLoadImages() && resource && resource->stillNeedsLoad()) {
+        resource->setLoading(true);
+        cache()->loader()->load(this, resource, true);
+    }
+    return resource;
 }
 
-CachedCSSStyleSheet *DocLoader::requestCSSStyleSheet(const String& url, const String& charset)
+CachedCSSStyleSheetDocLoader::requestCSSStyleSheet(const String& url, const String& charset)
 {
-    KURL fullURL = m_doc->completeURL(url.deprecatedString());
-
-    if (CheckIfReloading(this))
-        setCachePolicy(CachePolicyReload);
-
-    bool reload = needReload(fullURL);
-
-    CachedCSSStyleSheet* cachedObject = Cache::requestCSSStyleSheet(this, url, reload, m_expireDate, charset);
-    CheckCacheObjectStatus(this, cachedObject);
-    return cachedObject;
+    return static_cast<CachedCSSStyleSheet*>(requestResource(CachedResource::CSSStyleSheet, url, &charset));
 }
 
 CachedScript* DocLoader::requestScript(const String& url, const String& charset)
 {
-    KURL fullURL = m_doc->completeURL(url.deprecatedString());
-
-    if (CheckIfReloading(this))
-        setCachePolicy(CachePolicyReload);
-
-    bool reload = needReload(fullURL);
-
-    CachedScript *cachedObject = Cache::requestScript(this, url, reload, m_expireDate, charset);
-    CheckCacheObjectStatus(this, cachedObject);
-    return cachedObject;
+    return static_cast<CachedScript*>(requestResource(CachedResource::Script, url, &charset));
 }
 
 #ifdef XSLT_SUPPORT
 CachedXSLStyleSheet* DocLoader::requestXSLStyleSheet(const String& url)
 {
-    KURL fullURL = m_doc->completeURL(url.deprecatedString());
-    
-    if (CheckIfReloading(this))
-        setCachePolicy(CachePolicyReload);
-    
-    bool reload = needReload(fullURL);
-    
-    CachedXSLStyleSheet *cachedObject = Cache::requestXSLStyleSheet(this, url, reload, m_expireDate);
-    CheckCacheObjectStatus(this, cachedObject);
-    return cachedObject;
+    return static_cast<CachedXSLStyleSheet*>(requestResource(CachedResource::XSLStyleSheet, url));
 }
 #endif
 
 #ifdef XBL_SUPPORT
 CachedXBLDocument* DocLoader::requestXBLDocument(const String& url)
+{
+    return static_cast<CachedXSLStyleSheet*>(requestResource(CachedResource::XBL, url));
+}
+#endif
+
+CachedResource* DocLoader::requestResource(CachedResource::Type type, const String& url, const String* charset)
 {
     KURL fullURL = m_doc->completeURL(url.deprecatedString());
-    
-    // FIXME: Is this right for XBL?
-    if (m_frame && m_frame->onlyLocalReferences() && fullURL.protocol() != "file") return 0;
-    
+
     if (CheckIfReloading(this))
         setCachePolicy(CachePolicyReload);
+
+    checkForReload(fullURL);
+
+    CachedResource* resource = cache()->requestResource(this, type, fullURL, m_expireDate, charset);
+    m_docResources.set(resource->url(), resource);
     
-    bool reload = needReload(fullURL);
-    
-    CachedXBLDocument *cachedObject = Cache::requestXBLDocument(this, url, reload, m_expireDate);
-    CheckCacheObjectStatus(this, cachedObject);
-    return cachedObject;
+    CheckCacheObjectStatus(this, resource);
+    return resource;
 }
-#endif
 
-void DocLoader::setAutoloadImages(bool enable)
+void DocLoader::setAutoLoadImages(bool enable)
 {
-    if (enable == m_bautoloadImages)
+    if (enable == m_autoLoadImages)
         return;
 
-    m_bautoloadImages = enable;
+    m_autoLoadImages = enable;
 
-    if (!m_bautoloadImages)
+    if (!m_autoLoadImages)
         return;
 
-    HashMap<String, CachedResource*>::iterator end = m_docObjects.end();
-    for (HashMap<String, CachedResource*>::iterator it = m_docObjects.begin(); it != end; ++it) {
-        CachedResource* co = it->second;
-        if (co->type() == CachedResource::ImageResource) {
-            CachedImage *img = const_cast<CachedImage*>(static_cast<const CachedImage *>(co));
+    HashMap<String, CachedResource*>::iterator end = m_docResources.end();
+    for (HashMap<String, CachedResource*>::iterator it = m_docResources.begin(); it != end; ++it) {
+        CachedResource* resource = it->second;
+        if (resource->type() == CachedResource::ImageResource) {
+            CachedImage* image = const_cast<CachedImage*>(static_cast<const CachedImage *>(resource));
 
-            CachedResource::Status status = img->status();
+            CachedResource::Status status = image->status();
             if (status != CachedResource::Unknown)
                 continue;
 
-            Cache::loader()->load(this, img, true);
+            cache()->loader()->load(this, image, true);
         }
     }
 }
@@ -194,9 +163,9 @@ void DocLoader::setCachePolicy(CachePolicy cachePolicy)
     m_cachePolicy = cachePolicy;
 }
 
-void DocLoader::removeCachedObject(CachedResource* o) const
+void DocLoader::removeCachedResource(CachedResource* resource) const
 {
-    m_docObjects.remove(o->url());
+    m_docResources.remove(resource->url());
 }
 
 void DocLoader::setLoadInProgress(bool load)
index 1dd919944d35476a9a968332e558e98cf1383f6a..66fcc68f7b1ef6fd16bc5d641aa09e9a8cdd45f3 100644 (file)
@@ -27,6 +27,7 @@
 #ifndef DocLoader_h
 #define DocLoader_h
 
+#include "CachedResource.h"
 #include "CachePolicy.h"
 #include "Settings.h"
 #include "StringHash.h"
 #include <wtf/HashSet.h>
 
 namespace WebCore {
-    class CachedCSSStyleSheet;
-    class CachedImage;
-    class CachedResource;
-    class CachedScript;
-    class CachedXSLStyleSheet;
-    class Document;
-    class Frame;
-    class HTMLImageLoader;
-    class KURL;
-    
-    /**
-     * Manages the loading of scripts/images/stylesheets for a particular document
-     */
-    class DocLoader
-    {
-    public:
-        DocLoader(Frame*, Document*);
-        ~DocLoader();
-
-        CachedImage* requestImage(const String& url);
-        CachedCSSStyleSheet* requestCSSStyleSheet(const String& url, const String& charset);
-        CachedScript* requestScript(const String& url, const String& charset);
+
+class CachedCSSStyleSheet;
+class CachedImage;
+class CachedScript;
+class CachedXSLStyleSheet;
+class Document;
+class Frame;
+class HTMLImageLoader;
+class KURL;
+
+// The DocLoader manages the loading of scripts/images/stylesheets for a single document.
+class DocLoader
+{
+friend class Cache;
+friend class HTMLImageLoader;
+
+public:
+    DocLoader(Frame*, Document*);
+    ~DocLoader();
+
+    CachedImage* requestImage(const String& url);
+    CachedCSSStyleSheet* requestCSSStyleSheet(const String& url, const String& charset);
+    CachedScript* requestScript(const String& url, const String& charset);
 
 #ifdef XSLT_SUPPORT
-        CachedXSLStyleSheet* requestXSLStyleSheet(const String& url);
+    CachedXSLStyleSheet* requestXSLStyleSheet(const String& url);
 #endif
 #ifdef XBL_SUPPORT
-        CachedXBLDocument* requestXBLDocument(const String &url);
+    CachedXBLDocument* requestXBLDocument(const String &url);
 #endif
 
-        CachedResource* cachedObject(const String& url) const { return m_docObjects.get(url); }
-        const HashMap<String, CachedResource*>& allCachedObjects() const { return m_docObjects; }
-
-        bool autoloadImages() const { return m_bautoloadImages; }
-        CachePolicy cachePolicy() const { return m_cachePolicy; }
-        time_t expireDate() const { return m_expireDate; }
-        Frame* frame() const { return m_frame; }
-        Document* doc() const { return m_doc; }
-
-        void setExpireDate(time_t);
-        void setAutoloadImages(bool);
-        void setCachePolicy(CachePolicy);
-        void removeCachedObject(CachedResource*) const;
-
-        void setLoadInProgress(bool);
-        bool loadInProgress() const { return m_loadInProgress; }
-
-    private:
-        bool needReload(const KURL &fullUrl);
-
-        friend class Cache;
-        friend class Document;
-        friend class HTMLImageLoader;
-
-        HashSet<String> m_reloadedURLs;
-        mutable HashMap<String, CachedResource*> m_docObjects;
-        time_t m_expireDate;
-        CachePolicy m_cachePolicy;
-        bool m_bautoloadImages : 1;
-        Frame* m_frame;
-        Document *m_doc;
-        bool m_loadInProgress;
-    };
+    CachedResource* cachedResource(const String& url) const { return m_docResources.get(url); }
+    const HashMap<String, CachedResource*>& allCachedResources() const { return m_docResources; }
+
+    bool autoLoadImages() const { return m_autoLoadImages; }
+    void setAutoLoadImages(bool);
+    
+    CachePolicy cachePolicy() const { return m_cachePolicy; }
+    void setCachePolicy(CachePolicy);
+    
+    time_t expireDate() const { return m_expireDate; }
+    void setExpireDate(time_t);
+    
+    Frame* frame() const { return m_frame; }
+    Document* doc() const { return m_doc; }
+
+    void removeCachedResource(CachedResource*) const;
+
+    void setLoadInProgress(bool);
+    bool loadInProgress() const { return m_loadInProgress; }
+
+private:
+    CachedResource* requestResource(CachedResource::Type, const String& url, const String* charset = 0);
+
+    void checkForReload(const KURL&);
+
+    Cache* m_cache;
+    HashSet<String> m_reloadedURLs;
+    mutable HashMap<String, CachedResource*> m_docResources;
+    time_t m_expireDate;
+    CachePolicy m_cachePolicy;
+    bool m_autoLoadImages : 1;
+    Frame* m_frame;
+    Document *m_doc;
+    bool m_loadInProgress;
+};
 
 }
 
index 7826084fac926fb11e208927be24180703244c1f..079a9e0703a4b147a7d22dd44bfaeb2e5bc64532 100644 (file)
@@ -111,6 +111,7 @@ void ImageTokenizer::finish()
         CachedImage* cachedImage = m_imageElement->cachedImage();
         Vector<char>& buffer = cachedImage->bufferData(0, 0, 0);
         cachedImage->data(buffer, true);
+        cachedImage->finish();
 
         // FIXME: Need code to set the title for platforms other than Mac OS X.
 #if PLATFORM(MAC)
index af497dc05046e2c76e4570de3ed0408a078426a4..bb40674650f42713e4ec664107fca7aff000042c 100644 (file)
@@ -103,7 +103,7 @@ void Loader::receivedAllData(ResourceLoader* job, PlatformData allData)
         docLoader->setLoadInProgress(true);
         object->error();
         docLoader->setLoadInProgress(false);
-        Cache::remove(object);
+        cache()->remove(object);
     } else {
         docLoader->setLoadInProgress(true);
         object->data(req->buffer(), true);
@@ -195,7 +195,7 @@ void Loader::cancelRequests(DocLoader* dl)
     DeprecatedPtrListIterator<Request> pIt(m_requestsPending);
     while (pIt.current()) {
         if (pIt.current()->docLoader() == dl) {
-            Cache::remove(pIt.current()->cachedObject());
+            cache()->remove(pIt.current()->cachedObject());
             m_requestsPending.remove(pIt);
         } else
             ++pIt;
@@ -214,14 +214,14 @@ void Loader::cancelRequests(DocLoader* dl)
         ResourceLoader* job = jobsToCancel[i];
         Request* r = m_requestsLoading.get(job);
         m_requestsLoading.remove(job);
-        Cache::remove(r->cachedObject());
+        cache()->remove(r->cachedObject());
         job->kill();
     }
 
     DeprecatedPtrListIterator<Request> bdIt(m_requestsBackgroundDecoding);
     while (bdIt.current()) {
         if (bdIt.current()->docLoader() == dl) {
-            Cache::remove(bdIt.current()->cachedObject());
+            cache()->remove(bdIt.current()->cachedObject());
             m_requestsBackgroundDecoding.remove(bdIt);
         } else
             ++bdIt;
index a61c49cd2861354716fb5e479135bd6c315e65f5..48b28dfc77fa2c7623d63b906245b8df48032707 100644 (file)
@@ -169,7 +169,7 @@ Vector<char> ServeSynchronousRequest(Loader *loader, DocLoader *docLoader, Resou
 
 int NumberOfPendingOrLoadingRequests(DocLoader *dl)
 {
-    return Cache::loader()->numRequests(dl);
+    return cache()->loader()->numRequests(dl);
 }
 
 bool CheckIfReloading(DocLoader *loader)
@@ -188,9 +188,7 @@ void CheckCacheObjectStatus(DocLoader *loader, CachedResource *cachedObject)
     if (!cachedObject)
         return;
     switch (cachedObject->status()) {
-    case CachedResource::Persistent:
     case CachedResource::Cached:
-    case CachedResource::Uncacheable:
         break;
     case CachedResource::NotCached:
     case CachedResource::Unknown:
index fa510bc582d0e60cbc95e09b06b0ff54011cf01c..bfa28cdaf6b71047d6f852f54f3d9a65ce6ed45c 100644 (file)
@@ -123,9 +123,9 @@ const double autoscrollInterval = 0.1;
 
 class UserStyleSheetLoader : public CachedResourceClient {
 public:
-    UserStyleSheetLoader(Frame* frame, const String& url, DocLoader* dl)
+    UserStyleSheetLoader(Frame* frame, const String& url, DocLoader* docLoader)
         : m_frame(frame)
-        , m_cachedSheet(Cache::requestCSSStyleSheet(dl, url, false, 0, ""))
+        , m_cachedSheet(docLoader->requestCSSStyleSheet(url, ""))
     {
         m_cachedSheet->ref(this);
     }
@@ -162,7 +162,6 @@ Frame::Frame(Page* page, Element* ownerElement)
     : d(new FramePrivate(page, parentFromOwnerElement(ownerElement), this, ownerElement))
 {
     AtomicString::init();
-    Cache::init();
     EventNames::init();
     HTMLNames::init();
     QualifiedName::init();
@@ -337,7 +336,7 @@ void Frame::stopLoading(bool sendUnload)
 
   if (Document *doc = d->m_doc.get()) {
     if (DocLoader *docLoader = doc->docLoader())
-      Cache::loader()->cancelRequests(docLoader);
+      cache()->loader()->cancelRequests(docLoader);
       XMLHttpRequest::cancelRequests(doc);
   }
 
@@ -442,19 +441,19 @@ bool Frame::pluginsEnabled() const
     return d->m_bPluginsEnabled;
 }
 
-void Frame::setAutoloadImages(bool enable)
+void Frame::setAutoLoadImages(bool enable)
 {
-  if (d->m_doc && d->m_doc->docLoader()->autoloadImages() == enable)
+  if (d->m_doc && d->m_doc->docLoader()->autoLoadImages() == enable)
     return;
 
   if (d->m_doc)
-    d->m_doc->docLoader()->setAutoloadImages(enable);
+    d->m_doc->docLoader()->setAutoLoadImages(enable);
 }
 
-bool Frame::autoloadImages() const
+bool Frame::autoLoadImages() const
 {
   if (d->m_doc)
-    return d->m_doc->docLoader()->autoloadImages();
+    return d->m_doc->docLoader()->autoLoadImages();
 
   return true;
 }
@@ -672,7 +671,7 @@ void Frame::begin(const KURL& url)
 
   updatePolicyBaseURL();
 
-  setAutoloadImages(d->m_settings->autoLoadImages());
+  setAutoLoadImages(d->m_settings->autoLoadImages());
   const KURL& userStyleSheet = d->m_settings->userStyleSheetLocation();
 
   if (!userStyleSheet.isEmpty())
@@ -900,7 +899,7 @@ void Frame::checkCompleted()
   // Still waiting for images/scripts from the loader ?
   int requests = 0;
   if (d->m_doc && d->m_doc->docLoader())
-      requests = Cache::loader()->numRequests(d->m_doc->docLoader());
+      requests = cache()->loader()->numRequests(d->m_doc->docLoader());
 
   if (requests > 0)
       return;
@@ -1754,7 +1753,7 @@ String Frame::lastModified() const
 
 void Frame::reparseConfiguration()
 {
-    setAutoloadImages(d->m_settings->autoLoadImages());
+    setAutoLoadImages(d->m_settings->autoLoadImages());
         
     d->m_bJScriptEnabled = d->m_settings->isJavaScriptEnabled();
     d->m_bJavaEnabled = d->m_settings->isJavaEnabled();
index c289deae5d9df3f4c07f7a66d955410a710786ac..ca2832f15edb4e403543797bb832cf737a9f49d7 100644 (file)
@@ -164,14 +164,14 @@ public:
    *
    * @note Request will be ignored if called before @ref begin().
    */
-  void setAutoloadImages(bool enable);
+  void setAutoLoadImages(bool enable);
   /**
    * Returns whether images contained in the document are loaded automatically
    * or not.
    * @note that the returned information is unreliable as long as no begin()
    * was called.
    */
-  bool autoloadImages() const;
+  bool autoLoadImages() const;
 
   KURL baseURL() const;
   String baseTarget() const;
index 87f35984a7dacb9a6560903cc7d755a040fe0672..0b85756aad26b97b3b62641c88956f6644d4b90b 100644 (file)
@@ -90,7 +90,7 @@ static xmlDocPtr docLoaderFunc(const xmlChar *uri,
             xmlGenericErrorFunc oldErrorFunc = xmlGenericError;
             void *oldErrorContext = xmlGenericErrorContext;
             
-            Vector<char> data = ServeSynchronousRequest(Cache::loader(), globalDocLoader, loader.get(), finalURL, headers);
+            Vector<char> data = ServeSynchronousRequest(cache()->loader(), globalDocLoader, loader.get(), finalURL, headers);
         
             xmlSetGenericErrorFunc(0, parseErrorFunc);
             // We don't specify an encoding here. Neither Gecko nor WinIE respects
index ef02a5b3af56a193eb2075adeb6e190c6121b11d..5eae50a160f9d97c128fdfccbb711960c32f8042 100644 (file)
@@ -333,7 +333,7 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
         {
             // avoid deadlock in case the loader wants to use JS on a background thread
             KJS::JSLock::DropAllLocks dropLocks;
-            data = ServeSynchronousRequest(Cache::loader(), m_doc->docLoader(), m_loader.get(), finalURL, headers);
+            data = ServeSynchronousRequest(cache()->loader(), m_doc->docLoader(), m_loader.get(), finalURL, headers);
         }
 
         m_loader = 0;