blob: 0dd36c7af0e143b9eac73932f6214163652efad9 [file] [log] [blame]
[email protected]9045b8822012-01-13 20:35:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ac039522010-06-15 16:39:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/net/chrome_network_delegate.h"
6
[email protected]eac11e12013-03-19 22:04:327#include <stdlib.h>
8
[email protected]d1208ba32012-11-08 11:10:339#include <vector>
10
[email protected]d8e4f132012-09-06 04:28:0511#include "base/base_paths.h"
jochenb93dba3c2014-11-11 05:28:4112#include "base/debug/alias.h"
jochenb5680e62014-10-13 08:43:4113#include "base/debug/dump_without_crashing.h"
jochenb93dba3c2014-11-11 05:28:4114#include "base/debug/stack_trace.h"
[email protected]4aca5db2013-08-17 00:51:5615#include "base/debug/trace_event.h"
[email protected]7a299a92012-10-24 23:54:5016#include "base/logging.h"
17#include "base/metrics/histogram.h"
jochen0e3b3a62014-09-16 18:31:2318#include "base/metrics/user_metrics.h"
[email protected]d8e4f132012-09-06 04:28:0519#include "base/path_service.h"
[email protected]1ab137b2013-03-21 03:33:1820#include "base/prefs/pref_member.h"
[email protected]3853a4c2013-02-11 17:15:5721#include "base/prefs/pref_service.h"
vadimt81ef0df2014-11-18 19:42:3122#include "base/profiler/scoped_tracker.h"
[email protected]3ea1b182013-02-08 22:38:4123#include "base/strings/string_number_conversions.h"
[email protected]069c49162013-09-11 20:46:3524#include "base/time/time.h"
[email protected]6baff0b52012-03-06 01:30:1825#include "chrome/browser/browser_process.h"
[email protected]9c8ae8c2012-03-09 13:13:3526#include "chrome/browser/content_settings/cookie_settings.h"
27#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]8523ba52011-05-22 19:00:5828#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]4a2b6232014-06-19 08:44:1429#include "chrome/browser/net/chrome_extensions_network_delegate.h"
[email protected]3620bbc2013-10-05 05:07:2330#include "chrome/browser/net/client_hints.h"
[email protected]f53b4802012-12-20 17:04:2331#include "chrome/browser/net/connect_interceptor.h"
[email protected]184799df2014-07-22 16:03:2432#include "chrome/browser/net/safe_search_util.h"
[email protected]28c5d0b72014-05-13 08:19:5933#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]6baff0b52012-03-06 01:30:1834#include "chrome/browser/profiles/profile_manager.h"
[email protected]8523ba52011-05-22 19:00:5835#include "chrome/browser/task_manager/task_manager.h"
[email protected]0a8db0d2011-04-13 15:15:4036#include "chrome/common/pref_names.h"
megjablon3476e042014-10-14 19:21:5937#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
38#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h"
megjablon3476e042014-10-14 19:21:5939#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
40#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h"
jeremyimdb2599e2014-10-29 02:13:0941#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
[email protected]45de676a2014-03-18 23:52:0242#include "components/domain_reliability/monitor.h"
[email protected]c38831a12011-10-28 12:44:4943#include "content/public/browser/browser_thread.h"
[email protected]9dfed872013-12-30 23:08:5644#include "content/public/browser/render_frame_host.h"
[email protected]9c1662b2012-03-06 15:44:3345#include "content/public/browser/render_view_host.h"
[email protected]9c8ae8c2012-03-09 13:13:3546#include "content/public/browser/resource_request_info.h"
[email protected]82b42302011-04-20 16:28:1647#include "net/base/host_port_pair.h"
[email protected]8202d0c2011-02-23 08:31:1448#include "net/base/net_errors.h"
[email protected]6a5f77c32011-09-04 19:19:5949#include "net/base/net_log.h"
[email protected]5b9bc352012-07-18 13:13:3450#include "net/cookies/canonical_cookie.h"
51#include "net/cookies/cookie_options.h"
[email protected]ac039522010-06-15 16:39:4452#include "net/http/http_request_headers.h"
[email protected]48944382011-04-23 13:28:1653#include "net/http/http_response_headers.h"
[email protected]12731792014-08-14 11:45:5454#include "net/proxy/proxy_config.h"
[email protected]597a1ab2014-06-26 08:12:2755#include "net/proxy/proxy_info.h"
[email protected]12731792014-08-14 11:45:5456#include "net/proxy/proxy_retry_info.h"
[email protected]597a1ab2014-06-26 08:12:2757#include "net/proxy/proxy_server.h"
[email protected]d05ef99c2011-02-01 21:38:1658#include "net/url_request/url_request.h"
[email protected]28c5d0b72014-05-13 08:19:5959#include "net/url_request/url_request_context.h"
[email protected]d05ef99c2011-02-01 21:38:1660
[email protected]4a2b6232014-06-19 08:44:1461#if defined(OS_ANDROID)
62#include "chrome/browser/io_thread.h"
63#include "components/precache/content/precache_manager.h"
64#include "components/precache/content/precache_manager_factory.h"
65#endif
66
[email protected]4c219e22012-05-05 19:41:0467#if defined(OS_CHROMEOS)
[email protected]288538482012-09-06 21:09:3568#include "base/command_line.h"
[email protected]49c4cf852013-09-27 19:28:2469#include "base/sys_info.h"
[email protected]288538482012-09-06 21:09:3570#include "chrome/common/chrome_switches.h"
[email protected]4c219e22012-05-05 19:41:0471#endif
72
[email protected]3e598ff12011-09-06 11:22:3473#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]f522afa2014-01-08 15:36:3674#include "components/policy/core/browser/url_blacklist_manager.h"
[email protected]3e598ff12011-09-06 11:22:3475#endif
76
[email protected]84b7a552014-07-19 04:52:0677#if defined(ENABLE_EXTENSIONS)
78#include "extensions/common/constants.h"
79#endif
80
[email protected]631bb742011-11-02 11:29:3981using content::BrowserThread;
[email protected]eaabba22012-03-07 15:02:1182using content::RenderViewHost;
[email protected]ea114722012-03-12 01:11:2583using content::ResourceRequestInfo;
[email protected]7491ad02014-07-05 19:10:0784using content::ResourceType;
[email protected]631bb742011-11-02 11:29:3985
[email protected]d8e4f132012-09-06 04:28:0586// By default we don't allow access to all file:// urls on ChromeOS and
87// Android.
88#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:0489bool ChromeNetworkDelegate::g_allow_file_access_ = false;
90#else
91bool ChromeNetworkDelegate::g_allow_file_access_ = true;
92#endif
93
[email protected]84b7a552014-07-19 04:52:0694#if defined(ENABLE_EXTENSIONS)
[email protected]c4a7df82012-08-09 22:48:4695// This remains false unless the --disable-extensions-http-throttling
96// flag is passed to the browser.
97bool ChromeNetworkDelegate::g_never_throttle_requests_ = false;
[email protected]84b7a552014-07-19 04:52:0698#endif
[email protected]c4a7df82012-08-09 22:48:4699
[email protected]d05ef99c2011-02-01 21:38:16100namespace {
101
[email protected]9d8cfb682012-09-13 16:48:04102const char kDNTHeader[] = "DNT";
103
[email protected]d1208ba32012-11-08 11:10:33104// Gets called when the extensions finish work on the URL. If the extensions
105// did not do a redirect (so |new_url| is empty) then we enforce the
106// SafeSearch parameters. Otherwise we will get called again after the
107// redirect and we enforce SafeSearch then.
108void ForceGoogleSafeSearchCallbackWrapper(
109 const net::CompletionCallback& callback,
110 net::URLRequest* request,
111 GURL* new_url,
112 int rv) {
113 if (rv == net::OK && new_url->is_empty())
[email protected]184799df2014-07-22 16:03:24114 safe_search_util::ForceGoogleSafeSearch(request, new_url);
[email protected]d1208ba32012-11-08 11:10:33115 callback.Run(rv);
116}
117
[email protected]828eab22013-12-10 22:42:38118void UpdateContentLengthPrefs(
119 int received_content_length,
120 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42121 data_reduction_proxy::DataReductionProxyRequestType request_type,
megjablon53f608b2014-09-18 19:24:55122 Profile* profile,
123 data_reduction_proxy::DataReductionProxyStatisticsPrefs* statistics_prefs) {
[email protected]7a299a92012-10-24 23:54:50124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
125 DCHECK_GE(received_content_length, 0);
126 DCHECK_GE(original_content_length, 0);
127
[email protected]a09159a2012-11-29 12:51:48128 // Can be NULL in a unit test.
129 if (!g_browser_process)
130 return;
131
[email protected]b7796462013-12-12 19:42:34132 // Ignore off-the-record data.
133 if (!g_browser_process->profile_manager()->IsValidProfile(profile) ||
134 profile->IsOffTheRecord()) {
135 return;
136 }
megjablon53f608b2014-09-18 19:24:55137 data_reduction_proxy::UpdateContentLengthPrefs(
138 received_content_length,
139 original_content_length,
kundaji88ca4112014-09-23 01:35:21140 profile->GetPrefs(),
141 request_type, statistics_prefs);
[email protected]7a299a92012-10-24 23:54:50142}
143
[email protected]828eab22013-12-10 22:42:38144void StoreAccumulatedContentLength(
145 int received_content_length,
146 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42147 data_reduction_proxy::DataReductionProxyRequestType request_type,
megjablon53f608b2014-09-18 19:24:55148 Profile* profile,
149 data_reduction_proxy::DataReductionProxyStatisticsPrefs* statistics_prefs) {
[email protected]7a299a92012-10-24 23:54:50150 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
151 base::Bind(&UpdateContentLengthPrefs,
megjablon53f608b2014-09-18 19:24:55152 received_content_length,
153 original_content_length,
154 request_type,
155 profile,
156 statistics_prefs));
[email protected]7a299a92012-10-24 23:54:50157}
158
159void RecordContentLengthHistograms(
[email protected]f81a5ee2013-06-20 21:08:49160 int64 received_content_length,
161 int64 original_content_length,
162 const base::TimeDelta& freshness_lifetime) {
[email protected]7a299a92012-10-24 23:54:50163 // Add the current resource to these histograms only when a valid
164 // X-Original-Content-Length header is present.
165 if (original_content_length >= 0) {
166 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL",
167 received_content_length);
168 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL",
169 original_content_length);
170 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL",
171 original_content_length - received_content_length);
172 } else {
173 // Presume the original content length is the same as the received content
174 // length if the X-Original-Content-Header is not present.
175 original_content_length = received_content_length;
176 }
177 UMA_HISTOGRAM_COUNTS("Net.HttpContentLength", received_content_length);
178 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLength",
179 original_content_length);
180 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifference",
181 original_content_length - received_content_length);
[email protected]f81a5ee2013-06-20 21:08:49182 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpContentFreshnessLifetime",
183 freshness_lifetime.InSeconds(),
184 base::TimeDelta::FromHours(1).InSeconds(),
185 base::TimeDelta::FromDays(30).InSeconds(),
186 100);
187 if (freshness_lifetime.InSeconds() <= 0)
188 return;
189 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable",
190 received_content_length);
191 if (freshness_lifetime.InHours() < 4)
192 return;
193 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours",
194 received_content_length);
195
196 if (freshness_lifetime.InHours() < 24)
197 return;
198 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours",
199 received_content_length);
[email protected]7a299a92012-10-24 23:54:50200}
201
[email protected]35558812013-12-18 21:58:36202#if defined(OS_ANDROID)
203void RecordPrecacheStatsOnUIThread(const GURL& url,
204 const base::Time& fetch_time, int64 size,
205 bool was_cached, void* profile_id) {
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
207
208 Profile* profile = reinterpret_cast<Profile*>(profile_id);
209 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) {
210 return;
211 }
212
213 precache::PrecacheManager* precache_manager =
214 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
tanviraumi387f6332014-08-29 19:04:36215 if (!precache_manager || !precache_manager->IsPrecachingAllowed()) {
216 // |precache_manager| could be NULL if the profile is off the record.
[email protected]35558812013-12-18 21:58:36217 return;
218 }
219
220 precache_manager->RecordStatsForFetch(url, fetch_time, size, was_cached);
221}
[email protected]35558812013-12-18 21:58:36222#endif // defined(OS_ANDROID)
223
jochen0e3b3a62014-09-16 18:31:23224void ReportInvalidReferrerSend(const GURL& target_url,
jochenb93dba3c2014-11-11 05:28:41225 const GURL& referrer_url,
226 const base::debug::StackTrace& callstack) {
227 // Record information to help debug http://crbug.com/422871
228 base::debug::StackTrace trace = callstack;
229 base::debug::Alias(&trace);
230 enum { INVALID_URL, FILE_URL, DATA_URL, HTTP_URL, OTHER } reason = OTHER;
231 if (!target_url.is_valid())
232 reason = INVALID_URL;
233 else if (target_url.SchemeIsFile())
234 reason = FILE_URL;
235 else if (target_url.SchemeIs(url::kDataScheme))
236 reason = DATA_URL;
237 else if (target_url.SchemeIs(url::kHttpScheme))
238 reason = HTTP_URL;
239 base::debug::Alias(&reason);
jochen0e3b3a62014-09-16 18:31:23240 base::RecordAction(
241 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer"));
jochenb5680e62014-10-13 08:43:41242 base::debug::DumpWithoutCrashing();
243 NOTREACHED();
jochen0e3b3a62014-09-16 18:31:23244}
245
[email protected]d05ef99c2011-02-01 21:38:16246} // namespace
[email protected]ac039522010-06-15 16:39:44247
[email protected]0651b812011-02-24 00:22:50248ChromeNetworkDelegate::ChromeNetworkDelegate(
[email protected]5a38dfd2012-07-23 23:22:10249 extensions::EventRouterForwarder* event_router,
[email protected]a09159a2012-11-29 12:51:48250 BooleanPrefMember* enable_referrers)
[email protected]4a2b6232014-06-19 08:44:14251 : profile_(NULL),
[email protected]6a5f77c32011-09-04 19:19:59252 enable_referrers_(enable_referrers),
[email protected]a09159a2012-11-29 12:51:48253 enable_do_not_track_(NULL),
254 force_google_safe_search_(NULL),
[email protected]a948dad2014-07-25 00:39:38255 data_reduction_proxy_enabled_(NULL),
[email protected]4a2b6232014-06-19 08:44:14256#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]a09159a2012-11-29 12:51:48257 url_blacklist_manager_(NULL),
[email protected]4a2b6232014-06-19 08:44:14258#endif
[email protected]45de676a2014-03-18 23:52:02259 domain_reliability_monitor_(NULL),
[email protected]7a299a92012-10-24 23:54:50260 received_content_length_(0),
[email protected]d827e112014-03-31 17:45:05261 original_content_length_(0),
[email protected]28c5d0b72014-05-13 08:19:59262 first_request_(true),
[email protected]d8fc4722014-06-13 13:17:15263 prerender_tracker_(NULL),
[email protected]bceab7f2014-06-25 04:36:20264 data_reduction_proxy_params_(NULL),
[email protected]597a1ab2014-06-26 08:12:27265 data_reduction_proxy_usage_stats_(NULL),
megjablon53f608b2014-09-18 19:24:55266 data_reduction_proxy_auth_request_handler_(NULL),
267 data_reduction_proxy_statistics_prefs_(NULL) {
[email protected]0a8db0d2011-04-13 15:15:40268 DCHECK(enable_referrers);
[email protected]4a2b6232014-06-19 08:44:14269 extensions_delegate_.reset(
270 ChromeExtensionsNetworkDelegate::Create(event_router));
[email protected]0651b812011-02-24 00:22:50271}
272
[email protected]ac039522010-06-15 16:39:44273ChromeNetworkDelegate::~ChromeNetworkDelegate() {}
274
[email protected]a09159a2012-11-29 12:51:48275void ChromeNetworkDelegate::set_extension_info_map(
[email protected]38427a12013-11-09 17:34:20276 extensions::InfoMap* extension_info_map) {
[email protected]4a2b6232014-06-19 08:44:14277 extensions_delegate_->set_extension_info_map(extension_info_map);
278}
279
280void ChromeNetworkDelegate::set_profile(void* profile) {
281 profile_ = profile;
282 extensions_delegate_->set_profile(profile);
[email protected]a09159a2012-11-29 12:51:48283}
284
285void ChromeNetworkDelegate::set_cookie_settings(
286 CookieSettings* cookie_settings) {
287 cookie_settings_ = cookie_settings;
288}
289
[email protected]f53b4802012-12-20 17:04:23290void ChromeNetworkDelegate::set_predictor(
291 chrome_browser_net::Predictor* predictor) {
292 connect_interceptor_.reset(
293 new chrome_browser_net::ConnectInterceptor(predictor));
294}
295
[email protected]3620bbc2013-10-05 05:07:23296void ChromeNetworkDelegate::SetEnableClientHints() {
297 client_hints_.reset(new ClientHints());
298 client_hints_->Init();
299}
300
[email protected]c4a7df82012-08-09 22:48:46301// static
[email protected]84b7a552014-07-19 04:52:06302#if defined(ENABLE_EXTENSIONS)
[email protected]a1d4ab072012-06-07 13:21:15303void ChromeNetworkDelegate::NeverThrottleRequests() {
[email protected]c4a7df82012-08-09 22:48:46304 g_never_throttle_requests_ = true;
[email protected]a1d4ab072012-06-07 13:21:15305}
[email protected]84b7a552014-07-19 04:52:06306#endif
[email protected]a1d4ab072012-06-07 13:21:15307
[email protected]0a8db0d2011-04-13 15:15:40308// static
[email protected]9d8cfb682012-09-13 16:48:04309void ChromeNetworkDelegate::InitializePrefsOnUIThread(
[email protected]0a8db0d2011-04-13 15:15:40310 BooleanPrefMember* enable_referrers,
[email protected]9d8cfb682012-09-13 16:48:04311 BooleanPrefMember* enable_do_not_track,
[email protected]d1208ba32012-11-08 11:10:33312 BooleanPrefMember* force_google_safe_search,
[email protected]0a8db0d2011-04-13 15:15:40313 PrefService* pref_service) {
314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]96a5c342012-12-04 18:14:02315 enable_referrers->Init(prefs::kEnableReferrers, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43316 enable_referrers->MoveToThread(
317 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04318 if (enable_do_not_track) {
[email protected]96a5c342012-12-04 18:14:02319 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43320 enable_do_not_track->MoveToThread(
321 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04322 }
[email protected]d1208ba32012-11-08 11:10:33323 if (force_google_safe_search) {
[email protected]96a5c342012-12-04 18:14:02324 force_google_safe_search->Init(prefs::kForceSafeSearch, pref_service);
[email protected]d1208ba32012-11-08 11:10:33325 force_google_safe_search->MoveToThread(
326 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
327 }
[email protected]0a8db0d2011-04-13 15:15:40328}
329
[email protected]4c219e22012-05-05 19:41:04330// static
331void ChromeNetworkDelegate::AllowAccessToAllFiles() {
332 g_allow_file_access_ = true;
333}
334
[email protected]7a299a92012-10-24 23:54:50335// static
megjablon53f608b2014-09-18 19:24:55336// TODO(megjablon): Use data_reduction_proxy_delayed_pref_service to read prefs.
337// Until updated the pref values may be up to an hour behind on desktop.
megjablon16b7909472014-11-15 00:26:01338base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue(
339 PrefService* prefs) {
[email protected]7a299a92012-10-24 23:54:50340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a0a06932014-04-14 21:23:42341 int64 total_received = prefs->GetInt64(
342 data_reduction_proxy::prefs::kHttpReceivedContentLength);
343 int64 total_original = prefs->GetInt64(
344 data_reduction_proxy::prefs::kHttpOriginalContentLength);
[email protected]7a299a92012-10-24 23:54:50345
[email protected]cb1078de2013-12-23 20:04:22346 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42347 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
348 dict->SetString("historic_received_content_length",
349 base::Int64ToString(total_received));
350 dict->SetString("historic_original_content_length",
351 base::Int64ToString(total_original));
[email protected]7a299a92012-10-24 23:54:50352 return dict;
353}
354
[email protected]cb1078de2013-12-23 20:04:22355base::Value* ChromeNetworkDelegate::SessionNetworkStatsInfoToValue() const {
356 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42357 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
358 dict->SetString("session_received_content_length",
359 base::Int64ToString(received_content_length_));
360 dict->SetString("session_original_content_length",
361 base::Int64ToString(original_content_length_));
[email protected]7a299a92012-10-24 23:54:50362 return dict;
363}
364
[email protected]4875ba12011-03-30 22:31:51365int ChromeNetworkDelegate::OnBeforeURLRequest(
[email protected]4c76d7c2011-04-15 19:14:12366 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47367 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12368 GURL* new_url) {
[email protected]3e598ff12011-09-06 11:22:34369#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]6a5f77c32011-09-04 19:19:59370 // TODO(joaodasilva): This prevents extensions from seeing URLs that are
371 // blocked. However, an extension might redirect the request to another URL,
372 // which is not blocked.
[email protected]cb85f8e52014-04-08 11:44:40373 int error = net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]6a5f77c32011-09-04 19:19:59374 if (url_blacklist_manager_ &&
[email protected]cb85f8e52014-04-08 11:44:40375 url_blacklist_manager_->IsRequestBlocked(*request, &error)) {
[email protected]6a5f77c32011-09-04 19:19:59376 // URL access blocked by policy.
[email protected]6a5f77c32011-09-04 19:19:59377 request->net_log().AddEvent(
[email protected]2fa08912012-06-14 20:56:26378 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
379 net::NetLog::StringCallback("url",
380 &request->url().possibly_invalid_spec()));
[email protected]cb85f8e52014-04-08 11:44:40381 return error;
[email protected]6a5f77c32011-09-04 19:19:59382 }
[email protected]3e598ff12011-09-06 11:22:34383#endif
[email protected]6a5f77c32011-09-04 19:19:59384
[email protected]4a2b6232014-06-19 08:44:14385 extensions_delegate_->ForwardStartRequestStatus(request);
[email protected]6baff0b52012-03-06 01:30:18386
[email protected]0a8db0d2011-04-13 15:15:40387 if (!enable_referrers_->GetValue())
[email protected]99ecf6e2013-04-10 22:46:13388 request->SetReferrer(std::string());
[email protected]9d8cfb682012-09-13 16:48:04389 if (enable_do_not_track_ && enable_do_not_track_->GetValue())
390 request->SetExtraRequestHeaderByName(kDNTHeader, "1", true /* override */);
[email protected]d1208ba32012-11-08 11:10:33391
[email protected]3620bbc2013-10-05 05:07:23392 if (client_hints_) {
393 request->SetExtraRequestHeaderByName(
394 ClientHints::kDevicePixelRatioHeader,
395 client_hints_->GetDevicePixelRatioHeader(), true);
396 }
397
[email protected]d1208ba32012-11-08 11:10:33398 bool force_safe_search = force_google_safe_search_ &&
399 force_google_safe_search_->GetValue();
400
401 net::CompletionCallback wrapped_callback = callback;
402 if (force_safe_search) {
403 wrapped_callback = base::Bind(&ForceGoogleSafeSearchCallbackWrapper,
404 callback,
405 base::Unretained(request),
406 base::Unretained(new_url));
407 }
408
[email protected]4a2b6232014-06-19 08:44:14409 int rv = extensions_delegate_->OnBeforeURLRequest(
410 request, wrapped_callback, new_url);
[email protected]d1208ba32012-11-08 11:10:33411
412 if (force_safe_search && rv == net::OK && new_url->is_empty())
[email protected]184799df2014-07-22 16:03:24413 safe_search_util::ForceGoogleSafeSearch(request, new_url);
[email protected]d1208ba32012-11-08 11:10:33414
[email protected]f53b4802012-12-20 17:04:23415 if (connect_interceptor_)
416 connect_interceptor_->WitnessURLRequest(request);
417
[email protected]d1208ba32012-11-08 11:10:33418 return rv;
[email protected]d05ef99c2011-02-01 21:38:16419}
420
[email protected]a702da72014-07-09 05:23:54421void ChromeNetworkDelegate::OnResolveProxy(
[email protected]12731792014-08-14 11:45:54422 const GURL& url,
423 int load_flags,
424 const net::ProxyService& proxy_service,
425 net::ProxyInfo* result) {
426 if (!on_resolve_proxy_handler_.is_null() &&
427 !proxy_config_getter_.is_null()) {
[email protected]a702da72014-07-09 05:23:54428 on_resolve_proxy_handler_.Run(url, load_flags,
[email protected]12731792014-08-14 11:45:54429 proxy_config_getter_.Run(),
bengrf5c403d2014-11-04 03:02:57430 proxy_service.config(),
[email protected]12731792014-08-14 11:45:54431 proxy_service.proxy_retry_info(),
[email protected]a702da72014-07-09 05:23:54432 data_reduction_proxy_params_, result);
433 }
434}
435
[email protected]f09f9682014-08-10 01:21:39436void ChromeNetworkDelegate::OnProxyFallback(const net::ProxyServer& bad_proxy,
[email protected]d0483b192014-08-15 23:50:17437 int net_error) {
[email protected]f09f9682014-08-10 01:21:39438 if (data_reduction_proxy_usage_stats_) {
kundajia9a4b7da2014-09-23 21:10:56439 data_reduction_proxy_usage_stats_->OnProxyFallback(
[email protected]d0483b192014-08-15 23:50:17440 bad_proxy, net_error);
[email protected]f09f9682014-08-10 01:21:39441 }
442}
443
[email protected]4875ba12011-03-30 22:31:51444int ChromeNetworkDelegate::OnBeforeSendHeaders(
[email protected]636eccd2011-06-28 12:28:01445 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47446 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12447 net::HttpRequestHeaders* headers) {
[email protected]184799df2014-07-22 16:03:24448 bool force_safe_search = force_google_safe_search_ &&
449 force_google_safe_search_->GetValue();
450 if (force_safe_search)
451 safe_search_util::ForceYouTubeSafetyMode(request, headers);
452
[email protected]186468f2013-10-24 02:44:11453 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest");
[email protected]4a2b6232014-06-19 08:44:14454 return extensions_delegate_->OnBeforeSendHeaders(request, callback, headers);
[email protected]ac039522010-06-15 16:39:44455}
[email protected]8202d0c2011-02-23 08:31:14456
[email protected]597a1ab2014-06-26 08:12:27457void ChromeNetworkDelegate::OnBeforeSendProxyHeaders(
458 net::URLRequest* request,
459 const net::ProxyInfo& proxy_info,
460 net::HttpRequestHeaders* headers) {
461 if (data_reduction_proxy_auth_request_handler_) {
462 data_reduction_proxy_auth_request_handler_->MaybeAddRequestHeader(
463 request, proxy_info.proxy_server(), headers);
464 }
465}
466
[email protected]5796dc942011-07-14 19:26:10467void ChromeNetworkDelegate::OnSendHeaders(
468 net::URLRequest* request,
[email protected]783573b2011-05-13 11:05:15469 const net::HttpRequestHeaders& headers) {
[email protected]4a2b6232014-06-19 08:44:14470 extensions_delegate_->OnSendHeaders(request, headers);
[email protected]82b42302011-04-20 16:28:16471}
472
[email protected]ea8141e2011-10-05 13:12:51473int ChromeNetworkDelegate::OnHeadersReceived(
474 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47475 const net::CompletionCallback& callback,
[email protected]507af8f2012-10-20 00:42:32476 const net::HttpResponseHeaders* original_response_headers,
[email protected]5f714132014-03-26 10:41:16477 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
478 GURL* allowed_unsafe_redirect_url) {
[email protected]4a2b6232014-06-19 08:44:14479 return extensions_delegate_->OnHeadersReceived(
[email protected]5f714132014-03-26 10:41:16480 request,
481 callback,
482 original_response_headers,
483 override_response_headers,
484 allowed_unsafe_redirect_url);
[email protected]ea8141e2011-10-05 13:12:51485}
486
[email protected]31b2e5f2011-04-20 16:58:32487void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
488 const GURL& new_location) {
[email protected]45de676a2014-03-18 23:52:02489 if (domain_reliability_monitor_)
490 domain_reliability_monitor_->OnBeforeRedirect(request);
[email protected]4a2b6232014-06-19 08:44:14491 extensions_delegate_->OnBeforeRedirect(request, new_location);
[email protected]31b2e5f2011-04-20 16:58:32492}
493
494
[email protected]8202d0c2011-02-23 08:31:14495void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
[email protected]186468f2013-10-24 02:44:11496 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "ResponseStarted");
[email protected]4a2b6232014-06-19 08:44:14497 extensions_delegate_->OnResponseStarted(request);
[email protected]8202d0c2011-02-23 08:31:14498}
499
[email protected]8523ba52011-05-22 19:00:58500void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
501 int bytes_read) {
vadimt81ef0df2014-11-18 19:42:31502 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
503 tracked_objects::ScopedTracker tracking_profile(
504 FROM_HERE_WITH_EXPLICIT_FUNCTION(
505 "423948 ChromeNetworkDelegate::OnRawBytesRead"));
506
[email protected]186468f2013-10-24 02:44:11507 TRACE_EVENT_ASYNC_STEP_PAST1("net", "URLRequest", &request, "DidRead",
508 "bytes_read", bytes_read);
[email protected]44879ed2012-04-06 01:11:02509#if defined(ENABLE_TASK_MANAGER)
[email protected]17df9e7c2014-02-13 03:49:29510 // This is not completely accurate, but as a first approximation ignore
511 // requests that are served from the cache. See bug 330931 for more info.
512 if (!request.was_cached())
513 TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read);
[email protected]44879ed2012-04-06 01:11:02514#endif // defined(ENABLE_TASK_MANAGER)
[email protected]8523ba52011-05-22 19:00:58515}
516
[email protected]9045b8822012-01-13 20:35:35517void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
518 bool started) {
[email protected]bceab7f2014-06-25 04:36:20519 if (data_reduction_proxy_usage_stats_)
520 data_reduction_proxy_usage_stats_->OnUrlRequestCompleted(request, started);
521
[email protected]4aca5db2013-08-17 00:51:56522 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request);
[email protected]2756a8e2012-09-07 18:24:29523 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
[email protected]7a299a92012-10-24 23:54:50524 // For better accuracy, we use the actual bytes read instead of the length
525 // specified with the Content-Length header, which may be inaccurate,
526 // or missing, as is the case with chunked encoding.
527 int64 received_content_length = request->received_response_content_length();
528
[email protected]35558812013-12-18 21:58:36529#if defined(OS_ANDROID)
530 if (precache::PrecacheManager::IsPrecachingEnabled()) {
531 // Record precache metrics when a fetch is completed successfully, if
532 // precaching is enabled.
533 BrowserThread::PostTask(
534 BrowserThread::UI, FROM_HERE,
535 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(),
536 base::Time::Now(), received_content_length,
537 request->was_cached(), profile_));
538 }
539#endif // defined(OS_ANDROID)
540
[email protected]7a299a92012-10-24 23:54:50541 // Only record for http or https urls.
542 bool is_http = request->url().SchemeIs("http");
543 bool is_https = request->url().SchemeIs("https");
544
545 if (!request->was_cached() && // Don't record cached content
546 received_content_length && // Zero-byte responses aren't useful.
547 (is_http || is_https)) { // Only record for HTTP or HTTPS urls.
548 int64 original_content_length =
549 request->response_info().headers->GetInt64HeaderValue(
550 "x-original-content-length");
[email protected]a0a06932014-04-14 21:23:42551 data_reduction_proxy::DataReductionProxyRequestType request_type =
552 data_reduction_proxy::GetDataReductionProxyRequestType(request);
[email protected]2db93e42013-08-07 17:40:41553
[email protected]f81a5ee2013-06-20 21:08:49554 base::TimeDelta freshness_lifetime =
ricea43736982014-10-30 09:15:48555 request->response_info().headers->GetFreshnessLifetimes(
556 request->response_info().response_time).freshness;
[email protected]828eab22013-12-10 22:42:38557 int64 adjusted_original_content_length =
[email protected]a0a06932014-04-14 21:23:42558 data_reduction_proxy::GetAdjustedOriginalContentLength(
559 request_type, original_content_length,
[email protected]828eab22013-12-10 22:42:38560 received_content_length);
[email protected]7a299a92012-10-24 23:54:50561 AccumulateContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41562 adjusted_original_content_length,
[email protected]a0a06932014-04-14 21:23:42563 request_type);
[email protected]7a299a92012-10-24 23:54:50564 RecordContentLengthHistograms(received_content_length,
[email protected]f81a5ee2013-06-20 21:08:49565 original_content_length,
566 freshness_lifetime);
sclittlef72ee642014-09-24 20:04:28567
megjablon25ff71d32014-09-05 03:21:44568 if (data_reduction_proxy_enabled_ &&
569 data_reduction_proxy_usage_stats_ &&
570 !proxy_config_getter_.is_null()) {
sclittlef72ee642014-09-24 20:04:28571 data_reduction_proxy_usage_stats_->RecordBytesHistograms(
572 request,
megjablon25ff71d32014-09-05 03:21:44573 *data_reduction_proxy_enabled_,
574 proxy_config_getter_.Run());
[email protected]a948dad2014-07-25 00:39:38575 }
[email protected]7a299a92012-10-24 23:54:50576 DVLOG(2) << __FUNCTION__
577 << " received content length: " << received_content_length
578 << " original content length: " << original_content_length
579 << " url: " << request->url();
580 }
581
[email protected]4a2b6232014-06-19 08:44:14582 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01583 } else if (request->status().status() == net::URLRequestStatus::FAILED ||
584 request->status().status() == net::URLRequestStatus::CANCELED) {
[email protected]4a2b6232014-06-19 08:44:14585 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01586 } else {
587 NOTREACHED();
[email protected]48944382011-04-23 13:28:16588 }
[email protected]45de676a2014-03-18 23:52:02589 if (domain_reliability_monitor_)
590 domain_reliability_monitor_->OnCompleted(request, started);
[email protected]4a2b6232014-06-19 08:44:14591 extensions_delegate_->ForwardProxyErrors(request);
592 extensions_delegate_->ForwardDoneRequestStatus(request);
[email protected]8202d0c2011-02-23 08:31:14593}
[email protected]4b50cb52011-03-10 00:29:37594
[email protected]4875ba12011-03-30 22:31:51595void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
[email protected]4a2b6232014-06-19 08:44:14596 extensions_delegate_->OnURLRequestDestroyed(request);
[email protected]4875ba12011-03-30 22:31:51597}
598
[email protected]82a37672011-05-03 12:02:41599void ChromeNetworkDelegate::OnPACScriptError(int line_number,
[email protected]439f1e32013-12-09 20:09:09600 const base::string16& error) {
[email protected]4a2b6232014-06-19 08:44:14601 extensions_delegate_->OnPACScriptError(line_number, error);
[email protected]82a37672011-05-03 12:02:41602}
[email protected]7efc582d2011-08-03 20:46:35603
[email protected]c2911d72011-10-03 22:16:36604net::NetworkDelegate::AuthRequiredResponse
605ChromeNetworkDelegate::OnAuthRequired(
[email protected]7efc582d2011-08-03 20:46:35606 net::URLRequest* request,
[email protected]c2911d72011-10-03 22:16:36607 const net::AuthChallengeInfo& auth_info,
608 const AuthCallback& callback,
609 net::AuthCredentials* credentials) {
[email protected]4a2b6232014-06-19 08:44:14610 return extensions_delegate_->OnAuthRequired(
611 request, auth_info, callback, credentials);
[email protected]7efc582d2011-08-03 20:46:35612}
[email protected]9c8ae8c2012-03-09 13:13:35613
[email protected]4c219e22012-05-05 19:41:04614bool ChromeNetworkDelegate::OnCanGetCookies(
615 const net::URLRequest& request,
[email protected]9c8ae8c2012-03-09 13:13:35616 const net::CookieList& cookie_list) {
617 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02618 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35619 return true;
620
621 bool allow = cookie_settings_->IsReadingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04622 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35623
624 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16625 int render_frame_id = -1;
[email protected]f7fa5b62014-03-19 15:20:06626
627 // |is_for_blocking_resource| indicates whether the cookies read were for a
628 // blocking resource (eg script, css). It is only temporarily added for
629 // diagnostic purposes, per bug 353678. Will be removed again once data
630 // collection is finished.
631 bool is_for_blocking_resource = false;
632 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
633 if (info && ((!info->IsAsync()) ||
[email protected]6c1e05212014-07-31 00:59:40634 info->GetResourceType() == content::RESOURCE_TYPE_STYLESHEET ||
635 info->GetResourceType() == content::RESOURCE_TYPE_SCRIPT)) {
[email protected]f7fa5b62014-03-19 15:20:06636 is_for_blocking_resource = true;
637 }
638
[email protected]f3add922013-12-20 23:17:16639 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
640 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35641 BrowserThread::PostTask(
642 BrowserThread::UI, FROM_HERE,
643 base::Bind(&TabSpecificContentSettings::CookiesRead,
[email protected]f3add922013-12-20 23:17:16644 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04645 request.url(), request.first_party_for_cookies(),
[email protected]f7fa5b62014-03-19 15:20:06646 cookie_list, !allow, is_for_blocking_resource));
[email protected]9c8ae8c2012-03-09 13:13:35647 }
648
649 return allow;
650}
651
[email protected]4c219e22012-05-05 19:41:04652bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
653 const std::string& cookie_line,
654 net::CookieOptions* options) {
[email protected]9c8ae8c2012-03-09 13:13:35655 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02656 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35657 return true;
658
659 bool allow = cookie_settings_->IsSettingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04660 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35661
[email protected]9c8ae8c2012-03-09 13:13:35662 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16663 int render_frame_id = -1;
664 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
665 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35666 BrowserThread::PostTask(
667 BrowserThread::UI, FROM_HERE,
668 base::Bind(&TabSpecificContentSettings::CookieChanged,
[email protected]f3add922013-12-20 23:17:16669 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04670 request.url(), request.first_party_for_cookies(),
[email protected]fd473d12012-04-05 11:38:43671 cookie_line, *options, !allow));
[email protected]9c8ae8c2012-03-09 13:13:35672 }
673
[email protected]28c5d0b72014-05-13 08:19:59674 if (prerender_tracker_) {
675 prerender_tracker_->OnCookieChangedForURL(
676 render_process_id,
677 request.context()->cookie_store()->GetCookieMonster(),
678 request.url());
679 }
680
[email protected]9c8ae8c2012-03-09 13:13:35681 return allow;
682}
[email protected]4c219e22012-05-05 19:41:04683
684bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
[email protected]650b2d52013-02-10 03:41:45685 const base::FilePath& path) const {
[email protected]4c219e22012-05-05 19:41:04686 if (g_allow_file_access_)
687 return true;
688
[email protected]d8e4f132012-09-06 04:28:05689#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
690 return true;
691#else
[email protected]4c219e22012-05-05 19:41:04692#if defined(OS_CHROMEOS)
[email protected]d8e4f132012-09-06 04:28:05693 // If we're running Chrome for ChromeOS on Linux, we want to allow file
694 // access.
[email protected]49c4cf852013-09-27 19:28:24695 if (!base::SysInfo::IsRunningOnChromeOS() ||
[email protected]288538482012-09-06 21:09:35696 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
[email protected]d8e4f132012-09-06 04:28:05697 return true;
[email protected]288538482012-09-06 21:09:35698 }
[email protected]d8e4f132012-09-06 04:28:05699
700 // Use a whitelist to only allow access to files residing in the list of
701 // directories below.
[email protected]4c219e22012-05-05 19:41:04702 static const char* const kLocalAccessWhiteList[] = {
703 "/home/chronos/user/Downloads",
704 "/home/chronos/user/log",
[email protected]4791af43d2014-05-05 13:19:42705 "/home/chronos/user/WebRTC Logs",
[email protected]4c219e22012-05-05 19:41:04706 "/media",
707 "/opt/oem",
708 "/usr/share/chromeos-assets",
709 "/tmp",
710 "/var/log",
711 };
[email protected]ae015e12013-11-04 19:11:33712
[email protected]9e733282014-06-18 16:56:55713 // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under
714 // the profile path ("/home/chronos/user' is a hard link to current primary
715 // logged in profile.) For the support of multi-profile sessions, we are
716 // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such
717 // access.
[email protected]ae015e12013-11-04 19:11:33718 if (!profile_path_.empty()) {
719 const base::FilePath downloads = profile_path_.AppendASCII("Downloads");
720 if (downloads == path.StripTrailingSeparators() || downloads.IsParent(path))
721 return true;
[email protected]9e733282014-06-18 16:56:55722 const base::FilePath webrtc_logs = profile_path_.AppendASCII("WebRTC Logs");
723 if (webrtc_logs == path.StripTrailingSeparators() ||
724 webrtc_logs.IsParent(path)) {
725 return true;
726 }
[email protected]ae015e12013-11-04 19:11:33727 }
[email protected]d8e4f132012-09-06 04:28:05728#elif defined(OS_ANDROID)
729 // Access to files in external storage is allowed.
[email protected]650b2d52013-02-10 03:41:45730 base::FilePath external_storage_path;
[email protected]d8e4f132012-09-06 04:28:05731 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path);
732 if (external_storage_path.IsParent(path))
[email protected]4c219e22012-05-05 19:41:04733 return true;
734
[email protected]d8e4f132012-09-06 04:28:05735 // Whitelist of other allowed directories.
736 static const char* const kLocalAccessWhiteList[] = {
737 "/sdcard",
738 "/mnt/sdcard",
739 };
740#endif
741
[email protected]4c219e22012-05-05 19:41:04742 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
[email protected]650b2d52013-02-10 03:41:45743 const base::FilePath white_listed_path(kLocalAccessWhiteList[i]);
744 // base::FilePath::operator== should probably handle trailing separators.
[email protected]4c219e22012-05-05 19:41:04745 if (white_listed_path == path.StripTrailingSeparators() ||
746 white_listed_path.IsParent(path)) {
747 return true;
748 }
749 }
[email protected]d8e4f132012-09-06 04:28:05750
[email protected]288538482012-09-06 21:09:35751 DVLOG(1) << "File access denied - " << path.value().c_str();
[email protected]4c219e22012-05-05 19:41:04752 return false;
[email protected]d8e4f132012-09-06 04:28:05753#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:04754}
[email protected]a1d4ab072012-06-07 13:21:15755
756bool ChromeNetworkDelegate::OnCanThrottleRequest(
757 const net::URLRequest& request) const {
[email protected]84b7a552014-07-19 04:52:06758#if defined(ENABLE_EXTENSIONS)
[email protected]4a2b6232014-06-19 08:44:14759 if (g_never_throttle_requests_)
[email protected]a1d4ab072012-06-07 13:21:15760 return false;
[email protected]c4a7df82012-08-09 22:48:46761 return request.first_party_for_cookies().scheme() ==
[email protected]885c0e92012-11-13 20:27:42762 extensions::kExtensionScheme;
[email protected]84b7a552014-07-19 04:52:06763#else
764 return false;
765#endif
[email protected]a1d4ab072012-06-07 13:21:15766}
[email protected]aa28181e2012-06-13 00:53:58767
[email protected]e6d017652013-05-17 18:01:40768bool ChromeNetworkDelegate::OnCanEnablePrivacyMode(
769 const GURL& url,
770 const GURL& first_party_for_cookies) const {
771 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02772 if (!cookie_settings_.get())
[email protected]e6d017652013-05-17 18:01:40773 return false;
774
775 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed(
776 url, first_party_for_cookies);
777 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed(
778 url, first_party_for_cookies);
779 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed);
780 return privacy_mode;
781}
782
jochen0e3b3a62014-09-16 18:31:23783bool ChromeNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
784 const net::URLRequest& request,
785 const GURL& target_url,
786 const GURL& referrer_url) const {
jochenb93dba3c2014-11-11 05:28:41787 base::debug::StackTrace callstack;
jochen0e3b3a62014-09-16 18:31:23788 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
jochenb93dba3c2014-11-11 05:28:41789 base::Bind(&ReportInvalidReferrerSend, target_url,
790 referrer_url, callstack));
jochen0e3b3a62014-09-16 18:31:23791 return true;
792}
793
[email protected]7a299a92012-10-24 23:54:50794void ChromeNetworkDelegate::AccumulateContentLength(
[email protected]b7796462013-12-12 19:42:34795 int64 received_content_length,
796 int64 original_content_length,
[email protected]a0a06932014-04-14 21:23:42797 data_reduction_proxy::DataReductionProxyRequestType request_type) {
[email protected]7a299a92012-10-24 23:54:50798 DCHECK_GE(received_content_length, 0);
799 DCHECK_GE(original_content_length, 0);
megjablon53f608b2014-09-18 19:24:55800 if (data_reduction_proxy_statistics_prefs_) {
801 StoreAccumulatedContentLength(received_content_length,
802 original_content_length,
803 request_type,
804 reinterpret_cast<Profile*>(profile_),
805 data_reduction_proxy_statistics_prefs_);
806 }
[email protected]7a299a92012-10-24 23:54:50807 received_content_length_ += received_content_length;
808 original_content_length_ += original_content_length;
809}