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

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp

Issue 2279543004: [DocWriteBlocking] Add feature to block doc.written scripts if 2g-like network (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename Created 4 years, 3 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
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 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."; 87 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.";
88 document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMe ssageLevel, message)); 88 document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMe ssageLevel, message));
89 WTFLogAlways("%s", message.utf8().data()); 89 WTFLogAlways("%s", message.utf8().data());
90 } 90 }
91 91
92 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch Request::DeferOption defer, Document& document) 92 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch Request::DeferOption defer, Document& document)
93 { 93 {
94 // Only scripts inserted via document.write are candidates for having their 94 // Only scripts inserted via document.write are candidates for having their
95 // fetch disallowed. 95 // fetch disallowed.
96 if (!document.isInDocumentWrite()) 96 if (!document.isInDocumentWrite())
97 return false; 97 return false;
Yoav Weiss 2016/09/04 05:11:43 I'm new to this code, but won't that prevent scrip
jkarlin 2016/09/06 11:58:45 If shouldDisallowFetchForMainFrameScript returns t
98 98
99 if (!document.settings()) 99 if (!document.settings())
100 return false; 100 return false;
101 101
102 if (!document.frame()) 102 if (!document.frame())
103 return false; 103 return false;
104 104
105 // Only block synchronously loaded (parser blocking) scripts. 105 // Only block synchronously loaded (parser blocking) scripts.
106 if (defer != FetchRequest::NoDefer) 106 if (defer != FetchRequest::NoDefer)
107 return false; 107 return false;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // where a script was blocked could be indicative of a page break. 139 // where a script was blocked could be indicative of a page break.
140 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web LoadingBehaviorDocumentWriteBlockReload); 140 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web LoadingBehaviorDocumentWriteBlockReload);
141 return false; 141 return false;
142 } 142 }
143 143
144 // Add the metadata that this page has scripts inserted via document.write 144 // Add the metadata that this page has scripts inserted via document.write
145 // that are eligible for blocking. Note that if there are multiple scripts 145 // that are eligible for blocking. Note that if there are multiple scripts
146 // the flag will be conveyed to the browser process only once. 146 // the flag will be conveyed to the browser process only once.
147 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoad ingBehaviorDocumentWriteBlock); 147 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoad ingBehaviorDocumentWriteBlock);
148 148
149 const bool isSlowConnection = networkStateNotifier().connectionType() == Web ConnectionTypeCellular2G; 149 const bool is2G = networkStateNotifier().connectionType() == WebConnectionTy peCellular2G;
150 const bool disallowFetch = document.settings()->disallowFetchForDocWrittenSc riptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInM ainFrameOnSlowConnections() && isSlowConnection); 150 WebEffectiveConnectionType effectiveConnection = document.frame()->loader(). client()->getEffectiveConnectionType();
151 const bool is2GOrLike2G = is2G || effectiveConnection == WebEffectiveConnect ionType::Type2G || effectiveConnection == WebEffectiveConnectionType::TypeSlow2G ;
Yoav Weiss 2016/09/04 05:11:43 Would it have been better to change the WebEffecti
jkarlin 2016/09/06 11:58:45 I don't think a strict ordering on the enum makes
151 152
152 return disallowFetch; 153 return document.settings()->disallowFetchForDocWrittenScriptsInMainFrame() | | (document.settings()->disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnec tions() && is2G) || (RuntimeEnabledFeatures::blockDocWriteIfEffectively2GEnabled () && is2GOrLike2G);
153 } 154 }
154 155
155 } // namespace 156 } // namespace
156 157
157 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) 158 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document)
158 : m_document(document) 159 : m_document(document)
159 , m_documentLoader(loader) 160 , m_documentLoader(loader)
160 { 161 {
161 ASSERT(frame()); 162 ASSERT(frame());
162 } 163 }
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 } 832 }
832 833
833 DEFINE_TRACE(FrameFetchContext) 834 DEFINE_TRACE(FrameFetchContext)
834 { 835 {
835 visitor->trace(m_document); 836 visitor->trace(m_document);
836 visitor->trace(m_documentLoader); 837 visitor->trace(m_documentLoader);
837 FetchContext::trace(visitor); 838 FetchContext::trace(visitor);
838 } 839 }
839 840
840 } // namespace blink 841 } // namespace blink
OLDNEW
« no previous file with comments | « content/public/common/content_features.cc ('k') | third_party/WebKit/Source/platform/RuntimeEnabledFeatures.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698