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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 #include "core/inspector/InstrumentingAgents.h" | 50 #include "core/inspector/InstrumentingAgents.h" |
51 #include "core/loader/DocumentLoader.h" | 51 #include "core/loader/DocumentLoader.h" |
52 #include "core/loader/FrameLoader.h" | 52 #include "core/loader/FrameLoader.h" |
53 #include "core/loader/FrameLoaderClient.h" | 53 #include "core/loader/FrameLoaderClient.h" |
54 #include "core/loader/LinkLoader.h" | 54 #include "core/loader/LinkLoader.h" |
55 #include "core/loader/MixedContentChecker.h" | 55 #include "core/loader/MixedContentChecker.h" |
56 #include "core/loader/NetworkHintsInterface.h" | 56 #include "core/loader/NetworkHintsInterface.h" |
57 #include "core/loader/PingLoader.h" | 57 #include "core/loader/PingLoader.h" |
58 #include "core/loader/ProgressTracker.h" | 58 #include "core/loader/ProgressTracker.h" |
59 #include "core/loader/appcache/ApplicationCacheHost.h" | 59 #include "core/loader/appcache/ApplicationCacheHost.h" |
| 60 #include "core/page/NetworkStateNotifier.h" |
60 #include "core/page/Page.h" | 61 #include "core/page/Page.h" |
61 #include "core/svg/graphics/SVGImageChromeClient.h" | 62 #include "core/svg/graphics/SVGImageChromeClient.h" |
62 #include "core/timing/DOMWindowPerformance.h" | 63 #include "core/timing/DOMWindowPerformance.h" |
63 #include "core/timing/Performance.h" | 64 #include "core/timing/Performance.h" |
64 #include "platform/Logging.h" | 65 #include "platform/Logging.h" |
65 #include "platform/TracedValue.h" | 66 #include "platform/TracedValue.h" |
66 #include "platform/mhtml/MHTMLArchive.h" | 67 #include "platform/mhtml/MHTMLArchive.h" |
67 #include "platform/network/ResourceTimingInfo.h" | 68 #include "platform/network/ResourceTimingInfo.h" |
68 #include "platform/weborigin/SchemeRegistry.h" | 69 #include "platform/weborigin/SchemeRegistry.h" |
69 #include "platform/weborigin/SecurityPolicy.h" | 70 #include "platform/weborigin/SecurityPolicy.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return WebCachePolicy::UseProtocolCachePolicy; | 169 return WebCachePolicy::UseProtocolCachePolicy; |
169 if (policy == CachePolicyRevalidate) | 170 if (policy == CachePolicyRevalidate) |
170 return WebCachePolicy::ValidatingCacheData; | 171 return WebCachePolicy::ValidatingCacheData; |
171 if (policy == CachePolicyReload) | 172 if (policy == CachePolicyReload) |
172 return WebCachePolicy::BypassingCache; | 173 return WebCachePolicy::BypassingCache; |
173 if (policy == CachePolicyHistoryBuffer) | 174 if (policy == CachePolicyHistoryBuffer) |
174 return WebCachePolicy::ReturnCacheDataElseLoad; | 175 return WebCachePolicy::ReturnCacheDataElseLoad; |
175 return WebCachePolicy::UseProtocolCachePolicy; | 176 return WebCachePolicy::UseProtocolCachePolicy; |
176 } | 177 } |
177 | 178 |
178 WebCachePolicy FrameFetchContext::resourceRequestCachePolicy(const ResourceReque
st& request, Resource::Type type) const | 179 WebCachePolicy FrameFetchContext::resourceRequestCachePolicy(const ResourceReque
st& request, Resource::Type type, FetchRequest::DeferOption defer) const |
179 { | 180 { |
180 ASSERT(frame()); | 181 ASSERT(frame()); |
181 if (type == Resource::MainResource) { | 182 if (type == Resource::MainResource) { |
182 FrameLoadType frameLoadType = frame()->loader().loadType(); | 183 FrameLoadType frameLoadType = frame()->loader().loadType(); |
183 if (request.httpMethod() == "POST" && frameLoadType == FrameLoadTypeBack
Forward) | 184 if (request.httpMethod() == "POST" && frameLoadType == FrameLoadTypeBack
Forward) |
184 return WebCachePolicy::ReturnCacheDataDontLoad; | 185 return WebCachePolicy::ReturnCacheDataDontLoad; |
185 if (!frame()->host()->overrideEncoding().isEmpty()) | 186 if (!frame()->host()->overrideEncoding().isEmpty()) |
186 return WebCachePolicy::ReturnCacheDataElseLoad; | 187 return WebCachePolicy::ReturnCacheDataElseLoad; |
187 if (frameLoadType == FrameLoadTypeSame || request.isConditional() || req
uest.httpMethod() == "POST") | 188 if (frameLoadType == FrameLoadTypeSame || request.isConditional() || req
uest.httpMethod() == "POST") |
188 return WebCachePolicy::ValidatingCacheData; | 189 return WebCachePolicy::ValidatingCacheData; |
189 | 190 |
190 for (Frame* f = frame(); f; f = f->tree().parent()) { | 191 for (Frame* f = frame(); f; f = f->tree().parent()) { |
191 if (!f->isLocalFrame()) | 192 if (!f->isLocalFrame()) |
192 continue; | 193 continue; |
193 frameLoadType = toLocalFrame(f)->loader().loadType(); | 194 frameLoadType = toLocalFrame(f)->loader().loadType(); |
194 if (frameLoadType == FrameLoadTypeBackForward) | 195 if (frameLoadType == FrameLoadTypeBackForward) |
195 return WebCachePolicy::ReturnCacheDataElseLoad; | 196 return WebCachePolicy::ReturnCacheDataElseLoad; |
196 if (frameLoadType == FrameLoadTypeReloadBypassingCache) | 197 if (frameLoadType == FrameLoadTypeReloadBypassingCache) |
197 return WebCachePolicy::BypassingCache; | 198 return WebCachePolicy::BypassingCache; |
198 if (frameLoadType == FrameLoadTypeReload) | 199 if (frameLoadType == FrameLoadTypeReload) |
199 return WebCachePolicy::ValidatingCacheData; | 200 return WebCachePolicy::ValidatingCacheData; |
200 } | 201 } |
201 return WebCachePolicy::UseProtocolCachePolicy; | 202 return WebCachePolicy::UseProtocolCachePolicy; |
202 } | 203 } |
203 | 204 |
204 // For users on slow connections, we want to avoid blocking the parser in | 205 // 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 | 206 // 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. | 207 // add significant delays before page content is displayed on the screen. |
207 // For now, as a prototype, we block fetches for main frame scripts | |
208 // inserted via document.write as long as the | |
209 // disallowFetchForDocWrittenScriptsInMainFrame setting is enabled. In the | |
210 // future, we'll extend this logic to only block if estimated network RTT | |
211 // is above some threshold. | |
212 if (type == Resource::Script && isMainFrame()) { | 208 if (type == Resource::Script && isMainFrame()) { |
213 const bool isInDocumentWrite = m_document && m_document->isInDocumentWri
te(); | 209 const bool isInDocumentWrite = m_document && m_document->isInDocumentWri
te(); |
214 const bool disallowFetchForDocWriteScripts = frame()->settings() && fram
e()->settings()->disallowFetchForDocWrittenScriptsInMainFrame(); | 210 const bool disallowFetchForDocWriteScripts = frame()->settings() && fram
e()->settings()->disallowFetchForDocWrittenScriptsInMainFrame(); |
215 if (isInDocumentWrite && disallowFetchForDocWriteScripts) | 211 |
216 return WebCachePolicy::ReturnCacheDataDontLoad; | 212 if (isInDocumentWrite && disallowFetchForDocWriteScripts) { |
| 213 // only synchronously loaded scripts should be blocked |
| 214 const bool isSync = defer == FetchRequest::NoDefer; |
| 215 |
| 216 // Not blocking same origin scripts as they may be used to render ma
in page content |
| 217 // whereas cross-origin scripts inserted via document.write are like
ly |
| 218 // for third party content. |
| 219 const bool isThirdParty = request.url().host() != m_document->getSec
urityOrigin()->domain(); |
| 220 |
| 221 // Only blocking in slow connections where the performance penalty i
s worst case. |
| 222 // For now we restrict slow connections to 2G, in future this might
be expanded using the |
| 223 // network quality estimator. |
| 224 const bool isSlowConnection = networkStateNotifier().connectionType(
) == WebConnectionTypeCellular2G; |
| 225 |
| 226 if (isSync && isThirdParty && isSlowConnection) |
| 227 return WebCachePolicy::ReturnCacheDataDontLoad; |
| 228 } |
217 } | 229 } |
218 | 230 |
219 if (request.isConditional()) | 231 if (request.isConditional()) |
220 return WebCachePolicy::ValidatingCacheData; | 232 return WebCachePolicy::ValidatingCacheData; |
221 | 233 |
222 if (m_documentLoader && m_document && !m_document->loadEventFinished()) { | 234 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. | 235 // 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. | 236 // This policy should not be inherited by subresources. |
225 WebCachePolicy mainResourceCachePolicy = m_documentLoader->request().get
CachePolicy(); | 237 WebCachePolicy mainResourceCachePolicy = m_documentLoader->request().get
CachePolicy(); |
226 if (m_documentLoader->request().httpMethod() == "POST") { | 238 if (m_documentLoader->request().httpMethod() == "POST") { |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 } | 781 } |
770 | 782 |
771 DEFINE_TRACE(FrameFetchContext) | 783 DEFINE_TRACE(FrameFetchContext) |
772 { | 784 { |
773 visitor->trace(m_document); | 785 visitor->trace(m_document); |
774 visitor->trace(m_documentLoader); | 786 visitor->trace(m_documentLoader); |
775 FetchContext::trace(visitor); | 787 FetchContext::trace(visitor); |
776 } | 788 } |
777 | 789 |
778 } // namespace blink | 790 } // namespace blink |
OLD | NEW |