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 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 6 7 This library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Library General Public 9 License as published by the Free Software Foundation; either 10 version 2 of the License, or (at your option) any later version. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Library General Public License for more details. 16 17 You should have received a copy of the GNU Library General Public License 18 along with this library; see the file COPYING.LIB. If not, write to 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 Boston, MA 02110-1301, USA. 21 22 This class provides all functionality needed for loading images, style sheets and html 23 pages from the web. It has a memory cache for these objects. 24 */ 25 26 #ifndef DocLoader_h 27 #define DocLoader_h 28 29 #include "CachedResource.h" 30 #include "CachedResourceHandle.h" 31 #include "CachePolicy.h" 32 #include "StringHash.h" 33 #include <wtf/HashMap.h> 34 #include <wtf/HashSet.h> 35 #include <wtf/ListHashSet.h> 36 37 namespace WebCore { 38 39 class CachedCSSStyleSheet; 40 class CachedFont; 41 class CachedImage; 42 class CachedScript; 43 class CachedXSLStyleSheet; 44 class Document; 45 class Frame; 46 class ImageLoader; 47 class KURL; 48 49 // The DocLoader manages the loading of scripts/images/stylesheets for a single document. 50 class DocLoader 51 { 52 friend class Cache; 53 friend class ImageLoader; 54 55 public: 56 DocLoader(Document*); 57 ~DocLoader(); 58 59 CachedImage* requestImage(const String& url); 60 CachedCSSStyleSheet* requestCSSStyleSheet(const String& url, const String& charset); 61 CachedCSSStyleSheet* requestUserCSSStyleSheet(const String& url, const String& charset); 62 CachedScript* requestScript(const String& url, const String& charset); 63 CachedFont* requestFont(const String& url); 64 65 #if ENABLE(XSLT) 66 CachedXSLStyleSheet* requestXSLStyleSheet(const String& url); 67 #endif 68 #if ENABLE(XBL) 69 CachedXBLDocument* requestXBLDocument(const String &url); 70 #endif 71 72 // Logs an access denied message to the console for the specified URL. 73 void printAccessDeniedMessage(const KURL& url) const; 74 cachedResource(const String & url)75 CachedResource* cachedResource(const String& url) const { return m_documentResources.get(url).get(); } 76 77 typedef HashMap<String, CachedResourceHandle<CachedResource> > DocumentResourceMap; allCachedResources()78 const DocumentResourceMap& allCachedResources() const { return m_documentResources; } 79 autoLoadImages()80 bool autoLoadImages() const { return m_autoLoadImages; } 81 void setAutoLoadImages(bool); 82 83 #ifdef ANDROID_BLOCK_NETWORK_IMAGE blockNetworkImage()84 bool blockNetworkImage() const { return m_blockNetworkImage; } 85 void setBlockNetworkImage(bool); 86 bool shouldBlockNetworkImage(const String& url) const; 87 #endif 88 89 CachePolicy cachePolicy() const; 90 91 Frame* frame() const; // Can be NULL doc()92 Document* doc() const { return m_doc; } 93 94 void removeCachedResource(CachedResource*) const; 95 96 void setLoadInProgress(bool); loadInProgress()97 bool loadInProgress() const { return m_loadInProgress; } 98 setAllowStaleResources(bool allowStaleResources)99 void setAllowStaleResources(bool allowStaleResources) { m_allowStaleResources = allowStaleResources; } 100 101 void incrementRequestCount(); 102 void decrementRequestCount(); 103 int requestCount(); 104 105 void clearPreloads(); 106 void clearPendingPreloads(); 107 void preload(CachedResource::Type, const String& url, const String& charset, bool referencedFromBody); 108 void checkForPendingPreloads(); 109 void printPreloadStats(); 110 111 private: 112 CachedResource* requestResource(CachedResource::Type, const String& url, const String& charset, bool isPreload = false); 113 void requestPreload(CachedResource::Type, const String& url, const String& charset); 114 115 void checkForReload(const KURL&); 116 void checkCacheObjectStatus(CachedResource*); 117 bool canRequest(CachedResource::Type, const KURL&); 118 119 Cache* m_cache; 120 HashSet<String> m_reloadedURLs; 121 mutable DocumentResourceMap m_documentResources; 122 Document* m_doc; 123 124 int m_requestCount; 125 126 ListHashSet<CachedResource*> m_preloads; 127 struct PendingPreload { 128 CachedResource::Type m_type; 129 String m_url; 130 String m_charset; 131 }; 132 Vector<PendingPreload> m_pendingPreloads; 133 134 //29 bits left 135 #ifdef ANDROID_BLOCK_NETWORK_IMAGE 136 bool m_blockNetworkImage : 1; 137 #endif 138 bool m_autoLoadImages : 1; 139 bool m_loadInProgress : 1; 140 bool m_allowStaleResources : 1; 141 }; 142 143 } 144 145 #endif 146