]> git.saurik.com Git - iphone-api.git/blob - WebCore/DocLoader.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / DocLoader.h
1 /*
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.
5
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.
10
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.
15
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.
20
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.
23 */
24
25 #ifndef DocLoader_h
26 #define DocLoader_h
27
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>
35
36 namespace WebCore {
37
38 class CachedCSSStyleSheet;
39 class CachedFont;
40 class CachedImage;
41 class CachedScript;
42 class CachedXSLStyleSheet;
43 class Document;
44 class Frame;
45 class ImageLoader;
46 class KURL;
47
48 // The DocLoader manages the loading of scripts/images/stylesheets for a single document.
49 class DocLoader
50 {
51 friend class Cache;
52 friend class ImageLoader;
53
54 public:
55 DocLoader(Document*);
56 ~DocLoader();
57
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);
63
64 #if ENABLE(XSLT)
65 CachedXSLStyleSheet* requestXSLStyleSheet(const String& url);
66 #endif
67 #if ENABLE(XBL)
68 CachedXBLDocument* requestXBLDocument(const String &url);
69 #endif
70
71 // Logs an access denied message to the console for the specified URL.
72 void printAccessDeniedMessage(const KURL& url) const;
73
74 CachedResource* cachedResource(const String& url) const { return m_documentResources.get(url).get(); }
75
76 typedef HashMap<String, CachedResourceHandle<CachedResource> > DocumentResourceMap;
77 const DocumentResourceMap& allCachedResources() const { return m_documentResources; }
78
79 bool autoLoadImages() const { return m_autoLoadImages; }
80 void setAutoLoadImages(bool);
81
82 CachePolicy cachePolicy() const;
83
84 Frame* frame() const; // Can be NULL
85 Document* doc() const { return m_doc; }
86
87 void removeCachedResource(CachedResource*) const;
88
89 void setLoadInProgress(bool);
90 bool loadInProgress() const { return m_loadInProgress; }
91
92 void setAllowStaleResources(bool allowStaleResources) { m_allowStaleResources = allowStaleResources; }
93
94 #if USE(LOW_BANDWIDTH_DISPLAY)
95 void replaceDocument(Document* doc) { m_doc = doc; }
96 #endif
97
98 void incrementRequestCount();
99 void decrementRequestCount();
100 int requestCount();
101
102 void clearPreloads();
103 void preload(CachedResource::Type, const String& url, const String& charset, bool referencedFromBody);
104 void checkForPendingPreloads();
105 void printPreloadStats();
106
107 private:
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);
110
111 void checkForReload(const KURL&);
112 void checkCacheObjectStatus(CachedResource*);
113 bool canRequest(CachedResource::Type, const KURL&);
114
115 Cache* m_cache;
116 HashSet<String> m_reloadedURLs;
117 mutable DocumentResourceMap m_documentResources;
118 Document* m_doc;
119
120 int m_requestCount;
121
122 ListHashSet<CachedResource*> m_preloads;
123 struct PendingPreload {
124 CachedResource::Type m_type;
125 String m_url;
126 String m_charset;
127 };
128 Vector<PendingPreload> m_pendingPreloads;
129
130 //29 bits left
131 bool m_autoLoadImages : 1;
132 bool m_loadInProgress : 1;
133 bool m_allowStaleResources : 1;
134 };
135
136 }
137
138 #endif