blob: 765d1d0fe5124c99733098ae9258b65fdbb6f686 [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"
megjablon53f608b2014-09-18 19:24:5537#include "components/data_reduction_proxy/browser/data_reduction_proxy_statistics_prefs.h"
[email protected]bceab7f2014-06-25 04:36:2038#include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h"
[email protected]45de676a2014-03-18 23:52:0239#include "components/domain_reliability/monitor.h"
[email protected]c38831a12011-10-28 12:44:4940#include "content/public/browser/browser_thread.h"
[email protected]9dfed872013-12-30 23:08:5641#include "content/public/browser/render_frame_host.h"
[email protected]9c1662b2012-03-06 15:44:3342#include "content/public/browser/render_view_host.h"
[email protected]9c8ae8c2012-03-09 13:13:3543#include "content/public/browser/resource_request_info.h"
[email protected]82b42302011-04-20 16:28:1644#include "net/base/host_port_pair.h"
[email protected]8202d0c2011-02-23 08:31:1445#include "net/base/net_errors.h"
[email protected]6a5f77c32011-09-04 19:19:5946#include "net/base/net_log.h"
[email protected]5b9bc352012-07-18 13:13:3447#include "net/cookies/canonical_cookie.h"
48#include "net/cookies/cookie_options.h"
[email protected]ac039522010-06-15 16:39:4449#include "net/http/http_request_headers.h"
[email protected]48944382011-04-23 13:28:1650#include "net/http/http_response_headers.h"
[email protected]12731792014-08-14 11:45:5451#include "net/proxy/proxy_config.h"
[email protected]597a1ab2014-06-26 08:12:2752#include "net/proxy/proxy_info.h"
[email protected]12731792014-08-14 11:45:5453#include "net/proxy/proxy_retry_info.h"
[email protected]597a1ab2014-06-26 08:12:2754#include "net/proxy/proxy_server.h"
[email protected]aa28181e2012-06-13 00:53:5855#include "net/socket_stream/socket_stream.h"
[email protected]d05ef99c2011-02-01 21:38:1656#include "net/url_request/url_request.h"
[email protected]28c5d0b72014-05-13 08:19:5957#include "net/url_request/url_request_context.h"
[email protected]d05ef99c2011-02-01 21:38:1658
[email protected]4a2b6232014-06-19 08:44:1459#if defined(OS_ANDROID)
60#include "chrome/browser/io_thread.h"
61#include "components/precache/content/precache_manager.h"
62#include "components/precache/content/precache_manager_factory.h"
63#endif
64
[email protected]4c219e22012-05-05 19:41:0465#if defined(OS_CHROMEOS)
[email protected]288538482012-09-06 21:09:3566#include "base/command_line.h"
[email protected]49c4cf852013-09-27 19:28:2467#include "base/sys_info.h"
[email protected]288538482012-09-06 21:09:3568#include "chrome/common/chrome_switches.h"
[email protected]4c219e22012-05-05 19:41:0469#endif
70
[email protected]3e598ff12011-09-06 11:22:3471#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]f522afa2014-01-08 15:36:3672#include "components/policy/core/browser/url_blacklist_manager.h"
[email protected]3e598ff12011-09-06 11:22:3473#endif
74
[email protected]84b7a552014-07-19 04:52:0675#if defined(ENABLE_EXTENSIONS)
76#include "extensions/common/constants.h"
77#endif
78
[email protected]631bb742011-11-02 11:29:3979using content::BrowserThread;
[email protected]eaabba22012-03-07 15:02:1180using content::RenderViewHost;
[email protected]ea114722012-03-12 01:11:2581using content::ResourceRequestInfo;
[email protected]7491ad02014-07-05 19:10:0782using content::ResourceType;
[email protected]631bb742011-11-02 11:29:3983
[email protected]d8e4f132012-09-06 04:28:0584// By default we don't allow access to all file:// urls on ChromeOS and
85// Android.
86#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:0487bool ChromeNetworkDelegate::g_allow_file_access_ = false;
88#else
89bool ChromeNetworkDelegate::g_allow_file_access_ = true;
90#endif
91
[email protected]84b7a552014-07-19 04:52:0692#if defined(ENABLE_EXTENSIONS)
[email protected]c4a7df82012-08-09 22:48:4693// This remains false unless the --disable-extensions-http-throttling
94// flag is passed to the browser.
95bool ChromeNetworkDelegate::g_never_throttle_requests_ = false;
[email protected]84b7a552014-07-19 04:52:0696#endif
[email protected]c4a7df82012-08-09 22:48:4697
[email protected]d05ef99c2011-02-01 21:38:1698namespace {
99
[email protected]9d8cfb682012-09-13 16:48:04100const char kDNTHeader[] = "DNT";
101
[email protected]d1208ba32012-11-08 11:10:33102// Gets called when the extensions finish work on the URL. If the extensions
103// did not do a redirect (so |new_url| is empty) then we enforce the
104// SafeSearch parameters. Otherwise we will get called again after the
105// redirect and we enforce SafeSearch then.
106void ForceGoogleSafeSearchCallbackWrapper(
107 const net::CompletionCallback& callback,
108 net::URLRequest* request,
109 GURL* new_url,
110 int rv) {
111 if (rv == net::OK && new_url->is_empty())
[email protected]184799df2014-07-22 16:03:24112 safe_search_util::ForceGoogleSafeSearch(request, new_url);
[email protected]d1208ba32012-11-08 11:10:33113 callback.Run(rv);
114}
115
[email protected]828eab22013-12-10 22:42:38116void UpdateContentLengthPrefs(
117 int received_content_length,
118 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42119 data_reduction_proxy::DataReductionProxyRequestType request_type,
megjablon53f608b2014-09-18 19:24:55120 Profile* profile,
121 data_reduction_proxy::DataReductionProxyStatisticsPrefs* statistics_prefs) {
[email protected]7a299a92012-10-24 23:54:50122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
123 DCHECK_GE(received_content_length, 0);
124 DCHECK_GE(original_content_length, 0);
125
[email protected]a09159a2012-11-29 12:51:48126 // Can be NULL in a unit test.
127 if (!g_browser_process)
128 return;
129
[email protected]b7796462013-12-12 19:42:34130 // Ignore off-the-record data.
131 if (!g_browser_process->profile_manager()->IsValidProfile(profile) ||
132 profile->IsOffTheRecord()) {
133 return;
134 }
megjablon53f608b2014-09-18 19:24:55135 data_reduction_proxy::UpdateContentLengthPrefs(
136 received_content_length,
137 original_content_length,
kundaji88ca4112014-09-23 01:35:21138 profile->GetPrefs(),
139 request_type, statistics_prefs);
[email protected]7a299a92012-10-24 23:54:50140}
141
[email protected]828eab22013-12-10 22:42:38142void StoreAccumulatedContentLength(
143 int received_content_length,
144 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42145 data_reduction_proxy::DataReductionProxyRequestType request_type,
megjablon53f608b2014-09-18 19:24:55146 Profile* profile,
147 data_reduction_proxy::DataReductionProxyStatisticsPrefs* statistics_prefs) {
[email protected]7a299a92012-10-24 23:54:50148 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
149 base::Bind(&UpdateContentLengthPrefs,
megjablon53f608b2014-09-18 19:24:55150 received_content_length,
151 original_content_length,
152 request_type,
153 profile,
154 statistics_prefs));
[email protected]7a299a92012-10-24 23:54:50155}
156
157void RecordContentLengthHistograms(
[email protected]f81a5ee2013-06-20 21:08:49158 int64 received_content_length,
159 int64 original_content_length,
160 const base::TimeDelta& freshness_lifetime) {
[email protected]7a299a92012-10-24 23:54:50161 // Add the current resource to these histograms only when a valid
162 // X-Original-Content-Length header is present.
163 if (original_content_length >= 0) {
164 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL",
165 received_content_length);
166 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL",
167 original_content_length);
168 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL",
169 original_content_length - received_content_length);
170 } else {
171 // Presume the original content length is the same as the received content
172 // length if the X-Original-Content-Header is not present.
173 original_content_length = received_content_length;
174 }
175 UMA_HISTOGRAM_COUNTS("Net.HttpContentLength", received_content_length);
176 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLength",
177 original_content_length);
178 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifference",
179 original_content_length - received_content_length);
[email protected]f81a5ee2013-06-20 21:08:49180 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpContentFreshnessLifetime",
181 freshness_lifetime.InSeconds(),
182 base::TimeDelta::FromHours(1).InSeconds(),
183 base::TimeDelta::FromDays(30).InSeconds(),
184 100);
185 if (freshness_lifetime.InSeconds() <= 0)
186 return;
187 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable",
188 received_content_length);
189 if (freshness_lifetime.InHours() < 4)
190 return;
191 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours",
192 received_content_length);
193
194 if (freshness_lifetime.InHours() < 24)
195 return;
196 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours",
197 received_content_length);
[email protected]7a299a92012-10-24 23:54:50198}
199
[email protected]35558812013-12-18 21:58:36200#if defined(OS_ANDROID)
201void RecordPrecacheStatsOnUIThread(const GURL& url,
202 const base::Time& fetch_time, int64 size,
203 bool was_cached, void* profile_id) {
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
205
206 Profile* profile = reinterpret_cast<Profile*>(profile_id);
207 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) {
208 return;
209 }
210
211 precache::PrecacheManager* precache_manager =
212 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
tanviraumi387f6332014-08-29 19:04:36213 if (!precache_manager || !precache_manager->IsPrecachingAllowed()) {
214 // |precache_manager| could be NULL if the profile is off the record.
[email protected]35558812013-12-18 21:58:36215 return;
216 }
217
218 precache_manager->RecordStatsForFetch(url, fetch_time, size, was_cached);
219}
[email protected]d827e112014-03-31 17:45:05220
221void RecordIOThreadToRequestStartOnUIThread(
222 const base::TimeTicks& request_start) {
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
224 base::TimeDelta request_lag = request_start -
225 g_browser_process->io_thread()->creation_time();
226 UMA_HISTOGRAM_TIMES("Net.IOThreadCreationToHTTPRequestStart", request_lag);
227}
[email protected]35558812013-12-18 21:58:36228#endif // defined(OS_ANDROID)
229
jochen0e3b3a62014-09-16 18:31:23230void ReportInvalidReferrerSend(const GURL& target_url,
231 const GURL& referrer_url) {
232 base::RecordAction(
233 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer"));
234}
235
[email protected]d05ef99c2011-02-01 21:38:16236} // namespace
[email protected]ac039522010-06-15 16:39:44237
[email protected]0651b812011-02-24 00:22:50238ChromeNetworkDelegate::ChromeNetworkDelegate(
[email protected]5a38dfd2012-07-23 23:22:10239 extensions::EventRouterForwarder* event_router,
[email protected]a09159a2012-11-29 12:51:48240 BooleanPrefMember* enable_referrers)
[email protected]4a2b6232014-06-19 08:44:14241 : profile_(NULL),
[email protected]6a5f77c32011-09-04 19:19:59242 enable_referrers_(enable_referrers),
[email protected]a09159a2012-11-29 12:51:48243 enable_do_not_track_(NULL),
244 force_google_safe_search_(NULL),
[email protected]a948dad2014-07-25 00:39:38245 data_reduction_proxy_enabled_(NULL),
[email protected]4a2b6232014-06-19 08:44:14246#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]a09159a2012-11-29 12:51:48247 url_blacklist_manager_(NULL),
[email protected]4a2b6232014-06-19 08:44:14248#endif
[email protected]45de676a2014-03-18 23:52:02249 domain_reliability_monitor_(NULL),
[email protected]7a299a92012-10-24 23:54:50250 received_content_length_(0),
[email protected]d827e112014-03-31 17:45:05251 original_content_length_(0),
[email protected]28c5d0b72014-05-13 08:19:59252 first_request_(true),
[email protected]d8fc4722014-06-13 13:17:15253 prerender_tracker_(NULL),
[email protected]bceab7f2014-06-25 04:36:20254 data_reduction_proxy_params_(NULL),
[email protected]597a1ab2014-06-26 08:12:27255 data_reduction_proxy_usage_stats_(NULL),
megjablon53f608b2014-09-18 19:24:55256 data_reduction_proxy_auth_request_handler_(NULL),
257 data_reduction_proxy_statistics_prefs_(NULL) {
[email protected]0a8db0d2011-04-13 15:15:40258 DCHECK(enable_referrers);
[email protected]4a2b6232014-06-19 08:44:14259 extensions_delegate_.reset(
260 ChromeExtensionsNetworkDelegate::Create(event_router));
[email protected]0651b812011-02-24 00:22:50261}
262
[email protected]ac039522010-06-15 16:39:44263ChromeNetworkDelegate::~ChromeNetworkDelegate() {}
264
[email protected]a09159a2012-11-29 12:51:48265void ChromeNetworkDelegate::set_extension_info_map(
[email protected]38427a12013-11-09 17:34:20266 extensions::InfoMap* extension_info_map) {
[email protected]4a2b6232014-06-19 08:44:14267 extensions_delegate_->set_extension_info_map(extension_info_map);
268}
269
270void ChromeNetworkDelegate::set_profile(void* profile) {
271 profile_ = profile;
272 extensions_delegate_->set_profile(profile);
[email protected]a09159a2012-11-29 12:51:48273}
274
275void ChromeNetworkDelegate::set_cookie_settings(
276 CookieSettings* cookie_settings) {
277 cookie_settings_ = cookie_settings;
278}
279
[email protected]f53b4802012-12-20 17:04:23280void ChromeNetworkDelegate::set_predictor(
281 chrome_browser_net::Predictor* predictor) {
282 connect_interceptor_.reset(
283 new chrome_browser_net::ConnectInterceptor(predictor));
284}
285
[email protected]3620bbc2013-10-05 05:07:23286void ChromeNetworkDelegate::SetEnableClientHints() {
287 client_hints_.reset(new ClientHints());
288 client_hints_->Init();
289}
290
[email protected]c4a7df82012-08-09 22:48:46291// static
[email protected]84b7a552014-07-19 04:52:06292#if defined(ENABLE_EXTENSIONS)
[email protected]a1d4ab072012-06-07 13:21:15293void ChromeNetworkDelegate::NeverThrottleRequests() {
[email protected]c4a7df82012-08-09 22:48:46294 g_never_throttle_requests_ = true;
[email protected]a1d4ab072012-06-07 13:21:15295}
[email protected]84b7a552014-07-19 04:52:06296#endif
[email protected]a1d4ab072012-06-07 13:21:15297
[email protected]0a8db0d2011-04-13 15:15:40298// static
[email protected]9d8cfb682012-09-13 16:48:04299void ChromeNetworkDelegate::InitializePrefsOnUIThread(
[email protected]0a8db0d2011-04-13 15:15:40300 BooleanPrefMember* enable_referrers,
[email protected]9d8cfb682012-09-13 16:48:04301 BooleanPrefMember* enable_do_not_track,
[email protected]d1208ba32012-11-08 11:10:33302 BooleanPrefMember* force_google_safe_search,
[email protected]0a8db0d2011-04-13 15:15:40303 PrefService* pref_service) {
304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]96a5c342012-12-04 18:14:02305 enable_referrers->Init(prefs::kEnableReferrers, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43306 enable_referrers->MoveToThread(
307 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04308 if (enable_do_not_track) {
[email protected]96a5c342012-12-04 18:14:02309 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43310 enable_do_not_track->MoveToThread(
311 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04312 }
[email protected]d1208ba32012-11-08 11:10:33313 if (force_google_safe_search) {
[email protected]96a5c342012-12-04 18:14:02314 force_google_safe_search->Init(prefs::kForceSafeSearch, pref_service);
[email protected]d1208ba32012-11-08 11:10:33315 force_google_safe_search->MoveToThread(
316 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
317 }
[email protected]0a8db0d2011-04-13 15:15:40318}
319
[email protected]4c219e22012-05-05 19:41:04320// static
321void ChromeNetworkDelegate::AllowAccessToAllFiles() {
322 g_allow_file_access_ = true;
323}
324
[email protected]7a299a92012-10-24 23:54:50325// static
megjablon53f608b2014-09-18 19:24:55326// TODO(megjablon): Use data_reduction_proxy_delayed_pref_service to read prefs.
327// Until updated the pref values may be up to an hour behind on desktop.
[email protected]cb1078de2013-12-23 20:04:22328base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() {
[email protected]7a299a92012-10-24 23:54:50329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
330 PrefService* prefs = g_browser_process->local_state();
[email protected]a0a06932014-04-14 21:23:42331 int64 total_received = prefs->GetInt64(
332 data_reduction_proxy::prefs::kHttpReceivedContentLength);
333 int64 total_original = prefs->GetInt64(
334 data_reduction_proxy::prefs::kHttpOriginalContentLength);
[email protected]7a299a92012-10-24 23:54:50335
[email protected]cb1078de2013-12-23 20:04:22336 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42337 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
338 dict->SetString("historic_received_content_length",
339 base::Int64ToString(total_received));
340 dict->SetString("historic_original_content_length",
341 base::Int64ToString(total_original));
[email protected]7a299a92012-10-24 23:54:50342 return dict;
343}
344
[email protected]cb1078de2013-12-23 20:04:22345base::Value* ChromeNetworkDelegate::SessionNetworkStatsInfoToValue() const {
346 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42347 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
348 dict->SetString("session_received_content_length",
349 base::Int64ToString(received_content_length_));
350 dict->SetString("session_original_content_length",
351 base::Int64ToString(original_content_length_));
[email protected]7a299a92012-10-24 23:54:50352 return dict;
353}
354
[email protected]4875ba12011-03-30 22:31:51355int ChromeNetworkDelegate::OnBeforeURLRequest(
[email protected]4c76d7c2011-04-15 19:14:12356 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47357 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12358 GURL* new_url) {
[email protected]d827e112014-03-31 17:45:05359#if defined(OS_ANDROID)
360 // This UMA tracks the time to the first user-initiated request start, so
361 // only non-null profiles are considered.
362 if (first_request_ && profile_) {
363 bool record_timing = true;
[email protected]bec6a992014-06-19 01:03:21364 if (data_reduction_proxy_params_) {
365 record_timing =
366 (request->url() != data_reduction_proxy_params_->probe_url()) &&
367 (request->url() != data_reduction_proxy_params_->warmup_url());
368 }
[email protected]d827e112014-03-31 17:45:05369 if (record_timing) {
370 first_request_ = false;
371 net::LoadTimingInfo timing_info;
372 request->GetLoadTimingInfo(&timing_info);
373 BrowserThread::PostTask(
374 BrowserThread::UI, FROM_HERE,
375 base::Bind(&RecordIOThreadToRequestStartOnUIThread,
376 timing_info.request_start));
377 }
378 }
379#endif // defined(OS_ANDROID)
380
[email protected]3e598ff12011-09-06 11:22:34381#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]6a5f77c32011-09-04 19:19:59382 // TODO(joaodasilva): This prevents extensions from seeing URLs that are
383 // blocked. However, an extension might redirect the request to another URL,
384 // which is not blocked.
[email protected]cb85f8e52014-04-08 11:44:40385 int error = net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]6a5f77c32011-09-04 19:19:59386 if (url_blacklist_manager_ &&
[email protected]cb85f8e52014-04-08 11:44:40387 url_blacklist_manager_->IsRequestBlocked(*request, &error)) {
[email protected]6a5f77c32011-09-04 19:19:59388 // URL access blocked by policy.
[email protected]6a5f77c32011-09-04 19:19:59389 request->net_log().AddEvent(
[email protected]2fa08912012-06-14 20:56:26390 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
391 net::NetLog::StringCallback("url",
392 &request->url().possibly_invalid_spec()));
[email protected]cb85f8e52014-04-08 11:44:40393 return error;
[email protected]6a5f77c32011-09-04 19:19:59394 }
[email protected]3e598ff12011-09-06 11:22:34395#endif
[email protected]6a5f77c32011-09-04 19:19:59396
[email protected]4a2b6232014-06-19 08:44:14397 extensions_delegate_->ForwardStartRequestStatus(request);
[email protected]6baff0b52012-03-06 01:30:18398
[email protected]0a8db0d2011-04-13 15:15:40399 if (!enable_referrers_->GetValue())
[email protected]99ecf6e2013-04-10 22:46:13400 request->SetReferrer(std::string());
[email protected]9d8cfb682012-09-13 16:48:04401 if (enable_do_not_track_ && enable_do_not_track_->GetValue())
402 request->SetExtraRequestHeaderByName(kDNTHeader, "1", true /* override */);
[email protected]d1208ba32012-11-08 11:10:33403
[email protected]3620bbc2013-10-05 05:07:23404 if (client_hints_) {
405 request->SetExtraRequestHeaderByName(
406 ClientHints::kDevicePixelRatioHeader,
407 client_hints_->GetDevicePixelRatioHeader(), true);
408 }
409
[email protected]d1208ba32012-11-08 11:10:33410 bool force_safe_search = force_google_safe_search_ &&
411 force_google_safe_search_->GetValue();
412
413 net::CompletionCallback wrapped_callback = callback;
414 if (force_safe_search) {
415 wrapped_callback = base::Bind(&ForceGoogleSafeSearchCallbackWrapper,
416 callback,
417 base::Unretained(request),
418 base::Unretained(new_url));
419 }
420
[email protected]4a2b6232014-06-19 08:44:14421 int rv = extensions_delegate_->OnBeforeURLRequest(
422 request, wrapped_callback, new_url);
[email protected]d1208ba32012-11-08 11:10:33423
424 if (force_safe_search && rv == net::OK && new_url->is_empty())
[email protected]184799df2014-07-22 16:03:24425 safe_search_util::ForceGoogleSafeSearch(request, new_url);
[email protected]d1208ba32012-11-08 11:10:33426
[email protected]f53b4802012-12-20 17:04:23427 if (connect_interceptor_)
428 connect_interceptor_->WitnessURLRequest(request);
429
[email protected]d1208ba32012-11-08 11:10:33430 return rv;
[email protected]d05ef99c2011-02-01 21:38:16431}
432
[email protected]a702da72014-07-09 05:23:54433void ChromeNetworkDelegate::OnResolveProxy(
[email protected]12731792014-08-14 11:45:54434 const GURL& url,
435 int load_flags,
436 const net::ProxyService& proxy_service,
437 net::ProxyInfo* result) {
438 if (!on_resolve_proxy_handler_.is_null() &&
439 !proxy_config_getter_.is_null()) {
[email protected]a702da72014-07-09 05:23:54440 on_resolve_proxy_handler_.Run(url, load_flags,
[email protected]12731792014-08-14 11:45:54441 proxy_config_getter_.Run(),
442 proxy_service.proxy_retry_info(),
[email protected]a702da72014-07-09 05:23:54443 data_reduction_proxy_params_, result);
444 }
445}
446
[email protected]f09f9682014-08-10 01:21:39447void ChromeNetworkDelegate::OnProxyFallback(const net::ProxyServer& bad_proxy,
[email protected]d0483b192014-08-15 23:50:17448 int net_error) {
[email protected]f09f9682014-08-10 01:21:39449 if (data_reduction_proxy_usage_stats_) {
450 data_reduction_proxy_usage_stats_->RecordBypassEventHistograms(
[email protected]d0483b192014-08-15 23:50:17451 bad_proxy, net_error);
[email protected]f09f9682014-08-10 01:21:39452 }
453}
454
[email protected]4875ba12011-03-30 22:31:51455int ChromeNetworkDelegate::OnBeforeSendHeaders(
[email protected]636eccd2011-06-28 12:28:01456 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47457 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12458 net::HttpRequestHeaders* headers) {
[email protected]184799df2014-07-22 16:03:24459 bool force_safe_search = force_google_safe_search_ &&
460 force_google_safe_search_->GetValue();
461 if (force_safe_search)
462 safe_search_util::ForceYouTubeSafetyMode(request, headers);
463
[email protected]186468f2013-10-24 02:44:11464 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest");
[email protected]4a2b6232014-06-19 08:44:14465 return extensions_delegate_->OnBeforeSendHeaders(request, callback, headers);
[email protected]ac039522010-06-15 16:39:44466}
[email protected]8202d0c2011-02-23 08:31:14467
[email protected]597a1ab2014-06-26 08:12:27468void ChromeNetworkDelegate::OnBeforeSendProxyHeaders(
469 net::URLRequest* request,
470 const net::ProxyInfo& proxy_info,
471 net::HttpRequestHeaders* headers) {
472 if (data_reduction_proxy_auth_request_handler_) {
473 data_reduction_proxy_auth_request_handler_->MaybeAddRequestHeader(
474 request, proxy_info.proxy_server(), headers);
475 }
476}
477
[email protected]5796dc942011-07-14 19:26:10478void ChromeNetworkDelegate::OnSendHeaders(
479 net::URLRequest* request,
[email protected]783573b2011-05-13 11:05:15480 const net::HttpRequestHeaders& headers) {
[email protected]4a2b6232014-06-19 08:44:14481 extensions_delegate_->OnSendHeaders(request, headers);
[email protected]82b42302011-04-20 16:28:16482}
483
[email protected]ea8141e2011-10-05 13:12:51484int ChromeNetworkDelegate::OnHeadersReceived(
485 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47486 const net::CompletionCallback& callback,
[email protected]507af8f2012-10-20 00:42:32487 const net::HttpResponseHeaders* original_response_headers,
[email protected]5f714132014-03-26 10:41:16488 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
489 GURL* allowed_unsafe_redirect_url) {
[email protected]f09f9682014-08-10 01:21:39490 data_reduction_proxy::DataReductionProxyBypassType bypass_type;
[email protected]d8fc4722014-06-13 13:17:15491 if (data_reduction_proxy::MaybeBypassProxyAndPrepareToRetry(
492 data_reduction_proxy_params_,
493 request,
494 original_response_headers,
[email protected]a948dad2014-07-25 00:39:38495 override_response_headers,
496 &bypass_type)) {
497 if (data_reduction_proxy_usage_stats_)
498 data_reduction_proxy_usage_stats_->SetBypassType(bypass_type);
[email protected]d8fc4722014-06-13 13:17:15499 return net::OK;
500 }
501
[email protected]4a2b6232014-06-19 08:44:14502 return extensions_delegate_->OnHeadersReceived(
[email protected]5f714132014-03-26 10:41:16503 request,
504 callback,
505 original_response_headers,
506 override_response_headers,
507 allowed_unsafe_redirect_url);
[email protected]ea8141e2011-10-05 13:12:51508}
509
[email protected]31b2e5f2011-04-20 16:58:32510void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
511 const GURL& new_location) {
[email protected]45de676a2014-03-18 23:52:02512 if (domain_reliability_monitor_)
513 domain_reliability_monitor_->OnBeforeRedirect(request);
[email protected]4a2b6232014-06-19 08:44:14514 extensions_delegate_->OnBeforeRedirect(request, new_location);
[email protected]31b2e5f2011-04-20 16:58:32515}
516
517
[email protected]8202d0c2011-02-23 08:31:14518void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
[email protected]186468f2013-10-24 02:44:11519 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "ResponseStarted");
[email protected]4a2b6232014-06-19 08:44:14520 extensions_delegate_->OnResponseStarted(request);
[email protected]8202d0c2011-02-23 08:31:14521}
522
[email protected]8523ba52011-05-22 19:00:58523void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
524 int bytes_read) {
[email protected]186468f2013-10-24 02:44:11525 TRACE_EVENT_ASYNC_STEP_PAST1("net", "URLRequest", &request, "DidRead",
526 "bytes_read", bytes_read);
[email protected]44879ed2012-04-06 01:11:02527#if defined(ENABLE_TASK_MANAGER)
[email protected]17df9e7c2014-02-13 03:49:29528 // This is not completely accurate, but as a first approximation ignore
529 // requests that are served from the cache. See bug 330931 for more info.
530 if (!request.was_cached())
531 TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read);
[email protected]44879ed2012-04-06 01:11:02532#endif // defined(ENABLE_TASK_MANAGER)
[email protected]8523ba52011-05-22 19:00:58533}
534
[email protected]9045b8822012-01-13 20:35:35535void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
536 bool started) {
[email protected]bceab7f2014-06-25 04:36:20537 if (data_reduction_proxy_usage_stats_)
538 data_reduction_proxy_usage_stats_->OnUrlRequestCompleted(request, started);
539
[email protected]4aca5db2013-08-17 00:51:56540 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request);
[email protected]2756a8e2012-09-07 18:24:29541 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
[email protected]7a299a92012-10-24 23:54:50542 // For better accuracy, we use the actual bytes read instead of the length
543 // specified with the Content-Length header, which may be inaccurate,
544 // or missing, as is the case with chunked encoding.
545 int64 received_content_length = request->received_response_content_length();
546
[email protected]35558812013-12-18 21:58:36547#if defined(OS_ANDROID)
548 if (precache::PrecacheManager::IsPrecachingEnabled()) {
549 // Record precache metrics when a fetch is completed successfully, if
550 // precaching is enabled.
551 BrowserThread::PostTask(
552 BrowserThread::UI, FROM_HERE,
553 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(),
554 base::Time::Now(), received_content_length,
555 request->was_cached(), profile_));
556 }
557#endif // defined(OS_ANDROID)
558
[email protected]7a299a92012-10-24 23:54:50559 // Only record for http or https urls.
560 bool is_http = request->url().SchemeIs("http");
561 bool is_https = request->url().SchemeIs("https");
562
563 if (!request->was_cached() && // Don't record cached content
564 received_content_length && // Zero-byte responses aren't useful.
565 (is_http || is_https)) { // Only record for HTTP or HTTPS urls.
566 int64 original_content_length =
567 request->response_info().headers->GetInt64HeaderValue(
568 "x-original-content-length");
[email protected]a0a06932014-04-14 21:23:42569 data_reduction_proxy::DataReductionProxyRequestType request_type =
570 data_reduction_proxy::GetDataReductionProxyRequestType(request);
[email protected]2db93e42013-08-07 17:40:41571
[email protected]f81a5ee2013-06-20 21:08:49572 base::TimeDelta freshness_lifetime =
573 request->response_info().headers->GetFreshnessLifetime(
574 request->response_info().response_time);
[email protected]828eab22013-12-10 22:42:38575 int64 adjusted_original_content_length =
[email protected]a0a06932014-04-14 21:23:42576 data_reduction_proxy::GetAdjustedOriginalContentLength(
577 request_type, original_content_length,
[email protected]828eab22013-12-10 22:42:38578 received_content_length);
[email protected]7a299a92012-10-24 23:54:50579 AccumulateContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41580 adjusted_original_content_length,
[email protected]a0a06932014-04-14 21:23:42581 request_type);
[email protected]7a299a92012-10-24 23:54:50582 RecordContentLengthHistograms(received_content_length,
[email protected]f81a5ee2013-06-20 21:08:49583 original_content_length,
584 freshness_lifetime);
megjablon25ff71d32014-09-05 03:21:44585 if (data_reduction_proxy_enabled_ &&
586 data_reduction_proxy_usage_stats_ &&
587 !proxy_config_getter_.is_null()) {
[email protected]a948dad2014-07-25 00:39:38588 data_reduction_proxy_usage_stats_->RecordBypassedBytesHistograms(
megjablon25ff71d32014-09-05 03:21:44589 *request,
590 *data_reduction_proxy_enabled_,
591 proxy_config_getter_.Run());
[email protected]a948dad2014-07-25 00:39:38592 }
[email protected]7a299a92012-10-24 23:54:50593 DVLOG(2) << __FUNCTION__
594 << " received content length: " << received_content_length
595 << " original content length: " << original_content_length
596 << " url: " << request->url();
597 }
598
[email protected]4a2b6232014-06-19 08:44:14599 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01600 } else if (request->status().status() == net::URLRequestStatus::FAILED ||
601 request->status().status() == net::URLRequestStatus::CANCELED) {
[email protected]4a2b6232014-06-19 08:44:14602 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01603 } else {
604 NOTREACHED();
[email protected]48944382011-04-23 13:28:16605 }
[email protected]45de676a2014-03-18 23:52:02606 if (domain_reliability_monitor_)
607 domain_reliability_monitor_->OnCompleted(request, started);
[email protected]4a2b6232014-06-19 08:44:14608 extensions_delegate_->ForwardProxyErrors(request);
609 extensions_delegate_->ForwardDoneRequestStatus(request);
[email protected]8202d0c2011-02-23 08:31:14610}
[email protected]4b50cb52011-03-10 00:29:37611
[email protected]4875ba12011-03-30 22:31:51612void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
[email protected]4a2b6232014-06-19 08:44:14613 extensions_delegate_->OnURLRequestDestroyed(request);
[email protected]4875ba12011-03-30 22:31:51614}
615
[email protected]82a37672011-05-03 12:02:41616void ChromeNetworkDelegate::OnPACScriptError(int line_number,
[email protected]439f1e32013-12-09 20:09:09617 const base::string16& error) {
[email protected]4a2b6232014-06-19 08:44:14618 extensions_delegate_->OnPACScriptError(line_number, error);
[email protected]82a37672011-05-03 12:02:41619}
[email protected]7efc582d2011-08-03 20:46:35620
[email protected]c2911d72011-10-03 22:16:36621net::NetworkDelegate::AuthRequiredResponse
622ChromeNetworkDelegate::OnAuthRequired(
[email protected]7efc582d2011-08-03 20:46:35623 net::URLRequest* request,
[email protected]c2911d72011-10-03 22:16:36624 const net::AuthChallengeInfo& auth_info,
625 const AuthCallback& callback,
626 net::AuthCredentials* credentials) {
[email protected]4a2b6232014-06-19 08:44:14627 return extensions_delegate_->OnAuthRequired(
628 request, auth_info, callback, credentials);
[email protected]7efc582d2011-08-03 20:46:35629}
[email protected]9c8ae8c2012-03-09 13:13:35630
[email protected]4c219e22012-05-05 19:41:04631bool ChromeNetworkDelegate::OnCanGetCookies(
632 const net::URLRequest& request,
[email protected]9c8ae8c2012-03-09 13:13:35633 const net::CookieList& cookie_list) {
634 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02635 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35636 return true;
637
638 bool allow = cookie_settings_->IsReadingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04639 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35640
641 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16642 int render_frame_id = -1;
[email protected]f7fa5b62014-03-19 15:20:06643
644 // |is_for_blocking_resource| indicates whether the cookies read were for a
645 // blocking resource (eg script, css). It is only temporarily added for
646 // diagnostic purposes, per bug 353678. Will be removed again once data
647 // collection is finished.
648 bool is_for_blocking_resource = false;
649 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
650 if (info && ((!info->IsAsync()) ||
[email protected]6c1e05212014-07-31 00:59:40651 info->GetResourceType() == content::RESOURCE_TYPE_STYLESHEET ||
652 info->GetResourceType() == content::RESOURCE_TYPE_SCRIPT)) {
[email protected]f7fa5b62014-03-19 15:20:06653 is_for_blocking_resource = true;
654 }
655
[email protected]f3add922013-12-20 23:17:16656 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
657 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35658 BrowserThread::PostTask(
659 BrowserThread::UI, FROM_HERE,
660 base::Bind(&TabSpecificContentSettings::CookiesRead,
[email protected]f3add922013-12-20 23:17:16661 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04662 request.url(), request.first_party_for_cookies(),
[email protected]f7fa5b62014-03-19 15:20:06663 cookie_list, !allow, is_for_blocking_resource));
[email protected]9c8ae8c2012-03-09 13:13:35664 }
665
666 return allow;
667}
668
[email protected]4c219e22012-05-05 19:41:04669bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
670 const std::string& cookie_line,
671 net::CookieOptions* options) {
[email protected]9c8ae8c2012-03-09 13:13:35672 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02673 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35674 return true;
675
676 bool allow = cookie_settings_->IsSettingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04677 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35678
[email protected]9c8ae8c2012-03-09 13:13:35679 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16680 int render_frame_id = -1;
681 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
682 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35683 BrowserThread::PostTask(
684 BrowserThread::UI, FROM_HERE,
685 base::Bind(&TabSpecificContentSettings::CookieChanged,
[email protected]f3add922013-12-20 23:17:16686 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04687 request.url(), request.first_party_for_cookies(),
[email protected]fd473d12012-04-05 11:38:43688 cookie_line, *options, !allow));
[email protected]9c8ae8c2012-03-09 13:13:35689 }
690
[email protected]28c5d0b72014-05-13 08:19:59691 if (prerender_tracker_) {
692 prerender_tracker_->OnCookieChangedForURL(
693 render_process_id,
694 request.context()->cookie_store()->GetCookieMonster(),
695 request.url());
696 }
697
[email protected]9c8ae8c2012-03-09 13:13:35698 return allow;
699}
[email protected]4c219e22012-05-05 19:41:04700
701bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
[email protected]650b2d52013-02-10 03:41:45702 const base::FilePath& path) const {
[email protected]4c219e22012-05-05 19:41:04703 if (g_allow_file_access_)
704 return true;
705
[email protected]d8e4f132012-09-06 04:28:05706#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
707 return true;
708#else
[email protected]4c219e22012-05-05 19:41:04709#if defined(OS_CHROMEOS)
[email protected]d8e4f132012-09-06 04:28:05710 // If we're running Chrome for ChromeOS on Linux, we want to allow file
711 // access.
[email protected]49c4cf852013-09-27 19:28:24712 if (!base::SysInfo::IsRunningOnChromeOS() ||
[email protected]288538482012-09-06 21:09:35713 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
[email protected]d8e4f132012-09-06 04:28:05714 return true;
[email protected]288538482012-09-06 21:09:35715 }
[email protected]d8e4f132012-09-06 04:28:05716
717 // Use a whitelist to only allow access to files residing in the list of
718 // directories below.
[email protected]4c219e22012-05-05 19:41:04719 static const char* const kLocalAccessWhiteList[] = {
720 "/home/chronos/user/Downloads",
721 "/home/chronos/user/log",
[email protected]4791af43d2014-05-05 13:19:42722 "/home/chronos/user/WebRTC Logs",
[email protected]4c219e22012-05-05 19:41:04723 "/media",
724 "/opt/oem",
725 "/usr/share/chromeos-assets",
726 "/tmp",
727 "/var/log",
728 };
[email protected]ae015e12013-11-04 19:11:33729
[email protected]9e733282014-06-18 16:56:55730 // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under
731 // the profile path ("/home/chronos/user' is a hard link to current primary
732 // logged in profile.) For the support of multi-profile sessions, we are
733 // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such
734 // access.
[email protected]ae015e12013-11-04 19:11:33735 if (!profile_path_.empty()) {
736 const base::FilePath downloads = profile_path_.AppendASCII("Downloads");
737 if (downloads == path.StripTrailingSeparators() || downloads.IsParent(path))
738 return true;
[email protected]9e733282014-06-18 16:56:55739 const base::FilePath webrtc_logs = profile_path_.AppendASCII("WebRTC Logs");
740 if (webrtc_logs == path.StripTrailingSeparators() ||
741 webrtc_logs.IsParent(path)) {
742 return true;
743 }
[email protected]ae015e12013-11-04 19:11:33744 }
[email protected]d8e4f132012-09-06 04:28:05745#elif defined(OS_ANDROID)
746 // Access to files in external storage is allowed.
[email protected]650b2d52013-02-10 03:41:45747 base::FilePath external_storage_path;
[email protected]d8e4f132012-09-06 04:28:05748 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path);
749 if (external_storage_path.IsParent(path))
[email protected]4c219e22012-05-05 19:41:04750 return true;
751
[email protected]d8e4f132012-09-06 04:28:05752 // Whitelist of other allowed directories.
753 static const char* const kLocalAccessWhiteList[] = {
754 "/sdcard",
755 "/mnt/sdcard",
756 };
757#endif
758
[email protected]4c219e22012-05-05 19:41:04759 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
[email protected]650b2d52013-02-10 03:41:45760 const base::FilePath white_listed_path(kLocalAccessWhiteList[i]);
761 // base::FilePath::operator== should probably handle trailing separators.
[email protected]4c219e22012-05-05 19:41:04762 if (white_listed_path == path.StripTrailingSeparators() ||
763 white_listed_path.IsParent(path)) {
764 return true;
765 }
766 }
[email protected]d8e4f132012-09-06 04:28:05767
[email protected]288538482012-09-06 21:09:35768 DVLOG(1) << "File access denied - " << path.value().c_str();
[email protected]4c219e22012-05-05 19:41:04769 return false;
[email protected]d8e4f132012-09-06 04:28:05770#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:04771}
[email protected]a1d4ab072012-06-07 13:21:15772
773bool ChromeNetworkDelegate::OnCanThrottleRequest(
774 const net::URLRequest& request) const {
[email protected]84b7a552014-07-19 04:52:06775#if defined(ENABLE_EXTENSIONS)
[email protected]4a2b6232014-06-19 08:44:14776 if (g_never_throttle_requests_)
[email protected]a1d4ab072012-06-07 13:21:15777 return false;
[email protected]c4a7df82012-08-09 22:48:46778 return request.first_party_for_cookies().scheme() ==
[email protected]885c0e92012-11-13 20:27:42779 extensions::kExtensionScheme;
[email protected]84b7a552014-07-19 04:52:06780#else
781 return false;
782#endif
[email protected]a1d4ab072012-06-07 13:21:15783}
[email protected]aa28181e2012-06-13 00:53:58784
[email protected]e6d017652013-05-17 18:01:40785bool ChromeNetworkDelegate::OnCanEnablePrivacyMode(
786 const GURL& url,
787 const GURL& first_party_for_cookies) const {
788 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02789 if (!cookie_settings_.get())
[email protected]e6d017652013-05-17 18:01:40790 return false;
791
792 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed(
793 url, first_party_for_cookies);
794 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed(
795 url, first_party_for_cookies);
796 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed);
797 return privacy_mode;
798}
799
[email protected]aa28181e2012-06-13 00:53:58800int ChromeNetworkDelegate::OnBeforeSocketStreamConnect(
801 net::SocketStream* socket,
802 const net::CompletionCallback& callback) {
803#if defined(ENABLE_CONFIGURATION_POLICY)
804 if (url_blacklist_manager_ &&
805 url_blacklist_manager_->IsURLBlocked(socket->url())) {
806 // URL access blocked by policy.
[email protected]aa28181e2012-06-13 00:53:58807 socket->net_log()->AddEvent(
[email protected]2fa08912012-06-14 20:56:26808 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
809 net::NetLog::StringCallback("url",
810 &socket->url().possibly_invalid_spec()));
[email protected]91468a92013-03-06 17:21:55811 return net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]aa28181e2012-06-13 00:53:58812 }
813#endif
814 return net::OK;
815}
[email protected]5a07c192012-07-30 20:18:22816
jochen0e3b3a62014-09-16 18:31:23817bool ChromeNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
818 const net::URLRequest& request,
819 const GURL& target_url,
820 const GURL& referrer_url) const {
821 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
822 base::Bind(&ReportInvalidReferrerSend, target_url, referrer_url));
823 return true;
824}
825
[email protected]7a299a92012-10-24 23:54:50826void ChromeNetworkDelegate::AccumulateContentLength(
[email protected]b7796462013-12-12 19:42:34827 int64 received_content_length,
828 int64 original_content_length,
[email protected]a0a06932014-04-14 21:23:42829 data_reduction_proxy::DataReductionProxyRequestType request_type) {
[email protected]7a299a92012-10-24 23:54:50830 DCHECK_GE(received_content_length, 0);
831 DCHECK_GE(original_content_length, 0);
megjablon53f608b2014-09-18 19:24:55832 if (data_reduction_proxy_statistics_prefs_) {
833 StoreAccumulatedContentLength(received_content_length,
834 original_content_length,
835 request_type,
836 reinterpret_cast<Profile*>(profile_),
837 data_reduction_proxy_statistics_prefs_);
838 }
[email protected]7a299a92012-10-24 23:54:50839 received_content_length_ += received_content_length;
840 original_content_length_ += original_content_length;
841}