Chromium Code Reviews| Index: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp |
| diff --git a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp |
| index 5ad8728cef79d720c136425206b56954b23c7b6e..4f9bc061b2ca942cb12418c397953d9c24351b75 100644 |
| --- a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp |
| +++ b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp |
| @@ -75,6 +75,46 @@ |
| namespace blink { |
| +namespace { |
| + |
| + bool ShouldDisallowFetchForMainFrameScript(const ResourceRequest& request, FetchRequest::DeferOption defer, Document& document) |
|
kinuko
2016/04/11 13:02:27
Drive-by nit: please not indent in namespace
Bryan McQuade
2016/04/11 13:15:24
for some reason git cl format likes to add the spa
jkarlin
2016/04/11 14:52:27
const Document& ?
It looks like isInDocumentWrit
Bryan McQuade
2016/04/11 16:28:29
Done
|
| + { |
| + // Only scripts inserted via document.write are candidates for having their |
| + // fetch disallowed. |
| + if (!document.isInDocumentWrite()) { |
| + return false; |
| + } |
| + |
| + if (!document.settings()) { |
| + return false; |
| + } |
| + |
| + // Only blocking in slow connections where the performance penalty is worst |
| + // case. For now we restrict slow connections to 2G, in future this might |
| + // be expanded using the network quality estimator. |
|
jkarlin
2016/04/11 14:52:27
Not a sentence, perhaps s/Only Blocking in/Block i
Bryan McQuade
2016/04/11 16:28:30
Good call. Once I removed this part of the comment
|
| + const bool isSlowConnection = networkStateNotifier().connectionType() == WebConnectionTypeCellular2G; |
| + const bool disallowFetch = document.settings()->disallowFetchForDocWrittenScriptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections() && isSlowConnection); |
| + if (!disallowFetch) { |
| + return false; |
| + } |
| + |
| + // only synchronously loaded scripts should be blocked |
|
kinuko
2016/04/11 13:02:27
nit: only -> Only, and end comment with period
Bryan McQuade
2016/04/11 13:15:24
Done.
|
| + if (defer != FetchRequest::NoDefer) { |
| + return false; |
| + } |
| + |
| + // Not blocking same origin scripts as they may be used to render main page |
|
jkarlin
2016/04/11 14:52:27
Not a sentence, perhaps s/Not blocking/Don't block
Bryan McQuade
2016/04/11 16:28:29
Done
Bryan McQuade
2016/04/11 16:28:30
Done
|
| + // content whereas cross-origin scripts inserted via document.write are |
| + // likely to be third party content. |
| + if (request.url().host() == document.getSecurityOrigin()->domain()) { |
| + return false; |
| + } |
| + |
| + return true; |
| + } |
| + |
| +} // namespace |
| + |
| FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) |
| : m_document(document) |
| , m_documentLoader(loader) |
| @@ -205,27 +245,8 @@ WebCachePolicy FrameFetchContext::resourceRequestCachePolicy(const ResourceReque |
| // For users on slow connections, we want to avoid blocking the parser in |
| // the main frame on script loads inserted via document.write, since it can |
| // add significant delays before page content is displayed on the screen. |
| - if (type == Resource::Script && isMainFrame()) { |
| - const bool isInDocumentWrite = m_document && m_document->isInDocumentWrite(); |
| - const bool disallowFetchForDocWriteScripts = frame()->settings() && frame()->settings()->disallowFetchForDocWrittenScriptsInMainFrame(); |
| - |
| - if (isInDocumentWrite && disallowFetchForDocWriteScripts) { |
| - // only synchronously loaded scripts should be blocked |
| - const bool isSync = defer == FetchRequest::NoDefer; |
| - |
| - // Not blocking same origin scripts as they may be used to render main page content |
| - // whereas cross-origin scripts inserted via document.write are likely |
| - // for third party content. |
| - const bool isThirdParty = request.url().host() != m_document->getSecurityOrigin()->domain(); |
| - |
| - // Only blocking in slow connections where the performance penalty is worst case. |
| - // For now we restrict slow connections to 2G, in future this might be expanded using the |
| - // network quality estimator. |
| - const bool isSlowConnection = networkStateNotifier().connectionType() == WebConnectionTypeCellular2G; |
| - |
| - if (isSync && isThirdParty && isSlowConnection) |
| - return WebCachePolicy::ReturnCacheDataDontLoad; |
| - } |
| + if (type == Resource::Script && isMainFrame() && m_document && ShouldDisallowFetchForMainFrameScript(request, defer, *m_document)) { |
| + return WebCachePolicy::ReturnCacheDataDontLoad; |
| } |
| if (request.isConditional()) |