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

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

Issue 2389753002: doc.write blocking intervention warning header (Closed)
Patch Set: Rebased till refs/heads/master@{#422406} Created 4 years, 2 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
111 FetchRequest::DeferOption defer, 111 const ResourceRequest& request,
112 Document& document) { 112 FetchRequest::DeferOption defer,
113 Document& document,
114 std::pair<AtomicString, AtomicString>& customHeader) {
113 // Only scripts inserted via document.write are candidates for having their 115 // Only scripts inserted via document.write are candidates for having their
114 // fetch disallowed. 116 // fetch disallowed.
115 if (!document.isInDocumentWrite()) 117 if (!document.isInDocumentWrite())
116 return false; 118 return false;
117 119
118 if (!document.settings()) 120 if (!document.settings())
119 return false; 121 return false;
120 122
121 if (!document.frame()) 123 if (!document.frame())
122 return false; 124 return false;
(...skipping 21 matching lines...) Expand all
144 String documentDomain = NetworkUtils::getDomainAndRegistry( 146 String documentDomain = NetworkUtils::getDomainAndRegistry(
145 documentHost, NetworkUtils::IncludePrivateRegistries); 147 documentHost, NetworkUtils::IncludePrivateRegistries);
146 // getDomainAndRegistry will return the empty string for domains that are 148 // getDomainAndRegistry will return the empty string for domains that are
147 // already top-level, such as localhost. Thus we only compare domains if we 149 // already top-level, such as localhost. Thus we only compare domains if we
148 // get non-empty results back from getDomainAndRegistry. 150 // get non-empty results back from getDomainAndRegistry.
149 if (!requestDomain.isEmpty() && !documentDomain.isEmpty() && 151 if (!requestDomain.isEmpty() && !documentDomain.isEmpty() &&
150 requestDomain == documentDomain) 152 requestDomain == documentDomain)
151 return false; 153 return false;
152 154
153 emitWarningForDocWriteScripts(request.url().getString(), document); 155 emitWarningForDocWriteScripts(request.url().getString(), document);
156 customHeader.first = "Intervention";
157 customHeader.second =
158 "<https://www.chromestatus.com/feature/5718547946799104>; "
159 "level=\"warning\"";
154 160
155 // Do not block scripts if it is a page reload. This is to enable pages to 161 // 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 162 // recover if blocking of a script is leading to a page break and the user
157 // reloads the page. 163 // reloads the page.
158 const FrameLoadType loadType = document.frame()->loader().loadType(); 164 const FrameLoadType loadType = document.frame()->loader().loadType();
159 if (isReloadLoadType(loadType)) { 165 if (isReloadLoadType(loadType)) {
160 // Recording this metric since an increase in number of reloads for pages 166 // 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. 167 // where a script was blocked could be indicative of a page break.
162 document.loader()->didObserveLoadingBehavior( 168 document.loader()->didObserveLoadingBehavior(
163 WebLoadingBehaviorFlag::WebLoadingBehaviorDocumentWriteBlockReload); 169 WebLoadingBehaviorFlag::WebLoadingBehaviorDocumentWriteBlockReload);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 if (policy == CachePolicyReload) 296 if (policy == CachePolicyReload)
291 return WebCachePolicy::BypassingCache; 297 return WebCachePolicy::BypassingCache;
292 if (policy == CachePolicyHistoryBuffer) 298 if (policy == CachePolicyHistoryBuffer)
293 return WebCachePolicy::ReturnCacheDataElseLoad; 299 return WebCachePolicy::ReturnCacheDataElseLoad;
294 return WebCachePolicy::UseProtocolCachePolicy; 300 return WebCachePolicy::UseProtocolCachePolicy;
295 } 301 }
296 302
297 WebCachePolicy FrameFetchContext::resourceRequestCachePolicy( 303 WebCachePolicy FrameFetchContext::resourceRequestCachePolicy(
298 const ResourceRequest& request, 304 const ResourceRequest& request,
299 Resource::Type type, 305 Resource::Type type,
300 FetchRequest::DeferOption defer) const { 306 FetchRequest::DeferOption defer,
307 std::pair<AtomicString, AtomicString>& customHeader) const {
301 DCHECK(frame()); 308 DCHECK(frame());
302 if (type == Resource::MainResource) { 309 if (type == Resource::MainResource) {
303 FrameLoadType frameLoadType = frame()->loader().loadType(); 310 FrameLoadType frameLoadType = frame()->loader().loadType();
304 if (request.httpMethod() == "POST" && 311 if (request.httpMethod() == "POST" &&
305 frameLoadType == FrameLoadTypeBackForward) 312 frameLoadType == FrameLoadTypeBackForward)
306 return WebCachePolicy::ReturnCacheDataDontLoad; 313 return WebCachePolicy::ReturnCacheDataDontLoad;
307 if (frameLoadType == FrameLoadTypeReloadMainResource || 314 if (frameLoadType == FrameLoadTypeReloadMainResource ||
308 request.isConditional() || request.httpMethod() == "POST") 315 request.isConditional() || request.httpMethod() == "POST")
309 return WebCachePolicy::ValidatingCacheData; 316 return WebCachePolicy::ValidatingCacheData;
310 317
(...skipping 12 matching lines...) Expand all
323 // having special kinds of FrameLoadType as they are checked inside 330 // having special kinds of FrameLoadType as they are checked inside
324 // the for loop above, or |frameLoadType| being FrameLoadTypeStandard. 331 // the for loop above, or |frameLoadType| being FrameLoadTypeStandard.
325 // See public/web/WebFrameLoadType.h to know how these load types work. 332 // See public/web/WebFrameLoadType.h to know how these load types work.
326 return WebCachePolicy::UseProtocolCachePolicy; 333 return WebCachePolicy::UseProtocolCachePolicy;
327 } 334 }
328 335
329 // For users on slow connections, we want to avoid blocking the parser in 336 // For users on slow connections, we want to avoid blocking the parser in
330 // the main frame on script loads inserted via document.write, since it can 337 // the main frame on script loads inserted via document.write, since it can
331 // add significant delays before page content is displayed on the screen. 338 // add significant delays before page content is displayed on the screen.
332 if (type == Resource::Script && isMainFrame() && m_document && 339 if (type == Resource::Script && isMainFrame() && m_document &&
333 shouldDisallowFetchForMainFrameScript(request, defer, *m_document)) 340 shouldDisallowFetchForMainFrameScript(request, defer, *m_document,
341 customHeader))
334 return WebCachePolicy::ReturnCacheDataDontLoad; 342 return WebCachePolicy::ReturnCacheDataDontLoad;
335 343
336 if (request.isConditional()) 344 if (request.isConditional())
337 return WebCachePolicy::ValidatingCacheData; 345 return WebCachePolicy::ValidatingCacheData;
338 346
339 if (m_documentLoader && m_document && !m_document->loadEventFinished()) { 347 if (m_documentLoader && m_document && !m_document->loadEventFinished()) {
340 // For POST requests, we mutate the main resource's cache policy to avoid fo rm resubmission. 348 // For POST requests, we mutate the main resource's cache policy to avoid fo rm resubmission.
341 // This policy should not be inherited by subresources. 349 // This policy should not be inherited by subresources.
342 WebCachePolicy mainResourceCachePolicy = 350 WebCachePolicy mainResourceCachePolicy =
343 m_documentLoader->request().getCachePolicy(); 351 m_documentLoader->request().getCachePolicy();
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 response); 996 response);
989 } 997 }
990 998
991 DEFINE_TRACE(FrameFetchContext) { 999 DEFINE_TRACE(FrameFetchContext) {
992 visitor->trace(m_document); 1000 visitor->trace(m_document);
993 visitor->trace(m_documentLoader); 1001 visitor->trace(m_documentLoader);
994 FetchContext::trace(visitor); 1002 FetchContext::trace(visitor);
995 } 1003 }
996 1004
997 } // namespace blink 1005 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698