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) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. |
6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
7 | 7 |
8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 #include "core/loader/PingLoader.h" | 43 #include "core/loader/PingLoader.h" |
44 #include "core/loader/UniqueIdentifier.h" | 44 #include "core/loader/UniqueIdentifier.h" |
45 #include "core/loader/cache/CachedCSSStyleSheet.h" | 45 #include "core/loader/cache/CachedCSSStyleSheet.h" |
46 #include "core/loader/cache/CachedDocument.h" | 46 #include "core/loader/cache/CachedDocument.h" |
47 #include "core/loader/cache/CachedFont.h" | 47 #include "core/loader/cache/CachedFont.h" |
48 #include "core/loader/cache/CachedImage.h" | 48 #include "core/loader/cache/CachedImage.h" |
49 #include "core/loader/cache/CachedRawResource.h" | 49 #include "core/loader/cache/CachedRawResource.h" |
50 #include "core/loader/cache/CachedResourceRequest.h" | 50 #include "core/loader/cache/CachedResourceRequest.h" |
51 #include "core/loader/cache/CachedScript.h" | 51 #include "core/loader/cache/CachedScript.h" |
52 #include "core/loader/cache/CachedShader.h" | 52 #include "core/loader/cache/CachedShader.h" |
53 #include "core/loader/cache/CachedTextTrack.h" | |
53 #include "core/loader/cache/CachedXSLStyleSheet.h" | 54 #include "core/loader/cache/CachedXSLStyleSheet.h" |
54 #include "core/loader/cache/MemoryCache.h" | 55 #include "core/loader/cache/MemoryCache.h" |
55 #include "core/page/Console.h" | 56 #include "core/page/Console.h" |
56 #include "core/page/ContentSecurityPolicy.h" | 57 #include "core/page/ContentSecurityPolicy.h" |
57 #include "core/page/DOMWindow.h" | 58 #include "core/page/DOMWindow.h" |
58 #include "core/page/Frame.h" | 59 #include "core/page/Frame.h" |
59 #include "core/page/Performance.h" | 60 #include "core/page/Performance.h" |
60 #include "core/page/Settings.h" | 61 #include "core/page/Settings.h" |
61 #include "core/platform/Logging.h" | 62 #include "core/platform/Logging.h" |
63 #include "public/platform/Platform.h" | |
64 #include "public/platform/WebURL.h" | |
62 #include "weborigin/SecurityOrigin.h" | 65 #include "weborigin/SecurityOrigin.h" |
63 #include "weborigin/SecurityPolicy.h" | 66 #include "weborigin/SecurityPolicy.h" |
64 | 67 |
65 #include "core/loader/cache/CachedTextTrack.h" | |
66 | |
67 #define PRELOAD_DEBUG 0 | 68 #define PRELOAD_DEBUG 0 |
68 | 69 |
69 namespace WebCore { | 70 namespace WebCore { |
70 | 71 |
71 static CachedResource* createResource(CachedResource::Type type, ResourceRequest & request, const String& charset) | 72 static CachedResource* createResource(CachedResource::Type type, const ResourceR equest& request, const String& charset) |
72 { | 73 { |
73 switch (type) { | 74 switch (type) { |
74 case CachedResource::ImageResource: | 75 case CachedResource::ImageResource: |
75 return new CachedImage(request); | 76 return new CachedImage(request); |
76 case CachedResource::CSSStyleSheet: | 77 case CachedResource::CSSStyleSheet: |
77 return new CachedCSSStyleSheet(request, charset); | 78 return new CachedCSSStyleSheet(request, charset); |
78 case CachedResource::Script: | 79 case CachedResource::Script: |
79 return new CachedScript(request, charset); | 80 return new CachedScript(request, charset); |
80 case CachedResource::SVGDocumentResource: | 81 case CachedResource::SVGDocumentResource: |
81 return new CachedDocument(request, CachedResource::SVGDocumentResource); | 82 return new CachedDocument(request, CachedResource::SVGDocumentResource); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 return ResourceLoadPriorityLow; | 126 return ResourceLoadPriorityLow; |
126 case CachedResource::TextTrackResource: | 127 case CachedResource::TextTrackResource: |
127 return ResourceLoadPriorityLow; | 128 return ResourceLoadPriorityLow; |
128 case CachedResource::ShaderResource: | 129 case CachedResource::ShaderResource: |
129 return ResourceLoadPriorityMedium; | 130 return ResourceLoadPriorityMedium; |
130 } | 131 } |
131 ASSERT_NOT_REACHED(); | 132 ASSERT_NOT_REACHED(); |
132 return ResourceLoadPriorityUnresolved; | 133 return ResourceLoadPriorityUnresolved; |
133 } | 134 } |
134 | 135 |
136 static CachedResource* resourceFromDataURIRequest(const ResourceRequest& request ) | |
137 { | |
138 const KURL& url = request.url(); | |
139 ASSERT(url.protocolIsData()); | |
140 | |
141 WebKit::WebString mimetype; | |
142 WebKit::WebString charset; | |
143 RefPtr<SharedBuffer> data = PassRefPtr<SharedBuffer>(WebKit::Platform::curre nt()->parseDataURL(url, mimetype, charset)); | |
144 if (!data) | |
145 return 0; | |
146 ResourceResponse response(url, mimetype, data->size(), charset, String()); | |
147 | |
148 CachedResource* resource = createResource(CachedResource::ImageResource, req uest, charset); | |
149 resource->responseReceived(response); | |
150 // FIXME: AppendData causes an unnecessary memcpy. | |
151 if (data->size()) | |
152 resource->appendData(data->data(), data->size()); | |
153 resource->finish(); | |
154 return resource; | |
155 } | |
156 | |
135 CachedResourceLoader::CachedResourceLoader(DocumentLoader* documentLoader) | 157 CachedResourceLoader::CachedResourceLoader(DocumentLoader* documentLoader) |
136 : m_document(0) | 158 : m_document(0) |
137 , m_documentLoader(documentLoader) | 159 , m_documentLoader(documentLoader) |
138 , m_requestCount(0) | 160 , m_requestCount(0) |
139 , m_garbageCollectDocumentResourcesTimer(this, &CachedResourceLoader::garbag eCollectDocumentResourcesTimerFired) | 161 , m_garbageCollectDocumentResourcesTimer(this, &CachedResourceLoader::garbag eCollectDocumentResourcesTimerFired) |
140 , m_autoLoadImages(true) | 162 , m_autoLoadImages(true) |
141 , m_imagesEnabled(true) | 163 , m_imagesEnabled(true) |
142 , m_allowStaleResources(false) | 164 , m_allowStaleResources(false) |
143 { | 165 { |
144 } | 166 } |
(...skipping 29 matching lines...) Expand all Loading... | |
174 CachedResourceHandle<CachedImage> CachedResourceLoader::requestImage(CachedResou rceRequest& request) | 196 CachedResourceHandle<CachedImage> CachedResourceLoader::requestImage(CachedResou rceRequest& request) |
175 { | 197 { |
176 if (Frame* f = frame()) { | 198 if (Frame* f = frame()) { |
177 if (f->loader()->pageDismissalEventBeingDispatched() != FrameLoader::NoD ismissal) { | 199 if (f->loader()->pageDismissalEventBeingDispatched() != FrameLoader::NoD ismissal) { |
178 KURL requestURL = request.resourceRequest().url(); | 200 KURL requestURL = request.resourceRequest().url(); |
179 if (requestURL.isValid() && canRequest(CachedResource::ImageResource , requestURL, CheckContentSecurityPolicy)) | 201 if (requestURL.isValid() && canRequest(CachedResource::ImageResource , requestURL, CheckContentSecurityPolicy)) |
180 PingLoader::loadImage(f, requestURL); | 202 PingLoader::loadImage(f, requestURL); |
181 return 0; | 203 return 0; |
182 } | 204 } |
183 } | 205 } |
206 | |
207 if (request.resourceRequest().url().protocolIsData()) | |
208 preCacheDataURIImage(request); | |
209 | |
184 request.setDefer(clientDefersImage(request.resourceRequest().url()) ? Cached ResourceRequest::DeferredByClient : CachedResourceRequest::NoDefer); | 210 request.setDefer(clientDefersImage(request.resourceRequest().url()) ? Cached ResourceRequest::DeferredByClient : CachedResourceRequest::NoDefer); |
185 return static_cast<CachedImage*>(requestResource(CachedResource::ImageResour ce, request).get()); | 211 return static_cast<CachedImage*>(requestResource(CachedResource::ImageResour ce, request).get()); |
186 } | 212 } |
187 | 213 |
214 void CachedResourceLoader::preCacheDataURIImage(const CachedResourceRequest& req uest) | |
215 { | |
216 const KURL& url = request.resourceRequest().url(); | |
217 ASSERT(url.protocolIsData()); | |
218 | |
219 if (CachedResource* existing = memoryCache()->resourceForURL(url)) | |
220 return; | |
abarth-chromium
2013/06/09 05:57:39
Ok, this variation makes sense too.
| |
221 | |
222 if (CachedResource* resource = resourceFromDataURIRequest(request.resourceRe quest())) | |
223 memoryCache()->add(resource); | |
224 } | |
225 | |
188 CachedResourceHandle<CachedFont> CachedResourceLoader::requestFont(CachedResourc eRequest& request) | 226 CachedResourceHandle<CachedFont> CachedResourceLoader::requestFont(CachedResourc eRequest& request) |
189 { | 227 { |
190 return static_cast<CachedFont*>(requestResource(CachedResource::FontResource , request).get()); | 228 return static_cast<CachedFont*>(requestResource(CachedResource::FontResource , request).get()); |
191 } | 229 } |
192 | 230 |
193 CachedResourceHandle<CachedTextTrack> CachedResourceLoader::requestTextTrack(Cac hedResourceRequest& request) | 231 CachedResourceHandle<CachedTextTrack> CachedResourceLoader::requestTextTrack(Cac hedResourceRequest& request) |
194 { | 232 { |
195 return static_cast<CachedTextTrack*>(requestResource(CachedResource::TextTra ckResource, request).get()); | 233 return static_cast<CachedTextTrack*>(requestResource(CachedResource::TextTra ckResource, request).get()); |
196 } | 234 } |
197 | 235 |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 // We already have a preload going for this URL. | 695 // We already have a preload going for this URL. |
658 if (forPreload && existingResource->isPreloaded()) | 696 if (forPreload && existingResource->isPreloaded()) |
659 return Use; | 697 return Use; |
660 | 698 |
661 // If the same URL has been loaded as a different type, we need to reload. | 699 // If the same URL has been loaded as a different type, we need to reload. |
662 if (existingResource->type() != type) { | 700 if (existingResource->type() != type) { |
663 LOG(ResourceLoading, "CachedResourceLoader::determineRevalidationPolicy reloading due to type mismatch."); | 701 LOG(ResourceLoading, "CachedResourceLoader::determineRevalidationPolicy reloading due to type mismatch."); |
664 return Reload; | 702 return Reload; |
665 } | 703 } |
666 | 704 |
705 // Always use data uris. | |
706 // FIXME: Extend this to non-images. | |
707 if (type == CachedResource::ImageResource && request.url().protocolIsData()) | |
708 return Use; | |
709 | |
667 if (!existingResource->canReuse(request)) | 710 if (!existingResource->canReuse(request)) |
668 return Reload; | 711 return Reload; |
669 | 712 |
670 // Certain requests (e.g., XHRs) might have manually set headers that requir e revalidation. | 713 // Certain requests (e.g., XHRs) might have manually set headers that requir e revalidation. |
671 // FIXME: In theory, this should be a Revalidate case. In practice, the Memo ryCache revalidation path assumes a whole bunch | 714 // FIXME: In theory, this should be a Revalidate case. In practice, the Memo ryCache revalidation path assumes a whole bunch |
672 // of things about how revalidation works that manual headers violate, so pu nt to Reload instead. | 715 // of things about how revalidation works that manual headers violate, so pu nt to Reload instead. |
673 if (request.isConditional()) | 716 if (request.isConditional()) |
674 return Reload; | 717 return Reload; |
675 | 718 |
676 // Do not load from cache if images are not enabled. The load for this image will be blocked | 719 // Do not load from cache if images are not enabled. The load for this image will be blocked |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1062 info.addMember(m_garbageCollectDocumentResourcesTimer, "garbageCollectDocume ntResourcesTimer"); | 1105 info.addMember(m_garbageCollectDocumentResourcesTimer, "garbageCollectDocume ntResourcesTimer"); |
1063 } | 1106 } |
1064 | 1107 |
1065 const ResourceLoaderOptions& CachedResourceLoader::defaultCachedResourceOptions( ) | 1108 const ResourceLoaderOptions& CachedResourceLoader::defaultCachedResourceOptions( ) |
1066 { | 1109 { |
1067 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy)); | 1110 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy)); |
1068 return options; | 1111 return options; |
1069 } | 1112 } |
1070 | 1113 |
1071 } | 1114 } |
OLD | NEW |