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 fa07761e50d8d6c459cc42e5cac64ca0082c2e14..2af9b8252a89d383d51f669d9eda3f939da144c6 100644 |
| --- a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp |
| +++ b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp |
| @@ -57,6 +57,7 @@ |
| #include "core/loader/PingLoader.h" |
| #include "core/loader/ProgressTracker.h" |
| #include "core/loader/appcache/ApplicationCacheHost.h" |
| +#include "core/page/NetworkStateNotifier.h" |
| #include "core/page/Page.h" |
| #include "core/svg/graphics/SVGImageChromeClient.h" |
| #include "core/timing/DOMWindowPerformance.h" |
| @@ -175,7 +176,7 @@ static ResourceRequestCachePolicy memoryCachePolicyToResourceRequestCachePolicy( |
| return UseProtocolCachePolicy; |
| } |
| -ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const ResourceRequest& request, Resource::Type type) const |
| +ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const ResourceRequest& request, Resource::Type type, FetchRequest::DeferOption defer) const |
| { |
| ASSERT(frame()); |
| if (type == Resource::MainResource) { |
| @@ -204,16 +205,27 @@ ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const R |
| // 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. |
| - // For now, as a prototype, we block fetches for main frame scripts |
| - // inserted via document.write as long as the |
| - // disallowFetchForDocWrittenScriptsInMainFrame setting is enabled. In the |
| - // future, we'll extend this logic to only block if estimated network RTT |
| - // is above some threshold. |
| if (type == Resource::Script && isMainFrame()) { |
| - const bool isInDocumentWrite = m_document && m_document->isInDocumentWrite(); |
| const bool disallowFetchForDocWriteScripts = frame()->settings() && frame()->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
|
| - if (isInDocumentWrite && disallowFetchForDocWriteScripts) |
| - return ReturnCacheDataDontLoad; |
| + const bool isInDocumentWrite = m_document && m_document->isInDocumentWrite(); |
| + |
| + 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 ReturnCacheDataDontLoad; |
| + } |
| } |
| if (request.isConditional()) |