| 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 f040553594f41cd97ae0e4d1ae27be96348e4b53..ecec2b6e2b4022eab84fd7cc138b6ff38bd25bbf 100644
|
| --- a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
|
| +++ b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
|
| @@ -56,6 +56,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"
|
| @@ -173,7 +174,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) {
|
| @@ -202,16 +203,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();
|
| - 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())
|
|
|