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

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

Issue 1868413002: Add about:flags support for doc.write script blocking. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 5ad8728cef79d720c136425206b56954b23c7b6e..ebe2f4fbb4e99fcf27dc6c1d1dcf972b7a71547b 100644
--- a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
+++ b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
@@ -75,6 +75,49 @@
namespace blink {
+namespace {
+
+bool ShouldDisallowFetchForMainFrameScript(const ResourceRequest& request, FetchRequest::DeferOption defer, Document& document)
shivanisha 2016/04/11 14:26:56 const Document&
Bryan McQuade 2016/04/11 16:28:30 Done. I had to make Document::isInDocumentWrite a
+{
+ // Only scripts inserted via document.write are candidates for having their
+ // fetch disallowed.
+ if (!document.isInDocumentWrite()) {
+ return false;
+ }
+
+ if (!document.settings()) {
+ return false;
+ }
+
+ // By default, only block on 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. Additionally, if
+ // the disallowFetchForDocWrittenScriptsInMainFrame setting is specified,
+ // block regardless of connection type. This setting is intended for testing
+ // out doc.write script blocking without having to be on a slow connection.
+ const bool isSlowConnection = networkStateNotifier().connectionType() == WebConnectionTypeCellular2G;
+ const bool disallowFetch = document.settings()->disallowFetchForDocWrittenScriptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections() && isSlowConnection);
shivanisha 2016/04/11 14:26:56 do frame()->settings() and document.settings() alw
Bryan McQuade 2016/04/11 16:28:30 Yeah - Document::settings is implemented as: Setti
+ if (!disallowFetch) {
+ return false;
+ }
+
+ // Only block synchronously loaded scripts.
+ if (defer != FetchRequest::NoDefer) {
+ return false;
+ }
+
+ // 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 to be third party content.
+ if (request.url().host() == document.getSecurityOrigin()->domain()) {
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace
+
FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document)
: m_document(document)
, m_documentLoader(loader)
@@ -205,27 +248,8 @@ WebCachePolicy FrameFetchContext::resourceRequestCachePolicy(const ResourceReque
// 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.
- if (type == Resource::Script && isMainFrame()) {
- const bool isInDocumentWrite = m_document && m_document->isInDocumentWrite();
- const bool disallowFetchForDocWriteScripts = frame()->settings() && frame()->settings()->disallowFetchForDocWrittenScriptsInMainFrame();
-
- 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 WebCachePolicy::ReturnCacheDataDontLoad;
- }
+ if (type == Resource::Script && isMainFrame() && m_document && ShouldDisallowFetchForMainFrameScript(request, defer, *m_document)) {
+ return WebCachePolicy::ReturnCacheDataDontLoad;
}
if (request.isConditional())

Powered by Google App Engine
This is Rietveld 408576698