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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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; | 92 const bool isSlowConnection = networkStateNotifier().connectionType() == Web ConnectionTypeCellular2G; |
101 const bool disallowFetch = document.settings()->disallowFetchForDocWrittenSc riptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInM ainFrameOnSlowConnections() && isSlowConnection); | 93 const bool disallowFetch = document.settings()->disallowFetchForDocWrittenSc riptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInM ainFrameOnSlowConnections() && isSlowConnection); |
102 if (!disallowFetch) | 94 if (!disallowFetch) |
103 return false; | 95 return false; |
104 | 96 |
105 // Only block synchronously loaded (parser blocking) scripts. | 97 // Only block synchronously loaded (parser blocking) scripts. |
106 if (defer != FetchRequest::NoDefer) | 98 if (defer != FetchRequest::NoDefer) |
107 return false; | 99 return false; |
108 | 100 |
109 // Avoid blocking same origin scripts, as they may be used to render main | 101 // Avoid blocking same origin scripts, as they may be used to render main |
110 // page content, whereas cross-origin scripts inserted via document.write | 102 // page content, whereas cross-origin scripts inserted via document.write |
111 // are likely to be third party content. | 103 // are likely to be third party content. |
112 if (request.url().host() == document.getSecurityOrigin()->domain()) | 104 if (request.url().host() == document.getSecurityOrigin()->domain()) |
113 return false; | 105 return false; |
114 | 106 |
107 // Do not block scripts if it is a page reload. This is to enable pages to | |
108 // recover if blocking of a script is leading to a page break and the user | |
109 // reloads the page. | |
110 const FrameLoadType loadType = document.frame()->loader().loadType(); | |
111 const bool isReload = loadType == FrameLoadTypeReload || loadType == FrameLo adTypeReloadBypassingCache || loadType == FrameLoadTypeSame; | |
112 if (isReload) { | |
113 // Recording this metric since an increase in number of reloads for page s | |
114 // where a script was blocked could be indicative of a page break. | |
115 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web LoadingBehaviorDocumentWriteBlockReload); | |
116 return false; | |
117 } | |
118 | |
119 // Add the metadata that this page has scripts inserted via document.write | |
120 // that are eligible for blocking. Note that if there are multiple scripts | |
121 // the flag will be conveyed to the browser process only once. | |
122 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoad ingBehaviorDocumentWriteBlock); | |
Bryan McQuade
2016/04/30 01:10:09
i notice this will only trigger if the setting is
shivanisha
2016/04/30 19:11:11
Thanks for the catch. I will upload the fixed vers
| |
115 return true; | 123 return true; |
116 } | 124 } |
117 | 125 |
118 } // namespace | 126 } // namespace |
119 | 127 |
120 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) | 128 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) |
121 : m_document(document) | 129 : m_document(document) |
122 , m_documentLoader(loader) | 130 , m_documentLoader(loader) |
123 , m_imageFetched(false) | 131 , m_imageFetched(false) |
124 { | 132 { |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 } | 812 } |
805 | 813 |
806 DEFINE_TRACE(FrameFetchContext) | 814 DEFINE_TRACE(FrameFetchContext) |
807 { | 815 { |
808 visitor->trace(m_document); | 816 visitor->trace(m_document); |
809 visitor->trace(m_documentLoader); | 817 visitor->trace(m_documentLoader); |
810 FetchContext::trace(visitor); | 818 FetchContext::trace(visitor); |
811 } | 819 } |
812 | 820 |
813 } // namespace blink | 821 } // namespace blink |
OLD | NEW |