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