OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #include "core/page/Page.h" | 60 #include "core/page/Page.h" |
61 #include "core/svg/graphics/SVGImageChromeClient.h" | 61 #include "core/svg/graphics/SVGImageChromeClient.h" |
62 #include "core/timing/DOMWindowPerformance.h" | 62 #include "core/timing/DOMWindowPerformance.h" |
63 #include "core/timing/Performance.h" | 63 #include "core/timing/Performance.h" |
64 #include "platform/Logging.h" | 64 #include "platform/Logging.h" |
65 #include "platform/TracedValue.h" | 65 #include "platform/TracedValue.h" |
66 #include "platform/mhtml/MHTMLArchive.h" | 66 #include "platform/mhtml/MHTMLArchive.h" |
67 #include "platform/network/ResourceTimingInfo.h" | 67 #include "platform/network/ResourceTimingInfo.h" |
68 #include "platform/weborigin/SchemeRegistry.h" | 68 #include "platform/weborigin/SchemeRegistry.h" |
69 #include "platform/weborigin/SecurityPolicy.h" | 69 #include "platform/weborigin/SecurityPolicy.h" |
| 70 #include "public/platform/WebCachePolicy.h" |
70 #include "public/platform/WebFrameScheduler.h" | 71 #include "public/platform/WebFrameScheduler.h" |
71 | 72 |
72 #include <algorithm> | 73 #include <algorithm> |
73 | 74 |
74 namespace blink { | 75 namespace blink { |
75 | 76 |
76 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) | 77 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) |
77 : m_document(document) | 78 : m_document(document) |
78 , m_documentLoader(loader) | 79 , m_documentLoader(loader) |
79 , m_imageFetched(false) | 80 , m_imageFetched(false) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 Frame* parentFrame = frame()->tree().parent(); | 150 Frame* parentFrame = frame()->tree().parent(); |
150 if (parentFrame && parentFrame->isLocalFrame()) { | 151 if (parentFrame && parentFrame->isLocalFrame()) { |
151 CachePolicy parentCachePolicy = toLocalFrame(parentFrame)->document()->f
etcher()->context().getCachePolicy(); | 152 CachePolicy parentCachePolicy = toLocalFrame(parentFrame)->document()->f
etcher()->context().getCachePolicy(); |
152 if (parentCachePolicy != CachePolicyVerify) | 153 if (parentCachePolicy != CachePolicyVerify) |
153 return parentCachePolicy; | 154 return parentCachePolicy; |
154 } | 155 } |
155 | 156 |
156 if (loadType == FrameLoadTypeReload) | 157 if (loadType == FrameLoadTypeReload) |
157 return CachePolicyRevalidate; | 158 return CachePolicyRevalidate; |
158 | 159 |
159 if (m_documentLoader && m_documentLoader->request().getCachePolicy() == Retu
rnCacheDataElseLoad) | 160 if (m_documentLoader && m_documentLoader->request().getCachePolicy() == WebC
achePolicy::ReturnCacheDataElseLoad) |
160 return CachePolicyHistoryBuffer; | 161 return CachePolicyHistoryBuffer; |
161 return CachePolicyVerify; | 162 return CachePolicyVerify; |
162 | |
163 } | 163 } |
164 | 164 |
165 static ResourceRequestCachePolicy memoryCachePolicyToResourceRequestCachePolicy( | 165 static WebCachePolicy memoryCachePolicyToResourceRequestCachePolicy(const CacheP
olicy policy) |
166 const CachePolicy policy) { | 166 { |
167 if (policy == CachePolicyVerify) | 167 if (policy == CachePolicyVerify) |
168 return UseProtocolCachePolicy; | 168 return WebCachePolicy::UseProtocolCachePolicy; |
169 if (policy == CachePolicyRevalidate) | 169 if (policy == CachePolicyRevalidate) |
170 return ValidatingCacheData; | 170 return WebCachePolicy::ValidatingCacheData; |
171 if (policy == CachePolicyReload) | 171 if (policy == CachePolicyReload) |
172 return BypassingCache; | 172 return WebCachePolicy::BypassingCache; |
173 if (policy == CachePolicyHistoryBuffer) | 173 if (policy == CachePolicyHistoryBuffer) |
174 return ReturnCacheDataElseLoad; | 174 return WebCachePolicy::ReturnCacheDataElseLoad; |
175 return UseProtocolCachePolicy; | 175 return WebCachePolicy::UseProtocolCachePolicy; |
176 } | 176 } |
177 | 177 |
178 ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const R
esourceRequest& request, Resource::Type type) const | 178 WebCachePolicy FrameFetchContext::resourceRequestCachePolicy(const ResourceReque
st& request, Resource::Type type) const |
179 { | 179 { |
180 ASSERT(frame()); | 180 ASSERT(frame()); |
181 if (type == Resource::MainResource) { | 181 if (type == Resource::MainResource) { |
182 FrameLoadType frameLoadType = frame()->loader().loadType(); | 182 FrameLoadType frameLoadType = frame()->loader().loadType(); |
183 if (request.httpMethod() == "POST" && frameLoadType == FrameLoadTypeBack
Forward) | 183 if (request.httpMethod() == "POST" && frameLoadType == FrameLoadTypeBack
Forward) |
184 return ReturnCacheDataDontLoad; | 184 return WebCachePolicy::ReturnCacheDataDontLoad; |
185 if (!frame()->host()->overrideEncoding().isEmpty()) | 185 if (!frame()->host()->overrideEncoding().isEmpty()) |
186 return ReturnCacheDataElseLoad; | 186 return WebCachePolicy::ReturnCacheDataElseLoad; |
187 if (frameLoadType == FrameLoadTypeSame || request.isConditional() || req
uest.httpMethod() == "POST") | 187 if (frameLoadType == FrameLoadTypeSame || request.isConditional() || req
uest.httpMethod() == "POST") |
188 return ValidatingCacheData; | 188 return WebCachePolicy::ValidatingCacheData; |
189 | 189 |
190 for (Frame* f = frame(); f; f = f->tree().parent()) { | 190 for (Frame* f = frame(); f; f = f->tree().parent()) { |
191 if (!f->isLocalFrame()) | 191 if (!f->isLocalFrame()) |
192 continue; | 192 continue; |
193 frameLoadType = toLocalFrame(f)->loader().loadType(); | 193 frameLoadType = toLocalFrame(f)->loader().loadType(); |
194 if (frameLoadType == FrameLoadTypeBackForward) | 194 if (frameLoadType == FrameLoadTypeBackForward) |
195 return ReturnCacheDataElseLoad; | 195 return WebCachePolicy::ReturnCacheDataElseLoad; |
196 if (frameLoadType == FrameLoadTypeReloadBypassingCache) | 196 if (frameLoadType == FrameLoadTypeReloadBypassingCache) |
197 return BypassingCache; | 197 return WebCachePolicy::BypassingCache; |
198 if (frameLoadType == FrameLoadTypeReload) | 198 if (frameLoadType == FrameLoadTypeReload) |
199 return ValidatingCacheData; | 199 return WebCachePolicy::ValidatingCacheData; |
200 } | 200 } |
201 return UseProtocolCachePolicy; | 201 return WebCachePolicy::UseProtocolCachePolicy; |
202 } | 202 } |
203 | 203 |
204 // For users on slow connections, we want to avoid blocking the parser in | 204 // For users on slow connections, we want to avoid blocking the parser in |
205 // the main frame on script loads inserted via document.write, since it can | 205 // the main frame on script loads inserted via document.write, since it can |
206 // add significant delays before page content is displayed on the screen. | 206 // add significant delays before page content is displayed on the screen. |
207 // For now, as a prototype, we block fetches for main frame scripts | 207 // For now, as a prototype, we block fetches for main frame scripts |
208 // inserted via document.write as long as the | 208 // inserted via document.write as long as the |
209 // disallowFetchForDocWrittenScriptsInMainFrame setting is enabled. In the | 209 // disallowFetchForDocWrittenScriptsInMainFrame setting is enabled. In the |
210 // future, we'll extend this logic to only block if estimated network RTT | 210 // future, we'll extend this logic to only block if estimated network RTT |
211 // is above some threshold. | 211 // is above some threshold. |
212 if (type == Resource::Script && isMainFrame()) { | 212 if (type == Resource::Script && isMainFrame()) { |
213 const bool isInDocumentWrite = m_document && m_document->isInDocumentWri
te(); | 213 const bool isInDocumentWrite = m_document && m_document->isInDocumentWri
te(); |
214 const bool disallowFetchForDocWriteScripts = frame()->settings() && fram
e()->settings()->disallowFetchForDocWrittenScriptsInMainFrame(); | 214 const bool disallowFetchForDocWriteScripts = frame()->settings() && fram
e()->settings()->disallowFetchForDocWrittenScriptsInMainFrame(); |
215 if (isInDocumentWrite && disallowFetchForDocWriteScripts) | 215 if (isInDocumentWrite && disallowFetchForDocWriteScripts) |
216 return ReturnCacheDataDontLoad; | 216 return WebCachePolicy::ReturnCacheDataDontLoad; |
217 } | 217 } |
218 | 218 |
219 if (request.isConditional()) | 219 if (request.isConditional()) |
220 return ValidatingCacheData; | 220 return WebCachePolicy::ValidatingCacheData; |
221 | 221 |
222 if (m_documentLoader && m_document && !m_document->loadEventFinished()) { | 222 if (m_documentLoader && m_document && !m_document->loadEventFinished()) { |
223 // For POST requests, we mutate the main resource's cache policy to avoi
d form resubmission. | 223 // For POST requests, we mutate the main resource's cache policy to avoi
d form resubmission. |
224 // This policy should not be inherited by subresources. | 224 // This policy should not be inherited by subresources. |
225 ResourceRequestCachePolicy mainResourceCachePolicy = m_documentLoader->r
equest().getCachePolicy(); | 225 WebCachePolicy mainResourceCachePolicy = m_documentLoader->request().get
CachePolicy(); |
226 if (m_documentLoader->request().httpMethod() == "POST") { | 226 if (m_documentLoader->request().httpMethod() == "POST") { |
227 if (mainResourceCachePolicy == ReturnCacheDataDontLoad) | 227 if (mainResourceCachePolicy == WebCachePolicy::ReturnCacheDataDontLo
ad) |
228 return ReturnCacheDataElseLoad; | 228 return WebCachePolicy::ReturnCacheDataElseLoad; |
229 return UseProtocolCachePolicy; | 229 return WebCachePolicy::UseProtocolCachePolicy; |
230 } | 230 } |
231 return memoryCachePolicyToResourceRequestCachePolicy(getCachePolicy()); | 231 return memoryCachePolicyToResourceRequestCachePolicy(getCachePolicy()); |
232 } | 232 } |
233 return UseProtocolCachePolicy; | 233 return WebCachePolicy::UseProtocolCachePolicy; |
234 } | 234 } |
235 | 235 |
236 // FIXME(http://crbug.com/274173): | 236 // FIXME(http://crbug.com/274173): |
237 // |loader| can be null if the resource is loaded from imported document. | 237 // |loader| can be null if the resource is loaded from imported document. |
238 // This means inspector, which uses DocumentLoader as an grouping entity, | 238 // This means inspector, which uses DocumentLoader as an grouping entity, |
239 // cannot see imported documents. | 239 // cannot see imported documents. |
240 inline DocumentLoader* FrameFetchContext::ensureLoaderForNotifications() const | 240 inline DocumentLoader* FrameFetchContext::ensureLoaderForNotifications() const |
241 { | 241 { |
242 return m_documentLoader ? m_documentLoader.get() : frame()->loader().documen
tLoader(); | 242 return m_documentLoader ? m_documentLoader.get() : frame()->loader().documen
tLoader(); |
243 } | 243 } |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 } | 769 } |
770 | 770 |
771 DEFINE_TRACE(FrameFetchContext) | 771 DEFINE_TRACE(FrameFetchContext) |
772 { | 772 { |
773 visitor->trace(m_document); | 773 visitor->trace(m_document); |
774 visitor->trace(m_documentLoader); | 774 visitor->trace(m_documentLoader); |
775 FetchContext::trace(visitor); | 775 FetchContext::trace(visitor); |
776 } | 776 } |
777 | 777 |
778 } // namespace blink | 778 } // namespace blink |
OLD | NEW |