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

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

Issue 2279543004: [DocWriteBlocking] Add feature to block doc.written scripts if 2g-like network (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added helper method: isConnectionEffectively2G Created 4 years, 3 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 93725dc7081a5f72a128d1e95155e97cef7e3f11..17fc24d3db3ad742528fd44ce22159bcb56d7bf5 100644
--- a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
+++ b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
@@ -89,6 +89,22 @@ void emitWarningForDocWriteScripts(const String& url, Document& document)
WTFLogAlways("%s", message.utf8().data());
}
+bool isConnectionEffectively2G(WebEffectiveConnectionType effectiveType)
+{
+ switch (effectiveType) {
+ case WebEffectiveConnectionType::TypeSlow2G:
+ case WebEffectiveConnectionType::Type2G:
+ return true;
+ case WebEffectiveConnectionType::Type3G:
+ case WebEffectiveConnectionType::Type4G:
+ case WebEffectiveConnectionType::TypeUnknown:
+ case WebEffectiveConnectionType::TypeOffline:
+ return false;
+ }
+ NOTREACHED();
+ return false;
+}
+
bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, FetchRequest::DeferOption defer, Document& document)
{
// Only scripts inserted via document.write are candidates for having their
@@ -146,10 +162,11 @@ bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch
// 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);
+ const bool is2G = networkStateNotifier().connectionType() == WebConnectionTypeCellular2G;
+ WebEffectiveConnectionType effectiveConnection = document.frame()->loader().client()->getEffectiveConnectionType();
+ const bool is2GOrLike2G = is2G || isConnectionEffectively2G(effectiveConnection);
- return disallowFetch;
+ return document.settings()->disallowFetchForDocWrittenScriptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections() && is2G) || (RuntimeEnabledFeatures::blockDocWriteIfEffectively2GEnabled() && is2GOrLike2G);
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698