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 cachedResource(const String & url)74 CachedResource* cachedResource(const String& url) const { return m_documentResources.get(url).get(); } 75 76 typedef HashMap<String, CachedResourceHandle<CachedResource> > DocumentResourceMap; allCachedResources()77 const DocumentResourceMap& allCachedResources() const { return m_documentResources; } 78 autoLoadImages()79 bool autoLoadImages() const { return m_autoLoadImages; } 80 void setAutoLoadImages(bool); 81 82 #ifdef ANDROID_BLOCK_NETWORK_IMAGE blockNetworkImage()83 bool blockNetworkImage() const { return m_blockNetworkImage; } 84 void setBlockNetworkImage(bool); 85 bool shouldBlockNetworkImage(const String& url) const; 86 #endif 87 88 CachePolicy cachePolicy() const; 89 90 Frame* frame() const; // Can be NULL doc()91 Document* doc() const { return m_doc; } 92 93 void removeCachedResource(CachedResource*) const; 94 95 void setLoadInProgress(bool); loadInProgress()96 bool loadInProgress() const { return m_loadInProgress; } 97 setAllowStaleResources(bool allowStaleResources)98 void setAllowStaleResources(bool allowStaleResources) { m_allowStaleResources = allowStaleResources; } 99 100 #if USE(LOW_BANDWIDTH_DISPLAY) replaceDocument(Document * doc)101 void replaceDocument(Document* doc) { m_doc = doc; } 102 #endif 103 104 void incrementRequestCount(); 105 void decrementRequestCount(); 106 int requestCount(); 107 108 void clearPreloads(); 109 void preload(CachedResource::Type, const String& url, const String& charset, bool referencedFromBody); 110 void checkForPendingPreloads(); 111 void printPreloadStats(); 112 113 private: 114 CachedResource* requestResource(CachedResource::Type, const String& url, const String& charset, bool isPreload = false); 115 void requestPreload(CachedResource::Type, const String& url, const String& charset); 116 117 void checkForReload(const KURL&); 118 void checkCacheObjectStatus(CachedResource*); 119 bool canRequest(CachedResource::Type, const KURL&); 120 121 Cache* m_cache; 122 HashSet<String> m_reloadedURLs; 123 mutable DocumentResourceMap m_documentResources; 124 Document* m_doc; 125 126 int m_requestCount; 127 128 ListHashSet<CachedResource*> m_preloads; 129 struct PendingPreload { 130 CachedResource::Type m_type; 131 String m_url; 132 String m_charset; 133 }; 134 Vector<PendingPreload> m_pendingPreloads; 135 136 //29 bits left 137 #ifdef ANDROID_BLOCK_NETWORK_IMAGE 138 bool m_blockNetworkImage : 1; 139 #endif 140 bool m_autoLoadImages : 1; 141 bool m_loadInProgress : 1; 142 bool m_allowStaleResources : 1; 143 }; 144 145 } 146 147 #endif 148