| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 #include "public/platform/WebDocumentSubresourceFilter.h" | 73 #include "public/platform/WebDocumentSubresourceFilter.h" |
| 74 #include "public/platform/WebFrameScheduler.h" | 74 #include "public/platform/WebFrameScheduler.h" |
| 75 #include "public/platform/WebInsecureRequestPolicy.h" | 75 #include "public/platform/WebInsecureRequestPolicy.h" |
| 76 | 76 |
| 77 #include <algorithm> | 77 #include <algorithm> |
| 78 | 78 |
| 79 namespace blink { | 79 namespace blink { |
| 80 | 80 |
| 81 namespace { | 81 namespace { |
| 82 | 82 |
| 83 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch
Request::DeferOption defer, const Document& document) | 83 void emitWarningForDocWriteScripts(const String& url, Document& document) |
| 84 { |
| 85 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."; |
| 86 document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMe
ssageLevel, message)); |
| 87 WTFLogAlways("%s", message.utf8().data()); |
| 88 } |
| 89 |
| 90 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch
Request::DeferOption defer, Document& document) |
| 84 { | 91 { |
| 85 // Only scripts inserted via document.write are candidates for having their | 92 // Only scripts inserted via document.write are candidates for having their |
| 86 // fetch disallowed. | 93 // fetch disallowed. |
| 87 if (!document.isInDocumentWrite()) | 94 if (!document.isInDocumentWrite()) |
| 88 return false; | 95 return false; |
| 89 | 96 |
| 90 if (!document.settings()) | 97 if (!document.settings()) |
| 91 return false; | 98 return false; |
| 92 | 99 |
| 93 if (!document.frame()) | 100 if (!document.frame()) |
| 94 return false; | 101 return false; |
| 95 | 102 |
| 96 // Only block synchronously loaded (parser blocking) scripts. | 103 // Only block synchronously loaded (parser blocking) scripts. |
| 97 if (defer != FetchRequest::NoDefer) | 104 if (defer != FetchRequest::NoDefer) |
| 98 return false; | 105 return false; |
| 99 | 106 |
| 100 if (!request.url().protocolIsInHTTPFamily()) | 107 if (!request.url().protocolIsInHTTPFamily()) |
| 101 return false; | 108 return false; |
| 102 | 109 |
| 103 // Avoid blocking same origin scripts, as they may be used to render main | 110 // Avoid blocking same origin scripts, as they may be used to render main |
| 104 // page content, whereas cross-origin scripts inserted via document.write | 111 // page content, whereas cross-origin scripts inserted via document.write |
| 105 // are likely to be third party content. | 112 // are likely to be third party content. |
| 106 if (request.url().host() == document.getSecurityOrigin()->domain()) | 113 if (request.url().host() == document.getSecurityOrigin()->domain()) |
| 107 return false; | 114 return false; |
| 108 | 115 |
| 116 emitWarningForDocWriteScripts(request.url().getString(), document); |
| 117 |
| 109 // Do not block scripts if it is a page reload. This is to enable pages to | 118 // Do not block scripts if it is a page reload. This is to enable pages to |
| 110 // recover if blocking of a script is leading to a page break and the user | 119 // recover if blocking of a script is leading to a page break and the user |
| 111 // reloads the page. | 120 // reloads the page. |
| 112 const FrameLoadType loadType = document.frame()->loader().loadType(); | 121 const FrameLoadType loadType = document.frame()->loader().loadType(); |
| 113 const bool isReload = loadType == FrameLoadTypeReload || loadType == FrameLo
adTypeReloadBypassingCache || loadType == FrameLoadTypeReloadMainResource; | 122 const bool isReload = loadType == FrameLoadTypeReload || loadType == FrameLo
adTypeReloadBypassingCache || loadType == FrameLoadTypeReloadMainResource; |
| 114 if (isReload) { | 123 if (isReload) { |
| 115 // Recording this metric since an increase in number of reloads for page
s | 124 // Recording this metric since an increase in number of reloads for page
s |
| 116 // where a script was blocked could be indicative of a page break. | 125 // where a script was blocked could be indicative of a page break. |
| 117 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web
LoadingBehaviorDocumentWriteBlockReload); | 126 document.loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::Web
LoadingBehaviorDocumentWriteBlockReload); |
| 118 return false; | 127 return false; |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 } | 782 } |
| 774 | 783 |
| 775 DEFINE_TRACE(FrameFetchContext) | 784 DEFINE_TRACE(FrameFetchContext) |
| 776 { | 785 { |
| 777 visitor->trace(m_document); | 786 visitor->trace(m_document); |
| 778 visitor->trace(m_documentLoader); | 787 visitor->trace(m_documentLoader); |
| 779 FetchContext::trace(visitor); | 788 FetchContext::trace(visitor); |
| 780 } | 789 } |
| 781 | 790 |
| 782 } // namespace blink | 791 } // namespace blink |
| OLD | NEW |