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 f2cbded4f2adefc8f3706cb283e862b355a7fc52..f4cc514ba74c71905f196abd876dbc0570ee0171 100644 |
| --- a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp |
| +++ b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp |
| @@ -89,29 +89,38 @@ bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch |
| if (!document.frame()) |
| return false; |
| + // Only block synchronously loaded (parser blocking) scripts. |
| + if (defer != FetchRequest::NoDefer) |
| + return false; |
| + |
| + // Avoid blocking same origin scripts, as they may be used to render main |
| + // page 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; |
| + |
| // Do not block scripts if it is a page reload. This is to enable pages to |
| // recover if blocking of a script is leading to a page break and the user |
| // reloads the page. |
| const FrameLoadType loadType = document.frame()->loader().loadType(); |
| - const bool isReload = (loadType == FrameLoadTypeReload || loadType == FrameLoadTypeReloadBypassingCache || loadType == FrameLoadTypeSame); |
| - if (isReload) |
| + const bool isReload = loadType == FrameLoadTypeReload || loadType == FrameLoadTypeReloadBypassingCache || loadType == FrameLoadTypeSame; |
| + if (isReload) { |
| + // Recording this metric since an increase in number of reloads for pages |
| + // where a script was blocked could be indicative of a page break. |
| + document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoadingBehaviorDocumentWriteBlockReload); |
| return false; |
| + } |
| + |
| + // Add the metadata that this page has scripts inserted via document.write |
| + // that are eligible for blocking. Note that if there are multiple scripts |
| + // the flag will be conveyed to the browser process only once. |
| + document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoadingBehaviorDocumentWriteBlock); |
| const bool isSlowConnection = networkStateNotifier().connectionType() == WebConnectionTypeCellular2G; |
| const bool disallowFetch = document.settings()->disallowFetchForDocWrittenScriptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections() && isSlowConnection); |
| if (!disallowFetch) |
|
Bryan McQuade
2016/05/03 20:22:48
this could be updated to just
return disallowFetch
|
| return false; |
| - // Only block synchronously loaded (parser blocking) scripts. |
| - if (defer != FetchRequest::NoDefer) |
| - return false; |
| - |
| - // Avoid blocking same origin scripts, as they may be used to render main |
| - // page 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; |
| } |