2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org>
4 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
21 This class provides all functionality needed for loading images, style sheets and html
22 pages from the web. It has a memory cache for these objects.
28 #include "CachedResource.h"
29 #include "CachedResourceHandle.h"
30 #include "CachePolicy.h"
31 #include "StringHash.h"
32 #include <wtf/HashMap.h>
33 #include <wtf/HashSet.h>
34 #include <wtf/ListHashSet.h>
38 class CachedCSSStyleSheet
;
42 class CachedXSLStyleSheet
;
48 // The DocLoader manages the loading of scripts/images/stylesheets for a single document.
52 friend class ImageLoader
;
58 CachedImage
* requestImage(const String
& url
);
59 CachedCSSStyleSheet
* requestCSSStyleSheet(const String
& url
, const String
& charset
);
60 CachedCSSStyleSheet
* requestUserCSSStyleSheet(const String
& url
, const String
& charset
);
61 CachedScript
* requestScript(const String
& url
, const String
& charset
);
62 CachedFont
* requestFont(const String
& url
);
65 CachedXSLStyleSheet
* requestXSLStyleSheet(const String
& url
);
68 CachedXBLDocument
* requestXBLDocument(const String
&url
);
71 // Logs an access denied message to the console for the specified URL.
72 void printAccessDeniedMessage(const KURL
& url
) const;
74 CachedResource
* cachedResource(const String
& url
) const { return m_documentResources
.get(url
).get(); }
76 typedef HashMap
<String
, CachedResourceHandle
<CachedResource
> > DocumentResourceMap
;
77 const DocumentResourceMap
& allCachedResources() const { return m_documentResources
; }
79 bool autoLoadImages() const { return m_autoLoadImages
; }
80 void setAutoLoadImages(bool);
82 CachePolicy
cachePolicy() const;
84 Frame
* frame() const; // Can be NULL
85 Document
* doc() const { return m_doc
; }
87 void removeCachedResource(CachedResource
*) const;
89 void setLoadInProgress(bool);
90 bool loadInProgress() const { return m_loadInProgress
; }
92 void setAllowStaleResources(bool allowStaleResources
) { m_allowStaleResources
= allowStaleResources
; }
94 #if USE(LOW_BANDWIDTH_DISPLAY)
95 void replaceDocument(Document
* doc
) { m_doc
= doc
; }
98 void incrementRequestCount();
99 void decrementRequestCount();
102 void clearPreloads();
103 void preload(CachedResource::Type
, const String
& url
, const String
& charset
, bool referencedFromBody
);
104 void checkForPendingPreloads();
105 void printPreloadStats();
108 CachedResource
* requestResource(CachedResource::Type
, const String
& url
, const String
& charset
, bool isPreload
= false);
109 void requestPreload(CachedResource::Type
, const String
& url
, const String
& charset
);
111 void checkForReload(const KURL
&);
112 void checkCacheObjectStatus(CachedResource
*);
113 bool canRequest(CachedResource::Type
, const KURL
&);
116 HashSet
<String
> m_reloadedURLs
;
117 mutable DocumentResourceMap m_documentResources
;
122 ListHashSet
<CachedResource
*> m_preloads
;
123 struct PendingPreload
{
124 CachedResource::Type m_type
;
128 Vector
<PendingPreload
> m_pendingPreloads
;
131 bool m_autoLoadImages
: 1;
132 bool m_loadInProgress
: 1;
133 bool m_allowStaleResources
: 1;