Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp

Issue 2474943002: doc.write intervention warning message changed to replace cross-origin with cross site (etdl+1) (Closed)
Patch Set: Added a helper function Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
82 #include "public/platform/WebViewScheduler.h" 82 #include "public/platform/WebViewScheduler.h"
83 #include "wtf/Vector.h" 83 #include "wtf/Vector.h"
84 #include <algorithm> 84 #include <algorithm>
85 #include <memory> 85 #include <memory>
86 86
87 namespace blink { 87 namespace blink {
88 88
89 namespace { 89 namespace {
90 90
91 void emitWarningForDocWriteScripts(const String& url, Document& document) { 91 void emitWarningForDocWriteScripts(const String& url, Document& document) {
92 String message = "A Parser-blocking, cross-origin script, " + url + 92 String message =
93 ", is invoked via document.write. This may be blocked by " 93 "A Parser-blocking, cross site (i.e. different eTLD+1) script, " + url +
94 "the browser if the device has poor network connectivity. " 94 ", is invoked via document.write. This may be blocked by "
95 "See https://www.chromestatus.com/feature/5718547946799104 " 95 "the browser if the device has poor network connectivity. "
96 "for more details."; 96 "See https://www.chromestatus.com/feature/5718547946799104 "
97 "for more details.";
97 document.addConsoleMessage( 98 document.addConsoleMessage(
98 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); 99 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message));
99 WTFLogAlways("%s", message.utf8().data()); 100 WTFLogAlways("%s", message.utf8().data());
100 } 101 }
101 102
102 bool isConnectionEffectively2G(WebEffectiveConnectionType effectiveType) { 103 bool isConnectionEffectively2G(WebEffectiveConnectionType effectiveType) {
103 switch (effectiveType) { 104 switch (effectiveType) {
104 case WebEffectiveConnectionType::TypeSlow2G: 105 case WebEffectiveConnectionType::TypeSlow2G:
105 case WebEffectiveConnectionType::Type2G: 106 case WebEffectiveConnectionType::Type2G:
106 return true; 107 return true;
(...skipping 28 matching lines...) Expand all
135 PerformanceMonitor::documentWriteFetchScript(&document); 136 PerformanceMonitor::documentWriteFetchScript(&document);
136 137
137 if (!request.url().protocolIsInHTTPFamily()) 138 if (!request.url().protocolIsInHTTPFamily())
138 return false; 139 return false;
139 140
140 // Avoid blocking same origin scripts, as they may be used to render main 141 // Avoid blocking same origin scripts, as they may be used to render main
141 // page content, whereas cross-origin scripts inserted via document.write 142 // page content, whereas cross-origin scripts inserted via document.write
142 // are likely to be third party content. 143 // are likely to be third party content.
143 String requestHost = request.url().host(); 144 String requestHost = request.url().host();
144 String documentHost = document.getSecurityOrigin()->domain(); 145 String documentHost = document.getSecurityOrigin()->domain();
146
147 bool sameSite = false;
145 if (requestHost == documentHost) 148 if (requestHost == documentHost)
146 return false; 149 sameSite = true;
147 150
148 // If the hosts didn't match, then see if the domains match. For example, if 151 // If the hosts didn't match, then see if the domains match. For example, if
149 // a script is served from static.example.com for a document served from 152 // a script is served from static.example.com for a document served from
150 // www.example.com, we consider that a first party script and allow it. 153 // www.example.com, we consider that a first party script and allow it.
151 String requestDomain = NetworkUtils::getDomainAndRegistry( 154 String requestDomain = NetworkUtils::getDomainAndRegistry(
152 requestHost, NetworkUtils::IncludePrivateRegistries); 155 requestHost, NetworkUtils::IncludePrivateRegistries);
153 String documentDomain = NetworkUtils::getDomainAndRegistry( 156 String documentDomain = NetworkUtils::getDomainAndRegistry(
154 documentHost, NetworkUtils::IncludePrivateRegistries); 157 documentHost, NetworkUtils::IncludePrivateRegistries);
155 // getDomainAndRegistry will return the empty string for domains that are 158 // getDomainAndRegistry will return the empty string for domains that are
156 // already top-level, such as localhost. Thus we only compare domains if we 159 // already top-level, such as localhost. Thus we only compare domains if we
157 // get non-empty results back from getDomainAndRegistry. 160 // get non-empty results back from getDomainAndRegistry.
158 if (!requestDomain.isEmpty() && !documentDomain.isEmpty() && 161 if (!requestDomain.isEmpty() && !documentDomain.isEmpty() &&
159 requestDomain == documentDomain) 162 requestDomain == documentDomain)
163 sameSite = true;
164
165 if (sameSite) {
166 // This histogram is introduced to help decide whether we should also check
167 // same scheme while deciding whether or not to block the script as is done
168 // in other cases of "same site" usage. On the other hand we do not want to
169 // block more scripts than necessary.
170 if (request.url().protocol() != document.getSecurityOrigin()->protocol()) {
171 document.loader()->didObserveLoadingBehavior(
172 WebLoadingBehaviorFlag::
173 WebLoadingBehaviorDocumentWriteBlockDifferentScheme);
174 }
160 return false; 175 return false;
176 }
161 177
162 emitWarningForDocWriteScripts(request.url().getString(), document); 178 emitWarningForDocWriteScripts(request.url().getString(), document);
163 request.setHTTPHeaderField("Intervention", 179 request.setHTTPHeaderField("Intervention",
164 "<https://www.chromestatus.com/feature/" 180 "<https://www.chromestatus.com/feature/"
165 "5718547946799104>; level=\"warning\""); 181 "5718547946799104>; level=\"warning\"");
166 182
167 // Do not block scripts if it is a page reload. This is to enable pages to 183 // Do not block scripts if it is a page reload. This is to enable pages to
168 // recover if blocking of a script is leading to a page break and the user 184 // recover if blocking of a script is leading to a page break and the user
169 // reloads the page. 185 // reloads the page.
170 const FrameLoadType loadType = document.frame()->loader().loadType(); 186 const FrameLoadType loadType = document.frame()->loader().loadType();
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 response); 1074 response);
1059 } 1075 }
1060 1076
1061 DEFINE_TRACE(FrameFetchContext) { 1077 DEFINE_TRACE(FrameFetchContext) {
1062 visitor->trace(m_document); 1078 visitor->trace(m_document);
1063 visitor->trace(m_documentLoader); 1079 visitor->trace(m_documentLoader);
1064 FetchContext::trace(visitor); 1080 FetchContext::trace(visitor);
1065 } 1081 }
1066 1082
1067 } // namespace blink 1083 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698