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

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

Issue 1918373002: Metrics for document.write script blocking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bryan's comment: Returning disallowFetch from shouldDisallowFetchForMainFrameScript Created 4 years, 7 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // fetch disallowed. 82 // fetch disallowed.
83 if (!document.isInDocumentWrite()) 83 if (!document.isInDocumentWrite())
84 return false; 84 return false;
85 85
86 if (!document.settings()) 86 if (!document.settings())
87 return false; 87 return false;
88 88
89 if (!document.frame()) 89 if (!document.frame())
90 return false; 90 return false;
91 91
92 // Do not block scripts if it is a page reload. This is to enable pages to
93 // recover if blocking of a script is leading to a page break and the user
94 // reloads the page.
95 const FrameLoadType loadType = document.frame()->loader().loadType();
96 const bool isReload = (loadType == FrameLoadTypeReload || loadType == FrameL oadTypeReloadBypassingCache || loadType == FrameLoadTypeSame);
97 if (isReload)
98 return false;
99
100 const bool isSlowConnection = networkStateNotifier().connectionType() == Web ConnectionTypeCellular2G;
101 const bool disallowFetch = document.settings()->disallowFetchForDocWrittenSc riptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInM ainFrameOnSlowConnections() && isSlowConnection);
102 if (!disallowFetch)
103 return false;
104
105 // Only block synchronously loaded (parser blocking) scripts. 92 // Only block synchronously loaded (parser blocking) scripts.
106 if (defer != FetchRequest::NoDefer) 93 if (defer != FetchRequest::NoDefer)
107 return false; 94 return false;
108 95
109 // Avoid blocking same origin scripts, as they may be used to render main 96 // Avoid blocking same origin scripts, as they may be used to render main
110 // page content, whereas cross-origin scripts inserted via document.write 97 // page content, whereas cross-origin scripts inserted via document.write
111 // are likely to be third party content. 98 // are likely to be third party content.
112 if (request.url().host() == document.getSecurityOrigin()->domain()) 99 if (request.url().host() == document.getSecurityOrigin()->domain())
113 return false; 100 return false;
114 101
115 return true; 102 // Do not block scripts if it is a page reload. This is to enable pages to
103 // recover if blocking of a script is leading to a page break and the user
104 // reloads the page.
105 const FrameLoadType loadType = document.frame()->loader().loadType();
106 const bool isReload = loadType == FrameLoadTypeReload || loadType == FrameLo adTypeReloadBypassingCache || loadType == FrameLoadTypeSame;
107 if (isReload) {
108 // Recording this metric since an increase in number of reloads for page s
109 // where a script was blocked could be indicative of a page break.
110 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web LoadingBehaviorDocumentWriteBlockReload);
111 return false;
112 }
113
114 // Add the metadata that this page has scripts inserted via document.write
115 // that are eligible for blocking. Note that if there are multiple scripts
116 // the flag will be conveyed to the browser process only once.
117 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoad ingBehaviorDocumentWriteBlock);
118
119 const bool isSlowConnection = networkStateNotifier().connectionType() == Web ConnectionTypeCellular2G;
120 const bool disallowFetch = document.settings()->disallowFetchForDocWrittenSc riptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInM ainFrameOnSlowConnections() && isSlowConnection);
121
122 return disallowFetch;
116 } 123 }
117 124
118 } // namespace 125 } // namespace
119 126
120 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) 127 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document)
121 : m_document(document) 128 : m_document(document)
122 , m_documentLoader(loader) 129 , m_documentLoader(loader)
123 , m_imageFetched(false) 130 , m_imageFetched(false)
124 { 131 {
125 ASSERT(frame()); 132 ASSERT(frame());
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 } 811 }
805 812
806 DEFINE_TRACE(FrameFetchContext) 813 DEFINE_TRACE(FrameFetchContext)
807 { 814 {
808 visitor->trace(m_document); 815 visitor->trace(m_document);
809 visitor->trace(m_documentLoader); 816 visitor->trace(m_documentLoader);
810 FetchContext::trace(visitor); 817 FetchContext::trace(visitor);
811 } 818 }
812 819
813 } // namespace blink 820 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698