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

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

Issue 2338623004: Add Blink setting to block doc.written scripts on 2g-like networks (Closed)
Patch Set: Update test results after rebase 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
« no previous file with comments | « third_party/WebKit/Source/core/frame/Settings.in ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7f00bb8b4e5b0c68e556a8a7bf565316b802fac1..cdb2273d41aecea9346acce5f7b8715fd5a2c054 100644
--- a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
+++ b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
@@ -88,6 +88,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
@@ -145,10 +161,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) || (document.settings()->disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G() && is2GOrLike2G);
}
} // namespace
« no previous file with comments | « third_party/WebKit/Source/core/frame/Settings.in ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698