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

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

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