blob: 285a2e31f620f92b7a0e0c2c1cb236c792be813a [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"
[email protected]4aca5db2013-08-17 00:51:5612#include "base/debug/trace_event.h"
[email protected]7a299a92012-10-24 23:54:5013#include "base/logging.h"
14#include "base/metrics/histogram.h"
jochen0e3b3a62014-09-16 18:31:2315#include "base/metrics/user_metrics.h"
[email protected]d8e4f132012-09-06 04:28:0516#include "base/path_service.h"
[email protected]1ab137b2013-03-21 03:33:1817#include "base/prefs/pref_member.h"
[email protected]3853a4c2013-02-11 17:15:5718#include "base/prefs/pref_service.h"
[email protected]3ea1b182013-02-08 22:38:4119#include "base/strings/string_number_conversions.h"
[email protected]069c49162013-09-11 20:46:3520#include "base/time/time.h"
[email protected]6baff0b52012-03-06 01:30:1821#include "chrome/browser/browser_process.h"
[email protected]9c8ae8c2012-03-09 13:13:3522#include "chrome/browser/content_settings/cookie_settings.h"
23#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]8523ba52011-05-22 19:00:5824#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]4a2b6232014-06-19 08:44:1425#include "chrome/browser/net/chrome_extensions_network_delegate.h"
[email protected]3620bbc2013-10-05 05:07:2326#include "chrome/browser/net/client_hints.h"
[email protected]f53b4802012-12-20 17:04:2327#include "chrome/browser/net/connect_interceptor.h"
[email protected]184799df2014-07-22 16:03:2428#include "chrome/browser/net/safe_search_util.h"
[email protected]28c5d0b72014-05-13 08:19:5929#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]6baff0b52012-03-06 01:30:1830#include "chrome/browser/profiles/profile_manager.h"
[email protected]8523ba52011-05-22 19:00:5831#include "chrome/browser/task_manager/task_manager.h"
[email protected]0a8db0d2011-04-13 15:15:4032#include "chrome/common/pref_names.h"
[email protected]597a1ab2014-06-26 08:12:2733#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
[email protected]a0a06932014-04-14 21:23:4234#include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h"
[email protected]d8fc4722014-06-13 13:17:1535#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
36#include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.h"
[email protected]bceab7f2014-06-25 04:36:2037#include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h"
[email protected]45de676a2014-03-18 23:52:0238#include "components/domain_reliability/monitor.h"
[email protected]c38831a12011-10-28 12:44:4939#include "content/public/browser/browser_thread.h"
[email protected]9dfed872013-12-30 23:08:5640#include "content/public/browser/render_frame_host.h"
[email protected]9c1662b2012-03-06 15:44:3341#include "content/public/browser/render_view_host.h"
[email protected]9c8ae8c2012-03-09 13:13:3542#include "content/public/browser/resource_request_info.h"
[email protected]82b42302011-04-20 16:28:1643#include "net/base/host_port_pair.h"
[email protected]8202d0c2011-02-23 08:31:1444#include "net/base/net_errors.h"
[email protected]6a5f77c32011-09-04 19:19:5945#include "net/base/net_log.h"
[email protected]5b9bc352012-07-18 13:13:3446#include "net/cookies/canonical_cookie.h"
47#include "net/cookies/cookie_options.h"
[email protected]ac039522010-06-15 16:39:4448#include "net/http/http_request_headers.h"
[email protected]48944382011-04-23 13:28:1649#include "net/http/http_response_headers.h"
[email protected]12731792014-08-14 11:45:5450#include "net/proxy/proxy_config.h"
[email protected]597a1ab2014-06-26 08:12:2751#include "net/proxy/proxy_info.h"
[email protected]12731792014-08-14 11:45:5452#include "net/proxy/proxy_retry_info.h"
[email protected]597a1ab2014-06-26 08:12:2753#include "net/proxy/proxy_server.h"
[email protected]aa28181e2012-06-13 00:53:5854#include "net/socket_stream/socket_stream.h"
[email protected]d05ef99c2011-02-01 21:38:1655#include "net/url_request/url_request.h"
[email protected]28c5d0b72014-05-13 08:19:5956#include "net/url_request/url_request_context.h"
[email protected]d05ef99c2011-02-01 21:38:1657
[email protected]4a2b6232014-06-19 08:44:1458#if defined(OS_ANDROID)
59#include "chrome/browser/io_thread.h"
60#include "components/precache/content/precache_manager.h"
61#include "components/precache/content/precache_manager_factory.h"
62#endif
63
[email protected]4c219e22012-05-05 19:41:0464#if defined(OS_CHROMEOS)
[email protected]288538482012-09-06 21:09:3565#include "base/command_line.h"
[email protected]49c4cf852013-09-27 19:28:2466#include "base/sys_info.h"
[email protected]288538482012-09-06 21:09:3567#include "chrome/common/chrome_switches.h"
[email protected]4c219e22012-05-05 19:41:0468#endif
69
[email protected]3e598ff12011-09-06 11:22:3470#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]f522afa2014-01-08 15:36:3671#include "components/policy/core/browser/url_blacklist_manager.h"
[email protected]3e598ff12011-09-06 11:22:3472#endif
73
[email protected]84b7a552014-07-19 04:52:0674#if defined(ENABLE_EXTENSIONS)
75#include "extensions/common/constants.h"
76#endif
77
[email protected]631bb742011-11-02 11:29:3978using content::BrowserThread;
[email protected]eaabba22012-03-07 15:02:1179using content::RenderViewHost;
[email protected]ea114722012-03-12 01:11:2580using content::ResourceRequestInfo;
[email protected]7491ad02014-07-05 19:10:0781using content::ResourceType;
[email protected]631bb742011-11-02 11:29:3982
[email protected]d8e4f132012-09-06 04:28:0583// By default we don't allow access to all file:// urls on ChromeOS and
84// Android.
85#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:0486bool ChromeNetworkDelegate::g_allow_file_access_ = false;
87#else
88bool ChromeNetworkDelegate::g_allow_file_access_ = true;
89#endif
90
[email protected]84b7a552014-07-19 04:52:0691#if defined(ENABLE_EXTENSIONS)
[email protected]c4a7df82012-08-09 22:48:4692// This remains false unless the --disable-extensions-http-throttling
93// flag is passed to the browser.
94bool ChromeNetworkDelegate::g_never_throttle_requests_ = false;
[email protected]84b7a552014-07-19 04:52:0695#endif
[email protected]c4a7df82012-08-09 22:48:4696
[email protected]d05ef99c2011-02-01 21:38:1697namespace {
98
[email protected]9d8cfb682012-09-13 16:48:0499const char kDNTHeader[] = "DNT";
100
[email protected]d1208ba32012-11-08 11:10:33101// Gets called when the extensions finish work on the URL. If the extensions
102// did not do a redirect (so |new_url| is empty) then we enforce the
103// SafeSearch parameters. Otherwise we will get called again after the
104// redirect and we enforce SafeSearch then.
105void ForceGoogleSafeSearchCallbackWrapper(
106 const net::CompletionCallback& callback,
107 net::URLRequest* request,
108 GURL* new_url,
109 int rv) {
110 if (rv == net::OK && new_url->is_empty())
[email protected]184799df2014-07-22 16:03:24111 safe_search_util::ForceGoogleSafeSearch(request, new_url);
[email protected]d1208ba32012-11-08 11:10:33112 callback.Run(rv);
113}
114
[email protected]828eab22013-12-10 22:42:38115void UpdateContentLengthPrefs(
116 int received_content_length,
117 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42118 data_reduction_proxy::DataReductionProxyRequestType request_type,
[email protected]b7796462013-12-12 19:42:34119 Profile* profile) {
[email protected]7a299a92012-10-24 23:54:50120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
121 DCHECK_GE(received_content_length, 0);
122 DCHECK_GE(original_content_length, 0);
123
[email protected]a09159a2012-11-29 12:51:48124 // Can be NULL in a unit test.
125 if (!g_browser_process)
126 return;
127
[email protected]7a299a92012-10-24 23:54:50128 PrefService* prefs = g_browser_process->local_state();
[email protected]a09159a2012-11-29 12:51:48129 if (!prefs)
130 return;
[email protected]7a299a92012-10-24 23:54:50131
[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 }
[email protected]f4bfa7672014-08-08 09:50:46137#if defined(OS_ANDROID) && defined(SPDY_PROXY_AUTH_ORIGIN)
[email protected]b1d5ed52013-12-18 02:34:56138 // If Android ever goes multi profile, the profile should be passed so that
139 // the browser preference will be taken.
[email protected]0d36d1e2013-09-24 04:25:28140 bool with_data_reduction_proxy_enabled =
[email protected]b1d5ed52013-12-18 02:34:56141 ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean(
[email protected]a0a06932014-04-14 21:23:42142 data_reduction_proxy::prefs::kDataReductionProxyEnabled);
[email protected]0d36d1e2013-09-24 04:25:28143#else
144 bool with_data_reduction_proxy_enabled = false;
[email protected]eac11e12013-03-19 22:04:32145#endif
[email protected]0d36d1e2013-09-24 04:25:28146
[email protected]a0a06932014-04-14 21:23:42147 data_reduction_proxy::UpdateContentLengthPrefs(received_content_length,
148 original_content_length,
149 with_data_reduction_proxy_enabled,
150 request_type, prefs);
[email protected]7a299a92012-10-24 23:54:50151}
152
[email protected]828eab22013-12-10 22:42:38153void StoreAccumulatedContentLength(
154 int received_content_length,
155 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42156 data_reduction_proxy::DataReductionProxyRequestType request_type,
[email protected]b7796462013-12-12 19:42:34157 Profile* profile) {
[email protected]7a299a92012-10-24 23:54:50158 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
159 base::Bind(&UpdateContentLengthPrefs,
[email protected]2db93e42013-08-07 17:40:41160 received_content_length, original_content_length,
[email protected]a0a06932014-04-14 21:23:42161 request_type, profile));
[email protected]7a299a92012-10-24 23:54:50162}
163
164void RecordContentLengthHistograms(
[email protected]f81a5ee2013-06-20 21:08:49165 int64 received_content_length,
166 int64 original_content_length,
167 const base::TimeDelta& freshness_lifetime) {
[email protected]7a299a92012-10-24 23:54:50168 // Add the current resource to these histograms only when a valid
169 // X-Original-Content-Length header is present.
170 if (original_content_length >= 0) {
171 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL",
172 received_content_length);
173 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL",
174 original_content_length);
175 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL",
176 original_content_length - received_content_length);
177 } else {
178 // Presume the original content length is the same as the received content
179 // length if the X-Original-Content-Header is not present.
180 original_content_length = received_content_length;
181 }
182 UMA_HISTOGRAM_COUNTS("Net.HttpContentLength", received_content_length);
183 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLength",
184 original_content_length);
185 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifference",
186 original_content_length - received_content_length);
[email protected]f81a5ee2013-06-20 21:08:49187 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpContentFreshnessLifetime",
188 freshness_lifetime.InSeconds(),
189 base::TimeDelta::FromHours(1).InSeconds(),
190 base::TimeDelta::FromDays(30).InSeconds(),
191 100);
192 if (freshness_lifetime.InSeconds() <= 0)
193 return;
194 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable",
195 received_content_length);
196 if (freshness_lifetime.InHours() < 4)
197 return;
198 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours",
199 received_content_length);
200
201 if (freshness_lifetime.InHours() < 24)
202 return;
203 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours",
204 received_content_length);
[email protected]7a299a92012-10-24 23:54:50205}
206
[email protected]35558812013-12-18 21:58:36207#if defined(OS_ANDROID)
208void RecordPrecacheStatsOnUIThread(const GURL& url,
209 const base::Time& fetch_time, int64 size,
210 bool was_cached, void* profile_id) {
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
212
213 Profile* profile = reinterpret_cast<Profile*>(profile_id);
214 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) {
215 return;
216 }
217
218 precache::PrecacheManager* precache_manager =
219 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
tanviraumi387f6332014-08-29 19:04:36220 if (!precache_manager || !precache_manager->IsPrecachingAllowed()) {
221 // |precache_manager| could be NULL if the profile is off the record.
[email protected]35558812013-12-18 21:58:36222 return;
223 }
224
225 precache_manager->RecordStatsForFetch(url, fetch_time, size, was_cached);
226}
[email protected]d827e112014-03-31 17:45:05227
228void RecordIOThreadToRequestStartOnUIThread(
229 const base::TimeTicks& request_start) {
230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
231 base::TimeDelta request_lag = request_start -
232 g_browser_process->io_thread()->creation_time();
233 UMA_HISTOGRAM_TIMES("Net.IOThreadCreationToHTTPRequestStart", request_lag);
234}
[email protected]35558812013-12-18 21:58:36235#endif // defined(OS_ANDROID)
236
jochen0e3b3a62014-09-16 18:31:23237void ReportInvalidReferrerSend(const GURL& target_url,
238 const GURL& referrer_url) {
239 base::RecordAction(
240 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer"));
241}
242
[email protected]d05ef99c2011-02-01 21:38:16243} // namespace
[email protected]ac039522010-06-15 16:39:44244
[email protected]0651b812011-02-24 00:22:50245ChromeNetworkDelegate::ChromeNetworkDelegate(
[email protected]5a38dfd2012-07-23 23:22:10246 extensions::EventRouterForwarder* event_router,
[email protected]a09159a2012-11-29 12:51:48247 BooleanPrefMember* enable_referrers)
[email protected]4a2b6232014-06-19 08:44:14248 : profile_(NULL),
[email protected]6a5f77c32011-09-04 19:19:59249 enable_referrers_(enable_referrers),
[email protected]a09159a2012-11-29 12:51:48250 enable_do_not_track_(NULL),
251 force_google_safe_search_(NULL),
[email protected]a948dad2014-07-25 00:39:38252 data_reduction_proxy_enabled_(NULL),
[email protected]4a2b6232014-06-19 08:44:14253#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]a09159a2012-11-29 12:51:48254 url_blacklist_manager_(NULL),
[email protected]4a2b6232014-06-19 08:44:14255#endif
[email protected]45de676a2014-03-18 23:52:02256 domain_reliability_monitor_(NULL),
[email protected]7a299a92012-10-24 23:54:50257 received_content_length_(0),
[email protected]d827e112014-03-31 17:45:05258 original_content_length_(0),
[email protected]28c5d0b72014-05-13 08:19:59259 first_request_(true),
[email protected]d8fc4722014-06-13 13:17:15260 prerender_tracker_(NULL),
[email protected]bceab7f2014-06-25 04:36:20261 data_reduction_proxy_params_(NULL),
[email protected]597a1ab2014-06-26 08:12:27262 data_reduction_proxy_usage_stats_(NULL),
263 data_reduction_proxy_auth_request_handler_(NULL) {
[email protected]0a8db0d2011-04-13 15:15:40264 DCHECK(enable_referrers);
[email protected]4a2b6232014-06-19 08:44:14265 extensions_delegate_.reset(
266 ChromeExtensionsNetworkDelegate::Create(event_router));
[email protected]0651b812011-02-24 00:22:50267}
268
[email protected]ac039522010-06-15 16:39:44269ChromeNetworkDelegate::~ChromeNetworkDelegate() {}
270
[email protected]a09159a2012-11-29 12:51:48271void ChromeNetworkDelegate::set_extension_info_map(
[email protected]38427a12013-11-09 17:34:20272 extensions::InfoMap* extension_info_map) {
[email protected]4a2b6232014-06-19 08:44:14273 extensions_delegate_->set_extension_info_map(extension_info_map);
274}
275
276void ChromeNetworkDelegate::set_profile(void* profile) {
277 profile_ = profile;
278 extensions_delegate_->set_profile(profile);
[email protected]a09159a2012-11-29 12:51:48279}
280
281void ChromeNetworkDelegate::set_cookie_settings(
282 CookieSettings* cookie_settings) {
283 cookie_settings_ = cookie_settings;
284}
285
[email protected]f53b4802012-12-20 17:04:23286void ChromeNetworkDelegate::set_predictor(
287 chrome_browser_net::Predictor* predictor) {
288 connect_interceptor_.reset(
289 new chrome_browser_net::ConnectInterceptor(predictor));
290}
291
[email protected]3620bbc2013-10-05 05:07:23292void ChromeNetworkDelegate::SetEnableClientHints() {
293 client_hints_.reset(new ClientHints());
294 client_hints_->Init();
295}
296
[email protected]c4a7df82012-08-09 22:48:46297// static
[email protected]84b7a552014-07-19 04:52:06298#if defined(ENABLE_EXTENSIONS)
[email protected]a1d4ab072012-06-07 13:21:15299void ChromeNetworkDelegate::NeverThrottleRequests() {
[email protected]c4a7df82012-08-09 22:48:46300 g_never_throttle_requests_ = true;
[email protected]a1d4ab072012-06-07 13:21:15301}
[email protected]84b7a552014-07-19 04:52:06302#endif
[email protected]a1d4ab072012-06-07 13:21:15303
[email protected]0a8db0d2011-04-13 15:15:40304// static
[email protected]9d8cfb682012-09-13 16:48:04305void ChromeNetworkDelegate::InitializePrefsOnUIThread(
[email protected]0a8db0d2011-04-13 15:15:40306 BooleanPrefMember* enable_referrers,
[email protected]9d8cfb682012-09-13 16:48:04307 BooleanPrefMember* enable_do_not_track,
[email protected]d1208ba32012-11-08 11:10:33308 BooleanPrefMember* force_google_safe_search,
[email protected]0a8db0d2011-04-13 15:15:40309 PrefService* pref_service) {
310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]96a5c342012-12-04 18:14:02311 enable_referrers->Init(prefs::kEnableReferrers, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43312 enable_referrers->MoveToThread(
313 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04314 if (enable_do_not_track) {
[email protected]96a5c342012-12-04 18:14:02315 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43316 enable_do_not_track->MoveToThread(
317 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04318 }
[email protected]d1208ba32012-11-08 11:10:33319 if (force_google_safe_search) {
[email protected]96a5c342012-12-04 18:14:02320 force_google_safe_search->Init(prefs::kForceSafeSearch, pref_service);
[email protected]d1208ba32012-11-08 11:10:33321 force_google_safe_search->MoveToThread(
322 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
323 }
[email protected]0a8db0d2011-04-13 15:15:40324}
325
[email protected]4c219e22012-05-05 19:41:04326// static
327void ChromeNetworkDelegate::AllowAccessToAllFiles() {
328 g_allow_file_access_ = true;
329}
330
[email protected]7a299a92012-10-24 23:54:50331// static
[email protected]cb1078de2013-12-23 20:04:22332base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() {
[email protected]7a299a92012-10-24 23:54:50333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
334 PrefService* prefs = g_browser_process->local_state();
[email protected]a0a06932014-04-14 21:23:42335 int64 total_received = prefs->GetInt64(
336 data_reduction_proxy::prefs::kHttpReceivedContentLength);
337 int64 total_original = prefs->GetInt64(
338 data_reduction_proxy::prefs::kHttpOriginalContentLength);
[email protected]7a299a92012-10-24 23:54:50339
[email protected]cb1078de2013-12-23 20:04:22340 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42341 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
342 dict->SetString("historic_received_content_length",
343 base::Int64ToString(total_received));
344 dict->SetString("historic_original_content_length",
345 base::Int64ToString(total_original));
[email protected]7a299a92012-10-24 23:54:50346 return dict;
347}
348
[email protected]cb1078de2013-12-23 20:04:22349base::Value* ChromeNetworkDelegate::SessionNetworkStatsInfoToValue() const {
350 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42351 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
352 dict->SetString("session_received_content_length",
353 base::Int64ToString(received_content_length_));
354 dict->SetString("session_original_content_length",
355 base::Int64ToString(original_content_length_));
[email protected]7a299a92012-10-24 23:54:50356 return dict;
357}
358
[email protected]4875ba12011-03-30 22:31:51359int ChromeNetworkDelegate::OnBeforeURLRequest(
[email protected]4c76d7c2011-04-15 19:14:12360 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47361 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12362 GURL* new_url) {
[email protected]d827e112014-03-31 17:45:05363#if defined(OS_ANDROID)
364 // This UMA tracks the time to the first user-initiated request start, so
365 // only non-null profiles are considered.
366 if (first_request_ && profile_) {
367 bool record_timing = true;
[email protected]bec6a992014-06-19 01:03:21368 if (data_reduction_proxy_params_) {
369 record_timing =
370 (request->url() != data_reduction_proxy_params_->probe_url()) &&
371 (request->url() != data_reduction_proxy_params_->warmup_url());
372 }
[email protected]d827e112014-03-31 17:45:05373 if (record_timing) {
374 first_request_ = false;
375 net::LoadTimingInfo timing_info;
376 request->GetLoadTimingInfo(&timing_info);
377 BrowserThread::PostTask(
378 BrowserThread::UI, FROM_HERE,
379 base::Bind(&RecordIOThreadToRequestStartOnUIThread,
380 timing_info.request_start));
381 }
382 }
383#endif // defined(OS_ANDROID)
384
[email protected]3e598ff12011-09-06 11:22:34385#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]6a5f77c32011-09-04 19:19:59386 // TODO(joaodasilva): This prevents extensions from seeing URLs that are
387 // blocked. However, an extension might redirect the request to another URL,
388 // which is not blocked.
[email protected]cb85f8e52014-04-08 11:44:40389 int error = net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]6a5f77c32011-09-04 19:19:59390 if (url_blacklist_manager_ &&
[email protected]cb85f8e52014-04-08 11:44:40391 url_blacklist_manager_->IsRequestBlocked(*request, &error)) {
[email protected]6a5f77c32011-09-04 19:19:59392 // URL access blocked by policy.
[email protected]6a5f77c32011-09-04 19:19:59393 request->net_log().AddEvent(
[email protected]2fa08912012-06-14 20:56:26394 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
395 net::NetLog::StringCallback("url",
396 &request->url().possibly_invalid_spec()));
[email protected]cb85f8e52014-04-08 11:44:40397 return error;
[email protected]6a5f77c32011-09-04 19:19:59398 }
[email protected]3e598ff12011-09-06 11:22:34399#endif
[email protected]6a5f77c32011-09-04 19:19:59400
[email protected]4a2b6232014-06-19 08:44:14401 extensions_delegate_->ForwardStartRequestStatus(request);
[email protected]6baff0b52012-03-06 01:30:18402
[email protected]0a8db0d2011-04-13 15:15:40403 if (!enable_referrers_->GetValue())
[email protected]99ecf6e2013-04-10 22:46:13404 request->SetReferrer(std::string());
[email protected]9d8cfb682012-09-13 16:48:04405 if (enable_do_not_track_ && enable_do_not_track_->GetValue())
406 request->SetExtraRequestHeaderByName(kDNTHeader, "1", true /* override */);
[email protected]d1208ba32012-11-08 11:10:33407
[email protected]3620bbc2013-10-05 05:07:23408 if (client_hints_) {
409 request->SetExtraRequestHeaderByName(
410 ClientHints::kDevicePixelRatioHeader,
411 client_hints_->GetDevicePixelRatioHeader(), true);
412 }
413
[email protected]d1208ba32012-11-08 11:10:33414 bool force_safe_search = force_google_safe_search_ &&
415 force_google_safe_search_->GetValue();
416
417 net::CompletionCallback wrapped_callback = callback;
418 if (force_safe_search) {
419 wrapped_callback = base::Bind(&ForceGoogleSafeSearchCallbackWrapper,
420 callback,
421 base::Unretained(request),
422 base::Unretained(new_url));
423 }
424
[email protected]4a2b6232014-06-19 08:44:14425 int rv = extensions_delegate_->OnBeforeURLRequest(
426 request, wrapped_callback, new_url);
[email protected]d1208ba32012-11-08 11:10:33427
428 if (force_safe_search && rv == net::OK && new_url->is_empty())
[email protected]184799df2014-07-22 16:03:24429 safe_search_util::ForceGoogleSafeSearch(request, new_url);
[email protected]d1208ba32012-11-08 11:10:33430
[email protected]f53b4802012-12-20 17:04:23431 if (connect_interceptor_)
432 connect_interceptor_->WitnessURLRequest(request);
433
[email protected]d1208ba32012-11-08 11:10:33434 return rv;
[email protected]d05ef99c2011-02-01 21:38:16435}
436
[email protected]a702da72014-07-09 05:23:54437void ChromeNetworkDelegate::OnResolveProxy(
[email protected]12731792014-08-14 11:45:54438 const GURL& url,
439 int load_flags,
440 const net::ProxyService& proxy_service,
441 net::ProxyInfo* result) {
442 if (!on_resolve_proxy_handler_.is_null() &&
443 !proxy_config_getter_.is_null()) {
[email protected]a702da72014-07-09 05:23:54444 on_resolve_proxy_handler_.Run(url, load_flags,
[email protected]12731792014-08-14 11:45:54445 proxy_config_getter_.Run(),
446 proxy_service.proxy_retry_info(),
[email protected]a702da72014-07-09 05:23:54447 data_reduction_proxy_params_, result);
448 }
449}
450
[email protected]f09f9682014-08-10 01:21:39451void ChromeNetworkDelegate::OnProxyFallback(const net::ProxyServer& bad_proxy,
[email protected]d0483b192014-08-15 23:50:17452 int net_error) {
[email protected]f09f9682014-08-10 01:21:39453 if (data_reduction_proxy_usage_stats_) {
454 data_reduction_proxy_usage_stats_->RecordBypassEventHistograms(
[email protected]d0483b192014-08-15 23:50:17455 bad_proxy, net_error);
[email protected]f09f9682014-08-10 01:21:39456 }
457}
458
[email protected]4875ba12011-03-30 22:31:51459int ChromeNetworkDelegate::OnBeforeSendHeaders(
[email protected]636eccd2011-06-28 12:28:01460 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47461 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12462 net::HttpRequestHeaders* headers) {
[email protected]184799df2014-07-22 16:03:24463 bool force_safe_search = force_google_safe_search_ &&
464 force_google_safe_search_->GetValue();
465 if (force_safe_search)
466 safe_search_util::ForceYouTubeSafetyMode(request, headers);
467
[email protected]186468f2013-10-24 02:44:11468 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest");
[email protected]4a2b6232014-06-19 08:44:14469 return extensions_delegate_->OnBeforeSendHeaders(request, callback, headers);
[email protected]ac039522010-06-15 16:39:44470}
[email protected]8202d0c2011-02-23 08:31:14471
[email protected]597a1ab2014-06-26 08:12:27472void ChromeNetworkDelegate::OnBeforeSendProxyHeaders(
473 net::URLRequest* request,
474 const net::ProxyInfo& proxy_info,
475 net::HttpRequestHeaders* headers) {
476 if (data_reduction_proxy_auth_request_handler_) {
477 data_reduction_proxy_auth_request_handler_->MaybeAddRequestHeader(
478 request, proxy_info.proxy_server(), headers);
479 }
480}
481
[email protected]5796dc942011-07-14 19:26:10482void ChromeNetworkDelegate::OnSendHeaders(
483 net::URLRequest* request,
[email protected]783573b2011-05-13 11:05:15484 const net::HttpRequestHeaders& headers) {
[email protected]4a2b6232014-06-19 08:44:14485 extensions_delegate_->OnSendHeaders(request, headers);
[email protected]82b42302011-04-20 16:28:16486}
487
[email protected]ea8141e2011-10-05 13:12:51488int ChromeNetworkDelegate::OnHeadersReceived(
489 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47490 const net::CompletionCallback& callback,
[email protected]507af8f2012-10-20 00:42:32491 const net::HttpResponseHeaders* original_response_headers,
[email protected]5f714132014-03-26 10:41:16492 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
493 GURL* allowed_unsafe_redirect_url) {
[email protected]f09f9682014-08-10 01:21:39494 data_reduction_proxy::DataReductionProxyBypassType bypass_type;
[email protected]d8fc4722014-06-13 13:17:15495 if (data_reduction_proxy::MaybeBypassProxyAndPrepareToRetry(
496 data_reduction_proxy_params_,
497 request,
498 original_response_headers,
[email protected]a948dad2014-07-25 00:39:38499 override_response_headers,
500 &bypass_type)) {
501 if (data_reduction_proxy_usage_stats_)
502 data_reduction_proxy_usage_stats_->SetBypassType(bypass_type);
[email protected]d8fc4722014-06-13 13:17:15503 return net::OK;
504 }
505
[email protected]4a2b6232014-06-19 08:44:14506 return extensions_delegate_->OnHeadersReceived(
[email protected]5f714132014-03-26 10:41:16507 request,
508 callback,
509 original_response_headers,
510 override_response_headers,
511 allowed_unsafe_redirect_url);
[email protected]ea8141e2011-10-05 13:12:51512}
513
[email protected]31b2e5f2011-04-20 16:58:32514void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
515 const GURL& new_location) {
[email protected]45de676a2014-03-18 23:52:02516 if (domain_reliability_monitor_)
517 domain_reliability_monitor_->OnBeforeRedirect(request);
[email protected]4a2b6232014-06-19 08:44:14518 extensions_delegate_->OnBeforeRedirect(request, new_location);
[email protected]31b2e5f2011-04-20 16:58:32519}
520
521
[email protected]8202d0c2011-02-23 08:31:14522void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
[email protected]186468f2013-10-24 02:44:11523 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "ResponseStarted");
[email protected]4a2b6232014-06-19 08:44:14524 extensions_delegate_->OnResponseStarted(request);
[email protected]8202d0c2011-02-23 08:31:14525}
526
[email protected]8523ba52011-05-22 19:00:58527void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
528 int bytes_read) {
[email protected]186468f2013-10-24 02:44:11529 TRACE_EVENT_ASYNC_STEP_PAST1("net", "URLRequest", &request, "DidRead",
530 "bytes_read", bytes_read);
[email protected]44879ed2012-04-06 01:11:02531#if defined(ENABLE_TASK_MANAGER)
[email protected]17df9e7c2014-02-13 03:49:29532 // This is not completely accurate, but as a first approximation ignore
533 // requests that are served from the cache. See bug 330931 for more info.
534 if (!request.was_cached())
535 TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read);
[email protected]44879ed2012-04-06 01:11:02536#endif // defined(ENABLE_TASK_MANAGER)
[email protected]8523ba52011-05-22 19:00:58537}
538
[email protected]9045b8822012-01-13 20:35:35539void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
540 bool started) {
[email protected]bceab7f2014-06-25 04:36:20541 if (data_reduction_proxy_usage_stats_)
542 data_reduction_proxy_usage_stats_->OnUrlRequestCompleted(request, started);
543
[email protected]4aca5db2013-08-17 00:51:56544 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request);
[email protected]2756a8e2012-09-07 18:24:29545 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
[email protected]7a299a92012-10-24 23:54:50546 // For better accuracy, we use the actual bytes read instead of the length
547 // specified with the Content-Length header, which may be inaccurate,
548 // or missing, as is the case with chunked encoding.
549 int64 received_content_length = request->received_response_content_length();
550
[email protected]35558812013-12-18 21:58:36551#if defined(OS_ANDROID)
552 if (precache::PrecacheManager::IsPrecachingEnabled()) {
553 // Record precache metrics when a fetch is completed successfully, if
554 // precaching is enabled.
555 BrowserThread::PostTask(
556 BrowserThread::UI, FROM_HERE,
557 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(),
558 base::Time::Now(), received_content_length,
559 request->was_cached(), profile_));
560 }
561#endif // defined(OS_ANDROID)
562
[email protected]7a299a92012-10-24 23:54:50563 // Only record for http or https urls.
564 bool is_http = request->url().SchemeIs("http");
565 bool is_https = request->url().SchemeIs("https");
566
567 if (!request->was_cached() && // Don't record cached content
568 received_content_length && // Zero-byte responses aren't useful.
569 (is_http || is_https)) { // Only record for HTTP or HTTPS urls.
570 int64 original_content_length =
571 request->response_info().headers->GetInt64HeaderValue(
572 "x-original-content-length");
[email protected]a0a06932014-04-14 21:23:42573 data_reduction_proxy::DataReductionProxyRequestType request_type =
574 data_reduction_proxy::GetDataReductionProxyRequestType(request);
[email protected]2db93e42013-08-07 17:40:41575
[email protected]f81a5ee2013-06-20 21:08:49576 base::TimeDelta freshness_lifetime =
577 request->response_info().headers->GetFreshnessLifetime(
578 request->response_info().response_time);
[email protected]828eab22013-12-10 22:42:38579 int64 adjusted_original_content_length =
[email protected]a0a06932014-04-14 21:23:42580 data_reduction_proxy::GetAdjustedOriginalContentLength(
581 request_type, original_content_length,
[email protected]828eab22013-12-10 22:42:38582 received_content_length);
[email protected]7a299a92012-10-24 23:54:50583 AccumulateContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41584 adjusted_original_content_length,
[email protected]a0a06932014-04-14 21:23:42585 request_type);
[email protected]7a299a92012-10-24 23:54:50586 RecordContentLengthHistograms(received_content_length,
[email protected]f81a5ee2013-06-20 21:08:49587 original_content_length,
588 freshness_lifetime);
megjablon25ff71d32014-09-05 03:21:44589 if (data_reduction_proxy_enabled_ &&
590 data_reduction_proxy_usage_stats_ &&
591 !proxy_config_getter_.is_null()) {
[email protected]a948dad2014-07-25 00:39:38592 data_reduction_proxy_usage_stats_->RecordBypassedBytesHistograms(
megjablon25ff71d32014-09-05 03:21:44593 *request,
594 *data_reduction_proxy_enabled_,
595 proxy_config_getter_.Run());
[email protected]a948dad2014-07-25 00:39:38596 }
[email protected]7a299a92012-10-24 23:54:50597 DVLOG(2) << __FUNCTION__
598 << " received content length: " << received_content_length
599 << " original content length: " << original_content_length
600 << " url: " << request->url();
601 }
602
[email protected]4a2b6232014-06-19 08:44:14603 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01604 } else if (request->status().status() == net::URLRequestStatus::FAILED ||
605 request->status().status() == net::URLRequestStatus::CANCELED) {
[email protected]4a2b6232014-06-19 08:44:14606 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01607 } else {
608 NOTREACHED();
[email protected]48944382011-04-23 13:28:16609 }
[email protected]45de676a2014-03-18 23:52:02610 if (domain_reliability_monitor_)
611 domain_reliability_monitor_->OnCompleted(request, started);
[email protected]4a2b6232014-06-19 08:44:14612 extensions_delegate_->ForwardProxyErrors(request);
613 extensions_delegate_->ForwardDoneRequestStatus(request);
[email protected]8202d0c2011-02-23 08:31:14614}
[email protected]4b50cb52011-03-10 00:29:37615
[email protected]4875ba12011-03-30 22:31:51616void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
[email protected]4a2b6232014-06-19 08:44:14617 extensions_delegate_->OnURLRequestDestroyed(request);
[email protected]4875ba12011-03-30 22:31:51618}
619
[email protected]82a37672011-05-03 12:02:41620void ChromeNetworkDelegate::OnPACScriptError(int line_number,
[email protected]439f1e32013-12-09 20:09:09621 const base::string16& error) {
[email protected]4a2b6232014-06-19 08:44:14622 extensions_delegate_->OnPACScriptError(line_number, error);
[email protected]82a37672011-05-03 12:02:41623}
[email protected]7efc582d2011-08-03 20:46:35624
[email protected]c2911d72011-10-03 22:16:36625net::NetworkDelegate::AuthRequiredResponse
626ChromeNetworkDelegate::OnAuthRequired(
[email protected]7efc582d2011-08-03 20:46:35627 net::URLRequest* request,
[email protected]c2911d72011-10-03 22:16:36628 const net::AuthChallengeInfo& auth_info,
629 const AuthCallback& callback,
630 net::AuthCredentials* credentials) {
[email protected]4a2b6232014-06-19 08:44:14631 return extensions_delegate_->OnAuthRequired(
632 request, auth_info, callback, credentials);
[email protected]7efc582d2011-08-03 20:46:35633}
[email protected]9c8ae8c2012-03-09 13:13:35634
[email protected]4c219e22012-05-05 19:41:04635bool ChromeNetworkDelegate::OnCanGetCookies(
636 const net::URLRequest& request,
[email protected]9c8ae8c2012-03-09 13:13:35637 const net::CookieList& cookie_list) {
638 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02639 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35640 return true;
641
642 bool allow = cookie_settings_->IsReadingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04643 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35644
645 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16646 int render_frame_id = -1;
[email protected]f7fa5b62014-03-19 15:20:06647
648 // |is_for_blocking_resource| indicates whether the cookies read were for a
649 // blocking resource (eg script, css). It is only temporarily added for
650 // diagnostic purposes, per bug 353678. Will be removed again once data
651 // collection is finished.
652 bool is_for_blocking_resource = false;
653 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
654 if (info && ((!info->IsAsync()) ||
[email protected]6c1e05212014-07-31 00:59:40655 info->GetResourceType() == content::RESOURCE_TYPE_STYLESHEET ||
656 info->GetResourceType() == content::RESOURCE_TYPE_SCRIPT)) {
[email protected]f7fa5b62014-03-19 15:20:06657 is_for_blocking_resource = true;
658 }
659
[email protected]f3add922013-12-20 23:17:16660 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
661 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35662 BrowserThread::PostTask(
663 BrowserThread::UI, FROM_HERE,
664 base::Bind(&TabSpecificContentSettings::CookiesRead,
[email protected]f3add922013-12-20 23:17:16665 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04666 request.url(), request.first_party_for_cookies(),
[email protected]f7fa5b62014-03-19 15:20:06667 cookie_list, !allow, is_for_blocking_resource));
[email protected]9c8ae8c2012-03-09 13:13:35668 }
669
670 return allow;
671}
672
[email protected]4c219e22012-05-05 19:41:04673bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
674 const std::string& cookie_line,
675 net::CookieOptions* options) {
[email protected]9c8ae8c2012-03-09 13:13:35676 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02677 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35678 return true;
679
680 bool allow = cookie_settings_->IsSettingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04681 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35682
[email protected]9c8ae8c2012-03-09 13:13:35683 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16684 int render_frame_id = -1;
685 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
686 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35687 BrowserThread::PostTask(
688 BrowserThread::UI, FROM_HERE,
689 base::Bind(&TabSpecificContentSettings::CookieChanged,
[email protected]f3add922013-12-20 23:17:16690 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04691 request.url(), request.first_party_for_cookies(),
[email protected]fd473d12012-04-05 11:38:43692 cookie_line, *options, !allow));
[email protected]9c8ae8c2012-03-09 13:13:35693 }
694
[email protected]28c5d0b72014-05-13 08:19:59695 if (prerender_tracker_) {
696 prerender_tracker_->OnCookieChangedForURL(
697 render_process_id,
698 request.context()->cookie_store()->GetCookieMonster(),
699 request.url());
700 }
701
[email protected]9c8ae8c2012-03-09 13:13:35702 return allow;
703}
[email protected]4c219e22012-05-05 19:41:04704
705bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
[email protected]650b2d52013-02-10 03:41:45706 const base::FilePath& path) const {
[email protected]4c219e22012-05-05 19:41:04707 if (g_allow_file_access_)
708 return true;
709
[email protected]d8e4f132012-09-06 04:28:05710#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
711 return true;
712#else
[email protected]4c219e22012-05-05 19:41:04713#if defined(OS_CHROMEOS)
[email protected]d8e4f132012-09-06 04:28:05714 // If we're running Chrome for ChromeOS on Linux, we want to allow file
715 // access.
[email protected]49c4cf852013-09-27 19:28:24716 if (!base::SysInfo::IsRunningOnChromeOS() ||
[email protected]288538482012-09-06 21:09:35717 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
[email protected]d8e4f132012-09-06 04:28:05718 return true;
[email protected]288538482012-09-06 21:09:35719 }
[email protected]d8e4f132012-09-06 04:28:05720
721 // Use a whitelist to only allow access to files residing in the list of
722 // directories below.
[email protected]4c219e22012-05-05 19:41:04723 static const char* const kLocalAccessWhiteList[] = {
724 "/home/chronos/user/Downloads",
725 "/home/chronos/user/log",
[email protected]4791af43d2014-05-05 13:19:42726 "/home/chronos/user/WebRTC Logs",
[email protected]4c219e22012-05-05 19:41:04727 "/media",
728 "/opt/oem",
729 "/usr/share/chromeos-assets",
730 "/tmp",
731 "/var/log",
732 };
[email protected]ae015e12013-11-04 19:11:33733
[email protected]9e733282014-06-18 16:56:55734 // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under
735 // the profile path ("/home/chronos/user' is a hard link to current primary
736 // logged in profile.) For the support of multi-profile sessions, we are
737 // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such
738 // access.
[email protected]ae015e12013-11-04 19:11:33739 if (!profile_path_.empty()) {
740 const base::FilePath downloads = profile_path_.AppendASCII("Downloads");
741 if (downloads == path.StripTrailingSeparators() || downloads.IsParent(path))
742 return true;
[email protected]9e733282014-06-18 16:56:55743 const base::FilePath webrtc_logs = profile_path_.AppendASCII("WebRTC Logs");
744 if (webrtc_logs == path.StripTrailingSeparators() ||
745 webrtc_logs.IsParent(path)) {
746 return true;
747 }
[email protected]ae015e12013-11-04 19:11:33748 }
[email protected]d8e4f132012-09-06 04:28:05749#elif defined(OS_ANDROID)
750 // Access to files in external storage is allowed.
[email protected]650b2d52013-02-10 03:41:45751 base::FilePath external_storage_path;
[email protected]d8e4f132012-09-06 04:28:05752 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path);
753 if (external_storage_path.IsParent(path))
[email protected]4c219e22012-05-05 19:41:04754 return true;
755
[email protected]d8e4f132012-09-06 04:28:05756 // Whitelist of other allowed directories.
757 static const char* const kLocalAccessWhiteList[] = {
758 "/sdcard",
759 "/mnt/sdcard",
760 };
761#endif
762
[email protected]4c219e22012-05-05 19:41:04763 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
[email protected]650b2d52013-02-10 03:41:45764 const base::FilePath white_listed_path(kLocalAccessWhiteList[i]);
765 // base::FilePath::operator== should probably handle trailing separators.
[email protected]4c219e22012-05-05 19:41:04766 if (white_listed_path == path.StripTrailingSeparators() ||
767 white_listed_path.IsParent(path)) {
768 return true;
769 }
770 }
[email protected]d8e4f132012-09-06 04:28:05771
[email protected]288538482012-09-06 21:09:35772 DVLOG(1) << "File access denied - " << path.value().c_str();
[email protected]4c219e22012-05-05 19:41:04773 return false;
[email protected]d8e4f132012-09-06 04:28:05774#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:04775}
[email protected]a1d4ab072012-06-07 13:21:15776
777bool ChromeNetworkDelegate::OnCanThrottleRequest(
778 const net::URLRequest& request) const {
[email protected]84b7a552014-07-19 04:52:06779#if defined(ENABLE_EXTENSIONS)
[email protected]4a2b6232014-06-19 08:44:14780 if (g_never_throttle_requests_)
[email protected]a1d4ab072012-06-07 13:21:15781 return false;
[email protected]c4a7df82012-08-09 22:48:46782 return request.first_party_for_cookies().scheme() ==
[email protected]885c0e92012-11-13 20:27:42783 extensions::kExtensionScheme;
[email protected]84b7a552014-07-19 04:52:06784#else
785 return false;
786#endif
[email protected]a1d4ab072012-06-07 13:21:15787}
[email protected]aa28181e2012-06-13 00:53:58788
[email protected]e6d017652013-05-17 18:01:40789bool ChromeNetworkDelegate::OnCanEnablePrivacyMode(
790 const GURL& url,
791 const GURL& first_party_for_cookies) const {
792 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02793 if (!cookie_settings_.get())
[email protected]e6d017652013-05-17 18:01:40794 return false;
795
796 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed(
797 url, first_party_for_cookies);
798 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed(
799 url, first_party_for_cookies);
800 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed);
801 return privacy_mode;
802}
803
[email protected]aa28181e2012-06-13 00:53:58804int ChromeNetworkDelegate::OnBeforeSocketStreamConnect(
805 net::SocketStream* socket,
806 const net::CompletionCallback& callback) {
807#if defined(ENABLE_CONFIGURATION_POLICY)
808 if (url_blacklist_manager_ &&
809 url_blacklist_manager_->IsURLBlocked(socket->url())) {
810 // URL access blocked by policy.
[email protected]aa28181e2012-06-13 00:53:58811 socket->net_log()->AddEvent(
[email protected]2fa08912012-06-14 20:56:26812 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
813 net::NetLog::StringCallback("url",
814 &socket->url().possibly_invalid_spec()));
[email protected]91468a92013-03-06 17:21:55815 return net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]aa28181e2012-06-13 00:53:58816 }
817#endif
818 return net::OK;
819}
[email protected]5a07c192012-07-30 20:18:22820
jochen0e3b3a62014-09-16 18:31:23821bool ChromeNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
822 const net::URLRequest& request,
823 const GURL& target_url,
824 const GURL& referrer_url) const {
825 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
826 base::Bind(&ReportInvalidReferrerSend, target_url, referrer_url));
827 return true;
828}
829
[email protected]7a299a92012-10-24 23:54:50830void ChromeNetworkDelegate::AccumulateContentLength(
[email protected]b7796462013-12-12 19:42:34831 int64 received_content_length,
832 int64 original_content_length,
[email protected]a0a06932014-04-14 21:23:42833 data_reduction_proxy::DataReductionProxyRequestType request_type) {
[email protected]7a299a92012-10-24 23:54:50834 DCHECK_GE(received_content_length, 0);
835 DCHECK_GE(original_content_length, 0);
836 StoreAccumulatedContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41837 original_content_length,
[email protected]a0a06932014-04-14 21:23:42838 request_type,
[email protected]b7796462013-12-12 19:42:34839 reinterpret_cast<Profile*>(profile_));
[email protected]7a299a92012-10-24 23:54:50840 received_content_length_ += received_content_length;
841 original_content_length_ += original_content_length;
842}