| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 case WebEffectiveConnectionType::Type3G: | 100 case WebEffectiveConnectionType::Type3G: |
| 101 case WebEffectiveConnectionType::Type4G: | 101 case WebEffectiveConnectionType::Type4G: |
| 102 case WebEffectiveConnectionType::TypeUnknown: | 102 case WebEffectiveConnectionType::TypeUnknown: |
| 103 case WebEffectiveConnectionType::TypeOffline: | 103 case WebEffectiveConnectionType::TypeOffline: |
| 104 return false; | 104 return false; |
| 105 } | 105 } |
| 106 NOTREACHED(); | 106 NOTREACHED(); |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 | 109 |
| 110 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, | 110 bool shouldDisallowFetchForMainFrameScript(ResourceRequest& request, |
| 111 FetchRequest::DeferOption defer, | 111 FetchRequest::DeferOption defer, |
| 112 Document& document) { | 112 Document& document) { |
| 113 // Only scripts inserted via document.write are candidates for having their | 113 // Only scripts inserted via document.write are candidates for having their |
| 114 // fetch disallowed. | 114 // fetch disallowed. |
| 115 if (!document.isInDocumentWrite()) | 115 if (!document.isInDocumentWrite()) |
| 116 return false; | 116 return false; |
| 117 | 117 |
| 118 if (!document.settings()) | 118 if (!document.settings()) |
| 119 return false; | 119 return false; |
| 120 | 120 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 144 String documentDomain = NetworkUtils::getDomainAndRegistry( | 144 String documentDomain = NetworkUtils::getDomainAndRegistry( |
| 145 documentHost, NetworkUtils::IncludePrivateRegistries); | 145 documentHost, NetworkUtils::IncludePrivateRegistries); |
| 146 // getDomainAndRegistry will return the empty string for domains that are | 146 // getDomainAndRegistry will return the empty string for domains that are |
| 147 // already top-level, such as localhost. Thus we only compare domains if we | 147 // already top-level, such as localhost. Thus we only compare domains if we |
| 148 // get non-empty results back from getDomainAndRegistry. | 148 // get non-empty results back from getDomainAndRegistry. |
| 149 if (!requestDomain.isEmpty() && !documentDomain.isEmpty() && | 149 if (!requestDomain.isEmpty() && !documentDomain.isEmpty() && |
| 150 requestDomain == documentDomain) | 150 requestDomain == documentDomain) |
| 151 return false; | 151 return false; |
| 152 | 152 |
| 153 emitWarningForDocWriteScripts(request.url().getString(), document); | 153 emitWarningForDocWriteScripts(request.url().getString(), document); |
| 154 request.setHTTPHeaderField("Intervention", |
| 155 "<https://www.chromestatus.com/feature/" |
| 156 "5718547946799104>; level=\"warning\""); |
| 154 | 157 |
| 155 // Do not block scripts if it is a page reload. This is to enable pages to | 158 // Do not block scripts if it is a page reload. This is to enable pages to |
| 156 // recover if blocking of a script is leading to a page break and the user | 159 // recover if blocking of a script is leading to a page break and the user |
| 157 // reloads the page. | 160 // reloads the page. |
| 158 const FrameLoadType loadType = document.frame()->loader().loadType(); | 161 const FrameLoadType loadType = document.frame()->loader().loadType(); |
| 159 if (isReloadLoadType(loadType)) { | 162 if (isReloadLoadType(loadType)) { |
| 160 // Recording this metric since an increase in number of reloads for pages | 163 // Recording this metric since an increase in number of reloads for pages |
| 161 // where a script was blocked could be indicative of a page break. | 164 // where a script was blocked could be indicative of a page break. |
| 162 document.loader()->didObserveLoadingBehavior( | 165 document.loader()->didObserveLoadingBehavior( |
| 163 WebLoadingBehaviorFlag::WebLoadingBehaviorDocumentWriteBlockReload); | 166 WebLoadingBehaviorFlag::WebLoadingBehaviorDocumentWriteBlockReload); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 if (policy == CachePolicyRevalidate) | 291 if (policy == CachePolicyRevalidate) |
| 289 return WebCachePolicy::ValidatingCacheData; | 292 return WebCachePolicy::ValidatingCacheData; |
| 290 if (policy == CachePolicyReload) | 293 if (policy == CachePolicyReload) |
| 291 return WebCachePolicy::BypassingCache; | 294 return WebCachePolicy::BypassingCache; |
| 292 if (policy == CachePolicyHistoryBuffer) | 295 if (policy == CachePolicyHistoryBuffer) |
| 293 return WebCachePolicy::ReturnCacheDataElseLoad; | 296 return WebCachePolicy::ReturnCacheDataElseLoad; |
| 294 return WebCachePolicy::UseProtocolCachePolicy; | 297 return WebCachePolicy::UseProtocolCachePolicy; |
| 295 } | 298 } |
| 296 | 299 |
| 297 WebCachePolicy FrameFetchContext::resourceRequestCachePolicy( | 300 WebCachePolicy FrameFetchContext::resourceRequestCachePolicy( |
| 298 const ResourceRequest& request, | 301 ResourceRequest& request, |
| 299 Resource::Type type, | 302 Resource::Type type, |
| 300 FetchRequest::DeferOption defer) const { | 303 FetchRequest::DeferOption defer) const { |
| 301 DCHECK(frame()); | 304 DCHECK(frame()); |
| 302 if (type == Resource::MainResource) { | 305 if (type == Resource::MainResource) { |
| 303 FrameLoadType frameLoadType = frame()->loader().loadType(); | 306 FrameLoadType frameLoadType = frame()->loader().loadType(); |
| 304 if (request.httpMethod() == "POST" && | 307 if (request.httpMethod() == "POST" && |
| 305 frameLoadType == FrameLoadTypeBackForward) | 308 frameLoadType == FrameLoadTypeBackForward) |
| 306 return WebCachePolicy::ReturnCacheDataDontLoad; | 309 return WebCachePolicy::ReturnCacheDataDontLoad; |
| 307 if (frameLoadType == FrameLoadTypeReloadMainResource || | 310 if (frameLoadType == FrameLoadTypeReloadMainResource || |
| 308 request.isConditional() || request.httpMethod() == "POST") | 311 request.isConditional() || request.httpMethod() == "POST") |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 response); | 991 response); |
| 989 } | 992 } |
| 990 | 993 |
| 991 DEFINE_TRACE(FrameFetchContext) { | 994 DEFINE_TRACE(FrameFetchContext) { |
| 992 visitor->trace(m_document); | 995 visitor->trace(m_document); |
| 993 visitor->trace(m_documentLoader); | 996 visitor->trace(m_documentLoader); |
| 994 FetchContext::trace(visitor); | 997 FetchContext::trace(visitor); |
| 995 } | 998 } |
| 996 | 999 |
| 997 } // namespace blink | 1000 } // namespace blink |
| OLD | NEW |