OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> | 3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> |
4 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. | 4 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. |
5 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 5 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
6 | 6 |
7 This library is free software; you can redistribute it and/or | 7 This library is free software; you can redistribute it and/or |
8 modify it under the terms of the GNU Library General Public | 8 modify it under the terms of the GNU Library General Public |
9 License as published by the Free Software Foundation; either | 9 License as published by the Free Software Foundation; either |
10 version 2 of the License, or (at your option) any later version. | 10 version 2 of the License, or (at your option) any later version. |
(...skipping 16 matching lines...) Expand all Loading... |
27 #define ResourceFetcher_h | 27 #define ResourceFetcher_h |
28 | 28 |
29 #include "core/CoreExport.h" | 29 #include "core/CoreExport.h" |
30 #include "core/fetch/CachePolicy.h" | 30 #include "core/fetch/CachePolicy.h" |
31 #include "core/fetch/FetchContext.h" | 31 #include "core/fetch/FetchContext.h" |
32 #include "core/fetch/FetchInitiatorInfo.h" | 32 #include "core/fetch/FetchInitiatorInfo.h" |
33 #include "core/fetch/FetchRequest.h" | 33 #include "core/fetch/FetchRequest.h" |
34 #include "core/fetch/Resource.h" | 34 #include "core/fetch/Resource.h" |
35 #include "core/fetch/ResourceLoaderOptions.h" | 35 #include "core/fetch/ResourceLoaderOptions.h" |
36 #include "core/fetch/ResourcePtr.h" | 36 #include "core/fetch/ResourcePtr.h" |
| 37 #include "core/fetch/SubstituteData.h" |
37 #include "platform/Timer.h" | 38 #include "platform/Timer.h" |
38 #include "platform/network/ResourceError.h" | 39 #include "platform/network/ResourceError.h" |
39 #include "platform/network/ResourceLoadPriority.h" | 40 #include "platform/network/ResourceLoadPriority.h" |
40 #include "wtf/HashMap.h" | 41 #include "wtf/HashMap.h" |
41 #include "wtf/HashSet.h" | 42 #include "wtf/HashSet.h" |
42 #include "wtf/ListHashSet.h" | 43 #include "wtf/ListHashSet.h" |
43 #include "wtf/text/StringHash.h" | 44 #include "wtf/text/StringHash.h" |
44 | 45 |
45 namespace blink { | 46 namespace blink { |
46 | 47 |
47 class ArchiveResourceCollection; | 48 class ArchiveResourceCollection; |
48 class CSSStyleSheetResource; | 49 class CSSStyleSheetResource; |
49 class DocumentResource; | 50 class DocumentResource; |
50 class FontResource; | 51 class FontResource; |
51 class ImageResource; | 52 class ImageResource; |
52 class MHTMLArchive; | 53 class MHTMLArchive; |
53 class RawResource; | 54 class RawResource; |
54 class ScriptResource; | 55 class ScriptResource; |
55 class SubstituteData; | |
56 class XSLStyleSheetResource; | 56 class XSLStyleSheetResource; |
57 class KURL; | 57 class KURL; |
58 class ResourceTimingInfo; | 58 class ResourceTimingInfo; |
59 class ResourceLoaderSet; | 59 class ResourceLoaderSet; |
60 | 60 |
61 // The ResourceFetcher provides a per-context interface to the MemoryCache | 61 // The ResourceFetcher provides a per-context interface to the MemoryCache |
62 // and enforces a bunch of security checks and rules for resource revalidation. | 62 // and enforces a bunch of security checks and rules for resource revalidation. |
63 // Its lifetime is roughly per-DocumentLoader, in that it is generally created | 63 // Its lifetime is roughly per-DocumentLoader, in that it is generally created |
64 // in the DocumentLoader constructor and loses its ability to generate network | 64 // in the DocumentLoader constructor and loses its ability to generate network |
65 // requests when the DocumentLoader is destroyed. Documents also hold a pointer | 65 // requests when the DocumentLoader is destroyed. Documents also hold a pointer |
66 // to ResourceFetcher for their lifetime (and will create one if they | 66 // to ResourceFetcher for their lifetime (and will create one if they |
67 // are initialized without a LocalFrame), so a Document can keep a ResourceFetch
er | 67 // are initialized without a LocalFrame), so a Document can keep a ResourceFetch
er |
68 // alive past detach if scripts still reference the Document. | 68 // alive past detach if scripts still reference the Document. |
69 class CORE_EXPORT ResourceFetcher : public GarbageCollectedFinalized<ResourceFet
cher> { | 69 class CORE_EXPORT ResourceFetcher : public GarbageCollectedFinalized<ResourceFet
cher> { |
70 WTF_MAKE_NONCOPYABLE(ResourceFetcher); | 70 WTF_MAKE_NONCOPYABLE(ResourceFetcher); |
71 WILL_BE_USING_PRE_FINALIZER(ResourceFetcher, clearPreloads); | 71 WILL_BE_USING_PRE_FINALIZER(ResourceFetcher, clearPreloads); |
72 public: | 72 public: |
73 static ResourceFetcher* create(FetchContext* context) { return new ResourceF
etcher(context); } | 73 static ResourceFetcher* create(FetchContext* context) { return new ResourceF
etcher(context); } |
74 virtual ~ResourceFetcher(); | 74 virtual ~ResourceFetcher(); |
75 DECLARE_VIRTUAL_TRACE(); | 75 DECLARE_VIRTUAL_TRACE(); |
76 | 76 |
77 ResourcePtr<Resource> requestResource(FetchRequest&, const ResourceFactory&)
; | 77 ResourcePtr<Resource> requestResource(FetchRequest&, const ResourceFactory&,
const SubstituteData& = SubstituteData()); |
78 | 78 |
79 Resource* cachedResource(const KURL&) const; | 79 Resource* cachedResource(const KURL&) const; |
80 | 80 |
81 typedef HashMap<String, ResourcePtr<Resource>> DocumentResourceMap; | 81 typedef HashMap<String, ResourcePtr<Resource>> DocumentResourceMap; |
82 const DocumentResourceMap& allResources() const { return m_documentResources
; } | 82 const DocumentResourceMap& allResources() const { return m_documentResources
; } |
83 | 83 |
84 bool autoLoadImages() const { return m_autoLoadImages; } | 84 bool autoLoadImages() const { return m_autoLoadImages; } |
85 void setAutoLoadImages(bool); | 85 void setAutoLoadImages(bool); |
86 | 86 |
87 void setImagesEnabled(bool); | 87 void setImagesEnabled(bool); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 bool isControlledByServiceWorker() const; | 131 bool isControlledByServiceWorker() const; |
132 | 132 |
133 void acceptDataFromThreadedReceiver(unsigned long identifier, const char* da
ta, int dataLength, int encodedDataLength); | 133 void acceptDataFromThreadedReceiver(unsigned long identifier, const char* da
ta, int dataLength, int encodedDataLength); |
134 | 134 |
135 ResourceLoadPriority loadPriority(Resource::Type, const FetchRequest&); | 135 ResourceLoadPriority loadPriority(Resource::Type, const FetchRequest&); |
136 | 136 |
137 enum ResourceLoadStartType { | 137 enum ResourceLoadStartType { |
138 ResourceLoadingFromNetwork, | 138 ResourceLoadingFromNetwork, |
139 ResourceLoadingFromCache | 139 ResourceLoadingFromCache |
140 }; | 140 }; |
141 void requestLoadStarted(Resource*, const FetchRequest&, ResourceLoadStartTyp
e); | 141 void requestLoadStarted(Resource*, const FetchRequest&, ResourceLoadStartTyp
e, bool isStaticData = false); |
142 static const ResourceLoaderOptions& defaultResourceOptions(); | 142 static const ResourceLoaderOptions& defaultResourceOptions(); |
143 | 143 |
144 String getCacheIdentifier() const; | 144 String getCacheIdentifier() const; |
145 | 145 |
146 void scheduleDocumentResourcesGC(); | 146 void scheduleDocumentResourcesGC(); |
147 bool clientDefersImage(const KURL&) const; | 147 bool clientDefersImage(const KURL&) const; |
148 void determineRequestContext(ResourceRequest&, Resource::Type); | 148 void determineRequestContext(ResourceRequest&, Resource::Type); |
149 | 149 |
150 private: | 150 private: |
151 friend class ResourceCacheValidationSuppressor; | 151 friend class ResourceCacheValidationSuppressor; |
152 | 152 |
153 explicit ResourceFetcher(FetchContext*); | 153 explicit ResourceFetcher(FetchContext*); |
154 | 154 |
155 ResourcePtr<Resource> createResourceForRevalidation(const FetchRequest&, Res
ource*, const ResourceFactory&); | 155 ResourcePtr<Resource> createResourceForRevalidation(const FetchRequest&, Res
ource*, const ResourceFactory&); |
156 ResourcePtr<Resource> createResourceForLoading(FetchRequest&, const String&
charset, const ResourceFactory&); | 156 ResourcePtr<Resource> createResourceForLoading(FetchRequest&, const String&
charset, const ResourceFactory&); |
157 void storeResourceTimingInitiatorInformation(Resource*); | 157 void storeResourceTimingInitiatorInformation(Resource*); |
158 bool scheduleArchiveLoad(Resource*, const ResourceRequest&); | 158 bool scheduleArchiveLoad(Resource*, const ResourceRequest&); |
| 159 void preCacheData(const FetchRequest&, const ResourceFactory&, const Substit
uteData&); |
159 | 160 |
160 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; | 161 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; |
161 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource) const; | 162 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource, bool isStaticData) const; |
162 | 163 |
163 void initializeResourceRequest(ResourceRequest&, Resource::Type); | 164 void initializeResourceRequest(ResourceRequest&, Resource::Type); |
164 | 165 |
165 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo
licy); | 166 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo
licy); |
166 | 167 |
167 void notifyLoadedFromMemoryCache(Resource*); | 168 void notifyLoadedFromMemoryCache(Resource*); |
168 | 169 |
169 void garbageCollectDocumentResourcesTimerFired(Timer<ResourceFetcher>*); | 170 void garbageCollectDocumentResourcesTimerFired(Timer<ResourceFetcher>*); |
170 | 171 |
171 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); | 172 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 m_loader->m_allowStaleResources = m_previousState; | 242 m_loader->m_allowStaleResources = m_previousState; |
242 } | 243 } |
243 private: | 244 private: |
244 Member<ResourceFetcher> m_loader; | 245 Member<ResourceFetcher> m_loader; |
245 bool m_previousState; | 246 bool m_previousState; |
246 }; | 247 }; |
247 | 248 |
248 } // namespace blink | 249 } // namespace blink |
249 | 250 |
250 #endif // ResourceFetcher_h | 251 #endif // ResourceFetcher_h |
OLD | NEW |