| 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 | 82 |
| 83 namespace { | 83 namespace { |
| 84 | 84 |
| 85 void emitWarningForDocWriteScripts(const String& url, Document& document) | 85 void emitWarningForDocWriteScripts(const String& url, Document& document) |
| 86 { | 86 { |
| 87 String message = "A Parser-blocking, cross-origin script, " + url + ", is in
voked via document.write. This may be blocked by the browser if the device has p
oor network connectivity."; | 87 String message = "A Parser-blocking, cross-origin script, " + url + ", is in
voked via document.write. This may be blocked by the browser if the device has p
oor network connectivity."; |
| 88 document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMe
ssageLevel, message)); | 88 document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMe
ssageLevel, message)); |
| 89 WTFLogAlways("%s", message.utf8().data()); | 89 WTFLogAlways("%s", message.utf8().data()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool isConnectionEffectively2G(WebEffectiveConnectionType effectiveType) |
| 93 { |
| 94 switch (effectiveType) { |
| 95 case WebEffectiveConnectionType::TypeSlow2G: |
| 96 case WebEffectiveConnectionType::Type2G: |
| 97 return true; |
| 98 case WebEffectiveConnectionType::Type3G: |
| 99 case WebEffectiveConnectionType::Type4G: |
| 100 case WebEffectiveConnectionType::TypeUnknown: |
| 101 case WebEffectiveConnectionType::TypeOffline: |
| 102 return false; |
| 103 } |
| 104 NOTREACHED(); |
| 105 return false; |
| 106 } |
| 107 |
| 92 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch
Request::DeferOption defer, Document& document) | 108 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch
Request::DeferOption defer, Document& document) |
| 93 { | 109 { |
| 94 // Only scripts inserted via document.write are candidates for having their | 110 // Only scripts inserted via document.write are candidates for having their |
| 95 // fetch disallowed. | 111 // fetch disallowed. |
| 96 if (!document.isInDocumentWrite()) | 112 if (!document.isInDocumentWrite()) |
| 97 return false; | 113 return false; |
| 98 | 114 |
| 99 if (!document.settings()) | 115 if (!document.settings()) |
| 100 return false; | 116 return false; |
| 101 | 117 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 // where a script was blocked could be indicative of a page break. | 155 // where a script was blocked could be indicative of a page break. |
| 140 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web
LoadingBehaviorDocumentWriteBlockReload); | 156 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web
LoadingBehaviorDocumentWriteBlockReload); |
| 141 return false; | 157 return false; |
| 142 } | 158 } |
| 143 | 159 |
| 144 // Add the metadata that this page has scripts inserted via document.write | 160 // Add the metadata that this page has scripts inserted via document.write |
| 145 // that are eligible for blocking. Note that if there are multiple scripts | 161 // that are eligible for blocking. Note that if there are multiple scripts |
| 146 // the flag will be conveyed to the browser process only once. | 162 // the flag will be conveyed to the browser process only once. |
| 147 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoad
ingBehaviorDocumentWriteBlock); | 163 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoad
ingBehaviorDocumentWriteBlock); |
| 148 | 164 |
| 149 const bool isSlowConnection = networkStateNotifier().connectionType() == Web
ConnectionTypeCellular2G; | 165 const bool is2G = networkStateNotifier().connectionType() == WebConnectionTy
peCellular2G; |
| 150 const bool disallowFetch = document.settings()->disallowFetchForDocWrittenSc
riptsInMainFrame() || (document.settings()->disallowFetchForDocWrittenScriptsInM
ainFrameOnSlowConnections() && isSlowConnection); | 166 WebEffectiveConnectionType effectiveConnection = document.frame()->loader().
client()->getEffectiveConnectionType(); |
| 167 const bool is2GOrLike2G = is2G || isConnectionEffectively2G(effectiveConnect
ion); |
| 151 | 168 |
| 152 return disallowFetch; | 169 return document.settings()->disallowFetchForDocWrittenScriptsInMainFrame() |
| (document.settings()->disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnec
tions() && is2G) || (RuntimeEnabledFeatures::blockDocWriteIfEffectively2GEnabled
() && is2GOrLike2G); |
| 153 } | 170 } |
| 154 | 171 |
| 155 } // namespace | 172 } // namespace |
| 156 | 173 |
| 157 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) | 174 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) |
| 158 : m_document(document) | 175 : m_document(document) |
| 159 , m_documentLoader(loader) | 176 , m_documentLoader(loader) |
| 160 { | 177 { |
| 161 ASSERT(frame()); | 178 ASSERT(frame()); |
| 162 } | 179 } |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 } | 846 } |
| 830 | 847 |
| 831 DEFINE_TRACE(FrameFetchContext) | 848 DEFINE_TRACE(FrameFetchContext) |
| 832 { | 849 { |
| 833 visitor->trace(m_document); | 850 visitor->trace(m_document); |
| 834 visitor->trace(m_documentLoader); | 851 visitor->trace(m_documentLoader); |
| 835 FetchContext::trace(visitor); | 852 FetchContext::trace(visitor); |
| 836 } | 853 } |
| 837 | 854 |
| 838 } // namespace blink | 855 } // namespace blink |
| OLD | NEW |