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

Side by Side 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, 2 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/Source/core/frame/Settings.in ('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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 namespace { 82 namespace {
83 83
84 void emitWarningForDocWriteScripts(const String& url, Document& document) 84 void emitWarningForDocWriteScripts(const String& url, Document& document)
85 { 85 {
86 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. See https://www.chromestatus.com/feature/5718547946799 104 for more details."; 86 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. See https://www.chromestatus.com/feature/5718547946799 104 for more details.";
87 document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMe ssageLevel, message)); 87 document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMe ssageLevel, message));
88 WTFLogAlways("%s", message.utf8().data()); 88 WTFLogAlways("%s", message.utf8().data());
89 } 89 }
90 90
91 bool isConnectionEffectively2G(WebEffectiveConnectionType effectiveType)
92 {
93 switch (effectiveType) {
94 case WebEffectiveConnectionType::TypeSlow2G:
95 case WebEffectiveConnectionType::Type2G:
96 return true;
97 case WebEffectiveConnectionType::Type3G:
98 case WebEffectiveConnectionType::Type4G:
99 case WebEffectiveConnectionType::TypeUnknown:
100 case WebEffectiveConnectionType::TypeOffline:
101 return false;
102 }
103 NOTREACHED();
104 return false;
105 }
106
91 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch Request::DeferOption defer, Document& document) 107 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch Request::DeferOption defer, Document& document)
92 { 108 {
93 // Only scripts inserted via document.write are candidates for having their 109 // Only scripts inserted via document.write are candidates for having their
94 // fetch disallowed. 110 // fetch disallowed.
95 if (!document.isInDocumentWrite()) 111 if (!document.isInDocumentWrite())
96 return false; 112 return false;
97 113
98 if (!document.settings()) 114 if (!document.settings())
99 return false; 115 return false;
100 116
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // where a script was blocked could be indicative of a page break. 154 // where a script was blocked could be indicative of a page break.
139 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web LoadingBehaviorDocumentWriteBlockReload); 155 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web LoadingBehaviorDocumentWriteBlockReload);
140 return false; 156 return false;
141 } 157 }
142 158
143 // Add the metadata that this page has scripts inserted via document.write 159 // Add the metadata that this page has scripts inserted via document.write
144 // that are eligible for blocking. Note that if there are multiple scripts 160 // that are eligible for blocking. Note that if there are multiple scripts
145 // the flag will be conveyed to the browser process only once. 161 // the flag will be conveyed to the browser process only once.
146 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoad ingBehaviorDocumentWriteBlock); 162 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoad ingBehaviorDocumentWriteBlock);
147 163
148 const bool isSlowConnection = networkStateNotifier().connectionType() == Web ConnectionTypeCellular2G; 164 const bool is2G = networkStateNotifier().connectionType() == WebConnectionTy peCellular2G;
149 const bool disallowFetch = document.settings()->disallowFetchForDocWrittenSc riptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInM ainFrameOnSlowConnections() && isSlowConnection); 165 WebEffectiveConnectionType effectiveConnection = document.frame()->loader(). client()->getEffectiveConnectionType();
166 const bool is2GOrLike2G = is2G || isConnectionEffectively2G(effectiveConnect ion);
150 167
151 return disallowFetch; 168 return document.settings()->disallowFetchForDocWrittenScriptsInMainFrame() | | (document.settings()->disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnec tions() && is2G) || (document.settings()->disallowFetchForDocWrittenScriptsInMai nFrameIfEffectively2G() && is2GOrLike2G);
152 } 169 }
153 170
154 } // namespace 171 } // namespace
155 172
156 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) 173 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document)
157 : m_document(document) 174 : m_document(document)
158 , m_documentLoader(loader) 175 , m_documentLoader(loader)
159 { 176 {
160 DCHECK(frame()); 177 DCHECK(frame());
161 } 178 }
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 } 817 }
801 818
802 DEFINE_TRACE(FrameFetchContext) 819 DEFINE_TRACE(FrameFetchContext)
803 { 820 {
804 visitor->trace(m_document); 821 visitor->trace(m_document);
805 visitor->trace(m_documentLoader); 822 visitor->trace(m_documentLoader);
806 FetchContext::trace(visitor); 823 FetchContext::trace(visitor);
807 } 824 }
808 825
809 } // namespace blink 826 } // namespace blink
OLDNEW
« 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