| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "core/inspector/InstrumentingAgents.h" | 49 #include "core/inspector/InstrumentingAgents.h" |
| 50 #include "core/loader/DocumentLoader.h" | 50 #include "core/loader/DocumentLoader.h" |
| 51 #include "core/loader/FrameLoader.h" | 51 #include "core/loader/FrameLoader.h" |
| 52 #include "core/loader/FrameLoaderClient.h" | 52 #include "core/loader/FrameLoaderClient.h" |
| 53 #include "core/loader/LinkLoader.h" | 53 #include "core/loader/LinkLoader.h" |
| 54 #include "core/loader/MixedContentChecker.h" | 54 #include "core/loader/MixedContentChecker.h" |
| 55 #include "core/loader/NetworkHintsInterface.h" | 55 #include "core/loader/NetworkHintsInterface.h" |
| 56 #include "core/loader/PingLoader.h" | 56 #include "core/loader/PingLoader.h" |
| 57 #include "core/loader/ProgressTracker.h" | 57 #include "core/loader/ProgressTracker.h" |
| 58 #include "core/loader/appcache/ApplicationCacheHost.h" | 58 #include "core/loader/appcache/ApplicationCacheHost.h" |
| 59 #include "core/page/NetworkStateNotifier.h" |
| 59 #include "core/page/Page.h" | 60 #include "core/page/Page.h" |
| 60 #include "core/svg/graphics/SVGImageChromeClient.h" | 61 #include "core/svg/graphics/SVGImageChromeClient.h" |
| 61 #include "core/timing/DOMWindowPerformance.h" | 62 #include "core/timing/DOMWindowPerformance.h" |
| 62 #include "core/timing/Performance.h" | 63 #include "core/timing/Performance.h" |
| 63 #include "platform/Logging.h" | 64 #include "platform/Logging.h" |
| 64 #include "platform/mhtml/MHTMLArchive.h" | 65 #include "platform/mhtml/MHTMLArchive.h" |
| 65 #include "platform/network/ResourceTimingInfo.h" | 66 #include "platform/network/ResourceTimingInfo.h" |
| 66 #include "platform/weborigin/SchemeRegistry.h" | 67 #include "platform/weborigin/SchemeRegistry.h" |
| 67 #include "platform/weborigin/SecurityPolicy.h" | 68 #include "platform/weborigin/SecurityPolicy.h" |
| 68 #include "public/platform/WebFrameScheduler.h" | 69 #include "public/platform/WebFrameScheduler.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 return UseProtocolCachePolicy; | 167 return UseProtocolCachePolicy; |
| 167 if (policy == CachePolicyRevalidate) | 168 if (policy == CachePolicyRevalidate) |
| 168 return ReloadIgnoringCacheData; | 169 return ReloadIgnoringCacheData; |
| 169 if (policy == CachePolicyReload) | 170 if (policy == CachePolicyReload) |
| 170 return ReloadBypassingCache; | 171 return ReloadBypassingCache; |
| 171 if (policy == CachePolicyHistoryBuffer) | 172 if (policy == CachePolicyHistoryBuffer) |
| 172 return ReturnCacheDataElseLoad; | 173 return ReturnCacheDataElseLoad; |
| 173 return UseProtocolCachePolicy; | 174 return UseProtocolCachePolicy; |
| 174 } | 175 } |
| 175 | 176 |
| 176 ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const R
esourceRequest& request, Resource::Type type) const | 177 ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const R
esourceRequest& request, Resource::Type type, FetchRequest::DeferOption defer) c
onst |
| 177 { | 178 { |
| 178 ASSERT(frame()); | 179 ASSERT(frame()); |
| 179 if (type == Resource::MainResource) { | 180 if (type == Resource::MainResource) { |
| 180 FrameLoadType frameLoadType = frame()->loader().loadType(); | 181 FrameLoadType frameLoadType = frame()->loader().loadType(); |
| 181 if (request.httpMethod() == "POST" && frameLoadType == FrameLoadTypeBack
Forward) | 182 if (request.httpMethod() == "POST" && frameLoadType == FrameLoadTypeBack
Forward) |
| 182 return ReturnCacheDataDontLoad; | 183 return ReturnCacheDataDontLoad; |
| 183 if (!frame()->host()->overrideEncoding().isEmpty()) | 184 if (!frame()->host()->overrideEncoding().isEmpty()) |
| 184 return ReturnCacheDataElseLoad; | 185 return ReturnCacheDataElseLoad; |
| 185 if (frameLoadType == FrameLoadTypeSame || request.isConditional() || req
uest.httpMethod() == "POST") | 186 if (frameLoadType == FrameLoadTypeSame || request.isConditional() || req
uest.httpMethod() == "POST") |
| 186 return ReloadIgnoringCacheData; | 187 return ReloadIgnoringCacheData; |
| 187 | 188 |
| 188 for (Frame* f = frame(); f; f = f->tree().parent()) { | 189 for (Frame* f = frame(); f; f = f->tree().parent()) { |
| 189 if (!f->isLocalFrame()) | 190 if (!f->isLocalFrame()) |
| 190 continue; | 191 continue; |
| 191 frameLoadType = toLocalFrame(f)->loader().loadType(); | 192 frameLoadType = toLocalFrame(f)->loader().loadType(); |
| 192 if (frameLoadType == FrameLoadTypeBackForward) | 193 if (frameLoadType == FrameLoadTypeBackForward) |
| 193 return ReturnCacheDataElseLoad; | 194 return ReturnCacheDataElseLoad; |
| 194 if (frameLoadType == FrameLoadTypeReloadFromOrigin) | 195 if (frameLoadType == FrameLoadTypeReloadFromOrigin) |
| 195 return ReloadBypassingCache; | 196 return ReloadBypassingCache; |
| 196 if (frameLoadType == FrameLoadTypeReload) | 197 if (frameLoadType == FrameLoadTypeReload) |
| 197 return ReloadIgnoringCacheData; | 198 return ReloadIgnoringCacheData; |
| 198 } | 199 } |
| 199 return UseProtocolCachePolicy; | 200 return UseProtocolCachePolicy; |
| 200 } | 201 } |
| 201 | 202 |
| 202 // For users on slow connections, we want to avoid blocking the parser in | 203 // For users on slow connections, we want to avoid blocking the parser in |
| 203 // the main frame on script loads inserted via document.write, since it can | 204 // the main frame on script loads inserted via document.write, since it can |
| 204 // add significant delays before page content is displayed on the screen. | 205 // add significant delays before page content is displayed on the screen. |
| 205 // For now, as a prototype, we block fetches for main frame scripts | |
| 206 // inserted via document.write as long as the | |
| 207 // disallowFetchForDocWrittenScriptsInMainFrame setting is enabled. In the | |
| 208 // future, we'll extend this logic to only block if estimated network RTT | |
| 209 // is above some threshold. | |
| 210 if (type == Resource::Script && isMainFrame()) { | 206 if (type == Resource::Script && isMainFrame()) { |
| 207 const bool disallowFetchForDocWriteScripts = frame()->settings() && fram
e()->settings()->disallowFetchForDocWrittenScriptsInMainFrame(); |
| 211 const bool isInDocumentWrite = m_document && m_document->isInDocumentWri
te(); | 208 const bool isInDocumentWrite = m_document && m_document->isInDocumentWri
te(); |
| 212 const bool disallowFetchForDocWriteScripts = frame()->settings() && fram
e()->settings()->disallowFetchForDocWrittenScriptsInMainFrame(); | 209 |
| 213 if (isInDocumentWrite && disallowFetchForDocWriteScripts) | 210 if (isInDocumentWrite && disallowFetchForDocWriteScripts) { |
| 214 return ReturnCacheDataDontLoad; | 211 // only synchronously loaded scripts should be blocked |
| 212 const bool isSync = defer == FetchRequest::NoDefer; |
| 213 |
| 214 // Not blocking same origin scripts as they may be used to render ma
in page content |
| 215 // whereas cross-origin scripts inserted via document.write are like
ly |
| 216 // for third party content. |
| 217 const bool isThirdParty = request.url().host() != m_document->getSec
urityOrigin()->domain(); |
| 218 |
| 219 // Only blocking in slow connections where the performance penalty i
s worst case. |
| 220 // For now we restrict slow connections to 2G, in future this might
be expanded using the |
| 221 // network quality estimator. |
| 222 const bool isSlowConnection = networkStateNotifier().connectionType(
) == WebConnectionTypeCellular2G; |
| 223 |
| 224 if (isSync && isThirdParty && isSlowConnection) |
| 225 return ReturnCacheDataDontLoad; |
| 226 } |
| 215 } | 227 } |
| 216 | 228 |
| 217 if (request.isConditional()) | 229 if (request.isConditional()) |
| 218 return ReloadIgnoringCacheData; | 230 return ReloadIgnoringCacheData; |
| 219 | 231 |
| 220 if (m_documentLoader && m_document && !m_document->loadEventFinished()) { | 232 if (m_documentLoader && m_document && !m_document->loadEventFinished()) { |
| 221 // For POST requests, we mutate the main resource's cache policy to avoi
d form resubmission. | 233 // For POST requests, we mutate the main resource's cache policy to avoi
d form resubmission. |
| 222 // This policy should not be inherited by subresources. | 234 // This policy should not be inherited by subresources. |
| 223 ResourceRequestCachePolicy mainResourceCachePolicy = m_documentLoader->r
equest().getCachePolicy(); | 235 ResourceRequestCachePolicy mainResourceCachePolicy = m_documentLoader->r
equest().getCachePolicy(); |
| 224 if (m_documentLoader->request().httpMethod() == "POST") { | 236 if (m_documentLoader->request().httpMethod() == "POST") { |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 } | 818 } |
| 807 | 819 |
| 808 DEFINE_TRACE(FrameFetchContext) | 820 DEFINE_TRACE(FrameFetchContext) |
| 809 { | 821 { |
| 810 visitor->trace(m_document); | 822 visitor->trace(m_document); |
| 811 visitor->trace(m_documentLoader); | 823 visitor->trace(m_documentLoader); |
| 812 FetchContext::trace(visitor); | 824 FetchContext::trace(visitor); |
| 813 } | 825 } |
| 814 | 826 |
| 815 } // namespace blink | 827 } // namespace blink |
| OLD | NEW |