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

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

Issue 2045313003: Dev tools warning and console warning for document.write script blocking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/loader/FrameFetchContext.h ('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 c08ee5f31a0503f3eaff2cf213ad4023c961e87e..a1dff2a3b909478411e4faa936f6eddc4d6ca9a2 100644
--- a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
+++ b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
@@ -76,19 +76,24 @@
namespace blink {
-namespace {
+void FrameFetchContext::emitWarningForDocWriteScripts(const String& url) const
Nate Chapin 2016/06/09 23:44:44 Maybe take the a const Document& here and keep thi
+{
+ String message = "A Parser-blocking, cross-origin script " + url + " is invoked via document.write. This may get blocked by the browser in slow connections. It is recommended to invoke this script asynchronously.";
+ addConsoleMessage(message, WarningMessageLevel);
Nate Chapin 2016/06/09 23:44:44 Call frame()->document()->addConsoleMessage() dire
shivanisha 2016/06/10 14:41:01 Sounds good. Made these changes.
+ WTFLogAlways("%s", message.utf8().data());
+}
-bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, FetchRequest::DeferOption defer, const Document& document)
+bool FrameFetchContext::shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, FetchRequest::DeferOption defer) const
{
// Only scripts inserted via document.write are candidates for having their
// fetch disallowed.
- if (!document.isInDocumentWrite())
+ if (!m_document->isInDocumentWrite())
return false;
- if (!document.settings())
+ if (!m_document->settings())
return false;
- if (!document.frame())
+ if (!m_document->frame())
return false;
// Only block synchronously loaded (parser blocking) scripts.
@@ -101,34 +106,34 @@ bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch
// 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())
+ if (request.url().host() == m_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 FrameLoadType loadType = m_document->frame()->loader().loadType();
const bool isReload = loadType == FrameLoadTypeReload || loadType == FrameLoadTypeReloadBypassingCache || loadType == FrameLoadTypeReloadMainResource;
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);
+ m_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);
+ m_document->loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoadingBehaviorDocumentWriteBlock);
+
+ emitWarningForDocWriteScripts(request.url().getString());
const bool isSlowConnection = networkStateNotifier().connectionType() == WebConnectionTypeCellular2G;
- const bool disallowFetch = document.settings()->disallowFetchForDocWrittenScriptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections() && isSlowConnection);
+ const bool disallowFetch = m_document->settings()->disallowFetchForDocWrittenScriptsInMainFrame() || (m_document->settings()->disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections() && isSlowConnection);
return disallowFetch;
}
-} // namespace
-
FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document)
: m_document(document)
, m_documentLoader(loader)
@@ -258,7 +263,7 @@ 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() && m_document && shouldDisallowFetchForMainFrameScript(request, defer, *m_document))
+ if (type == Resource::Script && isMainFrame() && m_document && shouldDisallowFetchForMainFrameScript(request, defer))
return WebCachePolicy::ReturnCacheDataDontLoad;
if (request.isConditional())
@@ -632,6 +637,12 @@ void FrameFetchContext::sendImagePing(const KURL& url)
PingLoader::loadImage(frame(), url);
}
+void FrameFetchContext::addConsoleMessage(const String& message, MessageLevel level) const
+{
+ if (frame()->document())
+ frame()->document()->addConsoleMessage(ConsoleMessage::create(JSMessageSource, level, message));
+}
+
void FrameFetchContext::addConsoleMessage(const String& message) const
{
if (frame()->document())
« no previous file with comments | « third_party/WebKit/Source/core/loader/FrameFetchContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698