blob: 74ecef7c89f2edc612fadea5cbc756f4f948f4a6 [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"
[email protected]d8e4f132012-09-06 04:28:0515#include "base/path_service.h"
[email protected]1ab137b2013-03-21 03:33:1816#include "base/prefs/pref_member.h"
[email protected]3853a4c2013-02-11 17:15:5717#include "base/prefs/pref_service.h"
[email protected]3ea1b182013-02-08 22:38:4118#include "base/strings/string_number_conversions.h"
[email protected]069c49162013-09-11 20:46:3519#include "base/time/time.h"
[email protected]6baff0b52012-03-06 01:30:1820#include "chrome/browser/browser_process.h"
[email protected]9c8ae8c2012-03-09 13:13:3521#include "chrome/browser/content_settings/cookie_settings.h"
22#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]8523ba52011-05-22 19:00:5823#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]4a2b6232014-06-19 08:44:1424#include "chrome/browser/net/chrome_extensions_network_delegate.h"
[email protected]3620bbc2013-10-05 05:07:2325#include "chrome/browser/net/client_hints.h"
[email protected]f53b4802012-12-20 17:04:2326#include "chrome/browser/net/connect_interceptor.h"
[email protected]184799df2014-07-22 16:03:2427#include "chrome/browser/net/safe_search_util.h"
[email protected]6f4b4b42012-08-27 21:59:0728#include "chrome/browser/performance_monitor/performance_monitor.h"
[email protected]28c5d0b72014-05-13 08:19:5929#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]6baff0b52012-03-06 01:30:1830#include "chrome/browser/profiles/profile_manager.h"
[email protected]8523ba52011-05-22 19:00:5831#include "chrome/browser/task_manager/task_manager.h"
[email protected]0a8db0d2011-04-13 15:15:4032#include "chrome/common/pref_names.h"
[email protected]597a1ab2014-06-26 08:12:2733#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
[email protected]a0a06932014-04-14 21:23:4234#include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h"
[email protected]d8fc4722014-06-13 13:17:1535#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
36#include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.h"
[email protected]bceab7f2014-06-25 04:36:2037#include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h"
[email protected]45de676a2014-03-18 23:52:0238#include "components/domain_reliability/monitor.h"
[email protected]c38831a12011-10-28 12:44:4939#include "content/public/browser/browser_thread.h"
[email protected]9dfed872013-12-30 23:08:5640#include "content/public/browser/render_frame_host.h"
[email protected]9c1662b2012-03-06 15:44:3341#include "content/public/browser/render_view_host.h"
[email protected]9c8ae8c2012-03-09 13:13:3542#include "content/public/browser/resource_request_info.h"
[email protected]82b42302011-04-20 16:28:1643#include "net/base/host_port_pair.h"
[email protected]8202d0c2011-02-23 08:31:1444#include "net/base/net_errors.h"
[email protected]6a5f77c32011-09-04 19:19:5945#include "net/base/net_log.h"
[email protected]5b9bc352012-07-18 13:13:3446#include "net/cookies/canonical_cookie.h"
47#include "net/cookies/cookie_options.h"
[email protected]ac039522010-06-15 16:39:4448#include "net/http/http_request_headers.h"
[email protected]48944382011-04-23 13:28:1649#include "net/http/http_response_headers.h"
[email protected]597a1ab2014-06-26 08:12:2750#include "net/proxy/proxy_info.h"
51#include "net/proxy/proxy_server.h"
[email protected]aa28181e2012-06-13 00:53:5852#include "net/socket_stream/socket_stream.h"
[email protected]d05ef99c2011-02-01 21:38:1653#include "net/url_request/url_request.h"
[email protected]28c5d0b72014-05-13 08:19:5954#include "net/url_request/url_request_context.h"
[email protected]d05ef99c2011-02-01 21:38:1655
[email protected]4a2b6232014-06-19 08:44:1456#if defined(OS_ANDROID)
57#include "chrome/browser/io_thread.h"
58#include "components/precache/content/precache_manager.h"
59#include "components/precache/content/precache_manager_factory.h"
60#endif
61
[email protected]4c219e22012-05-05 19:41:0462#if defined(OS_CHROMEOS)
[email protected]288538482012-09-06 21:09:3563#include "base/command_line.h"
[email protected]49c4cf852013-09-27 19:28:2464#include "base/sys_info.h"
[email protected]288538482012-09-06 21:09:3565#include "chrome/common/chrome_switches.h"
[email protected]4c219e22012-05-05 19:41:0466#endif
67
[email protected]3e598ff12011-09-06 11:22:3468#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]f522afa2014-01-08 15:36:3669#include "components/policy/core/browser/url_blacklist_manager.h"
[email protected]3e598ff12011-09-06 11:22:3470#endif
71
[email protected]84b7a552014-07-19 04:52:0672#if defined(ENABLE_EXTENSIONS)
73#include "extensions/common/constants.h"
74#endif
75
[email protected]631bb742011-11-02 11:29:3976using content::BrowserThread;
[email protected]eaabba22012-03-07 15:02:1177using content::RenderViewHost;
[email protected]ea114722012-03-12 01:11:2578using content::ResourceRequestInfo;
[email protected]7491ad02014-07-05 19:10:0779using content::ResourceType;
[email protected]631bb742011-11-02 11:29:3980
[email protected]d8e4f132012-09-06 04:28:0581// By default we don't allow access to all file:// urls on ChromeOS and
82// Android.
83#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:0484bool ChromeNetworkDelegate::g_allow_file_access_ = false;
85#else
86bool ChromeNetworkDelegate::g_allow_file_access_ = true;
87#endif
88
[email protected]84b7a552014-07-19 04:52:0689#if defined(ENABLE_EXTENSIONS)
[email protected]c4a7df82012-08-09 22:48:4690// This remains false unless the --disable-extensions-http-throttling
91// flag is passed to the browser.
92bool ChromeNetworkDelegate::g_never_throttle_requests_ = false;
[email protected]84b7a552014-07-19 04:52:0693#endif
[email protected]c4a7df82012-08-09 22:48:4694
[email protected]d05ef99c2011-02-01 21:38:1695namespace {
96
[email protected]9d8cfb682012-09-13 16:48:0497const char kDNTHeader[] = "DNT";
98
[email protected]d1208ba32012-11-08 11:10:3399// Gets called when the extensions finish work on the URL. If the extensions
100// did not do a redirect (so |new_url| is empty) then we enforce the
101// SafeSearch parameters. Otherwise we will get called again after the
102// redirect and we enforce SafeSearch then.
103void ForceGoogleSafeSearchCallbackWrapper(
104 const net::CompletionCallback& callback,
105 net::URLRequest* request,
106 GURL* new_url,
107 int rv) {
108 if (rv == net::OK && new_url->is_empty())
[email protected]184799df2014-07-22 16:03:24109 safe_search_util::ForceGoogleSafeSearch(request, new_url);
[email protected]d1208ba32012-11-08 11:10:33110 callback.Run(rv);
111}
112
[email protected]828eab22013-12-10 22:42:38113void UpdateContentLengthPrefs(
114 int received_content_length,
115 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42116 data_reduction_proxy::DataReductionProxyRequestType request_type,
[email protected]b7796462013-12-12 19:42:34117 Profile* profile) {
[email protected]7a299a92012-10-24 23:54:50118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
119 DCHECK_GE(received_content_length, 0);
120 DCHECK_GE(original_content_length, 0);
121
[email protected]a09159a2012-11-29 12:51:48122 // Can be NULL in a unit test.
123 if (!g_browser_process)
124 return;
125
[email protected]7a299a92012-10-24 23:54:50126 PrefService* prefs = g_browser_process->local_state();
[email protected]a09159a2012-11-29 12:51:48127 if (!prefs)
128 return;
[email protected]7a299a92012-10-24 23:54:50129
[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 }
[email protected]f4bfa7672014-08-08 09:50:46135#if defined(OS_ANDROID) && defined(SPDY_PROXY_AUTH_ORIGIN)
[email protected]b1d5ed52013-12-18 02:34:56136 // If Android ever goes multi profile, the profile should be passed so that
137 // the browser preference will be taken.
[email protected]0d36d1e2013-09-24 04:25:28138 bool with_data_reduction_proxy_enabled =
[email protected]b1d5ed52013-12-18 02:34:56139 ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean(
[email protected]a0a06932014-04-14 21:23:42140 data_reduction_proxy::prefs::kDataReductionProxyEnabled);
[email protected]0d36d1e2013-09-24 04:25:28141#else
142 bool with_data_reduction_proxy_enabled = false;
[email protected]eac11e12013-03-19 22:04:32143#endif
[email protected]0d36d1e2013-09-24 04:25:28144
[email protected]a0a06932014-04-14 21:23:42145 data_reduction_proxy::UpdateContentLengthPrefs(received_content_length,
146 original_content_length,
147 with_data_reduction_proxy_enabled,
148 request_type, prefs);
[email protected]7a299a92012-10-24 23:54:50149}
150
[email protected]828eab22013-12-10 22:42:38151void StoreAccumulatedContentLength(
152 int received_content_length,
153 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42154 data_reduction_proxy::DataReductionProxyRequestType request_type,
[email protected]b7796462013-12-12 19:42:34155 Profile* profile) {
[email protected]7a299a92012-10-24 23:54:50156 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
157 base::Bind(&UpdateContentLengthPrefs,
[email protected]2db93e42013-08-07 17:40:41158 received_content_length, original_content_length,
[email protected]a0a06932014-04-14 21:23:42159 request_type, profile));
[email protected]7a299a92012-10-24 23:54:50160}
161
162void RecordContentLengthHistograms(
[email protected]f81a5ee2013-06-20 21:08:49163 int64 received_content_length,
164 int64 original_content_length,
165 const base::TimeDelta& freshness_lifetime) {
[email protected]7a299a92012-10-24 23:54:50166 // Add the current resource to these histograms only when a valid
167 // X-Original-Content-Length header is present.
168 if (original_content_length >= 0) {
169 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL",
170 received_content_length);
171 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL",
172 original_content_length);
173 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL",
174 original_content_length - received_content_length);
175 } else {
176 // Presume the original content length is the same as the received content
177 // length if the X-Original-Content-Header is not present.
178 original_content_length = received_content_length;
179 }
180 UMA_HISTOGRAM_COUNTS("Net.HttpContentLength", received_content_length);
181 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLength",
182 original_content_length);
183 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifference",
184 original_content_length - received_content_length);
[email protected]f81a5ee2013-06-20 21:08:49185 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpContentFreshnessLifetime",
186 freshness_lifetime.InSeconds(),
187 base::TimeDelta::FromHours(1).InSeconds(),
188 base::TimeDelta::FromDays(30).InSeconds(),
189 100);
190 if (freshness_lifetime.InSeconds() <= 0)
191 return;
192 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable",
193 received_content_length);
194 if (freshness_lifetime.InHours() < 4)
195 return;
196 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours",
197 received_content_length);
198
199 if (freshness_lifetime.InHours() < 24)
200 return;
201 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours",
202 received_content_length);
[email protected]7a299a92012-10-24 23:54:50203}
204
[email protected]35558812013-12-18 21:58:36205#if defined(OS_ANDROID)
206void RecordPrecacheStatsOnUIThread(const GURL& url,
207 const base::Time& fetch_time, int64 size,
208 bool was_cached, void* profile_id) {
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
210
211 Profile* profile = reinterpret_cast<Profile*>(profile_id);
212 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) {
213 return;
214 }
215
216 precache::PrecacheManager* precache_manager =
217 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
218 if (!precache_manager) {
219 // This could be NULL if the profile is off the record.
220 return;
221 }
222
223 precache_manager->RecordStatsForFetch(url, fetch_time, size, was_cached);
224}
[email protected]d827e112014-03-31 17:45:05225
226void RecordIOThreadToRequestStartOnUIThread(
227 const base::TimeTicks& request_start) {
228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
229 base::TimeDelta request_lag = request_start -
230 g_browser_process->io_thread()->creation_time();
231 UMA_HISTOGRAM_TIMES("Net.IOThreadCreationToHTTPRequestStart", request_lag);
232}
[email protected]35558812013-12-18 21:58:36233#endif // defined(OS_ANDROID)
234
[email protected]d05ef99c2011-02-01 21:38:16235} // namespace
[email protected]ac039522010-06-15 16:39:44236
[email protected]0651b812011-02-24 00:22:50237ChromeNetworkDelegate::ChromeNetworkDelegate(
[email protected]5a38dfd2012-07-23 23:22:10238 extensions::EventRouterForwarder* event_router,
[email protected]a09159a2012-11-29 12:51:48239 BooleanPrefMember* enable_referrers)
[email protected]4a2b6232014-06-19 08:44:14240 : profile_(NULL),
[email protected]6a5f77c32011-09-04 19:19:59241 enable_referrers_(enable_referrers),
[email protected]a09159a2012-11-29 12:51:48242 enable_do_not_track_(NULL),
243 force_google_safe_search_(NULL),
[email protected]a948dad2014-07-25 00:39:38244 data_reduction_proxy_enabled_(NULL),
[email protected]4a2b6232014-06-19 08:44:14245#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]a09159a2012-11-29 12:51:48246 url_blacklist_manager_(NULL),
[email protected]4a2b6232014-06-19 08:44:14247#endif
[email protected]45de676a2014-03-18 23:52:02248 domain_reliability_monitor_(NULL),
[email protected]7a299a92012-10-24 23:54:50249 received_content_length_(0),
[email protected]d827e112014-03-31 17:45:05250 original_content_length_(0),
[email protected]28c5d0b72014-05-13 08:19:59251 first_request_(true),
[email protected]d8fc4722014-06-13 13:17:15252 prerender_tracker_(NULL),
[email protected]bceab7f2014-06-25 04:36:20253 data_reduction_proxy_params_(NULL),
[email protected]597a1ab2014-06-26 08:12:27254 data_reduction_proxy_usage_stats_(NULL),
255 data_reduction_proxy_auth_request_handler_(NULL) {
[email protected]0a8db0d2011-04-13 15:15:40256 DCHECK(enable_referrers);
[email protected]4a2b6232014-06-19 08:44:14257 extensions_delegate_.reset(
258 ChromeExtensionsNetworkDelegate::Create(event_router));
[email protected]0651b812011-02-24 00:22:50259}
260
[email protected]ac039522010-06-15 16:39:44261ChromeNetworkDelegate::~ChromeNetworkDelegate() {}
262
[email protected]a09159a2012-11-29 12:51:48263void ChromeNetworkDelegate::set_extension_info_map(
[email protected]38427a12013-11-09 17:34:20264 extensions::InfoMap* extension_info_map) {
[email protected]4a2b6232014-06-19 08:44:14265 extensions_delegate_->set_extension_info_map(extension_info_map);
266}
267
268void ChromeNetworkDelegate::set_profile(void* profile) {
269 profile_ = profile;
270 extensions_delegate_->set_profile(profile);
[email protected]a09159a2012-11-29 12:51:48271}
272
273void ChromeNetworkDelegate::set_cookie_settings(
274 CookieSettings* cookie_settings) {
275 cookie_settings_ = cookie_settings;
276}
277
[email protected]f53b4802012-12-20 17:04:23278void ChromeNetworkDelegate::set_predictor(
279 chrome_browser_net::Predictor* predictor) {
280 connect_interceptor_.reset(
281 new chrome_browser_net::ConnectInterceptor(predictor));
282}
283
[email protected]3620bbc2013-10-05 05:07:23284void ChromeNetworkDelegate::SetEnableClientHints() {
285 client_hints_.reset(new ClientHints());
286 client_hints_->Init();
287}
288
[email protected]c4a7df82012-08-09 22:48:46289// static
[email protected]84b7a552014-07-19 04:52:06290#if defined(ENABLE_EXTENSIONS)
[email protected]a1d4ab072012-06-07 13:21:15291void ChromeNetworkDelegate::NeverThrottleRequests() {
[email protected]c4a7df82012-08-09 22:48:46292 g_never_throttle_requests_ = true;
[email protected]a1d4ab072012-06-07 13:21:15293}
[email protected]84b7a552014-07-19 04:52:06294#endif
[email protected]a1d4ab072012-06-07 13:21:15295
[email protected]0a8db0d2011-04-13 15:15:40296// static
[email protected]9d8cfb682012-09-13 16:48:04297void ChromeNetworkDelegate::InitializePrefsOnUIThread(
[email protected]0a8db0d2011-04-13 15:15:40298 BooleanPrefMember* enable_referrers,
[email protected]9d8cfb682012-09-13 16:48:04299 BooleanPrefMember* enable_do_not_track,
[email protected]d1208ba32012-11-08 11:10:33300 BooleanPrefMember* force_google_safe_search,
[email protected]0a8db0d2011-04-13 15:15:40301 PrefService* pref_service) {
302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]96a5c342012-12-04 18:14:02303 enable_referrers->Init(prefs::kEnableReferrers, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43304 enable_referrers->MoveToThread(
305 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04306 if (enable_do_not_track) {
[email protected]96a5c342012-12-04 18:14:02307 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43308 enable_do_not_track->MoveToThread(
309 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04310 }
[email protected]d1208ba32012-11-08 11:10:33311 if (force_google_safe_search) {
[email protected]96a5c342012-12-04 18:14:02312 force_google_safe_search->Init(prefs::kForceSafeSearch, pref_service);
[email protected]d1208ba32012-11-08 11:10:33313 force_google_safe_search->MoveToThread(
314 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
315 }
[email protected]0a8db0d2011-04-13 15:15:40316}
317
[email protected]4c219e22012-05-05 19:41:04318// static
319void ChromeNetworkDelegate::AllowAccessToAllFiles() {
320 g_allow_file_access_ = true;
321}
322
[email protected]7a299a92012-10-24 23:54:50323// static
[email protected]cb1078de2013-12-23 20:04:22324base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() {
[email protected]7a299a92012-10-24 23:54:50325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
326 PrefService* prefs = g_browser_process->local_state();
[email protected]a0a06932014-04-14 21:23:42327 int64 total_received = prefs->GetInt64(
328 data_reduction_proxy::prefs::kHttpReceivedContentLength);
329 int64 total_original = prefs->GetInt64(
330 data_reduction_proxy::prefs::kHttpOriginalContentLength);
[email protected]7a299a92012-10-24 23:54:50331
[email protected]cb1078de2013-12-23 20:04:22332 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42333 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
334 dict->SetString("historic_received_content_length",
335 base::Int64ToString(total_received));
336 dict->SetString("historic_original_content_length",
337 base::Int64ToString(total_original));
[email protected]7a299a92012-10-24 23:54:50338 return dict;
339}
340
[email protected]cb1078de2013-12-23 20:04:22341base::Value* ChromeNetworkDelegate::SessionNetworkStatsInfoToValue() const {
342 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42343 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
344 dict->SetString("session_received_content_length",
345 base::Int64ToString(received_content_length_));
346 dict->SetString("session_original_content_length",
347 base::Int64ToString(original_content_length_));
[email protected]7a299a92012-10-24 23:54:50348 return dict;
349}
350
[email protected]4875ba12011-03-30 22:31:51351int ChromeNetworkDelegate::OnBeforeURLRequest(
[email protected]4c76d7c2011-04-15 19:14:12352 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47353 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12354 GURL* new_url) {
[email protected]d827e112014-03-31 17:45:05355#if defined(OS_ANDROID)
356 // This UMA tracks the time to the first user-initiated request start, so
357 // only non-null profiles are considered.
358 if (first_request_ && profile_) {
359 bool record_timing = true;
[email protected]bec6a992014-06-19 01:03:21360 if (data_reduction_proxy_params_) {
361 record_timing =
362 (request->url() != data_reduction_proxy_params_->probe_url()) &&
363 (request->url() != data_reduction_proxy_params_->warmup_url());
364 }
[email protected]d827e112014-03-31 17:45:05365 if (record_timing) {
366 first_request_ = false;
367 net::LoadTimingInfo timing_info;
368 request->GetLoadTimingInfo(&timing_info);
369 BrowserThread::PostTask(
370 BrowserThread::UI, FROM_HERE,
371 base::Bind(&RecordIOThreadToRequestStartOnUIThread,
372 timing_info.request_start));
373 }
374 }
375#endif // defined(OS_ANDROID)
376
[email protected]3e598ff12011-09-06 11:22:34377#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]6a5f77c32011-09-04 19:19:59378 // TODO(joaodasilva): This prevents extensions from seeing URLs that are
379 // blocked. However, an extension might redirect the request to another URL,
380 // which is not blocked.
[email protected]cb85f8e52014-04-08 11:44:40381 int error = net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]6a5f77c32011-09-04 19:19:59382 if (url_blacklist_manager_ &&
[email protected]cb85f8e52014-04-08 11:44:40383 url_blacklist_manager_->IsRequestBlocked(*request, &error)) {
[email protected]6a5f77c32011-09-04 19:19:59384 // URL access blocked by policy.
[email protected]6a5f77c32011-09-04 19:19:59385 request->net_log().AddEvent(
[email protected]2fa08912012-06-14 20:56:26386 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
387 net::NetLog::StringCallback("url",
388 &request->url().possibly_invalid_spec()));
[email protected]cb85f8e52014-04-08 11:44:40389 return error;
[email protected]6a5f77c32011-09-04 19:19:59390 }
[email protected]3e598ff12011-09-06 11:22:34391#endif
[email protected]6a5f77c32011-09-04 19:19:59392
[email protected]4a2b6232014-06-19 08:44:14393 extensions_delegate_->ForwardStartRequestStatus(request);
[email protected]6baff0b52012-03-06 01:30:18394
[email protected]0a8db0d2011-04-13 15:15:40395 if (!enable_referrers_->GetValue())
[email protected]99ecf6e2013-04-10 22:46:13396 request->SetReferrer(std::string());
[email protected]9d8cfb682012-09-13 16:48:04397 if (enable_do_not_track_ && enable_do_not_track_->GetValue())
398 request->SetExtraRequestHeaderByName(kDNTHeader, "1", true /* override */);
[email protected]d1208ba32012-11-08 11:10:33399
[email protected]3620bbc2013-10-05 05:07:23400 if (client_hints_) {
401 request->SetExtraRequestHeaderByName(
402 ClientHints::kDevicePixelRatioHeader,
403 client_hints_->GetDevicePixelRatioHeader(), true);
404 }
405
[email protected]d1208ba32012-11-08 11:10:33406 bool force_safe_search = force_google_safe_search_ &&
407 force_google_safe_search_->GetValue();
408
409 net::CompletionCallback wrapped_callback = callback;
410 if (force_safe_search) {
411 wrapped_callback = base::Bind(&ForceGoogleSafeSearchCallbackWrapper,
412 callback,
413 base::Unretained(request),
414 base::Unretained(new_url));
415 }
416
[email protected]4a2b6232014-06-19 08:44:14417 int rv = extensions_delegate_->OnBeforeURLRequest(
418 request, wrapped_callback, new_url);
[email protected]d1208ba32012-11-08 11:10:33419
420 if (force_safe_search && rv == net::OK && new_url->is_empty())
[email protected]184799df2014-07-22 16:03:24421 safe_search_util::ForceGoogleSafeSearch(request, new_url);
[email protected]d1208ba32012-11-08 11:10:33422
[email protected]f53b4802012-12-20 17:04:23423 if (connect_interceptor_)
424 connect_interceptor_->WitnessURLRequest(request);
425
[email protected]d1208ba32012-11-08 11:10:33426 return rv;
[email protected]d05ef99c2011-02-01 21:38:16427}
428
[email protected]a702da72014-07-09 05:23:54429void ChromeNetworkDelegate::OnResolveProxy(
430 const GURL& url, int load_flags, net::ProxyInfo* result) {
431 if (!on_resolve_proxy_handler_.is_null()) {
432 on_resolve_proxy_handler_.Run(url, load_flags,
433 data_reduction_proxy_params_, result);
434 }
435}
436
[email protected]4875ba12011-03-30 22:31:51437int ChromeNetworkDelegate::OnBeforeSendHeaders(
[email protected]636eccd2011-06-28 12:28:01438 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47439 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12440 net::HttpRequestHeaders* headers) {
[email protected]184799df2014-07-22 16:03:24441 bool force_safe_search = force_google_safe_search_ &&
442 force_google_safe_search_->GetValue();
443 if (force_safe_search)
444 safe_search_util::ForceYouTubeSafetyMode(request, headers);
445
[email protected]186468f2013-10-24 02:44:11446 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest");
[email protected]4a2b6232014-06-19 08:44:14447 return extensions_delegate_->OnBeforeSendHeaders(request, callback, headers);
[email protected]ac039522010-06-15 16:39:44448}
[email protected]8202d0c2011-02-23 08:31:14449
[email protected]597a1ab2014-06-26 08:12:27450void ChromeNetworkDelegate::OnBeforeSendProxyHeaders(
451 net::URLRequest* request,
452 const net::ProxyInfo& proxy_info,
453 net::HttpRequestHeaders* headers) {
454 if (data_reduction_proxy_auth_request_handler_) {
455 data_reduction_proxy_auth_request_handler_->MaybeAddRequestHeader(
456 request, proxy_info.proxy_server(), headers);
457 }
458}
459
[email protected]5796dc942011-07-14 19:26:10460void ChromeNetworkDelegate::OnSendHeaders(
461 net::URLRequest* request,
[email protected]783573b2011-05-13 11:05:15462 const net::HttpRequestHeaders& headers) {
[email protected]4a2b6232014-06-19 08:44:14463 extensions_delegate_->OnSendHeaders(request, headers);
[email protected]82b42302011-04-20 16:28:16464}
465
[email protected]ea8141e2011-10-05 13:12:51466int ChromeNetworkDelegate::OnHeadersReceived(
467 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47468 const net::CompletionCallback& callback,
[email protected]507af8f2012-10-20 00:42:32469 const net::HttpResponseHeaders* original_response_headers,
[email protected]5f714132014-03-26 10:41:16470 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
471 GURL* allowed_unsafe_redirect_url) {
[email protected]a948dad2014-07-25 00:39:38472 net::ProxyService::DataReductionProxyBypassType bypass_type;
[email protected]d8fc4722014-06-13 13:17:15473 if (data_reduction_proxy::MaybeBypassProxyAndPrepareToRetry(
474 data_reduction_proxy_params_,
475 request,
476 original_response_headers,
[email protected]a948dad2014-07-25 00:39:38477 override_response_headers,
478 &bypass_type)) {
479 if (data_reduction_proxy_usage_stats_)
480 data_reduction_proxy_usage_stats_->SetBypassType(bypass_type);
[email protected]d8fc4722014-06-13 13:17:15481 return net::OK;
482 }
483
[email protected]4a2b6232014-06-19 08:44:14484 return extensions_delegate_->OnHeadersReceived(
[email protected]5f714132014-03-26 10:41:16485 request,
486 callback,
487 original_response_headers,
488 override_response_headers,
489 allowed_unsafe_redirect_url);
[email protected]ea8141e2011-10-05 13:12:51490}
491
[email protected]31b2e5f2011-04-20 16:58:32492void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
493 const GURL& new_location) {
[email protected]45de676a2014-03-18 23:52:02494 if (domain_reliability_monitor_)
495 domain_reliability_monitor_->OnBeforeRedirect(request);
[email protected]4a2b6232014-06-19 08:44:14496 extensions_delegate_->OnBeforeRedirect(request, new_location);
[email protected]31b2e5f2011-04-20 16:58:32497}
498
499
[email protected]8202d0c2011-02-23 08:31:14500void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
[email protected]186468f2013-10-24 02:44:11501 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "ResponseStarted");
[email protected]4a2b6232014-06-19 08:44:14502 extensions_delegate_->OnResponseStarted(request);
[email protected]8202d0c2011-02-23 08:31:14503}
504
[email protected]8523ba52011-05-22 19:00:58505void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
506 int bytes_read) {
[email protected]186468f2013-10-24 02:44:11507 TRACE_EVENT_ASYNC_STEP_PAST1("net", "URLRequest", &request, "DidRead",
508 "bytes_read", bytes_read);
[email protected]6f4b4b42012-08-27 21:59:07509 performance_monitor::PerformanceMonitor::GetInstance()->BytesReadOnIOThread(
510 request, bytes_read);
511
[email protected]44879ed2012-04-06 01:11:02512#if defined(ENABLE_TASK_MANAGER)
[email protected]17df9e7c2014-02-13 03:49:29513 // This is not completely accurate, but as a first approximation ignore
514 // requests that are served from the cache. See bug 330931 for more info.
515 if (!request.was_cached())
516 TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read);
[email protected]44879ed2012-04-06 01:11:02517#endif // defined(ENABLE_TASK_MANAGER)
[email protected]8523ba52011-05-22 19:00:58518}
519
[email protected]9045b8822012-01-13 20:35:35520void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
521 bool started) {
[email protected]bceab7f2014-06-25 04:36:20522 if (data_reduction_proxy_usage_stats_)
523 data_reduction_proxy_usage_stats_->OnUrlRequestCompleted(request, started);
524
[email protected]4aca5db2013-08-17 00:51:56525 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request);
[email protected]2756a8e2012-09-07 18:24:29526 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
[email protected]7a299a92012-10-24 23:54:50527 // For better accuracy, we use the actual bytes read instead of the length
528 // specified with the Content-Length header, which may be inaccurate,
529 // or missing, as is the case with chunked encoding.
530 int64 received_content_length = request->received_response_content_length();
531
[email protected]35558812013-12-18 21:58:36532#if defined(OS_ANDROID)
533 if (precache::PrecacheManager::IsPrecachingEnabled()) {
534 // Record precache metrics when a fetch is completed successfully, if
535 // precaching is enabled.
536 BrowserThread::PostTask(
537 BrowserThread::UI, FROM_HERE,
538 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(),
539 base::Time::Now(), received_content_length,
540 request->was_cached(), profile_));
541 }
542#endif // defined(OS_ANDROID)
543
[email protected]7a299a92012-10-24 23:54:50544 // Only record for http or https urls.
545 bool is_http = request->url().SchemeIs("http");
546 bool is_https = request->url().SchemeIs("https");
547
548 if (!request->was_cached() && // Don't record cached content
549 received_content_length && // Zero-byte responses aren't useful.
550 (is_http || is_https)) { // Only record for HTTP or HTTPS urls.
551 int64 original_content_length =
552 request->response_info().headers->GetInt64HeaderValue(
553 "x-original-content-length");
[email protected]a0a06932014-04-14 21:23:42554 data_reduction_proxy::DataReductionProxyRequestType request_type =
555 data_reduction_proxy::GetDataReductionProxyRequestType(request);
[email protected]2db93e42013-08-07 17:40:41556
[email protected]f81a5ee2013-06-20 21:08:49557 base::TimeDelta freshness_lifetime =
558 request->response_info().headers->GetFreshnessLifetime(
559 request->response_info().response_time);
[email protected]828eab22013-12-10 22:42:38560 int64 adjusted_original_content_length =
[email protected]a0a06932014-04-14 21:23:42561 data_reduction_proxy::GetAdjustedOriginalContentLength(
562 request_type, original_content_length,
[email protected]828eab22013-12-10 22:42:38563 received_content_length);
[email protected]7a299a92012-10-24 23:54:50564 AccumulateContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41565 adjusted_original_content_length,
[email protected]a0a06932014-04-14 21:23:42566 request_type);
[email protected]7a299a92012-10-24 23:54:50567 RecordContentLengthHistograms(received_content_length,
[email protected]f81a5ee2013-06-20 21:08:49568 original_content_length,
569 freshness_lifetime);
[email protected]a948dad2014-07-25 00:39:38570 if (data_reduction_proxy_enabled_ && data_reduction_proxy_usage_stats_) {
571 data_reduction_proxy_usage_stats_->RecordBypassedBytesHistograms(
572 *request, *data_reduction_proxy_enabled_);
573 }
[email protected]7a299a92012-10-24 23:54:50574 DVLOG(2) << __FUNCTION__
575 << " received content length: " << received_content_length
576 << " original content length: " << original_content_length
577 << " url: " << request->url();
578 }
579
[email protected]4a2b6232014-06-19 08:44:14580 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01581 } else if (request->status().status() == net::URLRequestStatus::FAILED ||
582 request->status().status() == net::URLRequestStatus::CANCELED) {
[email protected]4a2b6232014-06-19 08:44:14583 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01584 } else {
585 NOTREACHED();
[email protected]48944382011-04-23 13:28:16586 }
[email protected]45de676a2014-03-18 23:52:02587 if (domain_reliability_monitor_)
588 domain_reliability_monitor_->OnCompleted(request, started);
[email protected]4a2b6232014-06-19 08:44:14589 extensions_delegate_->ForwardProxyErrors(request);
590 extensions_delegate_->ForwardDoneRequestStatus(request);
[email protected]8202d0c2011-02-23 08:31:14591}
[email protected]4b50cb52011-03-10 00:29:37592
[email protected]4875ba12011-03-30 22:31:51593void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
[email protected]4a2b6232014-06-19 08:44:14594 extensions_delegate_->OnURLRequestDestroyed(request);
[email protected]4875ba12011-03-30 22:31:51595}
596
[email protected]82a37672011-05-03 12:02:41597void ChromeNetworkDelegate::OnPACScriptError(int line_number,
[email protected]439f1e32013-12-09 20:09:09598 const base::string16& error) {
[email protected]4a2b6232014-06-19 08:44:14599 extensions_delegate_->OnPACScriptError(line_number, error);
[email protected]82a37672011-05-03 12:02:41600}
[email protected]7efc582d2011-08-03 20:46:35601
[email protected]c2911d72011-10-03 22:16:36602net::NetworkDelegate::AuthRequiredResponse
603ChromeNetworkDelegate::OnAuthRequired(
[email protected]7efc582d2011-08-03 20:46:35604 net::URLRequest* request,
[email protected]c2911d72011-10-03 22:16:36605 const net::AuthChallengeInfo& auth_info,
606 const AuthCallback& callback,
607 net::AuthCredentials* credentials) {
[email protected]4a2b6232014-06-19 08:44:14608 return extensions_delegate_->OnAuthRequired(
609 request, auth_info, callback, credentials);
[email protected]7efc582d2011-08-03 20:46:35610}
[email protected]9c8ae8c2012-03-09 13:13:35611
[email protected]4c219e22012-05-05 19:41:04612bool ChromeNetworkDelegate::OnCanGetCookies(
613 const net::URLRequest& request,
[email protected]9c8ae8c2012-03-09 13:13:35614 const net::CookieList& cookie_list) {
615 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02616 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35617 return true;
618
619 bool allow = cookie_settings_->IsReadingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04620 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35621
622 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16623 int render_frame_id = -1;
[email protected]f7fa5b62014-03-19 15:20:06624
625 // |is_for_blocking_resource| indicates whether the cookies read were for a
626 // blocking resource (eg script, css). It is only temporarily added for
627 // diagnostic purposes, per bug 353678. Will be removed again once data
628 // collection is finished.
629 bool is_for_blocking_resource = false;
630 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
631 if (info && ((!info->IsAsync()) ||
[email protected]6c1e05212014-07-31 00:59:40632 info->GetResourceType() == content::RESOURCE_TYPE_STYLESHEET ||
633 info->GetResourceType() == content::RESOURCE_TYPE_SCRIPT)) {
[email protected]f7fa5b62014-03-19 15:20:06634 is_for_blocking_resource = true;
635 }
636
[email protected]f3add922013-12-20 23:17:16637 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
638 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35639 BrowserThread::PostTask(
640 BrowserThread::UI, FROM_HERE,
641 base::Bind(&TabSpecificContentSettings::CookiesRead,
[email protected]f3add922013-12-20 23:17:16642 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04643 request.url(), request.first_party_for_cookies(),
[email protected]f7fa5b62014-03-19 15:20:06644 cookie_list, !allow, is_for_blocking_resource));
[email protected]9c8ae8c2012-03-09 13:13:35645 }
646
647 return allow;
648}
649
[email protected]4c219e22012-05-05 19:41:04650bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
651 const std::string& cookie_line,
652 net::CookieOptions* options) {
[email protected]9c8ae8c2012-03-09 13:13:35653 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02654 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35655 return true;
656
657 bool allow = cookie_settings_->IsSettingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04658 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35659
[email protected]9c8ae8c2012-03-09 13:13:35660 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16661 int render_frame_id = -1;
662 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
663 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35664 BrowserThread::PostTask(
665 BrowserThread::UI, FROM_HERE,
666 base::Bind(&TabSpecificContentSettings::CookieChanged,
[email protected]f3add922013-12-20 23:17:16667 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04668 request.url(), request.first_party_for_cookies(),
[email protected]fd473d12012-04-05 11:38:43669 cookie_line, *options, !allow));
[email protected]9c8ae8c2012-03-09 13:13:35670 }
671
[email protected]28c5d0b72014-05-13 08:19:59672 if (prerender_tracker_) {
673 prerender_tracker_->OnCookieChangedForURL(
674 render_process_id,
675 request.context()->cookie_store()->GetCookieMonster(),
676 request.url());
677 }
678
[email protected]9c8ae8c2012-03-09 13:13:35679 return allow;
680}
[email protected]4c219e22012-05-05 19:41:04681
682bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
[email protected]650b2d52013-02-10 03:41:45683 const base::FilePath& path) const {
[email protected]4c219e22012-05-05 19:41:04684 if (g_allow_file_access_)
685 return true;
686
[email protected]d8e4f132012-09-06 04:28:05687#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
688 return true;
689#else
[email protected]4c219e22012-05-05 19:41:04690#if defined(OS_CHROMEOS)
[email protected]d8e4f132012-09-06 04:28:05691 // If we're running Chrome for ChromeOS on Linux, we want to allow file
692 // access.
[email protected]49c4cf852013-09-27 19:28:24693 if (!base::SysInfo::IsRunningOnChromeOS() ||
[email protected]288538482012-09-06 21:09:35694 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
[email protected]d8e4f132012-09-06 04:28:05695 return true;
[email protected]288538482012-09-06 21:09:35696 }
[email protected]d8e4f132012-09-06 04:28:05697
698 // Use a whitelist to only allow access to files residing in the list of
699 // directories below.
[email protected]4c219e22012-05-05 19:41:04700 static const char* const kLocalAccessWhiteList[] = {
701 "/home/chronos/user/Downloads",
702 "/home/chronos/user/log",
[email protected]4791af43d2014-05-05 13:19:42703 "/home/chronos/user/WebRTC Logs",
[email protected]4c219e22012-05-05 19:41:04704 "/media",
705 "/opt/oem",
706 "/usr/share/chromeos-assets",
707 "/tmp",
708 "/var/log",
709 };
[email protected]ae015e12013-11-04 19:11:33710
[email protected]9e733282014-06-18 16:56:55711 // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under
712 // the profile path ("/home/chronos/user' is a hard link to current primary
713 // logged in profile.) For the support of multi-profile sessions, we are
714 // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such
715 // access.
[email protected]ae015e12013-11-04 19:11:33716 if (!profile_path_.empty()) {
717 const base::FilePath downloads = profile_path_.AppendASCII("Downloads");
718 if (downloads == path.StripTrailingSeparators() || downloads.IsParent(path))
719 return true;
[email protected]9e733282014-06-18 16:56:55720 const base::FilePath webrtc_logs = profile_path_.AppendASCII("WebRTC Logs");
721 if (webrtc_logs == path.StripTrailingSeparators() ||
722 webrtc_logs.IsParent(path)) {
723 return true;
724 }
[email protected]ae015e12013-11-04 19:11:33725 }
[email protected]d8e4f132012-09-06 04:28:05726#elif defined(OS_ANDROID)
727 // Access to files in external storage is allowed.
[email protected]650b2d52013-02-10 03:41:45728 base::FilePath external_storage_path;
[email protected]d8e4f132012-09-06 04:28:05729 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path);
730 if (external_storage_path.IsParent(path))
[email protected]4c219e22012-05-05 19:41:04731 return true;
732
[email protected]d8e4f132012-09-06 04:28:05733 // Whitelist of other allowed directories.
734 static const char* const kLocalAccessWhiteList[] = {
735 "/sdcard",
736 "/mnt/sdcard",
737 };
738#endif
739
[email protected]4c219e22012-05-05 19:41:04740 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
[email protected]650b2d52013-02-10 03:41:45741 const base::FilePath white_listed_path(kLocalAccessWhiteList[i]);
742 // base::FilePath::operator== should probably handle trailing separators.
[email protected]4c219e22012-05-05 19:41:04743 if (white_listed_path == path.StripTrailingSeparators() ||
744 white_listed_path.IsParent(path)) {
745 return true;
746 }
747 }
[email protected]d8e4f132012-09-06 04:28:05748
[email protected]288538482012-09-06 21:09:35749 DVLOG(1) << "File access denied - " << path.value().c_str();
[email protected]4c219e22012-05-05 19:41:04750 return false;
[email protected]d8e4f132012-09-06 04:28:05751#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:04752}
[email protected]a1d4ab072012-06-07 13:21:15753
754bool ChromeNetworkDelegate::OnCanThrottleRequest(
755 const net::URLRequest& request) const {
[email protected]84b7a552014-07-19 04:52:06756#if defined(ENABLE_EXTENSIONS)
[email protected]4a2b6232014-06-19 08:44:14757 if (g_never_throttle_requests_)
[email protected]a1d4ab072012-06-07 13:21:15758 return false;
[email protected]c4a7df82012-08-09 22:48:46759 return request.first_party_for_cookies().scheme() ==
[email protected]885c0e92012-11-13 20:27:42760 extensions::kExtensionScheme;
[email protected]84b7a552014-07-19 04:52:06761#else
762 return false;
763#endif
[email protected]a1d4ab072012-06-07 13:21:15764}
[email protected]aa28181e2012-06-13 00:53:58765
[email protected]e6d017652013-05-17 18:01:40766bool ChromeNetworkDelegate::OnCanEnablePrivacyMode(
767 const GURL& url,
768 const GURL& first_party_for_cookies) const {
769 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02770 if (!cookie_settings_.get())
[email protected]e6d017652013-05-17 18:01:40771 return false;
772
773 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed(
774 url, first_party_for_cookies);
775 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed(
776 url, first_party_for_cookies);
777 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed);
778 return privacy_mode;
779}
780
[email protected]aa28181e2012-06-13 00:53:58781int ChromeNetworkDelegate::OnBeforeSocketStreamConnect(
782 net::SocketStream* socket,
783 const net::CompletionCallback& callback) {
784#if defined(ENABLE_CONFIGURATION_POLICY)
785 if (url_blacklist_manager_ &&
786 url_blacklist_manager_->IsURLBlocked(socket->url())) {
787 // URL access blocked by policy.
[email protected]aa28181e2012-06-13 00:53:58788 socket->net_log()->AddEvent(
[email protected]2fa08912012-06-14 20:56:26789 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
790 net::NetLog::StringCallback("url",
791 &socket->url().possibly_invalid_spec()));
[email protected]91468a92013-03-06 17:21:55792 return net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]aa28181e2012-06-13 00:53:58793 }
794#endif
795 return net::OK;
796}
[email protected]5a07c192012-07-30 20:18:22797
[email protected]7a299a92012-10-24 23:54:50798void ChromeNetworkDelegate::AccumulateContentLength(
[email protected]b7796462013-12-12 19:42:34799 int64 received_content_length,
800 int64 original_content_length,
[email protected]a0a06932014-04-14 21:23:42801 data_reduction_proxy::DataReductionProxyRequestType request_type) {
[email protected]7a299a92012-10-24 23:54:50802 DCHECK_GE(received_content_length, 0);
803 DCHECK_GE(original_content_length, 0);
804 StoreAccumulatedContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41805 original_content_length,
[email protected]a0a06932014-04-14 21:23:42806 request_type,
[email protected]b7796462013-12-12 19:42:34807 reinterpret_cast<Profile*>(profile_));
[email protected]7a299a92012-10-24 23:54:50808 received_content_length_ += received_content_length;
809 original_content_length_ += original_content_length;
810}