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 UseProtocolCachePolicy; | 169 return UseProtocolCachePolicy; |
169 if (policy == CachePolicyRevalidate) | 170 if (policy == CachePolicyRevalidate) |
170 return ValidatingCacheData; | 171 return ValidatingCacheData; |
171 if (policy == CachePolicyReload) | 172 if (policy == CachePolicyReload) |
172 return BypassingCache; | 173 return BypassingCache; |
173 if (policy == CachePolicyHistoryBuffer) | 174 if (policy == CachePolicyHistoryBuffer) |
174 return ReturnCacheDataElseLoad; | 175 return ReturnCacheDataElseLoad; |
175 return UseProtocolCachePolicy; | 176 return UseProtocolCachePolicy; |
176 } | 177 } |
177 | 178 |
178 ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const R esourceRequest& request, Resource::Type type) const | 179 ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const R esourceRequest& request, Resource::Type type, FetchRequest::DeferOption defer) c onst |
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 ReturnCacheDataDontLoad; | 185 return ReturnCacheDataDontLoad; |
185 if (!frame()->host()->overrideEncoding().isEmpty()) | 186 if (!frame()->host()->overrideEncoding().isEmpty()) |
186 return ReturnCacheDataElseLoad; | 187 return ReturnCacheDataElseLoad; |
187 if (frameLoadType == FrameLoadTypeSame || request.isConditional() || req uest.httpMethod() == "POST") | 188 if (frameLoadType == FrameLoadTypeSame || request.isConditional() || req uest.httpMethod() == "POST") |
188 return ValidatingCacheData; | 189 return 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 ReturnCacheDataElseLoad; | 196 return ReturnCacheDataElseLoad; |
196 if (frameLoadType == FrameLoadTypeReloadBypassingCache) | 197 if (frameLoadType == FrameLoadTypeReloadBypassingCache) |
197 return BypassingCache; | 198 return BypassingCache; |
198 if (frameLoadType == FrameLoadTypeReload) | 199 if (frameLoadType == FrameLoadTypeReload) |
199 return ValidatingCacheData; | 200 return ValidatingCacheData; |
200 } | 201 } |
201 return UseProtocolCachePolicy; | 202 return 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()) { |
209 const bool disallowFetchForDocWriteScripts = frame()->settings() && fram e()->settings()->disallowFetchForDocWrittenScriptsInMainFrame(); | |
Nate Chapin
2016/04/07 16:25:48
Why did this move?
shivanisha
2016/04/08 14:54:32
Moving it back in order to have less diffs
| |
213 const bool isInDocumentWrite = m_document && m_document->isInDocumentWri te(); | 210 const bool isInDocumentWrite = m_document && m_document->isInDocumentWri te(); |
214 const bool disallowFetchForDocWriteScripts = frame()->settings() && fram e()->settings()->disallowFetchForDocWrittenScriptsInMainFrame(); | 211 |
215 if (isInDocumentWrite && disallowFetchForDocWriteScripts) | 212 if (isInDocumentWrite && disallowFetchForDocWriteScripts) { |
216 return ReturnCacheDataDontLoad; | 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 ReturnCacheDataDontLoad; | |
228 } | |
217 } | 229 } |
218 | 230 |
219 if (request.isConditional()) | 231 if (request.isConditional()) |
220 return ValidatingCacheData; | 232 return 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 ResourceRequestCachePolicy mainResourceCachePolicy = m_documentLoader->r equest().getCachePolicy(); | 237 ResourceRequestCachePolicy mainResourceCachePolicy = m_documentLoader->r equest().getCachePolicy(); |
226 if (m_documentLoader->request().httpMethod() == "POST") { | 238 if (m_documentLoader->request().httpMethod() == "POST") { |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
821 } | 833 } |
822 | 834 |
823 DEFINE_TRACE(FrameFetchContext) | 835 DEFINE_TRACE(FrameFetchContext) |
824 { | 836 { |
825 visitor->trace(m_document); | 837 visitor->trace(m_document); |
826 visitor->trace(m_documentLoader); | 838 visitor->trace(m_documentLoader); |
827 FetchContext::trace(visitor); | 839 FetchContext::trace(visitor); |
828 } | 840 } |
829 | 841 |
830 } // namespace blink | 842 } // namespace blink |
OLD | NEW |