| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // RefPtr<ResourceFetcher> for their lifetime (and will create one if they | 66 // RefPtr<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 RefCountedWillBeGarbageCollectedFinal
ized<ResourceFetcher> { | 69 class CORE_EXPORT ResourceFetcher : public RefCountedWillBeGarbageCollectedFinal
ized<ResourceFetcher> { |
| 70 WTF_MAKE_NONCOPYABLE(ResourceFetcher); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOV
ED(ResourceFetcher); | 70 WTF_MAKE_NONCOPYABLE(ResourceFetcher); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOV
ED(ResourceFetcher); |
| 71 public: | 71 public: |
| 72 static PassRefPtrWillBeRawPtr<ResourceFetcher> create(PassOwnPtrWillBeRawPtr
<FetchContext> context) { return adoptRefWillBeNoop(new ResourceFetcher(context)
); } | 72 static PassRefPtrWillBeRawPtr<ResourceFetcher> create(PassOwnPtrWillBeRawPtr
<FetchContext> context) { return adoptRefWillBeNoop(new ResourceFetcher(context)
); } |
| 73 virtual ~ResourceFetcher(); | 73 virtual ~ResourceFetcher(); |
| 74 DECLARE_VIRTUAL_TRACE(); | 74 DECLARE_VIRTUAL_TRACE(); |
| 75 | 75 |
| 76 ResourcePtr<Resource> fetchSynchronously(FetchRequest&); | 76 ResourcePtr<Resource> requestResource(FetchRequest&, const ResourceFactory&)
; |
| 77 ResourcePtr<ImageResource> fetchImage(FetchRequest&); | |
| 78 ResourcePtr<CSSStyleSheetResource> fetchCSSStyleSheet(FetchRequest&); | |
| 79 ResourcePtr<ScriptResource> fetchScript(FetchRequest&); | |
| 80 ResourcePtr<FontResource> fetchFont(FetchRequest&); | |
| 81 ResourcePtr<RawResource> fetchRawResource(FetchRequest&); | |
| 82 ResourcePtr<RawResource> fetchMainResource(FetchRequest&, const SubstituteDa
ta&); | |
| 83 ResourcePtr<DocumentResource> fetchSVGDocument(FetchRequest&); | |
| 84 ResourcePtr<XSLStyleSheetResource> fetchXSLStyleSheet(FetchRequest&); | |
| 85 ResourcePtr<Resource> fetchLinkResource(Resource::Type, FetchRequest&); | |
| 86 ResourcePtr<Resource> fetchLinkPreloadResource(Resource::Type, FetchRequest&
); | |
| 87 ResourcePtr<RawResource> fetchImport(FetchRequest&); | |
| 88 ResourcePtr<RawResource> fetchMedia(FetchRequest&); | |
| 89 ResourcePtr<RawResource> fetchTextTrack(FetchRequest&); | |
| 90 | 77 |
| 91 Resource* cachedResource(const KURL&) const; | 78 Resource* cachedResource(const KURL&) const; |
| 92 | 79 |
| 93 typedef HashMap<String, ResourcePtr<Resource>> DocumentResourceMap; | 80 typedef HashMap<String, ResourcePtr<Resource>> DocumentResourceMap; |
| 94 const DocumentResourceMap& allResources() const { return m_documentResources
; } | 81 const DocumentResourceMap& allResources() const { return m_documentResources
; } |
| 95 | 82 |
| 96 bool autoLoadImages() const { return m_autoLoadImages; } | 83 bool autoLoadImages() const { return m_autoLoadImages; } |
| 97 void setAutoLoadImages(bool); | 84 void setAutoLoadImages(bool); |
| 98 | 85 |
| 99 void setImagesEnabled(bool); | 86 void setImagesEnabled(bool); |
| 100 | 87 |
| 101 bool shouldDeferImageLoad(const KURL&) const; | 88 bool shouldDeferImageLoad(const KURL&) const; |
| 102 | 89 |
| 103 FetchContext& context() const { return m_context ? *m_context.get() : FetchC
ontext::nullInstance(); } | 90 FetchContext& context() const { return m_context ? *m_context.get() : FetchC
ontext::nullInstance(); } |
| 104 void clearContext() { m_context.clear(); } | 91 void clearContext() { m_context.clear(); } |
| 105 | 92 |
| 106 void garbageCollectDocumentResources(); | 93 void garbageCollectDocumentResources(); |
| 107 | 94 |
| 108 int requestCount() const; | 95 int requestCount() const; |
| 109 | 96 |
| 110 bool isPreloaded(const KURL&) const; | 97 bool isPreloaded(const KURL&) const; |
| 111 void clearPreloads(); | 98 void clearPreloads(); |
| 112 void preload(Resource::Type, FetchRequest&, const String& charset); | 99 void preloadStarted(Resource*); |
| 113 void printPreloadStats(); | 100 void printPreloadStats(); |
| 114 | 101 |
| 115 void addAllArchiveResources(MHTMLArchive*); | 102 void addAllArchiveResources(MHTMLArchive*); |
| 116 ArchiveResourceCollection* archiveResourceCollection() const { return m_arch
iveResourceCollection.get(); } | 103 ArchiveResourceCollection* archiveResourceCollection() const { return m_arch
iveResourceCollection.get(); } |
| 117 | 104 |
| 118 void setDefersLoading(bool); | 105 void setDefersLoading(bool); |
| 119 void stopFetching(); | 106 void stopFetching(); |
| 120 bool isFetching() const; | 107 bool isFetching() const; |
| 121 | 108 |
| 122 void didLoadResource(); | 109 void didLoadResource(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 148 | 135 |
| 149 enum ResourceLoadStartType { | 136 enum ResourceLoadStartType { |
| 150 ResourceLoadingFromNetwork, | 137 ResourceLoadingFromNetwork, |
| 151 ResourceLoadingFromCache | 138 ResourceLoadingFromCache |
| 152 }; | 139 }; |
| 153 void requestLoadStarted(Resource*, const FetchRequest&, ResourceLoadStartTyp
e); | 140 void requestLoadStarted(Resource*, const FetchRequest&, ResourceLoadStartTyp
e); |
| 154 static const ResourceLoaderOptions& defaultResourceOptions(); | 141 static const ResourceLoaderOptions& defaultResourceOptions(); |
| 155 | 142 |
| 156 String getCacheIdentifier() const; | 143 String getCacheIdentifier() const; |
| 157 | 144 |
| 145 void scheduleDocumentResourcesGC(); |
| 146 bool clientDefersImage(const KURL&) const; |
| 147 void determineRequestContext(ResourceRequest&, Resource::Type); |
| 148 |
| 158 private: | 149 private: |
| 159 friend class ResourceCacheValidationSuppressor; | 150 friend class ResourceCacheValidationSuppressor; |
| 160 | 151 |
| 161 explicit ResourceFetcher(PassOwnPtrWillBeRawPtr<FetchContext>); | 152 explicit ResourceFetcher(PassOwnPtrWillBeRawPtr<FetchContext>); |
| 162 | 153 |
| 163 ResourcePtr<Resource> requestResource(Resource::Type, FetchRequest&); | 154 ResourcePtr<Resource> createResourceForRevalidation(const FetchRequest&, Res
ource*, const ResourceFactory&); |
| 164 ResourcePtr<Resource> createResourceForRevalidation(const FetchRequest&, Res
ource*); | 155 ResourcePtr<Resource> createResourceForLoading(FetchRequest&, const String&
charset, const ResourceFactory&); |
| 165 ResourcePtr<Resource> createResourceForLoading(Resource::Type, FetchRequest&
, const String& charset); | |
| 166 void preCacheDataURIImage(const FetchRequest&); | |
| 167 void preCacheSubstituteDataForMainResource(const FetchRequest&, const Substi
tuteData&); | |
| 168 void storeResourceTimingInitiatorInformation(Resource*); | 156 void storeResourceTimingInitiatorInformation(Resource*); |
| 169 bool scheduleArchiveLoad(Resource*, const ResourceRequest&); | 157 bool scheduleArchiveLoad(Resource*, const ResourceRequest&); |
| 170 | 158 |
| 171 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; | 159 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; |
| 172 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource) const; | 160 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource) const; |
| 173 | 161 |
| 174 void determineRequestContext(ResourceRequest&, Resource::Type); | |
| 175 void addAdditionalRequestHeaders(ResourceRequest&, Resource::Type); | 162 void addAdditionalRequestHeaders(ResourceRequest&, Resource::Type); |
| 176 | 163 |
| 177 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo
licy); | 164 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo
licy); |
| 178 | 165 |
| 179 void notifyLoadedFromMemoryCache(Resource*); | 166 void notifyLoadedFromMemoryCache(Resource*); |
| 180 | 167 |
| 181 void garbageCollectDocumentResourcesTimerFired(Timer<ResourceFetcher>*); | 168 void garbageCollectDocumentResourcesTimerFired(Timer<ResourceFetcher>*); |
| 182 void scheduleDocumentResourcesGC(); | |
| 183 | 169 |
| 184 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); | 170 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); |
| 185 | 171 |
| 186 bool clientDefersImage(const KURL&) const; | |
| 187 void reloadImagesIfNotDeferred(); | 172 void reloadImagesIfNotDeferred(); |
| 188 | 173 |
| 189 void willTerminateResourceLoader(ResourceLoader*); | 174 void willTerminateResourceLoader(ResourceLoader*); |
| 190 | 175 |
| 191 OwnPtrWillBeMember<FetchContext> m_context; | 176 OwnPtrWillBeMember<FetchContext> m_context; |
| 192 | 177 |
| 193 HashSet<String> m_validatedURLs; | 178 HashSet<String> m_validatedURLs; |
| 194 mutable DocumentResourceMap m_documentResources; | 179 mutable DocumentResourceMap m_documentResources; |
| 195 | 180 |
| 196 OwnPtr<ListHashSet<Resource*>> m_preloads; | 181 OwnPtr<ListHashSet<Resource*>> m_preloads; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 m_loader->m_allowStaleResources = m_previousState; | 232 m_loader->m_allowStaleResources = m_previousState; |
| 248 } | 233 } |
| 249 private: | 234 private: |
| 250 RawPtrWillBeMember<ResourceFetcher> m_loader; | 235 RawPtrWillBeMember<ResourceFetcher> m_loader; |
| 251 bool m_previousState; | 236 bool m_previousState; |
| 252 }; | 237 }; |
| 253 | 238 |
| 254 } // namespace blink | 239 } // namespace blink |
| 255 | 240 |
| 256 #endif // ResourceFetcher_h | 241 #endif // ResourceFetcher_h |
| OLD | NEW |