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

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

Issue 1512783002: disable fetches for parser blocking scripts inserted via doc.write (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return ReloadIgnoringCacheData; 164 return ReloadIgnoringCacheData;
165 if (policy == CachePolicyReload) 165 if (policy == CachePolicyReload)
166 return ReloadBypassingCache; 166 return ReloadBypassingCache;
167 if (policy == CachePolicyHistoryBuffer) 167 if (policy == CachePolicyHistoryBuffer)
168 return ReturnCacheDataElseLoad; 168 return ReturnCacheDataElseLoad;
169 return UseProtocolCachePolicy; 169 return UseProtocolCachePolicy;
170 } 170 }
171 171
172 ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const R esourceRequest& request, Resource::Type type) const 172 ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const R esourceRequest& request, Resource::Type type) const
173 { 173 {
174 ASSERT(frame());
174 if (type == Resource::MainResource) { 175 if (type == Resource::MainResource) {
175 FrameLoadType frameLoadType = frame()->loader().loadType(); 176 FrameLoadType frameLoadType = frame()->loader().loadType();
176 if (request.httpMethod() == "POST" && frameLoadType == FrameLoadTypeBack Forward) 177 if (request.httpMethod() == "POST" && frameLoadType == FrameLoadTypeBack Forward)
177 return ReturnCacheDataDontLoad; 178 return ReturnCacheDataDontLoad;
178 if (!frame()->host()->overrideEncoding().isEmpty()) 179 if (!frame()->host()->overrideEncoding().isEmpty())
179 return ReturnCacheDataElseLoad; 180 return ReturnCacheDataElseLoad;
180 if (frameLoadType == FrameLoadTypeSame || request.isConditional() || req uest.httpMethod() == "POST") 181 if (frameLoadType == FrameLoadTypeSame || request.isConditional() || req uest.httpMethod() == "POST")
181 return ReloadIgnoringCacheData; 182 return ReloadIgnoringCacheData;
182 183
183 for (Frame* f = frame(); f; f = f->tree().parent()) { 184 for (Frame* f = frame(); f; f = f->tree().parent()) {
184 if (!f->isLocalFrame()) 185 if (!f->isLocalFrame())
185 continue; 186 continue;
186 frameLoadType = toLocalFrame(f)->loader().loadType(); 187 frameLoadType = toLocalFrame(f)->loader().loadType();
187 if (frameLoadType == FrameLoadTypeBackForward) 188 if (frameLoadType == FrameLoadTypeBackForward)
188 return ReturnCacheDataElseLoad; 189 return ReturnCacheDataElseLoad;
189 if (frameLoadType == FrameLoadTypeReloadFromOrigin) 190 if (frameLoadType == FrameLoadTypeReloadFromOrigin)
190 return ReloadBypassingCache; 191 return ReloadBypassingCache;
191 if (frameLoadType == FrameLoadTypeReload) 192 if (frameLoadType == FrameLoadTypeReload)
192 return ReloadIgnoringCacheData; 193 return ReloadIgnoringCacheData;
193 } 194 }
194 return UseProtocolCachePolicy; 195 return UseProtocolCachePolicy;
195 } 196 }
196 197
198 // For users on slow connections, we want to avoid blocking the parser in
199 // the main frame on script loads inserted via document.write, since it can
200 // add significant delays before page content is displayed on the screen.
201 // For now, as a prototype, we block fetches for main frame scripts
202 // inserted via document.write as long as the
203 // disallowFetchForDocWrittenScriptsInMainFrame setting is enabled. In the
204 // future, we'll extend this logic to only block if estimated network RTT
205 // is above some threshold.
206 if (type == Resource::Script && isMainFrame()) {
207 const bool isInDocumentWrite = m_document && m_document->isInDocumentWri te();
208 const bool disallowFetchForDocWriteScripts = frame()->settings() && fram e()->settings()->disallowFetchForDocWrittenScriptsInMainFrame();
209 if (isInDocumentWrite && disallowFetchForDocWriteScripts)
210 return ReturnCacheDataDontLoad;
211 }
212
197 if (request.isConditional()) 213 if (request.isConditional())
198 return ReloadIgnoringCacheData; 214 return ReloadIgnoringCacheData;
199 215
200 if (m_documentLoader && m_document && !m_document->loadEventFinished()) { 216 if (m_documentLoader && m_document && !m_document->loadEventFinished()) {
201 // For POST requests, we mutate the main resource's cache policy to avoi d form resubmission. 217 // For POST requests, we mutate the main resource's cache policy to avoi d form resubmission.
202 // This policy should not be inherited by subresources. 218 // This policy should not be inherited by subresources.
203 ResourceRequestCachePolicy mainResourceCachePolicy = m_documentLoader->r equest().cachePolicy(); 219 ResourceRequestCachePolicy mainResourceCachePolicy = m_documentLoader->r equest().cachePolicy();
204 if (m_documentLoader->request().httpMethod() == "POST") { 220 if (m_documentLoader->request().httpMethod() == "POST") {
205 if (mainResourceCachePolicy == ReturnCacheDataDontLoad) 221 if (mainResourceCachePolicy == ReturnCacheDataDontLoad)
206 return ReturnCacheDataElseLoad; 222 return ReturnCacheDataElseLoad;
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 } 781 }
766 782
767 DEFINE_TRACE(FrameFetchContext) 783 DEFINE_TRACE(FrameFetchContext)
768 { 784 {
769 visitor->trace(m_document); 785 visitor->trace(m_document);
770 visitor->trace(m_documentLoader); 786 visitor->trace(m_documentLoader);
771 FetchContext::trace(visitor); 787 FetchContext::trace(visitor);
772 } 788 }
773 789
774 } // namespace blink 790 } // 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