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

Side by Side 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: Update layout tests for the new console warnings 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/loading/doc-write-sync-third-party-script-reload-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 #include "platform/weborigin/SecurityPolicy.h" 71 #include "platform/weborigin/SecurityPolicy.h"
72 #include "public/platform/WebCachePolicy.h" 72 #include "public/platform/WebCachePolicy.h"
73 #include "public/platform/WebFrameScheduler.h" 73 #include "public/platform/WebFrameScheduler.h"
74 74
75 #include <algorithm> 75 #include <algorithm>
76 76
77 namespace blink { 77 namespace blink {
78 78
79 namespace { 79 namespace {
80 80
81 void emitWarningForDocWriteScripts(const String& url, const Document& document)
82 {
83 String message = "A Parser-blocking, cross-origin script " + url + " is invo ked via document.write. This may get blocked by the browser in slow connections. It is recommended to invoke this script asynchronously.";
jkarlin 2016/06/10 18:38:36 There should also be a link to a help page explain
jkarlin 2016/06/10 18:38:36 Commas needed around the url. s/may get blocked/m
shivanisha 2016/06/20 14:28:06 Created https://bugs.chromium.org/p/chromium/issue
84 const_cast <Document &>(document).addConsoleMessage(ConsoleMessage::create(J SMessageSource, WarningMessageLevel, message));
Nate Chapin 2016/06/10 23:34:32 Nit: Pass the Document non-const instead of const_
shivanisha 2016/06/20 14:28:06 done.
85 WTFLogAlways("%s", message.utf8().data());
86 }
87
81 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch Request::DeferOption defer, const Document& document) 88 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch Request::DeferOption defer, const Document& document)
82 { 89 {
83 // Only scripts inserted via document.write are candidates for having their 90 // Only scripts inserted via document.write are candidates for having their
84 // fetch disallowed. 91 // fetch disallowed.
85 if (!document.isInDocumentWrite()) 92 if (!document.isInDocumentWrite())
86 return false; 93 return false;
87 94
88 if (!document.settings()) 95 if (!document.settings())
89 return false; 96 return false;
90 97
(...skipping 15 matching lines...) Expand all
106 113
107 // Do not block scripts if it is a page reload. This is to enable pages to 114 // Do not block scripts if it is a page reload. This is to enable pages to
108 // recover if blocking of a script is leading to a page break and the user 115 // recover if blocking of a script is leading to a page break and the user
109 // reloads the page. 116 // reloads the page.
110 const FrameLoadType loadType = document.frame()->loader().loadType(); 117 const FrameLoadType loadType = document.frame()->loader().loadType();
111 const bool isReload = loadType == FrameLoadTypeReload || loadType == FrameLo adTypeReloadBypassingCache || loadType == FrameLoadTypeReloadMainResource; 118 const bool isReload = loadType == FrameLoadTypeReload || loadType == FrameLo adTypeReloadBypassingCache || loadType == FrameLoadTypeReloadMainResource;
112 if (isReload) { 119 if (isReload) {
113 // Recording this metric since an increase in number of reloads for page s 120 // Recording this metric since an increase in number of reloads for page s
114 // where a script was blocked could be indicative of a page break. 121 // where a script was blocked could be indicative of a page break.
115 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web LoadingBehaviorDocumentWriteBlockReload); 122 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web LoadingBehaviorDocumentWriteBlockReload);
123 emitWarningForDocWriteScripts(request.url().getString(), document);
116 return false; 124 return false;
117 } 125 }
118 126
119 // Add the metadata that this page has scripts inserted via document.write 127 // Add the metadata that this page has scripts inserted via document.write
120 // that are eligible for blocking. Note that if there are multiple scripts 128 // that are eligible for blocking. Note that if there are multiple scripts
121 // the flag will be conveyed to the browser process only once. 129 // the flag will be conveyed to the browser process only once.
122 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoad ingBehaviorDocumentWriteBlock); 130 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoad ingBehaviorDocumentWriteBlock);
123 131
132 emitWarningForDocWriteScripts(request.url().getString(), document);
133
124 const bool isSlowConnection = networkStateNotifier().connectionType() == Web ConnectionTypeCellular2G; 134 const bool isSlowConnection = networkStateNotifier().connectionType() == Web ConnectionTypeCellular2G;
125 const bool disallowFetch = document.settings()->disallowFetchForDocWrittenSc riptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInM ainFrameOnSlowConnections() && isSlowConnection); 135 const bool disallowFetch = document.settings()->disallowFetchForDocWrittenSc riptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInM ainFrameOnSlowConnections() && isSlowConnection);
126 136
127 return disallowFetch; 137 return disallowFetch;
128 } 138 }
129 139
130 } // namespace 140 } // namespace
131 141
132 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) 142 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document)
133 : m_document(document) 143 : m_document(document)
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 } 767 }
758 768
759 DEFINE_TRACE(FrameFetchContext) 769 DEFINE_TRACE(FrameFetchContext)
760 { 770 {
761 visitor->trace(m_document); 771 visitor->trace(m_document);
762 visitor->trace(m_documentLoader); 772 visitor->trace(m_documentLoader);
763 FetchContext::trace(visitor); 773 FetchContext::trace(visitor);
764 } 774 }
765 775
766 } // namespace blink 776 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/loading/doc-write-sync-third-party-script-reload-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698