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

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

Issue 2771803002: FrameFetchContext should not always respect conditional requests (Closed)
Patch Set: tests Created 3 years, 8 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 | « no previous file | third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp » ('j') | 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 is2G) || 214 is2G) ||
215 (document.settings() 215 (document.settings()
216 ->getDisallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G() && 216 ->getDisallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G() &&
217 isConnectionEffectively2G(effectiveConnection)); 217 isConnectionEffectively2G(effectiveConnection));
218 } 218 }
219 219
220 enum class RequestMethod { kIsPost, kIsNotPost }; 220 enum class RequestMethod { kIsPost, kIsNotPost };
221 enum class RequestType { kIsConditional, kIsNotConditional }; 221 enum class RequestType { kIsConditional, kIsNotConditional };
222 enum class ResourceType { kIsMainResource, kIsNotMainResource }; 222 enum class ResourceType { kIsMainResource, kIsNotMainResource };
223 223
224 // Determines WebCachePolicy for a main resource, or WebCachePolicy that is
225 // corresponding to FrameLoadType.
226 // TODO(toyoshim): Probably, we should split FrameLoadType to WebCachePolicy
227 // conversion logic into a separate function once other TODOs in this function
228 // are resolved.
224 WebCachePolicy determineWebCachePolicy(RequestMethod method, 229 WebCachePolicy determineWebCachePolicy(RequestMethod method,
225 RequestType requestType, 230 RequestType requestType,
226 ResourceType resourceType, 231 ResourceType resourceType,
227 FrameLoadType loadType) { 232 FrameLoadType loadType) {
228 switch (loadType) { 233 switch (loadType) {
229 case FrameLoadTypeStandard: 234 case FrameLoadTypeStandard:
230 return (requestType == RequestType::kIsConditional || 235 return (requestType == RequestType::kIsConditional ||
231 method == RequestMethod::kIsPost) 236 method == RequestMethod::kIsPost)
232 ? WebCachePolicy::ValidatingCacheData 237 ? WebCachePolicy::ValidatingCacheData
233 : WebCachePolicy::UseProtocolCachePolicy; 238 : WebCachePolicy::UseProtocolCachePolicy;
(...skipping 29 matching lines...) Expand all
263 return (resourceType == ResourceType::kIsMainResource && 268 return (resourceType == ResourceType::kIsMainResource &&
264 (requestType == RequestType::kIsConditional || 269 (requestType == RequestType::kIsConditional ||
265 method == RequestMethod::kIsPost)) 270 method == RequestMethod::kIsPost))
266 ? WebCachePolicy::ValidatingCacheData 271 ? WebCachePolicy::ValidatingCacheData
267 : WebCachePolicy::BypassingCache; 272 : WebCachePolicy::BypassingCache;
268 } 273 }
269 NOTREACHED(); 274 NOTREACHED();
270 return WebCachePolicy::UseProtocolCachePolicy; 275 return WebCachePolicy::UseProtocolCachePolicy;
271 } 276 }
272 277
273 // TODO(toyoshim): Remove |resourceType|. See comments in 278 // Determines WebCachePolicy for |frame|. This WebCachePolicy should be a base
274 // resourceRequestCachePolicy(). 279 // policy to consider one of each resource belonging to the frame, and should
280 // not count resource specific conditions in.
281 // TODO(toyoshim): Remove |resourceType| to realize the design described above.
282 // See also comments in resourceRequestCachePolicy().
275 WebCachePolicy determineFrameWebCachePolicy(Frame* frame, 283 WebCachePolicy determineFrameWebCachePolicy(Frame* frame,
276 ResourceType resourceType) { 284 ResourceType resourceType) {
277 if (!frame) 285 if (!frame)
278 return WebCachePolicy::UseProtocolCachePolicy; 286 return WebCachePolicy::UseProtocolCachePolicy;
279 if (!frame->isLocalFrame()) 287 if (!frame->isLocalFrame())
280 return determineFrameWebCachePolicy(frame->tree().parent(), resourceType); 288 return determineFrameWebCachePolicy(frame->tree().parent(), resourceType);
281 289
282 // Does not propagate cache policy for subresources after the load event. 290 // Does not propagate cache policy for subresources after the load event.
283 // TODO(toyoshim): We should be able to remove following parents' policy check 291 // TODO(toyoshim): We should be able to remove following parents' policy check
284 // if each frame has a relevant FrameLoadType for reload and history 292 // if each frame has a relevant FrameLoadType for reload and history
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 415
408 // For users on slow connections, we want to avoid blocking the parser in 416 // For users on slow connections, we want to avoid blocking the parser in
409 // the main frame on script loads inserted via document.write, since it can 417 // the main frame on script loads inserted via document.write, since it can
410 // add significant delays before page content is displayed on the screen. 418 // add significant delays before page content is displayed on the screen.
411 // TODO(toyoshim): Move following logic that rewrites ResourceRequest to 419 // TODO(toyoshim): Move following logic that rewrites ResourceRequest to
412 // somewhere that should be relevant to the script resource handling. 420 // somewhere that should be relevant to the script resource handling.
413 if (type == Resource::Script && isMainFrame() && m_document && 421 if (type == Resource::Script && isMainFrame() && m_document &&
414 shouldDisallowFetchForMainFrameScript(request, defer, *m_document)) 422 shouldDisallowFetchForMainFrameScript(request, defer, *m_document))
415 return WebCachePolicy::ReturnCacheDataDontLoad; 423 return WebCachePolicy::ReturnCacheDataDontLoad;
416 424
417 // TODO(toyoshim): We should check isConditional() and use ValidatingCacheData 425 const WebCachePolicy cachePolicy =
418 // only when |cachePolicy| below is UseProtocolCachePolicy. 426 determineFrameWebCachePolicy(frame(), ResourceType::kIsNotMainResource);
419 if (request.isConditional()) 427
428 // TODO(toyoshim): Revisit to consider if this clause can be merged to
429 // determineWebCachePolicy or determineFrameWebCachePolicy.
430 if (cachePolicy == WebCachePolicy::UseProtocolCachePolicy &&
431 request.isConditional()) {
420 return WebCachePolicy::ValidatingCacheData; 432 return WebCachePolicy::ValidatingCacheData;
421 433 }
422 return determineFrameWebCachePolicy(frame(), 434 return cachePolicy;
423 ResourceType::kIsNotMainResource);
424 } 435 }
425 436
426 // The |m_documentLoader| is null in the FrameFetchContext of an imported 437 // The |m_documentLoader| is null in the FrameFetchContext of an imported
427 // document. 438 // document.
428 // FIXME(http://crbug.com/274173): This means Inspector, which uses 439 // FIXME(http://crbug.com/274173): This means Inspector, which uses
429 // DocumentLoader as a grouping entity, cannot see imported documents. 440 // DocumentLoader as a grouping entity, cannot see imported documents.
430 inline DocumentLoader* FrameFetchContext::masterDocumentLoader() const { 441 inline DocumentLoader* FrameFetchContext::masterDocumentLoader() const {
431 if (m_documentLoader) 442 if (m_documentLoader)
432 return m_documentLoader.get(); 443 return m_documentLoader.get();
433 444
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 response); 1083 response);
1073 } 1084 }
1074 1085
1075 DEFINE_TRACE(FrameFetchContext) { 1086 DEFINE_TRACE(FrameFetchContext) {
1076 visitor->trace(m_document); 1087 visitor->trace(m_document);
1077 visitor->trace(m_documentLoader); 1088 visitor->trace(m_documentLoader);
1078 FetchContext::trace(visitor); 1089 FetchContext::trace(visitor);
1079 } 1090 }
1080 1091
1081 } // namespace blink 1092 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698