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

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

Issue 2653673006: Move loadType() to DocumentLoader (Closed)
Patch Set: Move loadType() to DocumentLoader Created 3 years, 11 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return false; 159 return false;
160 160
161 emitWarningForDocWriteScripts(request.url().getString(), document); 161 emitWarningForDocWriteScripts(request.url().getString(), document);
162 request.setHTTPHeaderField("Intervention", 162 request.setHTTPHeaderField("Intervention",
163 "<https://www.chromestatus.com/feature/" 163 "<https://www.chromestatus.com/feature/"
164 "5718547946799104>; level=\"warning\""); 164 "5718547946799104>; level=\"warning\"");
165 165
166 // Do not block scripts if it is a page reload. This is to enable pages to 166 // Do not block scripts if it is a page reload. This is to enable pages to
167 // recover if blocking of a script is leading to a page break and the user 167 // recover if blocking of a script is leading to a page break and the user
168 // reloads the page. 168 // reloads the page.
169 const FrameLoadType loadType = document.frame()->loader().loadType(); 169 const FrameLoadType loadType = document.loader()->loadType();
170 if (isReloadLoadType(loadType)) { 170 if (isReloadLoadType(loadType)) {
171 // Recording this metric since an increase in number of reloads for pages 171 // Recording this metric since an increase in number of reloads for pages
172 // where a script was blocked could be indicative of a page break. 172 // where a script was blocked could be indicative of a page break.
173 document.loader()->didObserveLoadingBehavior( 173 document.loader()->didObserveLoadingBehavior(
174 WebLoadingBehaviorFlag::WebLoadingBehaviorDocumentWriteBlockReload); 174 WebLoadingBehaviorFlag::WebLoadingBehaviorDocumentWriteBlockReload);
175 return false; 175 return false;
176 } 176 }
177 177
178 // Add the metadata that this page has scripts inserted via document.write 178 // Add the metadata that this page has scripts inserted via document.write
179 // that are eligible for blocking. Note that if there are multiple scripts 179 // that are eligible for blocking. Note that if there are multiple scripts
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 252
253 if (m_document) { 253 if (m_document) {
254 request.setExternalRequestStateFromRequestorAddressSpace( 254 request.setExternalRequestStateFromRequestorAddressSpace(
255 m_document->addressSpace()); 255 m_document->addressSpace());
256 } 256 }
257 257
258 // The remaining modifications are only necessary for HTTP and HTTPS. 258 // The remaining modifications are only necessary for HTTP and HTTPS.
259 if (!request.url().isEmpty() && !request.url().protocolIsInHTTPFamily()) 259 if (!request.url().isEmpty() && !request.url().protocolIsInHTTPFamily())
260 return; 260 return;
261 261
262 if (frame()->loader().loadType() == FrameLoadTypeReload) 262 if (masterDocumentLoader()->loadType() == FrameLoadTypeReload)
263 request.clearHTTPHeaderField("Save-Data"); 263 request.clearHTTPHeaderField("Save-Data");
264 264
265 if (frame()->settings() && frame()->settings()->getDataSaverEnabled()) 265 if (frame()->settings() && frame()->settings()->getDataSaverEnabled())
266 request.setHTTPHeaderField("Save-Data", "on"); 266 request.setHTTPHeaderField("Save-Data", "on");
267 } 267 }
268 268
269 CachePolicy FrameFetchContext::getCachePolicy() const { 269 CachePolicy FrameFetchContext::getCachePolicy() const {
270 if (m_document && m_document->loadEventFinished()) 270 if (m_document && m_document->loadEventFinished())
271 return CachePolicyVerify; 271 return CachePolicyVerify;
272 272
273 FrameLoadType loadType = frame()->loader().loadType(); 273 FrameLoadType loadType = masterDocumentLoader()->loadType();
274 if (loadType == FrameLoadTypeReloadBypassingCache) 274 if (loadType == FrameLoadTypeReloadBypassingCache)
275 return CachePolicyReload; 275 return CachePolicyReload;
276 276
277 Frame* parentFrame = frame()->tree().parent(); 277 Frame* parentFrame = frame()->tree().parent();
278 if (parentFrame && parentFrame->isLocalFrame()) { 278 if (parentFrame && parentFrame->isLocalFrame()) {
279 CachePolicy parentCachePolicy = toLocalFrame(parentFrame) 279 CachePolicy parentCachePolicy = toLocalFrame(parentFrame)
280 ->document() 280 ->document()
281 ->fetcher() 281 ->fetcher()
282 ->context() 282 ->context()
283 .getCachePolicy(); 283 .getCachePolicy();
(...skipping 21 matching lines...) Expand all
305 return WebCachePolicy::UseProtocolCachePolicy; 305 return WebCachePolicy::UseProtocolCachePolicy;
306 if (policy == CachePolicyRevalidate) 306 if (policy == CachePolicyRevalidate)
307 return WebCachePolicy::ValidatingCacheData; 307 return WebCachePolicy::ValidatingCacheData;
308 if (policy == CachePolicyReload) 308 if (policy == CachePolicyReload)
309 return WebCachePolicy::BypassingCache; 309 return WebCachePolicy::BypassingCache;
310 if (policy == CachePolicyHistoryBuffer) 310 if (policy == CachePolicyHistoryBuffer)
311 return WebCachePolicy::ReturnCacheDataElseLoad; 311 return WebCachePolicy::ReturnCacheDataElseLoad;
312 return WebCachePolicy::UseProtocolCachePolicy; 312 return WebCachePolicy::UseProtocolCachePolicy;
313 } 313 }
314 314
315 static WebCachePolicy frameLoadTypeToWebCachePolicy(FrameLoadType type) {
316 if (type == FrameLoadTypeBackForward)
317 return WebCachePolicy::ReturnCacheDataElseLoad;
318 if (type == FrameLoadTypeReloadBypassingCache)
319 return WebCachePolicy::BypassingCache;
320 if (type == FrameLoadTypeReload)
321 return WebCachePolicy::ValidatingCacheData;
322 return WebCachePolicy::UseProtocolCachePolicy;
323 }
324
315 WebCachePolicy FrameFetchContext::resourceRequestCachePolicy( 325 WebCachePolicy FrameFetchContext::resourceRequestCachePolicy(
316 ResourceRequest& request, 326 ResourceRequest& request,
317 Resource::Type type, 327 Resource::Type type,
318 FetchRequest::DeferOption defer) const { 328 FetchRequest::DeferOption defer) const {
319 DCHECK(frame()); 329 DCHECK(frame());
320 if (type == Resource::MainResource) { 330 if (type == Resource::MainResource) {
321 FrameLoadType frameLoadType = frame()->loader().loadType(); 331 FrameLoadType frameLoadType = masterDocumentLoader()->loadType();
322 if (request.httpMethod() == "POST" && 332 if (request.httpMethod() == "POST" &&
323 frameLoadType == FrameLoadTypeBackForward) 333 frameLoadType == FrameLoadTypeBackForward)
324 return WebCachePolicy::ReturnCacheDataDontLoad; 334 return WebCachePolicy::ReturnCacheDataDontLoad;
325 if (frameLoadType == FrameLoadTypeReloadMainResource || 335 if (frameLoadType == FrameLoadTypeReloadMainResource ||
326 request.isConditional() || request.httpMethod() == "POST") 336 request.isConditional() || request.httpMethod() == "POST")
327 return WebCachePolicy::ValidatingCacheData; 337 return WebCachePolicy::ValidatingCacheData;
328 338
329 for (Frame* f = frame(); f; f = f->tree().parent()) { 339 WebCachePolicy policy = frameLoadTypeToWebCachePolicy(frameLoadType);
340 if (policy != WebCachePolicy::UseProtocolCachePolicy)
341 return policy;
342
343 for (Frame* f = frame()->tree().parent(); f; f = f->tree().parent()) {
330 if (!f->isLocalFrame()) 344 if (!f->isLocalFrame())
331 continue; 345 continue;
332 FrameLoadType parentFrameLoadType = toLocalFrame(f)->loader().loadType(); 346 policy = frameLoadTypeToWebCachePolicy(
333 if (parentFrameLoadType == FrameLoadTypeBackForward) 347 toLocalFrame(f)->loader().documentLoader()->loadType());
334 return WebCachePolicy::ReturnCacheDataElseLoad; 348 if (policy != WebCachePolicy::UseProtocolCachePolicy)
335 if (parentFrameLoadType == FrameLoadTypeReloadBypassingCache) 349 return policy;
336 return WebCachePolicy::BypassingCache;
337 if (parentFrameLoadType == FrameLoadTypeReload)
338 return WebCachePolicy::ValidatingCacheData;
339 } 350 }
340 // Returns UseProtocolCachePolicy for other cases, parent frames not having 351 // Returns UseProtocolCachePolicy for other cases, parent frames not having
341 // special kinds of FrameLoadType as they are checked inside the for loop 352 // special kinds of FrameLoadType as they are checked inside the for loop
342 // above, or |frameLoadType| being FrameLoadTypeStandard. See 353 // above, or |frameLoadType| being FrameLoadTypeStandard. See
343 // public/web/WebFrameLoadType.h to know how these load types work. 354 // public/web/WebFrameLoadType.h to know how these load types work.
344 return WebCachePolicy::UseProtocolCachePolicy; 355 return WebCachePolicy::UseProtocolCachePolicy;
345 } 356 }
346 357
347 // For users on slow connections, we want to avoid blocking the parser in 358 // For users on slow connections, we want to avoid blocking the parser in
348 // the main frame on script loads inserted via document.write, since it can 359 // the main frame on script loads inserted via document.write, since it can
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 ResourceTimingInfo* info) { 871 ResourceTimingInfo* info) {
861 // <iframe>s should report the initial navigation requested by the parent 872 // <iframe>s should report the initial navigation requested by the parent
862 // document, but not subsequent navigations. 873 // document, but not subsequent navigations.
863 // FIXME: Resource timing is broken when the parent is a remote frame. 874 // FIXME: Resource timing is broken when the parent is a remote frame.
864 if (!frame()->deprecatedLocalOwner() || 875 if (!frame()->deprecatedLocalOwner() ||
865 frame()->deprecatedLocalOwner()->loadedNonEmptyDocument()) 876 frame()->deprecatedLocalOwner()->loadedNonEmptyDocument())
866 return false; 877 return false;
867 frame()->deprecatedLocalOwner()->didLoadNonEmptyDocument(); 878 frame()->deprecatedLocalOwner()->didLoadNonEmptyDocument();
868 // Do not report iframe navigation that restored from history, since its 879 // Do not report iframe navigation that restored from history, since its
869 // location may have been changed after initial navigation. 880 // location may have been changed after initial navigation.
870 if (frame()->loader().loadType() == FrameLoadTypeInitialHistoryLoad) 881 if (masterDocumentLoader()->loadType() == FrameLoadTypeInitialHistoryLoad)
871 return false; 882 return false;
872 info->setInitiatorType(frame()->deprecatedLocalOwner()->localName()); 883 info->setInitiatorType(frame()->deprecatedLocalOwner()->localName());
873 return true; 884 return true;
874 } 885 }
875 886
876 void FrameFetchContext::sendImagePing(const KURL& url) { 887 void FrameFetchContext::sendImagePing(const KURL& url) {
877 PingLoader::loadImage(frame(), url); 888 PingLoader::loadImage(frame(), url);
878 } 889 }
879 890
880 void FrameFetchContext::addConsoleMessage(const String& message, 891 void FrameFetchContext::addConsoleMessage(const String& message,
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 response); 1068 response);
1058 } 1069 }
1059 1070
1060 DEFINE_TRACE(FrameFetchContext) { 1071 DEFINE_TRACE(FrameFetchContext) {
1061 visitor->trace(m_document); 1072 visitor->trace(m_document);
1062 visitor->trace(m_documentLoader); 1073 visitor->trace(m_documentLoader);
1063 FetchContext::trace(visitor); 1074 FetchContext::trace(visitor);
1064 } 1075 }
1065 1076
1066 } // namespace blink 1077 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698