blob: 4b4d618896e0f2ff14371b63e9cd91c85fa12d9b [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"
[email protected]3ea1b182013-02-08 22:38:4122#include "base/strings/string_number_conversions.h"
[email protected]069c49162013-09-11 20:46:3523#include "base/time/time.h"
[email protected]6baff0b52012-03-06 01:30:1824#include "chrome/browser/browser_process.h"
[email protected]9c8ae8c2012-03-09 13:13:3525#include "chrome/browser/content_settings/cookie_settings.h"
26#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]8523ba52011-05-22 19:00:5827#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]4a2b6232014-06-19 08:44:1428#include "chrome/browser/net/chrome_extensions_network_delegate.h"
[email protected]3620bbc2013-10-05 05:07:2329#include "chrome/browser/net/client_hints.h"
[email protected]f53b4802012-12-20 17:04:2330#include "chrome/browser/net/connect_interceptor.h"
[email protected]184799df2014-07-22 16:03:2431#include "chrome/browser/net/safe_search_util.h"
[email protected]28c5d0b72014-05-13 08:19:5932#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]6baff0b52012-03-06 01:30:1833#include "chrome/browser/profiles/profile_manager.h"
[email protected]8523ba52011-05-22 19:00:5834#include "chrome/browser/task_manager/task_manager.h"
[email protected]0a8db0d2011-04-13 15:15:4035#include "chrome/common/pref_names.h"
megjablon3476e042014-10-14 19:21:5936#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
37#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h"
megjablon3476e042014-10-14 19:21:5938#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
39#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h"
jeremyimdb2599e2014-10-29 02:13:0940#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
[email protected]45de676a2014-03-18 23:52:0241#include "components/domain_reliability/monitor.h"
[email protected]c38831a12011-10-28 12:44:4942#include "content/public/browser/browser_thread.h"
[email protected]9dfed872013-12-30 23:08:5643#include "content/public/browser/render_frame_host.h"
[email protected]9c1662b2012-03-06 15:44:3344#include "content/public/browser/render_view_host.h"
[email protected]9c8ae8c2012-03-09 13:13:3545#include "content/public/browser/resource_request_info.h"
[email protected]82b42302011-04-20 16:28:1646#include "net/base/host_port_pair.h"
[email protected]8202d0c2011-02-23 08:31:1447#include "net/base/net_errors.h"
[email protected]6a5f77c32011-09-04 19:19:5948#include "net/base/net_log.h"
[email protected]5b9bc352012-07-18 13:13:3449#include "net/cookies/canonical_cookie.h"
50#include "net/cookies/cookie_options.h"
[email protected]ac039522010-06-15 16:39:4451#include "net/http/http_request_headers.h"
[email protected]48944382011-04-23 13:28:1652#include "net/http/http_response_headers.h"
[email protected]12731792014-08-14 11:45:5453#include "net/proxy/proxy_config.h"
[email protected]597a1ab2014-06-26 08:12:2754#include "net/proxy/proxy_info.h"
[email protected]12731792014-08-14 11:45:5455#include "net/proxy/proxy_retry_info.h"
[email protected]597a1ab2014-06-26 08:12:2756#include "net/proxy/proxy_server.h"
[email protected]d05ef99c2011-02-01 21:38:1657#include "net/url_request/url_request.h"
[email protected]28c5d0b72014-05-13 08:19:5958#include "net/url_request/url_request_context.h"
[email protected]d05ef99c2011-02-01 21:38:1659
[email protected]4a2b6232014-06-19 08:44:1460#if defined(OS_ANDROID)
61#include "chrome/browser/io_thread.h"
62#include "components/precache/content/precache_manager.h"
63#include "components/precache/content/precache_manager_factory.h"
64#endif
65
[email protected]4c219e22012-05-05 19:41:0466#if defined(OS_CHROMEOS)
[email protected]288538482012-09-06 21:09:3567#include "base/command_line.h"
[email protected]49c4cf852013-09-27 19:28:2468#include "base/sys_info.h"
[email protected]288538482012-09-06 21:09:3569#include "chrome/common/chrome_switches.h"
[email protected]4c219e22012-05-05 19:41:0470#endif
71
[email protected]3e598ff12011-09-06 11:22:3472#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]f522afa2014-01-08 15:36:3673#include "components/policy/core/browser/url_blacklist_manager.h"
[email protected]3e598ff12011-09-06 11:22:3474#endif
75
[email protected]84b7a552014-07-19 04:52:0676#if defined(ENABLE_EXTENSIONS)
77#include "extensions/common/constants.h"
78#endif
79
[email protected]631bb742011-11-02 11:29:3980using content::BrowserThread;
[email protected]eaabba22012-03-07 15:02:1181using content::RenderViewHost;
[email protected]ea114722012-03-12 01:11:2582using content::ResourceRequestInfo;
[email protected]7491ad02014-07-05 19:10:0783using content::ResourceType;
[email protected]631bb742011-11-02 11:29:3984
[email protected]d8e4f132012-09-06 04:28:0585// By default we don't allow access to all file:// urls on ChromeOS and
86// Android.
87#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:0488bool ChromeNetworkDelegate::g_allow_file_access_ = false;
89#else
90bool ChromeNetworkDelegate::g_allow_file_access_ = true;
91#endif
92
[email protected]84b7a552014-07-19 04:52:0693#if defined(ENABLE_EXTENSIONS)
[email protected]c4a7df82012-08-09 22:48:4694// This remains false unless the --disable-extensions-http-throttling
95// flag is passed to the browser.
96bool ChromeNetworkDelegate::g_never_throttle_requests_ = false;
[email protected]84b7a552014-07-19 04:52:0697#endif
[email protected]c4a7df82012-08-09 22:48:4698
[email protected]d05ef99c2011-02-01 21:38:1699namespace {
100
[email protected]9d8cfb682012-09-13 16:48:04101const char kDNTHeader[] = "DNT";
102
[email protected]d1208ba32012-11-08 11:10:33103// Gets called when the extensions finish work on the URL. If the extensions
104// did not do a redirect (so |new_url| is empty) then we enforce the
105// SafeSearch parameters. Otherwise we will get called again after the
106// redirect and we enforce SafeSearch then.
107void ForceGoogleSafeSearchCallbackWrapper(
108 const net::CompletionCallback& callback,
109 net::URLRequest* request,
110 GURL* new_url,
111 int rv) {
112 if (rv == net::OK && new_url->is_empty())
[email protected]184799df2014-07-22 16:03:24113 safe_search_util::ForceGoogleSafeSearch(request, new_url);
[email protected]d1208ba32012-11-08 11:10:33114 callback.Run(rv);
115}
116
[email protected]828eab22013-12-10 22:42:38117void UpdateContentLengthPrefs(
118 int received_content_length,
119 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42120 data_reduction_proxy::DataReductionProxyRequestType request_type,
megjablon53f608b2014-09-18 19:24:55121 Profile* profile,
122 data_reduction_proxy::DataReductionProxyStatisticsPrefs* statistics_prefs) {
[email protected]7a299a92012-10-24 23:54:50123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
124 DCHECK_GE(received_content_length, 0);
125 DCHECK_GE(original_content_length, 0);
126
[email protected]a09159a2012-11-29 12:51:48127 // Can be NULL in a unit test.
128 if (!g_browser_process)
129 return;
130
[email protected]b7796462013-12-12 19:42:34131 // Ignore off-the-record data.
132 if (!g_browser_process->profile_manager()->IsValidProfile(profile) ||
133 profile->IsOffTheRecord()) {
134 return;
135 }
megjablon53f608b2014-09-18 19:24:55136 data_reduction_proxy::UpdateContentLengthPrefs(
137 received_content_length,
138 original_content_length,
kundaji88ca4112014-09-23 01:35:21139 profile->GetPrefs(),
140 request_type, statistics_prefs);
[email protected]7a299a92012-10-24 23:54:50141}
142
[email protected]828eab22013-12-10 22:42:38143void StoreAccumulatedContentLength(
144 int received_content_length,
145 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42146 data_reduction_proxy::DataReductionProxyRequestType request_type,
megjablon53f608b2014-09-18 19:24:55147 Profile* profile,
148 data_reduction_proxy::DataReductionProxyStatisticsPrefs* statistics_prefs) {
[email protected]7a299a92012-10-24 23:54:50149 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
150 base::Bind(&UpdateContentLengthPrefs,
megjablon53f608b2014-09-18 19:24:55151 received_content_length,
152 original_content_length,
153 request_type,
154 profile,
155 statistics_prefs));
[email protected]7a299a92012-10-24 23:54:50156}
157
158void RecordContentLengthHistograms(
[email protected]f81a5ee2013-06-20 21:08:49159 int64 received_content_length,
160 int64 original_content_length,
161 const base::TimeDelta& freshness_lifetime) {
[email protected]7a299a92012-10-24 23:54:50162 // Add the current resource to these histograms only when a valid
163 // X-Original-Content-Length header is present.
164 if (original_content_length >= 0) {
165 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL",
166 received_content_length);
167 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL",
168 original_content_length);
169 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL",
170 original_content_length - received_content_length);
171 } else {
172 // Presume the original content length is the same as the received content
173 // length if the X-Original-Content-Header is not present.
174 original_content_length = received_content_length;
175 }
176 UMA_HISTOGRAM_COUNTS("Net.HttpContentLength", received_content_length);
177 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLength",
178 original_content_length);
179 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifference",
180 original_content_length - received_content_length);
[email protected]f81a5ee2013-06-20 21:08:49181 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpContentFreshnessLifetime",
182 freshness_lifetime.InSeconds(),
183 base::TimeDelta::FromHours(1).InSeconds(),
184 base::TimeDelta::FromDays(30).InSeconds(),
185 100);
186 if (freshness_lifetime.InSeconds() <= 0)
187 return;
188 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable",
189 received_content_length);
190 if (freshness_lifetime.InHours() < 4)
191 return;
192 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours",
193 received_content_length);
194
195 if (freshness_lifetime.InHours() < 24)
196 return;
197 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours",
198 received_content_length);
[email protected]7a299a92012-10-24 23:54:50199}
200
[email protected]35558812013-12-18 21:58:36201#if defined(OS_ANDROID)
202void RecordPrecacheStatsOnUIThread(const GURL& url,
203 const base::Time& fetch_time, int64 size,
204 bool was_cached, void* profile_id) {
205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
206
207 Profile* profile = reinterpret_cast<Profile*>(profile_id);
208 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) {
209 return;
210 }
211
212 precache::PrecacheManager* precache_manager =
213 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
tanviraumi387f6332014-08-29 19:04:36214 if (!precache_manager || !precache_manager->IsPrecachingAllowed()) {
215 // |precache_manager| could be NULL if the profile is off the record.
[email protected]35558812013-12-18 21:58:36216 return;
217 }
218
219 precache_manager->RecordStatsForFetch(url, fetch_time, size, was_cached);
220}
[email protected]d827e112014-03-31 17:45:05221
222void RecordIOThreadToRequestStartOnUIThread(
223 const base::TimeTicks& request_start) {
224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
225 base::TimeDelta request_lag = request_start -
226 g_browser_process->io_thread()->creation_time();
227 UMA_HISTOGRAM_TIMES("Net.IOThreadCreationToHTTPRequestStart", request_lag);
228}
[email protected]35558812013-12-18 21:58:36229#endif // defined(OS_ANDROID)
230
jochen0e3b3a62014-09-16 18:31:23231void ReportInvalidReferrerSend(const GURL& target_url,
jochenb93dba3c2014-11-11 05:28:41232 const GURL& referrer_url,
233 const base::debug::StackTrace& callstack) {
234 // Record information to help debug http://crbug.com/422871
235 base::debug::StackTrace trace = callstack;
236 base::debug::Alias(&trace);
237 enum { INVALID_URL, FILE_URL, DATA_URL, HTTP_URL, OTHER } reason = OTHER;
238 if (!target_url.is_valid())
239 reason = INVALID_URL;
240 else if (target_url.SchemeIsFile())
241 reason = FILE_URL;
242 else if (target_url.SchemeIs(url::kDataScheme))
243 reason = DATA_URL;
244 else if (target_url.SchemeIs(url::kHttpScheme))
245 reason = HTTP_URL;
246 base::debug::Alias(&reason);
jochen0e3b3a62014-09-16 18:31:23247 base::RecordAction(
248 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer"));
jochenb5680e62014-10-13 08:43:41249 base::debug::DumpWithoutCrashing();
250 NOTREACHED();
jochen0e3b3a62014-09-16 18:31:23251}
252
[email protected]d05ef99c2011-02-01 21:38:16253} // namespace
[email protected]ac039522010-06-15 16:39:44254
[email protected]0651b812011-02-24 00:22:50255ChromeNetworkDelegate::ChromeNetworkDelegate(
[email protected]5a38dfd2012-07-23 23:22:10256 extensions::EventRouterForwarder* event_router,
[email protected]a09159a2012-11-29 12:51:48257 BooleanPrefMember* enable_referrers)
[email protected]4a2b6232014-06-19 08:44:14258 : profile_(NULL),
[email protected]6a5f77c32011-09-04 19:19:59259 enable_referrers_(enable_referrers),
[email protected]a09159a2012-11-29 12:51:48260 enable_do_not_track_(NULL),
261 force_google_safe_search_(NULL),
[email protected]a948dad2014-07-25 00:39:38262 data_reduction_proxy_enabled_(NULL),
[email protected]4a2b6232014-06-19 08:44:14263#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]a09159a2012-11-29 12:51:48264 url_blacklist_manager_(NULL),
[email protected]4a2b6232014-06-19 08:44:14265#endif
[email protected]45de676a2014-03-18 23:52:02266 domain_reliability_monitor_(NULL),
[email protected]7a299a92012-10-24 23:54:50267 received_content_length_(0),
[email protected]d827e112014-03-31 17:45:05268 original_content_length_(0),
[email protected]28c5d0b72014-05-13 08:19:59269 first_request_(true),
[email protected]d8fc4722014-06-13 13:17:15270 prerender_tracker_(NULL),
[email protected]bceab7f2014-06-25 04:36:20271 data_reduction_proxy_params_(NULL),
[email protected]597a1ab2014-06-26 08:12:27272 data_reduction_proxy_usage_stats_(NULL),
megjablon53f608b2014-09-18 19:24:55273 data_reduction_proxy_auth_request_handler_(NULL),
274 data_reduction_proxy_statistics_prefs_(NULL) {
[email protected]0a8db0d2011-04-13 15:15:40275 DCHECK(enable_referrers);
[email protected]4a2b6232014-06-19 08:44:14276 extensions_delegate_.reset(
277 ChromeExtensionsNetworkDelegate::Create(event_router));
[email protected]0651b812011-02-24 00:22:50278}
279
[email protected]ac039522010-06-15 16:39:44280ChromeNetworkDelegate::~ChromeNetworkDelegate() {}
281
[email protected]a09159a2012-11-29 12:51:48282void ChromeNetworkDelegate::set_extension_info_map(
[email protected]38427a12013-11-09 17:34:20283 extensions::InfoMap* extension_info_map) {
[email protected]4a2b6232014-06-19 08:44:14284 extensions_delegate_->set_extension_info_map(extension_info_map);
285}
286
287void ChromeNetworkDelegate::set_profile(void* profile) {
288 profile_ = profile;
289 extensions_delegate_->set_profile(profile);
[email protected]a09159a2012-11-29 12:51:48290}
291
292void ChromeNetworkDelegate::set_cookie_settings(
293 CookieSettings* cookie_settings) {
294 cookie_settings_ = cookie_settings;
295}
296
[email protected]f53b4802012-12-20 17:04:23297void ChromeNetworkDelegate::set_predictor(
298 chrome_browser_net::Predictor* predictor) {
299 connect_interceptor_.reset(
300 new chrome_browser_net::ConnectInterceptor(predictor));
301}
302
[email protected]3620bbc2013-10-05 05:07:23303void ChromeNetworkDelegate::SetEnableClientHints() {
304 client_hints_.reset(new ClientHints());
305 client_hints_->Init();
306}
307
[email protected]c4a7df82012-08-09 22:48:46308// static
[email protected]84b7a552014-07-19 04:52:06309#if defined(ENABLE_EXTENSIONS)
[email protected]a1d4ab072012-06-07 13:21:15310void ChromeNetworkDelegate::NeverThrottleRequests() {
[email protected]c4a7df82012-08-09 22:48:46311 g_never_throttle_requests_ = true;
[email protected]a1d4ab072012-06-07 13:21:15312}
[email protected]84b7a552014-07-19 04:52:06313#endif
[email protected]a1d4ab072012-06-07 13:21:15314
[email protected]0a8db0d2011-04-13 15:15:40315// static
[email protected]9d8cfb682012-09-13 16:48:04316void ChromeNetworkDelegate::InitializePrefsOnUIThread(
[email protected]0a8db0d2011-04-13 15:15:40317 BooleanPrefMember* enable_referrers,
[email protected]9d8cfb682012-09-13 16:48:04318 BooleanPrefMember* enable_do_not_track,
[email protected]d1208ba32012-11-08 11:10:33319 BooleanPrefMember* force_google_safe_search,
[email protected]0a8db0d2011-04-13 15:15:40320 PrefService* pref_service) {
321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]96a5c342012-12-04 18:14:02322 enable_referrers->Init(prefs::kEnableReferrers, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43323 enable_referrers->MoveToThread(
324 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04325 if (enable_do_not_track) {
[email protected]96a5c342012-12-04 18:14:02326 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43327 enable_do_not_track->MoveToThread(
328 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04329 }
[email protected]d1208ba32012-11-08 11:10:33330 if (force_google_safe_search) {
[email protected]96a5c342012-12-04 18:14:02331 force_google_safe_search->Init(prefs::kForceSafeSearch, pref_service);
[email protected]d1208ba32012-11-08 11:10:33332 force_google_safe_search->MoveToThread(
333 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
334 }
[email protected]0a8db0d2011-04-13 15:15:40335}
336
[email protected]4c219e22012-05-05 19:41:04337// static
338void ChromeNetworkDelegate::AllowAccessToAllFiles() {
339 g_allow_file_access_ = true;
340}
341
[email protected]7a299a92012-10-24 23:54:50342// static
megjablon53f608b2014-09-18 19:24:55343// TODO(megjablon): Use data_reduction_proxy_delayed_pref_service to read prefs.
344// Until updated the pref values may be up to an hour behind on desktop.
[email protected]cb1078de2013-12-23 20:04:22345base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() {
[email protected]7a299a92012-10-24 23:54:50346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
347 PrefService* prefs = g_browser_process->local_state();
[email protected]a0a06932014-04-14 21:23:42348 int64 total_received = prefs->GetInt64(
349 data_reduction_proxy::prefs::kHttpReceivedContentLength);
350 int64 total_original = prefs->GetInt64(
351 data_reduction_proxy::prefs::kHttpOriginalContentLength);
[email protected]7a299a92012-10-24 23:54:50352
[email protected]cb1078de2013-12-23 20:04:22353 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42354 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
355 dict->SetString("historic_received_content_length",
356 base::Int64ToString(total_received));
357 dict->SetString("historic_original_content_length",
358 base::Int64ToString(total_original));
[email protected]7a299a92012-10-24 23:54:50359 return dict;
360}
361
[email protected]cb1078de2013-12-23 20:04:22362base::Value* ChromeNetworkDelegate::SessionNetworkStatsInfoToValue() const {
363 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42364 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
365 dict->SetString("session_received_content_length",
366 base::Int64ToString(received_content_length_));
367 dict->SetString("session_original_content_length",
368 base::Int64ToString(original_content_length_));
[email protected]7a299a92012-10-24 23:54:50369 return dict;
370}
371
[email protected]4875ba12011-03-30 22:31:51372int ChromeNetworkDelegate::OnBeforeURLRequest(
[email protected]4c76d7c2011-04-15 19:14:12373 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47374 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12375 GURL* new_url) {
[email protected]d827e112014-03-31 17:45:05376#if defined(OS_ANDROID)
377 // This UMA tracks the time to the first user-initiated request start, so
378 // only non-null profiles are considered.
379 if (first_request_ && profile_) {
380 bool record_timing = true;
[email protected]bec6a992014-06-19 01:03:21381 if (data_reduction_proxy_params_) {
382 record_timing =
383 (request->url() != data_reduction_proxy_params_->probe_url()) &&
384 (request->url() != data_reduction_proxy_params_->warmup_url());
385 }
[email protected]d827e112014-03-31 17:45:05386 if (record_timing) {
387 first_request_ = false;
388 net::LoadTimingInfo timing_info;
389 request->GetLoadTimingInfo(&timing_info);
390 BrowserThread::PostTask(
391 BrowserThread::UI, FROM_HERE,
392 base::Bind(&RecordIOThreadToRequestStartOnUIThread,
393 timing_info.request_start));
394 }
395 }
396#endif // defined(OS_ANDROID)
397
[email protected]3e598ff12011-09-06 11:22:34398#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]6a5f77c32011-09-04 19:19:59399 // TODO(joaodasilva): This prevents extensions from seeing URLs that are
400 // blocked. However, an extension might redirect the request to another URL,
401 // which is not blocked.
[email protected]cb85f8e52014-04-08 11:44:40402 int error = net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]6a5f77c32011-09-04 19:19:59403 if (url_blacklist_manager_ &&
[email protected]cb85f8e52014-04-08 11:44:40404 url_blacklist_manager_->IsRequestBlocked(*request, &error)) {
[email protected]6a5f77c32011-09-04 19:19:59405 // URL access blocked by policy.
[email protected]6a5f77c32011-09-04 19:19:59406 request->net_log().AddEvent(
[email protected]2fa08912012-06-14 20:56:26407 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
408 net::NetLog::StringCallback("url",
409 &request->url().possibly_invalid_spec()));
[email protected]cb85f8e52014-04-08 11:44:40410 return error;
[email protected]6a5f77c32011-09-04 19:19:59411 }
[email protected]3e598ff12011-09-06 11:22:34412#endif
[email protected]6a5f77c32011-09-04 19:19:59413
[email protected]4a2b6232014-06-19 08:44:14414 extensions_delegate_->ForwardStartRequestStatus(request);
[email protected]6baff0b52012-03-06 01:30:18415
[email protected]0a8db0d2011-04-13 15:15:40416 if (!enable_referrers_->GetValue())
[email protected]99ecf6e2013-04-10 22:46:13417 request->SetReferrer(std::string());
[email protected]9d8cfb682012-09-13 16:48:04418 if (enable_do_not_track_ && enable_do_not_track_->GetValue())
419 request->SetExtraRequestHeaderByName(kDNTHeader, "1", true /* override */);
[email protected]d1208ba32012-11-08 11:10:33420
[email protected]3620bbc2013-10-05 05:07:23421 if (client_hints_) {
422 request->SetExtraRequestHeaderByName(
423 ClientHints::kDevicePixelRatioHeader,
424 client_hints_->GetDevicePixelRatioHeader(), true);
425 }
426
[email protected]d1208ba32012-11-08 11:10:33427 bool force_safe_search = force_google_safe_search_ &&
428 force_google_safe_search_->GetValue();
429
430 net::CompletionCallback wrapped_callback = callback;
431 if (force_safe_search) {
432 wrapped_callback = base::Bind(&ForceGoogleSafeSearchCallbackWrapper,
433 callback,
434 base::Unretained(request),
435 base::Unretained(new_url));
436 }
437
[email protected]4a2b6232014-06-19 08:44:14438 int rv = extensions_delegate_->OnBeforeURLRequest(
439 request, wrapped_callback, new_url);
[email protected]d1208ba32012-11-08 11:10:33440
441 if (force_safe_search && rv == net::OK && new_url->is_empty())
[email protected]184799df2014-07-22 16:03:24442 safe_search_util::ForceGoogleSafeSearch(request, new_url);
[email protected]d1208ba32012-11-08 11:10:33443
[email protected]f53b4802012-12-20 17:04:23444 if (connect_interceptor_)
445 connect_interceptor_->WitnessURLRequest(request);
446
[email protected]d1208ba32012-11-08 11:10:33447 return rv;
[email protected]d05ef99c2011-02-01 21:38:16448}
449
[email protected]a702da72014-07-09 05:23:54450void ChromeNetworkDelegate::OnResolveProxy(
[email protected]12731792014-08-14 11:45:54451 const GURL& url,
452 int load_flags,
453 const net::ProxyService& proxy_service,
454 net::ProxyInfo* result) {
455 if (!on_resolve_proxy_handler_.is_null() &&
456 !proxy_config_getter_.is_null()) {
[email protected]a702da72014-07-09 05:23:54457 on_resolve_proxy_handler_.Run(url, load_flags,
[email protected]12731792014-08-14 11:45:54458 proxy_config_getter_.Run(),
bengrf5c403d2014-11-04 03:02:57459 proxy_service.config(),
[email protected]12731792014-08-14 11:45:54460 proxy_service.proxy_retry_info(),
[email protected]a702da72014-07-09 05:23:54461 data_reduction_proxy_params_, result);
462 }
463}
464
[email protected]f09f9682014-08-10 01:21:39465void ChromeNetworkDelegate::OnProxyFallback(const net::ProxyServer& bad_proxy,
[email protected]d0483b192014-08-15 23:50:17466 int net_error) {
[email protected]f09f9682014-08-10 01:21:39467 if (data_reduction_proxy_usage_stats_) {
kundajia9a4b7da2014-09-23 21:10:56468 data_reduction_proxy_usage_stats_->OnProxyFallback(
[email protected]d0483b192014-08-15 23:50:17469 bad_proxy, net_error);
[email protected]f09f9682014-08-10 01:21:39470 }
471}
472
[email protected]4875ba12011-03-30 22:31:51473int ChromeNetworkDelegate::OnBeforeSendHeaders(
[email protected]636eccd2011-06-28 12:28:01474 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47475 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12476 net::HttpRequestHeaders* headers) {
[email protected]184799df2014-07-22 16:03:24477 bool force_safe_search = force_google_safe_search_ &&
478 force_google_safe_search_->GetValue();
479 if (force_safe_search)
480 safe_search_util::ForceYouTubeSafetyMode(request, headers);
481
[email protected]186468f2013-10-24 02:44:11482 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest");
[email protected]4a2b6232014-06-19 08:44:14483 return extensions_delegate_->OnBeforeSendHeaders(request, callback, headers);
[email protected]ac039522010-06-15 16:39:44484}
[email protected]8202d0c2011-02-23 08:31:14485
[email protected]597a1ab2014-06-26 08:12:27486void ChromeNetworkDelegate::OnBeforeSendProxyHeaders(
487 net::URLRequest* request,
488 const net::ProxyInfo& proxy_info,
489 net::HttpRequestHeaders* headers) {
490 if (data_reduction_proxy_auth_request_handler_) {
491 data_reduction_proxy_auth_request_handler_->MaybeAddRequestHeader(
492 request, proxy_info.proxy_server(), headers);
493 }
494}
495
[email protected]5796dc942011-07-14 19:26:10496void ChromeNetworkDelegate::OnSendHeaders(
497 net::URLRequest* request,
[email protected]783573b2011-05-13 11:05:15498 const net::HttpRequestHeaders& headers) {
[email protected]4a2b6232014-06-19 08:44:14499 extensions_delegate_->OnSendHeaders(request, headers);
[email protected]82b42302011-04-20 16:28:16500}
501
[email protected]ea8141e2011-10-05 13:12:51502int ChromeNetworkDelegate::OnHeadersReceived(
503 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47504 const net::CompletionCallback& callback,
[email protected]507af8f2012-10-20 00:42:32505 const net::HttpResponseHeaders* original_response_headers,
[email protected]5f714132014-03-26 10:41:16506 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
507 GURL* allowed_unsafe_redirect_url) {
[email protected]4a2b6232014-06-19 08:44:14508 return extensions_delegate_->OnHeadersReceived(
[email protected]5f714132014-03-26 10:41:16509 request,
510 callback,
511 original_response_headers,
512 override_response_headers,
513 allowed_unsafe_redirect_url);
[email protected]ea8141e2011-10-05 13:12:51514}
515
[email protected]31b2e5f2011-04-20 16:58:32516void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
517 const GURL& new_location) {
[email protected]45de676a2014-03-18 23:52:02518 if (domain_reliability_monitor_)
519 domain_reliability_monitor_->OnBeforeRedirect(request);
[email protected]4a2b6232014-06-19 08:44:14520 extensions_delegate_->OnBeforeRedirect(request, new_location);
[email protected]31b2e5f2011-04-20 16:58:32521}
522
523
[email protected]8202d0c2011-02-23 08:31:14524void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
[email protected]186468f2013-10-24 02:44:11525 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "ResponseStarted");
[email protected]4a2b6232014-06-19 08:44:14526 extensions_delegate_->OnResponseStarted(request);
[email protected]8202d0c2011-02-23 08:31:14527}
528
[email protected]8523ba52011-05-22 19:00:58529void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
530 int bytes_read) {
[email protected]186468f2013-10-24 02:44:11531 TRACE_EVENT_ASYNC_STEP_PAST1("net", "URLRequest", &request, "DidRead",
532 "bytes_read", bytes_read);
[email protected]44879ed2012-04-06 01:11:02533#if defined(ENABLE_TASK_MANAGER)
[email protected]17df9e7c2014-02-13 03:49:29534 // This is not completely accurate, but as a first approximation ignore
535 // requests that are served from the cache. See bug 330931 for more info.
536 if (!request.was_cached())
537 TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read);
[email protected]44879ed2012-04-06 01:11:02538#endif // defined(ENABLE_TASK_MANAGER)
[email protected]8523ba52011-05-22 19:00:58539}
540
[email protected]9045b8822012-01-13 20:35:35541void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
542 bool started) {
[email protected]bceab7f2014-06-25 04:36:20543 if (data_reduction_proxy_usage_stats_)
544 data_reduction_proxy_usage_stats_->OnUrlRequestCompleted(request, started);
545
[email protected]4aca5db2013-08-17 00:51:56546 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request);
[email protected]2756a8e2012-09-07 18:24:29547 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
[email protected]7a299a92012-10-24 23:54:50548 // For better accuracy, we use the actual bytes read instead of the length
549 // specified with the Content-Length header, which may be inaccurate,
550 // or missing, as is the case with chunked encoding.
551 int64 received_content_length = request->received_response_content_length();
552
[email protected]35558812013-12-18 21:58:36553#if defined(OS_ANDROID)
554 if (precache::PrecacheManager::IsPrecachingEnabled()) {
555 // Record precache metrics when a fetch is completed successfully, if
556 // precaching is enabled.
557 BrowserThread::PostTask(
558 BrowserThread::UI, FROM_HERE,
559 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(),
560 base::Time::Now(), received_content_length,
561 request->was_cached(), profile_));
562 }
563#endif // defined(OS_ANDROID)
564
[email protected]7a299a92012-10-24 23:54:50565 // Only record for http or https urls.
566 bool is_http = request->url().SchemeIs("http");
567 bool is_https = request->url().SchemeIs("https");
568
569 if (!request->was_cached() && // Don't record cached content
570 received_content_length && // Zero-byte responses aren't useful.
571 (is_http || is_https)) { // Only record for HTTP or HTTPS urls.
572 int64 original_content_length =
573 request->response_info().headers->GetInt64HeaderValue(
574 "x-original-content-length");
[email protected]a0a06932014-04-14 21:23:42575 data_reduction_proxy::DataReductionProxyRequestType request_type =
576 data_reduction_proxy::GetDataReductionProxyRequestType(request);
[email protected]2db93e42013-08-07 17:40:41577
[email protected]f81a5ee2013-06-20 21:08:49578 base::TimeDelta freshness_lifetime =
ricea43736982014-10-30 09:15:48579 request->response_info().headers->GetFreshnessLifetimes(
580 request->response_info().response_time).freshness;
[email protected]828eab22013-12-10 22:42:38581 int64 adjusted_original_content_length =
[email protected]a0a06932014-04-14 21:23:42582 data_reduction_proxy::GetAdjustedOriginalContentLength(
583 request_type, original_content_length,
[email protected]828eab22013-12-10 22:42:38584 received_content_length);
[email protected]7a299a92012-10-24 23:54:50585 AccumulateContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41586 adjusted_original_content_length,
[email protected]a0a06932014-04-14 21:23:42587 request_type);
[email protected]7a299a92012-10-24 23:54:50588 RecordContentLengthHistograms(received_content_length,
[email protected]f81a5ee2013-06-20 21:08:49589 original_content_length,
590 freshness_lifetime);
sclittlef72ee642014-09-24 20:04:28591
megjablon25ff71d32014-09-05 03:21:44592 if (data_reduction_proxy_enabled_ &&
593 data_reduction_proxy_usage_stats_ &&
594 !proxy_config_getter_.is_null()) {
sclittlef72ee642014-09-24 20:04:28595 data_reduction_proxy_usage_stats_->RecordBytesHistograms(
596 request,
megjablon25ff71d32014-09-05 03:21:44597 *data_reduction_proxy_enabled_,
598 proxy_config_getter_.Run());
[email protected]a948dad2014-07-25 00:39:38599 }
[email protected]7a299a92012-10-24 23:54:50600 DVLOG(2) << __FUNCTION__
601 << " received content length: " << received_content_length
602 << " original content length: " << original_content_length
603 << " url: " << request->url();
604 }
605
[email protected]4a2b6232014-06-19 08:44:14606 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01607 } else if (request->status().status() == net::URLRequestStatus::FAILED ||
608 request->status().status() == net::URLRequestStatus::CANCELED) {
[email protected]4a2b6232014-06-19 08:44:14609 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01610 } else {
611 NOTREACHED();
[email protected]48944382011-04-23 13:28:16612 }
[email protected]45de676a2014-03-18 23:52:02613 if (domain_reliability_monitor_)
614 domain_reliability_monitor_->OnCompleted(request, started);
[email protected]4a2b6232014-06-19 08:44:14615 extensions_delegate_->ForwardProxyErrors(request);
616 extensions_delegate_->ForwardDoneRequestStatus(request);
[email protected]8202d0c2011-02-23 08:31:14617}
[email protected]4b50cb52011-03-10 00:29:37618
[email protected]4875ba12011-03-30 22:31:51619void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
[email protected]4a2b6232014-06-19 08:44:14620 extensions_delegate_->OnURLRequestDestroyed(request);
[email protected]4875ba12011-03-30 22:31:51621}
622
[email protected]82a37672011-05-03 12:02:41623void ChromeNetworkDelegate::OnPACScriptError(int line_number,
[email protected]439f1e32013-12-09 20:09:09624 const base::string16& error) {
[email protected]4a2b6232014-06-19 08:44:14625 extensions_delegate_->OnPACScriptError(line_number, error);
[email protected]82a37672011-05-03 12:02:41626}
[email protected]7efc582d2011-08-03 20:46:35627
[email protected]c2911d72011-10-03 22:16:36628net::NetworkDelegate::AuthRequiredResponse
629ChromeNetworkDelegate::OnAuthRequired(
[email protected]7efc582d2011-08-03 20:46:35630 net::URLRequest* request,
[email protected]c2911d72011-10-03 22:16:36631 const net::AuthChallengeInfo& auth_info,
632 const AuthCallback& callback,
633 net::AuthCredentials* credentials) {
[email protected]4a2b6232014-06-19 08:44:14634 return extensions_delegate_->OnAuthRequired(
635 request, auth_info, callback, credentials);
[email protected]7efc582d2011-08-03 20:46:35636}
[email protected]9c8ae8c2012-03-09 13:13:35637
[email protected]4c219e22012-05-05 19:41:04638bool ChromeNetworkDelegate::OnCanGetCookies(
639 const net::URLRequest& request,
[email protected]9c8ae8c2012-03-09 13:13:35640 const net::CookieList& cookie_list) {
641 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02642 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35643 return true;
644
645 bool allow = cookie_settings_->IsReadingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04646 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35647
648 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16649 int render_frame_id = -1;
[email protected]f7fa5b62014-03-19 15:20:06650
651 // |is_for_blocking_resource| indicates whether the cookies read were for a
652 // blocking resource (eg script, css). It is only temporarily added for
653 // diagnostic purposes, per bug 353678. Will be removed again once data
654 // collection is finished.
655 bool is_for_blocking_resource = false;
656 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
657 if (info && ((!info->IsAsync()) ||
[email protected]6c1e05212014-07-31 00:59:40658 info->GetResourceType() == content::RESOURCE_TYPE_STYLESHEET ||
659 info->GetResourceType() == content::RESOURCE_TYPE_SCRIPT)) {
[email protected]f7fa5b62014-03-19 15:20:06660 is_for_blocking_resource = true;
661 }
662
[email protected]f3add922013-12-20 23:17:16663 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
664 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35665 BrowserThread::PostTask(
666 BrowserThread::UI, FROM_HERE,
667 base::Bind(&TabSpecificContentSettings::CookiesRead,
[email protected]f3add922013-12-20 23:17:16668 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04669 request.url(), request.first_party_for_cookies(),
[email protected]f7fa5b62014-03-19 15:20:06670 cookie_list, !allow, is_for_blocking_resource));
[email protected]9c8ae8c2012-03-09 13:13:35671 }
672
673 return allow;
674}
675
[email protected]4c219e22012-05-05 19:41:04676bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
677 const std::string& cookie_line,
678 net::CookieOptions* options) {
[email protected]9c8ae8c2012-03-09 13:13:35679 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02680 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35681 return true;
682
683 bool allow = cookie_settings_->IsSettingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04684 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35685
[email protected]9c8ae8c2012-03-09 13:13:35686 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16687 int render_frame_id = -1;
688 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
689 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35690 BrowserThread::PostTask(
691 BrowserThread::UI, FROM_HERE,
692 base::Bind(&TabSpecificContentSettings::CookieChanged,
[email protected]f3add922013-12-20 23:17:16693 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04694 request.url(), request.first_party_for_cookies(),
[email protected]fd473d12012-04-05 11:38:43695 cookie_line, *options, !allow));
[email protected]9c8ae8c2012-03-09 13:13:35696 }
697
[email protected]28c5d0b72014-05-13 08:19:59698 if (prerender_tracker_) {
699 prerender_tracker_->OnCookieChangedForURL(
700 render_process_id,
701 request.context()->cookie_store()->GetCookieMonster(),
702 request.url());
703 }
704
[email protected]9c8ae8c2012-03-09 13:13:35705 return allow;
706}
[email protected]4c219e22012-05-05 19:41:04707
708bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
[email protected]650b2d52013-02-10 03:41:45709 const base::FilePath& path) const {
[email protected]4c219e22012-05-05 19:41:04710 if (g_allow_file_access_)
711 return true;
712
[email protected]d8e4f132012-09-06 04:28:05713#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
714 return true;
715#else
[email protected]4c219e22012-05-05 19:41:04716#if defined(OS_CHROMEOS)
[email protected]d8e4f132012-09-06 04:28:05717 // If we're running Chrome for ChromeOS on Linux, we want to allow file
718 // access.
[email protected]49c4cf852013-09-27 19:28:24719 if (!base::SysInfo::IsRunningOnChromeOS() ||
[email protected]288538482012-09-06 21:09:35720 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
[email protected]d8e4f132012-09-06 04:28:05721 return true;
[email protected]288538482012-09-06 21:09:35722 }
[email protected]d8e4f132012-09-06 04:28:05723
724 // Use a whitelist to only allow access to files residing in the list of
725 // directories below.
[email protected]4c219e22012-05-05 19:41:04726 static const char* const kLocalAccessWhiteList[] = {
727 "/home/chronos/user/Downloads",
728 "/home/chronos/user/log",
[email protected]4791af43d2014-05-05 13:19:42729 "/home/chronos/user/WebRTC Logs",
[email protected]4c219e22012-05-05 19:41:04730 "/media",
731 "/opt/oem",
732 "/usr/share/chromeos-assets",
733 "/tmp",
734 "/var/log",
735 };
[email protected]ae015e12013-11-04 19:11:33736
[email protected]9e733282014-06-18 16:56:55737 // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under
738 // the profile path ("/home/chronos/user' is a hard link to current primary
739 // logged in profile.) For the support of multi-profile sessions, we are
740 // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such
741 // access.
[email protected]ae015e12013-11-04 19:11:33742 if (!profile_path_.empty()) {
743 const base::FilePath downloads = profile_path_.AppendASCII("Downloads");
744 if (downloads == path.StripTrailingSeparators() || downloads.IsParent(path))
745 return true;
[email protected]9e733282014-06-18 16:56:55746 const base::FilePath webrtc_logs = profile_path_.AppendASCII("WebRTC Logs");
747 if (webrtc_logs == path.StripTrailingSeparators() ||
748 webrtc_logs.IsParent(path)) {
749 return true;
750 }
[email protected]ae015e12013-11-04 19:11:33751 }
[email protected]d8e4f132012-09-06 04:28:05752#elif defined(OS_ANDROID)
753 // Access to files in external storage is allowed.
[email protected]650b2d52013-02-10 03:41:45754 base::FilePath external_storage_path;
[email protected]d8e4f132012-09-06 04:28:05755 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path);
756 if (external_storage_path.IsParent(path))
[email protected]4c219e22012-05-05 19:41:04757 return true;
758
[email protected]d8e4f132012-09-06 04:28:05759 // Whitelist of other allowed directories.
760 static const char* const kLocalAccessWhiteList[] = {
761 "/sdcard",
762 "/mnt/sdcard",
763 };
764#endif
765
[email protected]4c219e22012-05-05 19:41:04766 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
[email protected]650b2d52013-02-10 03:41:45767 const base::FilePath white_listed_path(kLocalAccessWhiteList[i]);
768 // base::FilePath::operator== should probably handle trailing separators.
[email protected]4c219e22012-05-05 19:41:04769 if (white_listed_path == path.StripTrailingSeparators() ||
770 white_listed_path.IsParent(path)) {
771 return true;
772 }
773 }
[email protected]d8e4f132012-09-06 04:28:05774
[email protected]288538482012-09-06 21:09:35775 DVLOG(1) << "File access denied - " << path.value().c_str();
[email protected]4c219e22012-05-05 19:41:04776 return false;
[email protected]d8e4f132012-09-06 04:28:05777#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:04778}
[email protected]a1d4ab072012-06-07 13:21:15779
780bool ChromeNetworkDelegate::OnCanThrottleRequest(
781 const net::URLRequest& request) const {
[email protected]84b7a552014-07-19 04:52:06782#if defined(ENABLE_EXTENSIONS)
[email protected]4a2b6232014-06-19 08:44:14783 if (g_never_throttle_requests_)
[email protected]a1d4ab072012-06-07 13:21:15784 return false;
[email protected]c4a7df82012-08-09 22:48:46785 return request.first_party_for_cookies().scheme() ==
[email protected]885c0e92012-11-13 20:27:42786 extensions::kExtensionScheme;
[email protected]84b7a552014-07-19 04:52:06787#else
788 return false;
789#endif
[email protected]a1d4ab072012-06-07 13:21:15790}
[email protected]aa28181e2012-06-13 00:53:58791
[email protected]e6d017652013-05-17 18:01:40792bool ChromeNetworkDelegate::OnCanEnablePrivacyMode(
793 const GURL& url,
794 const GURL& first_party_for_cookies) const {
795 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02796 if (!cookie_settings_.get())
[email protected]e6d017652013-05-17 18:01:40797 return false;
798
799 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed(
800 url, first_party_for_cookies);
801 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed(
802 url, first_party_for_cookies);
803 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed);
804 return privacy_mode;
805}
806
jochen0e3b3a62014-09-16 18:31:23807bool ChromeNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
808 const net::URLRequest& request,
809 const GURL& target_url,
810 const GURL& referrer_url) const {
jochenb93dba3c2014-11-11 05:28:41811 base::debug::StackTrace callstack;
jochen0e3b3a62014-09-16 18:31:23812 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
jochenb93dba3c2014-11-11 05:28:41813 base::Bind(&ReportInvalidReferrerSend, target_url,
814 referrer_url, callstack));
jochen0e3b3a62014-09-16 18:31:23815 return true;
816}
817
[email protected]7a299a92012-10-24 23:54:50818void ChromeNetworkDelegate::AccumulateContentLength(
[email protected]b7796462013-12-12 19:42:34819 int64 received_content_length,
820 int64 original_content_length,
[email protected]a0a06932014-04-14 21:23:42821 data_reduction_proxy::DataReductionProxyRequestType request_type) {
[email protected]7a299a92012-10-24 23:54:50822 DCHECK_GE(received_content_length, 0);
823 DCHECK_GE(original_content_length, 0);
megjablon53f608b2014-09-18 19:24:55824 if (data_reduction_proxy_statistics_prefs_) {
825 StoreAccumulatedContentLength(received_content_length,
826 original_content_length,
827 request_type,
828 reinterpret_cast<Profile*>(profile_),
829 data_reduction_proxy_statistics_prefs_);
830 }
[email protected]7a299a92012-10-24 23:54:50831 received_content_length_ += received_content_length;
832 original_content_length_ += original_content_length;
833}