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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 #include "public/platform/WebInsecureRequestPolicy.h" | 75 #include "public/platform/WebInsecureRequestPolicy.h" |
76 #include "public/platform/WebViewScheduler.h" | 76 #include "public/platform/WebViewScheduler.h" |
77 #include <algorithm> | 77 #include <algorithm> |
78 #include <memory> | 78 #include <memory> |
79 | 79 |
80 namespace blink { | 80 namespace blink { |
81 | 81 |
82 namespace { | 82 namespace { |
83 | 83 |
84 void emitWarningForDocWriteScripts(const String& url, Document& document) { | 84 void emitWarningForDocWriteScripts(const String& url, Document& document) { |
85 String message = "A Parser-blocking, cross-origin script, " + url + | 85 String message = |
86 ", is invoked via document.write. This may be blocked by " | 86 "A Parser-blocking, cross site (i.e. different eTLD+1) script, " + url + |
jkarlin
2016/11/29 16:19:12
s/cross site/cross-site/
shivanisha
2016/12/06 18:18:08
done
| |
87 "the browser if the device has poor network connectivity. " | 87 ", is invoked via document.write. This may be blocked by " |
88 "See https://www.chromestatus.com/feature/5718547946799104 " | 88 "the browser if the device has poor network connectivity. " |
89 "for more details."; | 89 "See https://www.chromestatus.com/feature/5718547946799104 " |
90 "for more details."; | |
90 document.addConsoleMessage( | 91 document.addConsoleMessage( |
91 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); | 92 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); |
92 WTFLogAlways("%s", message.utf8().data()); | 93 WTFLogAlways("%s", message.utf8().data()); |
93 } | 94 } |
94 | 95 |
95 bool isConnectionEffectively2G(WebEffectiveConnectionType effectiveType) { | 96 bool isConnectionEffectively2G(WebEffectiveConnectionType effectiveType) { |
96 switch (effectiveType) { | 97 switch (effectiveType) { |
97 case WebEffectiveConnectionType::TypeSlow2G: | 98 case WebEffectiveConnectionType::TypeSlow2G: |
98 case WebEffectiveConnectionType::Type2G: | 99 case WebEffectiveConnectionType::Type2G: |
99 return true; | 100 return true; |
(...skipping 28 matching lines...) Expand all Loading... | |
128 PerformanceMonitor::documentWriteFetchScript(&document); | 129 PerformanceMonitor::documentWriteFetchScript(&document); |
129 | 130 |
130 if (!request.url().protocolIsInHTTPFamily()) | 131 if (!request.url().protocolIsInHTTPFamily()) |
131 return false; | 132 return false; |
132 | 133 |
133 // Avoid blocking same origin scripts, as they may be used to render main | 134 // Avoid blocking same origin scripts, as they may be used to render main |
134 // page content, whereas cross-origin scripts inserted via document.write | 135 // page content, whereas cross-origin scripts inserted via document.write |
135 // are likely to be third party content. | 136 // are likely to be third party content. |
136 String requestHost = request.url().host(); | 137 String requestHost = request.url().host(); |
137 String documentHost = document.getSecurityOrigin()->domain(); | 138 String documentHost = document.getSecurityOrigin()->domain(); |
139 | |
140 bool sameSite = false; | |
138 if (requestHost == documentHost) | 141 if (requestHost == documentHost) |
139 return false; | 142 sameSite = true; |
140 | 143 |
141 // If the hosts didn't match, then see if the domains match. For example, if | 144 // If the hosts didn't match, then see if the domains match. For example, if |
142 // a script is served from static.example.com for a document served from | 145 // a script is served from static.example.com for a document served from |
143 // www.example.com, we consider that a first party script and allow it. | 146 // www.example.com, we consider that a first party script and allow it. |
144 String requestDomain = NetworkUtils::getDomainAndRegistry( | 147 String requestDomain = NetworkUtils::getDomainAndRegistry( |
145 requestHost, NetworkUtils::IncludePrivateRegistries); | 148 requestHost, NetworkUtils::IncludePrivateRegistries); |
146 String documentDomain = NetworkUtils::getDomainAndRegistry( | 149 String documentDomain = NetworkUtils::getDomainAndRegistry( |
147 documentHost, NetworkUtils::IncludePrivateRegistries); | 150 documentHost, NetworkUtils::IncludePrivateRegistries); |
148 // getDomainAndRegistry will return the empty string for domains that are | 151 // getDomainAndRegistry will return the empty string for domains that are |
149 // already top-level, such as localhost. Thus we only compare domains if we | 152 // already top-level, such as localhost. Thus we only compare domains if we |
150 // get non-empty results back from getDomainAndRegistry. | 153 // get non-empty results back from getDomainAndRegistry. |
151 if (!requestDomain.isEmpty() && !documentDomain.isEmpty() && | 154 if (!requestDomain.isEmpty() && !documentDomain.isEmpty() && |
152 requestDomain == documentDomain) | 155 requestDomain == documentDomain) |
156 sameSite = true; | |
157 | |
158 if (sameSite) { | |
159 // This histogram is introduced to help decide whether we should also check | |
160 // same scheme while deciding not to block the script as is done in other | |
jkarlin
2016/11/29 16:19:12
s/deciding not to block/deciding whether or not to
shivanisha
2016/12/06 18:18:08
done.
| |
161 // cases of "same site" usage. On the other hand we do not want to block the | |
162 // scripts very aggressively causing page breaks. Thus, will see the counts | |
jkarlin
2016/11/29 16:19:12
s/the scripts very aggressively causing page break
jkarlin
2016/11/29 16:19:12
Final sentence can go, that's made clear from the
shivanisha
2016/12/06 18:18:08
Done
| |
163 // before deciding. | |
164 if (request.url().protocol() != document.getSecurityOrigin()->protocol()) { | |
165 document.loader()->didObserveLoadingBehavior( | |
166 WebLoadingBehaviorFlag:: | |
167 WebLoadingBehaviorDocumentWriteBlockDifferentScheme); | |
168 } | |
153 return false; | 169 return false; |
170 } | |
154 | 171 |
155 emitWarningForDocWriteScripts(request.url().getString(), document); | 172 emitWarningForDocWriteScripts(request.url().getString(), document); |
156 request.setHTTPHeaderField("Intervention", | 173 request.setHTTPHeaderField("Intervention", |
157 "<https://www.chromestatus.com/feature/" | 174 "<https://www.chromestatus.com/feature/" |
158 "5718547946799104>; level=\"warning\""); | 175 "5718547946799104>; level=\"warning\""); |
159 | 176 |
160 // Do not block scripts if it is a page reload. This is to enable pages to | 177 // Do not block scripts if it is a page reload. This is to enable pages to |
161 // recover if blocking of a script is leading to a page break and the user | 178 // recover if blocking of a script is leading to a page break and the user |
162 // reloads the page. | 179 // reloads the page. |
163 const FrameLoadType loadType = document.frame()->loader().loadType(); | 180 const FrameLoadType loadType = document.frame()->loader().loadType(); |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1004 response); | 1021 response); |
1005 } | 1022 } |
1006 | 1023 |
1007 DEFINE_TRACE(FrameFetchContext) { | 1024 DEFINE_TRACE(FrameFetchContext) { |
1008 visitor->trace(m_document); | 1025 visitor->trace(m_document); |
1009 visitor->trace(m_documentLoader); | 1026 visitor->trace(m_documentLoader); |
1010 FetchContext::trace(visitor); | 1027 FetchContext::trace(visitor); |
1011 } | 1028 } |
1012 | 1029 |
1013 } // namespace blink | 1030 } // namespace blink |
OLD | NEW |