Chromium Code Reviews| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 class XSLStyleSheetResource; | 54 class XSLStyleSheetResource; |
| 55 class Document; | 55 class Document; |
| 56 class DocumentLoader; | 56 class DocumentLoader; |
| 57 class Frame; | 57 class Frame; |
| 58 class FrameLoader; | 58 class FrameLoader; |
| 59 class ImageLoader; | 59 class ImageLoader; |
| 60 class KURL; | 60 class KURL; |
| 61 class ResourceTimingInfo; | 61 class ResourceTimingInfo; |
| 62 class ResourceLoaderSet; | 62 class ResourceLoaderSet; |
| 63 | 63 |
| 64 enum OriginRestriction { | |
|
sof
2013/11/15 08:11:58
Finding appropriate names for this one (and the on
| |
| 65 UseDefaultOriginRestrictionForType, | |
| 66 RestrictToSameOrigin | |
| 67 }; | |
| 68 | |
| 69 enum CrossOriginEnabled { | |
| 70 NotCrossOriginEnabled, | |
| 71 PotentiallyCrossOriginEnabled // Indicates "potentially CORS-enabled fetch" in HTML standard. | |
| 72 }; | |
| 73 | |
| 64 // The ResourceFetcher provides a per-context interface to the MemoryCache | 74 // The ResourceFetcher provides a per-context interface to the MemoryCache |
| 65 // and enforces a bunch of security checks and rules for resource revalidation. | 75 // and enforces a bunch of security checks and rules for resource revalidation. |
| 66 // Its lifetime is roughly per-DocumentLoader, in that it is generally created | 76 // Its lifetime is roughly per-DocumentLoader, in that it is generally created |
| 67 // in the DocumentLoader constructor and loses its ability to generate network | 77 // in the DocumentLoader constructor and loses its ability to generate network |
| 68 // requests when the DocumentLoader is destroyed. Documents also hold a | 78 // requests when the DocumentLoader is destroyed. Documents also hold a |
| 69 // RefPtr<ResourceFetcher> for their lifetime (and will create one if they | 79 // RefPtr<ResourceFetcher> for their lifetime (and will create one if they |
| 70 // are initialized without a Frame), so a Document can keep a ResourceFetcher | 80 // are initialized without a Frame), so a Document can keep a ResourceFetcher |
| 71 // alive past detach if scripts still reference the Document. | 81 // alive past detach if scripts still reference the Document. |
| 72 class ResourceFetcher : public RefCounted<ResourceFetcher>, public ResourceLoade rHost { | 82 class ResourceFetcher : public RefCounted<ResourceFetcher>, public ResourceLoade rHost { |
| 73 WTF_MAKE_NONCOPYABLE(ResourceFetcher); WTF_MAKE_FAST_ALLOCATED; | 83 WTF_MAKE_NONCOPYABLE(ResourceFetcher); WTF_MAKE_FAST_ALLOCATED; |
| 74 friend class ImageLoader; | 84 friend class ImageLoader; |
| 75 friend class ResourceCacheValidationSuppressor; | 85 friend class ResourceCacheValidationSuppressor; |
| 76 | 86 |
| 77 public: | 87 public: |
| 78 static PassRefPtr<ResourceFetcher> create(DocumentLoader* documentLoader) { return adoptRef(new ResourceFetcher(documentLoader)); } | 88 static PassRefPtr<ResourceFetcher> create(DocumentLoader* documentLoader) { return adoptRef(new ResourceFetcher(documentLoader)); } |
| 79 virtual ~ResourceFetcher(); | 89 virtual ~ResourceFetcher(); |
| 80 | 90 |
| 81 using RefCounted<ResourceFetcher>::ref; | 91 using RefCounted<ResourceFetcher>::ref; |
| 82 using RefCounted<ResourceFetcher>::deref; | 92 using RefCounted<ResourceFetcher>::deref; |
| 83 | 93 |
| 84 ResourcePtr<Resource> fetchSynchronously(FetchRequest&); | 94 ResourcePtr<Resource> fetchSynchronously(FetchRequest&, OriginRestriction = UseDefaultOriginRestrictionForType); |
| 85 ResourcePtr<ImageResource> fetchImage(FetchRequest&); | 95 ResourcePtr<ImageResource> fetchImage(FetchRequest&, OriginRestriction = Use DefaultOriginRestrictionForType); |
|
sof
2013/11/15 08:11:58
Notice that none of the other fetch{ResourceType}(
abarth-chromium
2013/11/15 15:47:52
These functions used to take a large number of par
sof
2013/11/15 17:05:18
Done. Thank you, sorry for not picking up on that
| |
| 86 ResourcePtr<CSSStyleSheetResource> fetchCSSStyleSheet(FetchRequest&); | 96 ResourcePtr<CSSStyleSheetResource> fetchCSSStyleSheet(FetchRequest&); |
| 87 ResourcePtr<CSSStyleSheetResource> fetchUserCSSStyleSheet(FetchRequest&); | 97 ResourcePtr<CSSStyleSheetResource> fetchUserCSSStyleSheet(FetchRequest&); |
| 88 ResourcePtr<ScriptResource> fetchScript(FetchRequest&); | 98 ResourcePtr<ScriptResource> fetchScript(FetchRequest&); |
| 89 ResourcePtr<FontResource> fetchFont(FetchRequest&); | 99 ResourcePtr<FontResource> fetchFont(FetchRequest&); |
| 90 ResourcePtr<RawResource> fetchRawResource(FetchRequest&); | 100 ResourcePtr<RawResource> fetchRawResource(FetchRequest&); |
| 91 ResourcePtr<RawResource> fetchMainResource(FetchRequest&); | 101 ResourcePtr<RawResource> fetchMainResource(FetchRequest&); |
| 92 ResourcePtr<DocumentResource> fetchSVGDocument(FetchRequest&); | 102 ResourcePtr<DocumentResource> fetchSVGDocument(FetchRequest&); |
| 93 ResourcePtr<XSLStyleSheetResource> fetchXSLStyleSheet(FetchRequest&); | 103 ResourcePtr<XSLStyleSheetResource> fetchXSLStyleSheet(FetchRequest&); |
| 94 ResourcePtr<Resource> fetchLinkResource(Resource::Type, FetchRequest&); | 104 ResourcePtr<Resource> fetchLinkResource(Resource::Type, FetchRequest&); |
| 95 ResourcePtr<TextTrackResource> fetchTextTrack(FetchRequest&); | 105 ResourcePtr<TextTrackResource> fetchTextTrack(FetchRequest&); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 123 void garbageCollectDocumentResources(); | 133 void garbageCollectDocumentResources(); |
| 124 | 134 |
| 125 int requestCount() const { return m_requestCount; } | 135 int requestCount() const { return m_requestCount; } |
| 126 | 136 |
| 127 bool isPreloaded(const String& urlString) const; | 137 bool isPreloaded(const String& urlString) const; |
| 128 void clearPreloads(); | 138 void clearPreloads(); |
| 129 void clearPendingPreloads(); | 139 void clearPendingPreloads(); |
| 130 void preload(Resource::Type, FetchRequest&, const String& charset); | 140 void preload(Resource::Type, FetchRequest&, const String& charset); |
| 131 void checkForPendingPreloads(); | 141 void checkForPendingPreloads(); |
| 132 void printPreloadStats(); | 142 void printPreloadStats(); |
| 133 bool canAccess(Resource*); | 143 bool canAccess(Resource*, CrossOriginEnabled, OriginRestriction = UseDefault OriginRestrictionForType); |
| 134 | 144 |
| 135 void setDefersLoading(bool); | 145 void setDefersLoading(bool); |
| 136 void stopFetching(); | 146 void stopFetching(); |
| 137 bool isFetching() const; | 147 bool isFetching() const; |
| 138 | 148 |
| 139 // ResourceLoaderHost | 149 // ResourceLoaderHost |
| 140 virtual void incrementRequestCount(const Resource*) OVERRIDE; | 150 virtual void incrementRequestCount(const Resource*) OVERRIDE; |
| 141 virtual void decrementRequestCount(const Resource*) OVERRIDE; | 151 virtual void decrementRequestCount(const Resource*) OVERRIDE; |
| 142 virtual void didLoadResource(Resource*) OVERRIDE; | 152 virtual void didLoadResource(Resource*) OVERRIDE; |
| 143 virtual void redirectReceived(Resource*, const ResourceResponse&) OVERRIDE; | 153 virtual void redirectReceived(Resource*, const ResourceResponse&) OVERRIDE; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 157 virtual void refResourceLoaderHost() OVERRIDE; | 167 virtual void refResourceLoaderHost() OVERRIDE; |
| 158 virtual void derefResourceLoaderHost() OVERRIDE; | 168 virtual void derefResourceLoaderHost() OVERRIDE; |
| 159 | 169 |
| 160 static const ResourceLoaderOptions& defaultResourceOptions(); | 170 static const ResourceLoaderOptions& defaultResourceOptions(); |
| 161 private: | 171 private: |
| 162 | 172 |
| 163 explicit ResourceFetcher(DocumentLoader*); | 173 explicit ResourceFetcher(DocumentLoader*); |
| 164 | 174 |
| 165 bool shouldLoadNewResource() const; | 175 bool shouldLoadNewResource() const; |
| 166 | 176 |
| 167 ResourcePtr<Resource> requestResource(Resource::Type, FetchRequest&); | 177 ResourcePtr<Resource> requestResource(Resource::Type, FetchRequest&, OriginR estriction = UseDefaultOriginRestrictionForType); |
| 168 ResourcePtr<Resource> revalidateResource(const FetchRequest&, Resource*); | 178 ResourcePtr<Resource> revalidateResource(const FetchRequest&, Resource*); |
| 169 ResourcePtr<Resource> loadResource(Resource::Type, FetchRequest&, const Stri ng& charset); | 179 ResourcePtr<Resource> loadResource(Resource::Type, FetchRequest&, const Stri ng& charset); |
| 170 void preCacheDataURIImage(const FetchRequest&); | 180 void preCacheDataURIImage(const FetchRequest&); |
| 171 void storeResourceTimingInitiatorInformation(const ResourcePtr<Resource>&, c onst FetchRequest&); | 181 void storeResourceTimingInitiatorInformation(const ResourcePtr<Resource>&, c onst FetchRequest&); |
| 172 void requestPreload(Resource::Type, FetchRequest&, const String& charset); | 182 void requestPreload(Resource::Type, FetchRequest&, const String& charset); |
| 173 | 183 |
| 174 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; | 184 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; |
| 175 RevalidationPolicy determineRevalidationPolicy(Resource::Type, ResourceReque st&, bool forPreload, Resource* existingResource, FetchRequest::DeferOption) con st; | 185 RevalidationPolicy determineRevalidationPolicy(Resource::Type, ResourceReque st&, bool forPreload, Resource* existingResource, FetchRequest::DeferOption) con st; |
| 176 | 186 |
| 177 void determineTargetType(ResourceRequest&, Resource::Type); | 187 void determineTargetType(ResourceRequest&, Resource::Type); |
| 178 ResourceRequestCachePolicy resourceRequestCachePolicy(const ResourceRequest& , Resource::Type); | 188 ResourceRequestCachePolicy resourceRequestCachePolicy(const ResourceRequest& , Resource::Type); |
| 179 void addAdditionalRequestHeaders(ResourceRequest&, Resource::Type); | 189 void addAdditionalRequestHeaders(ResourceRequest&, Resource::Type); |
| 180 | 190 |
| 181 bool canRequest(Resource::Type, const KURL&, const ResourceLoaderOptions&, b ool forPreload = false); | 191 bool canRequest(Resource::Type, const KURL&, const ResourceLoaderOptions&, b ool forPreload, OriginRestriction); |
| 182 bool checkInsecureContent(Resource::Type, const KURL&, MixedContentBlockingT reatment) const; | 192 bool checkInsecureContent(Resource::Type, const KURL&, MixedContentBlockingT reatment) const; |
| 183 | 193 |
| 184 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo licy); | 194 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo licy); |
| 185 | 195 |
| 186 void notifyLoadedFromMemoryCache(Resource*); | 196 void notifyLoadedFromMemoryCache(Resource*); |
| 187 | 197 |
| 188 void garbageCollectDocumentResourcesTimerFired(Timer<ResourceFetcher>*); | 198 void garbageCollectDocumentResourcesTimerFired(Timer<ResourceFetcher>*); |
| 189 void performPostLoadActions(); | 199 void performPostLoadActions(); |
| 190 | 200 |
| 191 bool clientDefersImage(const KURL&) const; | 201 bool clientDefersImage(const KURL&) const; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 m_loader->m_allowStaleResources = m_previousState; | 249 m_loader->m_allowStaleResources = m_previousState; |
| 240 } | 250 } |
| 241 private: | 251 private: |
| 242 ResourceFetcher* m_loader; | 252 ResourceFetcher* m_loader; |
| 243 bool m_previousState; | 253 bool m_previousState; |
| 244 }; | 254 }; |
| 245 | 255 |
| 246 } // namespace WebCore | 256 } // namespace WebCore |
| 247 | 257 |
| 248 #endif | 258 #endif |
| OLD | NEW |