Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(581)

Unified Diff: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp

Issue 1957703002: This CL logs the metrics to see the impact of document.write script blocking feature. The metrics a… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 90c70752091b874fb4603c40663c661ad53aa06f..59c2d988d446e8945ae7fd6590031a87a1ac2e3a 100644
--- a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
+++ b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
@@ -90,19 +90,6 @@ bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch
if (!document.frame())
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)
- return false;
-
- const bool isSlowConnection = networkStateNotifier().connectionType() == WebConnectionTypeCellular2G;
- const bool disallowFetch = document.settings()->disallowFetchForDocWrittenScriptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections() && isSlowConnection);
- if (!disallowFetch)
- return false;
-
// Only block synchronously loaded (parser blocking) scripts.
if (defer != FetchRequest::NoDefer)
return false;
@@ -113,7 +100,27 @@ bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch
if (request.url().host() == document.getSecurityOrigin()->domain())
return false;
- return true;
+ // 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) {
+ // 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);
+
+ return disallowFetch;
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698