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

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: fixed layout tests. 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #include "public/platform/WebDocumentSubresourceFilter.h" 73 #include "public/platform/WebDocumentSubresourceFilter.h"
74 #include "public/platform/WebFrameScheduler.h" 74 #include "public/platform/WebFrameScheduler.h"
75 #include "public/platform/WebInsecureRequestPolicy.h" 75 #include "public/platform/WebInsecureRequestPolicy.h"
76 76
77 #include <algorithm> 77 #include <algorithm>
78 78
79 namespace blink { 79 namespace blink {
80 80
81 namespace { 81 namespace {
82 82
83 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch Request::DeferOption defer, const Document& document) 83 void emitWarningForDocWriteScripts(const String& url, Document& document)
84 {
85 String message = "A Parser-blocking, cross-origin script, " + url + ", is in voked via document.write. This may be blocked by the browser if the device has p oor network connectivity.";
86 document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMe ssageLevel, message));
87 WTFLogAlways("%s", message.utf8().data());
88 }
89
90 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch Request::DeferOption defer, Document& document)
84 { 91 {
85 // Only scripts inserted via document.write are candidates for having their 92 // Only scripts inserted via document.write are candidates for having their
86 // fetch disallowed. 93 // fetch disallowed.
87 if (!document.isInDocumentWrite()) 94 if (!document.isInDocumentWrite())
88 return false; 95 return false;
89 96
90 if (!document.settings()) 97 if (!document.settings())
91 return false; 98 return false;
92 99
93 if (!document.frame()) 100 if (!document.frame())
(...skipping 14 matching lines...) Expand all
108 115
109 // Do not block scripts if it is a page reload. This is to enable pages to 116 // Do not block scripts if it is a page reload. This is to enable pages to
110 // recover if blocking of a script is leading to a page break and the user 117 // recover if blocking of a script is leading to a page break and the user
111 // reloads the page. 118 // reloads the page.
112 const FrameLoadType loadType = document.frame()->loader().loadType(); 119 const FrameLoadType loadType = document.frame()->loader().loadType();
113 const bool isReload = loadType == FrameLoadTypeReload || loadType == FrameLo adTypeReloadBypassingCache || loadType == FrameLoadTypeReloadMainResource; 120 const bool isReload = loadType == FrameLoadTypeReload || loadType == FrameLo adTypeReloadBypassingCache || loadType == FrameLoadTypeReloadMainResource;
114 if (isReload) { 121 if (isReload) {
115 // Recording this metric since an increase in number of reloads for page s 122 // Recording this metric since an increase in number of reloads for page s
116 // where a script was blocked could be indicative of a page break. 123 // where a script was blocked could be indicative of a page break.
117 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web LoadingBehaviorDocumentWriteBlockReload); 124 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web LoadingBehaviorDocumentWriteBlockReload);
125 emitWarningForDocWriteScripts(request.url().getString(), document);
jkarlin 2016/06/23 11:20:41 no need to have two emitWarning calls. Can just ha
shivanisha 2016/06/23 13:56:04 done.
118 return false; 126 return false;
119 } 127 }
120 128
121 // Add the metadata that this page has scripts inserted via document.write 129 // Add the metadata that this page has scripts inserted via document.write
122 // that are eligible for blocking. Note that if there are multiple scripts 130 // that are eligible for blocking. Note that if there are multiple scripts
123 // the flag will be conveyed to the browser process only once. 131 // the flag will be conveyed to the browser process only once.
124 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoad ingBehaviorDocumentWriteBlock); 132 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoad ingBehaviorDocumentWriteBlock);
125 133
134 emitWarningForDocWriteScripts(request.url().getString(), document);
135
126 const bool isSlowConnection = networkStateNotifier().connectionType() == Web ConnectionTypeCellular2G; 136 const bool isSlowConnection = networkStateNotifier().connectionType() == Web ConnectionTypeCellular2G;
127 const bool disallowFetch = document.settings()->disallowFetchForDocWrittenSc riptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInM ainFrameOnSlowConnections() && isSlowConnection); 137 const bool disallowFetch = document.settings()->disallowFetchForDocWrittenSc riptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInM ainFrameOnSlowConnections() && isSlowConnection);
128 138
129 return disallowFetch; 139 return disallowFetch;
130 } 140 }
131 141
132 } // namespace 142 } // namespace
133 143
134 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) 144 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document)
135 : m_document(document) 145 : m_document(document)
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 } 783 }
774 784
775 DEFINE_TRACE(FrameFetchContext) 785 DEFINE_TRACE(FrameFetchContext)
776 { 786 {
777 visitor->trace(m_document); 787 visitor->trace(m_document);
778 visitor->trace(m_documentLoader); 788 visitor->trace(m_documentLoader);
779 FetchContext::trace(visitor); 789 FetchContext::trace(visitor);
780 } 790 }
781 791
782 } // namespace blink 792 } // 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