Chromium Code Reviews| 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; | |
| 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 |
| 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 if (!disallowFetch) | |
|
Bryan McQuade
2016/05/03 20:22:48
this could be updated to just
return disallowFetch
| |
| 122 return false; | |
| 123 | |
| 115 return true; | 124 return true; |
| 116 } | 125 } |
| 117 | 126 |
| 118 } // namespace | 127 } // namespace |
| 119 | 128 |
| 120 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) | 129 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) |
| 121 : m_document(document) | 130 : m_document(document) |
| 122 , m_documentLoader(loader) | 131 , m_documentLoader(loader) |
| 123 , m_imageFetched(false) | 132 , m_imageFetched(false) |
| 124 { | 133 { |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 804 } | 813 } |
| 805 | 814 |
| 806 DEFINE_TRACE(FrameFetchContext) | 815 DEFINE_TRACE(FrameFetchContext) |
| 807 { | 816 { |
| 808 visitor->trace(m_document); | 817 visitor->trace(m_document); |
| 809 visitor->trace(m_documentLoader); | 818 visitor->trace(m_documentLoader); |
| 810 FetchContext::trace(visitor); | 819 FetchContext::trace(visitor); |
| 811 } | 820 } |
| 812 | 821 |
| 813 } // namespace blink | 822 } // namespace blink |
| OLD | NEW |