blob: 6ef937414ede7db9d576657e8456e546a1cd4ba0 [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]1988e1c2013-02-28 20:27:4219#include "base/strings/string_split.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]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]a1d4ab072012-06-07 13:21:1533#include "chrome/common/url_constants.h"
[email protected]597a1ab2014-06-26 08:12:2734#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
[email protected]a0a06932014-04-14 21:23:4235#include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h"
[email protected]d8fc4722014-06-13 13:17:1536#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
37#include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.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]8e44a5b02014-06-19 19:03:2440#include "components/google/core/browser/google_util.h"
[email protected]c38831a12011-10-28 12:44:4941#include "content/public/browser/browser_thread.h"
[email protected]9dfed872013-12-30 23:08:5642#include "content/public/browser/render_frame_host.h"
[email protected]9c1662b2012-03-06 15:44:3343#include "content/public/browser/render_view_host.h"
[email protected]9c8ae8c2012-03-09 13:13:3544#include "content/public/browser/resource_request_info.h"
[email protected]885c0e92012-11-13 20:27:4245#include "extensions/common/constants.h"
[email protected]82b42302011-04-20 16:28:1646#include "net/base/host_port_pair.h"
[email protected]8202d0c2011-02-23 08:31:1447#include "net/base/net_errors.h"
[email protected]6a5f77c32011-09-04 19:19:5948#include "net/base/net_log.h"
[email protected]5b9bc352012-07-18 13:13:3449#include "net/cookies/canonical_cookie.h"
50#include "net/cookies/cookie_options.h"
[email protected]ac039522010-06-15 16:39:4451#include "net/http/http_request_headers.h"
[email protected]48944382011-04-23 13:28:1652#include "net/http/http_response_headers.h"
[email protected]597a1ab2014-06-26 08:12:2753#include "net/proxy/proxy_info.h"
54#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]631bb742011-11-02 11:29:3975using content::BrowserThread;
[email protected]eaabba22012-03-07 15:02:1176using content::RenderViewHost;
[email protected]ea114722012-03-12 01:11:2577using content::ResourceRequestInfo;
[email protected]7491ad02014-07-05 19:10:0778using content::ResourceType;
[email protected]631bb742011-11-02 11:29:3979
[email protected]d8e4f132012-09-06 04:28:0580// By default we don't allow access to all file:// urls on ChromeOS and
81// Android.
82#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:0483bool ChromeNetworkDelegate::g_allow_file_access_ = false;
84#else
85bool ChromeNetworkDelegate::g_allow_file_access_ = true;
86#endif
87
[email protected]c4a7df82012-08-09 22:48:4688// This remains false unless the --disable-extensions-http-throttling
89// flag is passed to the browser.
90bool ChromeNetworkDelegate::g_never_throttle_requests_ = false;
91
[email protected]d05ef99c2011-02-01 21:38:1692namespace {
93
[email protected]9d8cfb682012-09-13 16:48:0494const char kDNTHeader[] = "DNT";
95
[email protected]d1208ba32012-11-08 11:10:3396// Returns whether a URL parameter, |first_parameter| (e.g. foo=bar), has the
97// same key as the the |second_parameter| (e.g. foo=baz). Both parameters
98// must be in key=value form.
99bool HasSameParameterKey(const std::string& first_parameter,
100 const std::string& second_parameter) {
101 DCHECK(second_parameter.find("=") != std::string::npos);
102 // Prefix for "foo=bar" is "foo=".
103 std::string parameter_prefix = second_parameter.substr(
104 0, second_parameter.find("=") + 1);
105 return StartsWithASCII(first_parameter, parameter_prefix, false);
106}
107
108// Examines the query string containing parameters and adds the necessary ones
109// so that SafeSearch is active. |query| is the string to examine and the
110// return value is the |query| string modified such that SafeSearch is active.
111std::string AddSafeSearchParameters(const std::string& query) {
112 std::vector<std::string> new_parameters;
113 std::string safe_parameter = chrome::kSafeSearchSafeParameter;
114 std::string ssui_parameter = chrome::kSafeSearchSsuiParameter;
115
116 std::vector<std::string> parameters;
117 base::SplitString(query, '&', &parameters);
118
119 std::vector<std::string>::iterator it;
120 for (it = parameters.begin(); it < parameters.end(); ++it) {
121 if (!HasSameParameterKey(*it, safe_parameter) &&
122 !HasSameParameterKey(*it, ssui_parameter)) {
123 new_parameters.push_back(*it);
124 }
125 }
126
127 new_parameters.push_back(safe_parameter);
128 new_parameters.push_back(ssui_parameter);
129 return JoinString(new_parameters, '&');
130}
131
132// If |request| is a request to Google Web Search the function
133// enforces that the SafeSearch query parameters are set to active.
134// Sets the query part of |new_url| with the new value of the parameters.
135void ForceGoogleSafeSearch(net::URLRequest* request,
136 GURL* new_url) {
[email protected]c02f79d2013-06-27 21:46:47137 if (!google_util::IsGoogleSearchUrl(request->url()) &&
138 !google_util::IsGoogleHomePageUrl(request->url()))
[email protected]d1208ba32012-11-08 11:10:33139 return;
140
141 std::string query = request->url().query();
142 std::string new_query = AddSafeSearchParameters(query);
143 if (query == new_query)
144 return;
145
146 GURL::Replacements replacements;
147 replacements.SetQueryStr(new_query);
148 *new_url = request->url().ReplaceComponents(replacements);
149}
150
151// Gets called when the extensions finish work on the URL. If the extensions
152// did not do a redirect (so |new_url| is empty) then we enforce the
153// SafeSearch parameters. Otherwise we will get called again after the
154// redirect and we enforce SafeSearch then.
155void ForceGoogleSafeSearchCallbackWrapper(
156 const net::CompletionCallback& callback,
157 net::URLRequest* request,
158 GURL* new_url,
159 int rv) {
160 if (rv == net::OK && new_url->is_empty())
161 ForceGoogleSafeSearch(request, new_url);
162 callback.Run(rv);
163}
164
[email protected]828eab22013-12-10 22:42:38165void UpdateContentLengthPrefs(
166 int received_content_length,
167 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42168 data_reduction_proxy::DataReductionProxyRequestType request_type,
[email protected]b7796462013-12-12 19:42:34169 Profile* profile) {
[email protected]7a299a92012-10-24 23:54:50170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
171 DCHECK_GE(received_content_length, 0);
172 DCHECK_GE(original_content_length, 0);
173
[email protected]a09159a2012-11-29 12:51:48174 // Can be NULL in a unit test.
175 if (!g_browser_process)
176 return;
177
[email protected]7a299a92012-10-24 23:54:50178 PrefService* prefs = g_browser_process->local_state();
[email protected]a09159a2012-11-29 12:51:48179 if (!prefs)
180 return;
[email protected]7a299a92012-10-24 23:54:50181
[email protected]b7796462013-12-12 19:42:34182 // Ignore off-the-record data.
183 if (!g_browser_process->profile_manager()->IsValidProfile(profile) ||
184 profile->IsOffTheRecord()) {
185 return;
186 }
[email protected]0d36d1e2013-09-24 04:25:28187#if defined(OS_ANDROID)
[email protected]b1d5ed52013-12-18 02:34:56188 // If Android ever goes multi profile, the profile should be passed so that
189 // the browser preference will be taken.
[email protected]0d36d1e2013-09-24 04:25:28190 bool with_data_reduction_proxy_enabled =
[email protected]b1d5ed52013-12-18 02:34:56191 ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean(
[email protected]a0a06932014-04-14 21:23:42192 data_reduction_proxy::prefs::kDataReductionProxyEnabled);
[email protected]0d36d1e2013-09-24 04:25:28193#else
194 bool with_data_reduction_proxy_enabled = false;
[email protected]eac11e12013-03-19 22:04:32195#endif
[email protected]0d36d1e2013-09-24 04:25:28196
[email protected]a0a06932014-04-14 21:23:42197 data_reduction_proxy::UpdateContentLengthPrefs(received_content_length,
198 original_content_length,
199 with_data_reduction_proxy_enabled,
200 request_type, prefs);
[email protected]7a299a92012-10-24 23:54:50201}
202
[email protected]828eab22013-12-10 22:42:38203void StoreAccumulatedContentLength(
204 int received_content_length,
205 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42206 data_reduction_proxy::DataReductionProxyRequestType request_type,
[email protected]b7796462013-12-12 19:42:34207 Profile* profile) {
[email protected]7a299a92012-10-24 23:54:50208 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
209 base::Bind(&UpdateContentLengthPrefs,
[email protected]2db93e42013-08-07 17:40:41210 received_content_length, original_content_length,
[email protected]a0a06932014-04-14 21:23:42211 request_type, profile));
[email protected]7a299a92012-10-24 23:54:50212}
213
214void RecordContentLengthHistograms(
[email protected]f81a5ee2013-06-20 21:08:49215 int64 received_content_length,
216 int64 original_content_length,
217 const base::TimeDelta& freshness_lifetime) {
[email protected]7a299a92012-10-24 23:54:50218 // Add the current resource to these histograms only when a valid
219 // X-Original-Content-Length header is present.
220 if (original_content_length >= 0) {
221 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL",
222 received_content_length);
223 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL",
224 original_content_length);
225 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL",
226 original_content_length - received_content_length);
227 } else {
228 // Presume the original content length is the same as the received content
229 // length if the X-Original-Content-Header is not present.
230 original_content_length = received_content_length;
231 }
232 UMA_HISTOGRAM_COUNTS("Net.HttpContentLength", received_content_length);
233 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLength",
234 original_content_length);
235 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifference",
236 original_content_length - received_content_length);
[email protected]f81a5ee2013-06-20 21:08:49237 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpContentFreshnessLifetime",
238 freshness_lifetime.InSeconds(),
239 base::TimeDelta::FromHours(1).InSeconds(),
240 base::TimeDelta::FromDays(30).InSeconds(),
241 100);
242 if (freshness_lifetime.InSeconds() <= 0)
243 return;
244 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable",
245 received_content_length);
246 if (freshness_lifetime.InHours() < 4)
247 return;
248 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours",
249 received_content_length);
250
251 if (freshness_lifetime.InHours() < 24)
252 return;
253 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours",
254 received_content_length);
[email protected]7a299a92012-10-24 23:54:50255}
256
[email protected]35558812013-12-18 21:58:36257#if defined(OS_ANDROID)
258void RecordPrecacheStatsOnUIThread(const GURL& url,
259 const base::Time& fetch_time, int64 size,
260 bool was_cached, void* profile_id) {
261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
262
263 Profile* profile = reinterpret_cast<Profile*>(profile_id);
264 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) {
265 return;
266 }
267
268 precache::PrecacheManager* precache_manager =
269 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
270 if (!precache_manager) {
271 // This could be NULL if the profile is off the record.
272 return;
273 }
274
275 precache_manager->RecordStatsForFetch(url, fetch_time, size, was_cached);
276}
[email protected]d827e112014-03-31 17:45:05277
278void RecordIOThreadToRequestStartOnUIThread(
279 const base::TimeTicks& request_start) {
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
281 base::TimeDelta request_lag = request_start -
282 g_browser_process->io_thread()->creation_time();
283 UMA_HISTOGRAM_TIMES("Net.IOThreadCreationToHTTPRequestStart", request_lag);
284}
[email protected]35558812013-12-18 21:58:36285#endif // defined(OS_ANDROID)
286
[email protected]d05ef99c2011-02-01 21:38:16287} // namespace
[email protected]ac039522010-06-15 16:39:44288
[email protected]0651b812011-02-24 00:22:50289ChromeNetworkDelegate::ChromeNetworkDelegate(
[email protected]5a38dfd2012-07-23 23:22:10290 extensions::EventRouterForwarder* event_router,
[email protected]a09159a2012-11-29 12:51:48291 BooleanPrefMember* enable_referrers)
[email protected]4a2b6232014-06-19 08:44:14292 : profile_(NULL),
[email protected]6a5f77c32011-09-04 19:19:59293 enable_referrers_(enable_referrers),
[email protected]a09159a2012-11-29 12:51:48294 enable_do_not_track_(NULL),
295 force_google_safe_search_(NULL),
[email protected]4a2b6232014-06-19 08:44:14296#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]a09159a2012-11-29 12:51:48297 url_blacklist_manager_(NULL),
[email protected]4a2b6232014-06-19 08:44:14298#endif
[email protected]45de676a2014-03-18 23:52:02299 domain_reliability_monitor_(NULL),
[email protected]7a299a92012-10-24 23:54:50300 received_content_length_(0),
[email protected]d827e112014-03-31 17:45:05301 original_content_length_(0),
[email protected]28c5d0b72014-05-13 08:19:59302 first_request_(true),
[email protected]d8fc4722014-06-13 13:17:15303 prerender_tracker_(NULL),
[email protected]bceab7f2014-06-25 04:36:20304 data_reduction_proxy_params_(NULL),
[email protected]597a1ab2014-06-26 08:12:27305 data_reduction_proxy_usage_stats_(NULL),
306 data_reduction_proxy_auth_request_handler_(NULL) {
[email protected]0a8db0d2011-04-13 15:15:40307 DCHECK(enable_referrers);
[email protected]4a2b6232014-06-19 08:44:14308 extensions_delegate_.reset(
309 ChromeExtensionsNetworkDelegate::Create(event_router));
[email protected]0651b812011-02-24 00:22:50310}
311
[email protected]ac039522010-06-15 16:39:44312ChromeNetworkDelegate::~ChromeNetworkDelegate() {}
313
[email protected]a09159a2012-11-29 12:51:48314void ChromeNetworkDelegate::set_extension_info_map(
[email protected]38427a12013-11-09 17:34:20315 extensions::InfoMap* extension_info_map) {
[email protected]4a2b6232014-06-19 08:44:14316 extensions_delegate_->set_extension_info_map(extension_info_map);
317}
318
319void ChromeNetworkDelegate::set_profile(void* profile) {
320 profile_ = profile;
321 extensions_delegate_->set_profile(profile);
[email protected]a09159a2012-11-29 12:51:48322}
323
324void ChromeNetworkDelegate::set_cookie_settings(
325 CookieSettings* cookie_settings) {
326 cookie_settings_ = cookie_settings;
327}
328
[email protected]f53b4802012-12-20 17:04:23329void ChromeNetworkDelegate::set_predictor(
330 chrome_browser_net::Predictor* predictor) {
331 connect_interceptor_.reset(
332 new chrome_browser_net::ConnectInterceptor(predictor));
333}
334
[email protected]3620bbc2013-10-05 05:07:23335void ChromeNetworkDelegate::SetEnableClientHints() {
336 client_hints_.reset(new ClientHints());
337 client_hints_->Init();
338}
339
[email protected]c4a7df82012-08-09 22:48:46340// static
[email protected]a1d4ab072012-06-07 13:21:15341void ChromeNetworkDelegate::NeverThrottleRequests() {
[email protected]c4a7df82012-08-09 22:48:46342 g_never_throttle_requests_ = true;
[email protected]a1d4ab072012-06-07 13:21:15343}
344
[email protected]0a8db0d2011-04-13 15:15:40345// static
[email protected]9d8cfb682012-09-13 16:48:04346void ChromeNetworkDelegate::InitializePrefsOnUIThread(
[email protected]0a8db0d2011-04-13 15:15:40347 BooleanPrefMember* enable_referrers,
[email protected]9d8cfb682012-09-13 16:48:04348 BooleanPrefMember* enable_do_not_track,
[email protected]d1208ba32012-11-08 11:10:33349 BooleanPrefMember* force_google_safe_search,
[email protected]0a8db0d2011-04-13 15:15:40350 PrefService* pref_service) {
351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]96a5c342012-12-04 18:14:02352 enable_referrers->Init(prefs::kEnableReferrers, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43353 enable_referrers->MoveToThread(
354 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04355 if (enable_do_not_track) {
[email protected]96a5c342012-12-04 18:14:02356 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43357 enable_do_not_track->MoveToThread(
358 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04359 }
[email protected]d1208ba32012-11-08 11:10:33360 if (force_google_safe_search) {
[email protected]96a5c342012-12-04 18:14:02361 force_google_safe_search->Init(prefs::kForceSafeSearch, pref_service);
[email protected]d1208ba32012-11-08 11:10:33362 force_google_safe_search->MoveToThread(
363 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
364 }
[email protected]0a8db0d2011-04-13 15:15:40365}
366
[email protected]4c219e22012-05-05 19:41:04367// static
368void ChromeNetworkDelegate::AllowAccessToAllFiles() {
369 g_allow_file_access_ = true;
370}
371
[email protected]7a299a92012-10-24 23:54:50372// static
[email protected]cb1078de2013-12-23 20:04:22373base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() {
[email protected]7a299a92012-10-24 23:54:50374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
375 PrefService* prefs = g_browser_process->local_state();
[email protected]a0a06932014-04-14 21:23:42376 int64 total_received = prefs->GetInt64(
377 data_reduction_proxy::prefs::kHttpReceivedContentLength);
378 int64 total_original = prefs->GetInt64(
379 data_reduction_proxy::prefs::kHttpOriginalContentLength);
[email protected]7a299a92012-10-24 23:54:50380
[email protected]cb1078de2013-12-23 20:04:22381 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42382 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
383 dict->SetString("historic_received_content_length",
384 base::Int64ToString(total_received));
385 dict->SetString("historic_original_content_length",
386 base::Int64ToString(total_original));
[email protected]7a299a92012-10-24 23:54:50387 return dict;
388}
389
[email protected]cb1078de2013-12-23 20:04:22390base::Value* ChromeNetworkDelegate::SessionNetworkStatsInfoToValue() const {
391 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42392 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
393 dict->SetString("session_received_content_length",
394 base::Int64ToString(received_content_length_));
395 dict->SetString("session_original_content_length",
396 base::Int64ToString(original_content_length_));
[email protected]7a299a92012-10-24 23:54:50397 return dict;
398}
399
[email protected]4875ba12011-03-30 22:31:51400int ChromeNetworkDelegate::OnBeforeURLRequest(
[email protected]4c76d7c2011-04-15 19:14:12401 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47402 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12403 GURL* new_url) {
[email protected]d827e112014-03-31 17:45:05404#if defined(OS_ANDROID)
405 // This UMA tracks the time to the first user-initiated request start, so
406 // only non-null profiles are considered.
407 if (first_request_ && profile_) {
408 bool record_timing = true;
[email protected]bec6a992014-06-19 01:03:21409 if (data_reduction_proxy_params_) {
410 record_timing =
411 (request->url() != data_reduction_proxy_params_->probe_url()) &&
412 (request->url() != data_reduction_proxy_params_->warmup_url());
413 }
[email protected]d827e112014-03-31 17:45:05414 if (record_timing) {
415 first_request_ = false;
416 net::LoadTimingInfo timing_info;
417 request->GetLoadTimingInfo(&timing_info);
418 BrowserThread::PostTask(
419 BrowserThread::UI, FROM_HERE,
420 base::Bind(&RecordIOThreadToRequestStartOnUIThread,
421 timing_info.request_start));
422 }
423 }
424#endif // defined(OS_ANDROID)
425
[email protected]3e598ff12011-09-06 11:22:34426#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]6a5f77c32011-09-04 19:19:59427 // TODO(joaodasilva): This prevents extensions from seeing URLs that are
428 // blocked. However, an extension might redirect the request to another URL,
429 // which is not blocked.
[email protected]cb85f8e52014-04-08 11:44:40430 int error = net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]6a5f77c32011-09-04 19:19:59431 if (url_blacklist_manager_ &&
[email protected]cb85f8e52014-04-08 11:44:40432 url_blacklist_manager_->IsRequestBlocked(*request, &error)) {
[email protected]6a5f77c32011-09-04 19:19:59433 // URL access blocked by policy.
[email protected]6a5f77c32011-09-04 19:19:59434 request->net_log().AddEvent(
[email protected]2fa08912012-06-14 20:56:26435 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
436 net::NetLog::StringCallback("url",
437 &request->url().possibly_invalid_spec()));
[email protected]cb85f8e52014-04-08 11:44:40438 return error;
[email protected]6a5f77c32011-09-04 19:19:59439 }
[email protected]3e598ff12011-09-06 11:22:34440#endif
[email protected]6a5f77c32011-09-04 19:19:59441
[email protected]4a2b6232014-06-19 08:44:14442 extensions_delegate_->ForwardStartRequestStatus(request);
[email protected]6baff0b52012-03-06 01:30:18443
[email protected]0a8db0d2011-04-13 15:15:40444 if (!enable_referrers_->GetValue())
[email protected]99ecf6e2013-04-10 22:46:13445 request->SetReferrer(std::string());
[email protected]9d8cfb682012-09-13 16:48:04446 if (enable_do_not_track_ && enable_do_not_track_->GetValue())
447 request->SetExtraRequestHeaderByName(kDNTHeader, "1", true /* override */);
[email protected]d1208ba32012-11-08 11:10:33448
[email protected]3620bbc2013-10-05 05:07:23449 if (client_hints_) {
450 request->SetExtraRequestHeaderByName(
451 ClientHints::kDevicePixelRatioHeader,
452 client_hints_->GetDevicePixelRatioHeader(), true);
453 }
454
[email protected]d1208ba32012-11-08 11:10:33455 bool force_safe_search = force_google_safe_search_ &&
456 force_google_safe_search_->GetValue();
457
458 net::CompletionCallback wrapped_callback = callback;
459 if (force_safe_search) {
460 wrapped_callback = base::Bind(&ForceGoogleSafeSearchCallbackWrapper,
461 callback,
462 base::Unretained(request),
463 base::Unretained(new_url));
464 }
465
[email protected]4a2b6232014-06-19 08:44:14466 int rv = extensions_delegate_->OnBeforeURLRequest(
467 request, wrapped_callback, new_url);
[email protected]d1208ba32012-11-08 11:10:33468
469 if (force_safe_search && rv == net::OK && new_url->is_empty())
470 ForceGoogleSafeSearch(request, new_url);
471
[email protected]f53b4802012-12-20 17:04:23472 if (connect_interceptor_)
473 connect_interceptor_->WitnessURLRequest(request);
474
[email protected]d1208ba32012-11-08 11:10:33475 return rv;
[email protected]d05ef99c2011-02-01 21:38:16476}
477
[email protected]4875ba12011-03-30 22:31:51478int ChromeNetworkDelegate::OnBeforeSendHeaders(
[email protected]636eccd2011-06-28 12:28:01479 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47480 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12481 net::HttpRequestHeaders* headers) {
[email protected]186468f2013-10-24 02:44:11482 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest");
[email protected]4a2b6232014-06-19 08:44:14483 return extensions_delegate_->OnBeforeSendHeaders(request, callback, headers);
[email protected]ac039522010-06-15 16:39:44484}
[email protected]8202d0c2011-02-23 08:31:14485
[email protected]597a1ab2014-06-26 08:12:27486void ChromeNetworkDelegate::OnBeforeSendProxyHeaders(
487 net::URLRequest* request,
488 const net::ProxyInfo& proxy_info,
489 net::HttpRequestHeaders* headers) {
490 if (data_reduction_proxy_auth_request_handler_) {
491 data_reduction_proxy_auth_request_handler_->MaybeAddRequestHeader(
492 request, proxy_info.proxy_server(), headers);
493 }
494}
495
[email protected]5796dc942011-07-14 19:26:10496void ChromeNetworkDelegate::OnSendHeaders(
497 net::URLRequest* request,
[email protected]783573b2011-05-13 11:05:15498 const net::HttpRequestHeaders& headers) {
[email protected]4a2b6232014-06-19 08:44:14499 extensions_delegate_->OnSendHeaders(request, headers);
[email protected]82b42302011-04-20 16:28:16500}
501
[email protected]ea8141e2011-10-05 13:12:51502int ChromeNetworkDelegate::OnHeadersReceived(
503 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47504 const net::CompletionCallback& callback,
[email protected]507af8f2012-10-20 00:42:32505 const net::HttpResponseHeaders* original_response_headers,
[email protected]5f714132014-03-26 10:41:16506 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
507 GURL* allowed_unsafe_redirect_url) {
[email protected]d8fc4722014-06-13 13:17:15508 if (data_reduction_proxy::MaybeBypassProxyAndPrepareToRetry(
509 data_reduction_proxy_params_,
510 request,
511 original_response_headers,
512 override_response_headers)) {
513 return net::OK;
514 }
515
[email protected]4a2b6232014-06-19 08:44:14516 return extensions_delegate_->OnHeadersReceived(
[email protected]5f714132014-03-26 10:41:16517 request,
518 callback,
519 original_response_headers,
520 override_response_headers,
521 allowed_unsafe_redirect_url);
[email protected]ea8141e2011-10-05 13:12:51522}
523
[email protected]31b2e5f2011-04-20 16:58:32524void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
525 const GURL& new_location) {
[email protected]45de676a2014-03-18 23:52:02526 if (domain_reliability_monitor_)
527 domain_reliability_monitor_->OnBeforeRedirect(request);
[email protected]4a2b6232014-06-19 08:44:14528 extensions_delegate_->OnBeforeRedirect(request, new_location);
[email protected]31b2e5f2011-04-20 16:58:32529}
530
531
[email protected]8202d0c2011-02-23 08:31:14532void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
[email protected]186468f2013-10-24 02:44:11533 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "ResponseStarted");
[email protected]4a2b6232014-06-19 08:44:14534 extensions_delegate_->OnResponseStarted(request);
[email protected]8202d0c2011-02-23 08:31:14535}
536
[email protected]8523ba52011-05-22 19:00:58537void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
538 int bytes_read) {
[email protected]186468f2013-10-24 02:44:11539 TRACE_EVENT_ASYNC_STEP_PAST1("net", "URLRequest", &request, "DidRead",
540 "bytes_read", bytes_read);
[email protected]6f4b4b42012-08-27 21:59:07541 performance_monitor::PerformanceMonitor::GetInstance()->BytesReadOnIOThread(
542 request, bytes_read);
543
[email protected]44879ed2012-04-06 01:11:02544#if defined(ENABLE_TASK_MANAGER)
[email protected]17df9e7c2014-02-13 03:49:29545 // This is not completely accurate, but as a first approximation ignore
546 // requests that are served from the cache. See bug 330931 for more info.
547 if (!request.was_cached())
548 TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read);
[email protected]44879ed2012-04-06 01:11:02549#endif // defined(ENABLE_TASK_MANAGER)
[email protected]8523ba52011-05-22 19:00:58550}
551
[email protected]9045b8822012-01-13 20:35:35552void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
553 bool started) {
[email protected]bceab7f2014-06-25 04:36:20554 if (data_reduction_proxy_usage_stats_)
555 data_reduction_proxy_usage_stats_->OnUrlRequestCompleted(request, started);
556
[email protected]4aca5db2013-08-17 00:51:56557 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request);
[email protected]2756a8e2012-09-07 18:24:29558 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
[email protected]7a299a92012-10-24 23:54:50559 // For better accuracy, we use the actual bytes read instead of the length
560 // specified with the Content-Length header, which may be inaccurate,
561 // or missing, as is the case with chunked encoding.
562 int64 received_content_length = request->received_response_content_length();
563
[email protected]35558812013-12-18 21:58:36564#if defined(OS_ANDROID)
565 if (precache::PrecacheManager::IsPrecachingEnabled()) {
566 // Record precache metrics when a fetch is completed successfully, if
567 // precaching is enabled.
568 BrowserThread::PostTask(
569 BrowserThread::UI, FROM_HERE,
570 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(),
571 base::Time::Now(), received_content_length,
572 request->was_cached(), profile_));
573 }
574#endif // defined(OS_ANDROID)
575
[email protected]7a299a92012-10-24 23:54:50576 // Only record for http or https urls.
577 bool is_http = request->url().SchemeIs("http");
578 bool is_https = request->url().SchemeIs("https");
579
580 if (!request->was_cached() && // Don't record cached content
581 received_content_length && // Zero-byte responses aren't useful.
582 (is_http || is_https)) { // Only record for HTTP or HTTPS urls.
583 int64 original_content_length =
584 request->response_info().headers->GetInt64HeaderValue(
585 "x-original-content-length");
[email protected]a0a06932014-04-14 21:23:42586 data_reduction_proxy::DataReductionProxyRequestType request_type =
587 data_reduction_proxy::GetDataReductionProxyRequestType(request);
[email protected]2db93e42013-08-07 17:40:41588
[email protected]f81a5ee2013-06-20 21:08:49589 base::TimeDelta freshness_lifetime =
590 request->response_info().headers->GetFreshnessLifetime(
591 request->response_info().response_time);
[email protected]828eab22013-12-10 22:42:38592 int64 adjusted_original_content_length =
[email protected]a0a06932014-04-14 21:23:42593 data_reduction_proxy::GetAdjustedOriginalContentLength(
594 request_type, original_content_length,
[email protected]828eab22013-12-10 22:42:38595 received_content_length);
[email protected]7a299a92012-10-24 23:54:50596 AccumulateContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41597 adjusted_original_content_length,
[email protected]a0a06932014-04-14 21:23:42598 request_type);
[email protected]7a299a92012-10-24 23:54:50599 RecordContentLengthHistograms(received_content_length,
[email protected]f81a5ee2013-06-20 21:08:49600 original_content_length,
601 freshness_lifetime);
[email protected]7a299a92012-10-24 23:54:50602 DVLOG(2) << __FUNCTION__
603 << " received content length: " << received_content_length
604 << " original content length: " << original_content_length
605 << " url: " << request->url();
606 }
607
[email protected]4a2b6232014-06-19 08:44:14608 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01609 } else if (request->status().status() == net::URLRequestStatus::FAILED ||
610 request->status().status() == net::URLRequestStatus::CANCELED) {
[email protected]4a2b6232014-06-19 08:44:14611 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01612 } else {
613 NOTREACHED();
[email protected]48944382011-04-23 13:28:16614 }
[email protected]45de676a2014-03-18 23:52:02615 if (domain_reliability_monitor_)
616 domain_reliability_monitor_->OnCompleted(request, started);
[email protected]4a2b6232014-06-19 08:44:14617 extensions_delegate_->ForwardProxyErrors(request);
618 extensions_delegate_->ForwardDoneRequestStatus(request);
[email protected]8202d0c2011-02-23 08:31:14619}
[email protected]4b50cb52011-03-10 00:29:37620
[email protected]4875ba12011-03-30 22:31:51621void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
[email protected]4a2b6232014-06-19 08:44:14622 extensions_delegate_->OnURLRequestDestroyed(request);
[email protected]4875ba12011-03-30 22:31:51623}
624
[email protected]82a37672011-05-03 12:02:41625void ChromeNetworkDelegate::OnPACScriptError(int line_number,
[email protected]439f1e32013-12-09 20:09:09626 const base::string16& error) {
[email protected]4a2b6232014-06-19 08:44:14627 extensions_delegate_->OnPACScriptError(line_number, error);
[email protected]82a37672011-05-03 12:02:41628}
[email protected]7efc582d2011-08-03 20:46:35629
[email protected]c2911d72011-10-03 22:16:36630net::NetworkDelegate::AuthRequiredResponse
631ChromeNetworkDelegate::OnAuthRequired(
[email protected]7efc582d2011-08-03 20:46:35632 net::URLRequest* request,
[email protected]c2911d72011-10-03 22:16:36633 const net::AuthChallengeInfo& auth_info,
634 const AuthCallback& callback,
635 net::AuthCredentials* credentials) {
[email protected]4a2b6232014-06-19 08:44:14636 return extensions_delegate_->OnAuthRequired(
637 request, auth_info, callback, credentials);
[email protected]7efc582d2011-08-03 20:46:35638}
[email protected]9c8ae8c2012-03-09 13:13:35639
[email protected]4c219e22012-05-05 19:41:04640bool ChromeNetworkDelegate::OnCanGetCookies(
641 const net::URLRequest& request,
[email protected]9c8ae8c2012-03-09 13:13:35642 const net::CookieList& cookie_list) {
643 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02644 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35645 return true;
646
647 bool allow = cookie_settings_->IsReadingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04648 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35649
650 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16651 int render_frame_id = -1;
[email protected]f7fa5b62014-03-19 15:20:06652
653 // |is_for_blocking_resource| indicates whether the cookies read were for a
654 // blocking resource (eg script, css). It is only temporarily added for
655 // diagnostic purposes, per bug 353678. Will be removed again once data
656 // collection is finished.
657 bool is_for_blocking_resource = false;
658 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
659 if (info && ((!info->IsAsync()) ||
660 info->GetResourceType() == ResourceType::STYLESHEET ||
661 info->GetResourceType() == ResourceType::SCRIPT)) {
662 is_for_blocking_resource = true;
663 }
664
[email protected]f3add922013-12-20 23:17:16665 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
666 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35667 BrowserThread::PostTask(
668 BrowserThread::UI, FROM_HERE,
669 base::Bind(&TabSpecificContentSettings::CookiesRead,
[email protected]f3add922013-12-20 23:17:16670 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04671 request.url(), request.first_party_for_cookies(),
[email protected]f7fa5b62014-03-19 15:20:06672 cookie_list, !allow, is_for_blocking_resource));
[email protected]9c8ae8c2012-03-09 13:13:35673 }
674
675 return allow;
676}
677
[email protected]4c219e22012-05-05 19:41:04678bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
679 const std::string& cookie_line,
680 net::CookieOptions* options) {
[email protected]9c8ae8c2012-03-09 13:13:35681 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02682 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35683 return true;
684
685 bool allow = cookie_settings_->IsSettingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04686 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35687
[email protected]9c8ae8c2012-03-09 13:13:35688 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16689 int render_frame_id = -1;
690 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
691 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35692 BrowserThread::PostTask(
693 BrowserThread::UI, FROM_HERE,
694 base::Bind(&TabSpecificContentSettings::CookieChanged,
[email protected]f3add922013-12-20 23:17:16695 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04696 request.url(), request.first_party_for_cookies(),
[email protected]fd473d12012-04-05 11:38:43697 cookie_line, *options, !allow));
[email protected]9c8ae8c2012-03-09 13:13:35698 }
699
[email protected]28c5d0b72014-05-13 08:19:59700 if (prerender_tracker_) {
701 prerender_tracker_->OnCookieChangedForURL(
702 render_process_id,
703 request.context()->cookie_store()->GetCookieMonster(),
704 request.url());
705 }
706
[email protected]9c8ae8c2012-03-09 13:13:35707 return allow;
708}
[email protected]4c219e22012-05-05 19:41:04709
710bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
[email protected]650b2d52013-02-10 03:41:45711 const base::FilePath& path) const {
[email protected]4c219e22012-05-05 19:41:04712 if (g_allow_file_access_)
713 return true;
714
[email protected]d8e4f132012-09-06 04:28:05715#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
716 return true;
717#else
[email protected]4c219e22012-05-05 19:41:04718#if defined(OS_CHROMEOS)
[email protected]d8e4f132012-09-06 04:28:05719 // If we're running Chrome for ChromeOS on Linux, we want to allow file
720 // access.
[email protected]49c4cf852013-09-27 19:28:24721 if (!base::SysInfo::IsRunningOnChromeOS() ||
[email protected]288538482012-09-06 21:09:35722 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
[email protected]d8e4f132012-09-06 04:28:05723 return true;
[email protected]288538482012-09-06 21:09:35724 }
[email protected]d8e4f132012-09-06 04:28:05725
726 // Use a whitelist to only allow access to files residing in the list of
727 // directories below.
[email protected]4c219e22012-05-05 19:41:04728 static const char* const kLocalAccessWhiteList[] = {
729 "/home/chronos/user/Downloads",
730 "/home/chronos/user/log",
[email protected]4791af43d2014-05-05 13:19:42731 "/home/chronos/user/WebRTC Logs",
[email protected]4c219e22012-05-05 19:41:04732 "/media",
733 "/opt/oem",
734 "/usr/share/chromeos-assets",
735 "/tmp",
736 "/var/log",
737 };
[email protected]ae015e12013-11-04 19:11:33738
[email protected]9e733282014-06-18 16:56:55739 // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under
740 // the profile path ("/home/chronos/user' is a hard link to current primary
741 // logged in profile.) For the support of multi-profile sessions, we are
742 // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such
743 // access.
[email protected]ae015e12013-11-04 19:11:33744 if (!profile_path_.empty()) {
745 const base::FilePath downloads = profile_path_.AppendASCII("Downloads");
746 if (downloads == path.StripTrailingSeparators() || downloads.IsParent(path))
747 return true;
[email protected]9e733282014-06-18 16:56:55748 const base::FilePath webrtc_logs = profile_path_.AppendASCII("WebRTC Logs");
749 if (webrtc_logs == path.StripTrailingSeparators() ||
750 webrtc_logs.IsParent(path)) {
751 return true;
752 }
[email protected]ae015e12013-11-04 19:11:33753 }
[email protected]d8e4f132012-09-06 04:28:05754#elif defined(OS_ANDROID)
755 // Access to files in external storage is allowed.
[email protected]650b2d52013-02-10 03:41:45756 base::FilePath external_storage_path;
[email protected]d8e4f132012-09-06 04:28:05757 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path);
758 if (external_storage_path.IsParent(path))
[email protected]4c219e22012-05-05 19:41:04759 return true;
760
[email protected]d8e4f132012-09-06 04:28:05761 // Whitelist of other allowed directories.
762 static const char* const kLocalAccessWhiteList[] = {
763 "/sdcard",
764 "/mnt/sdcard",
765 };
766#endif
767
[email protected]4c219e22012-05-05 19:41:04768 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
[email protected]650b2d52013-02-10 03:41:45769 const base::FilePath white_listed_path(kLocalAccessWhiteList[i]);
770 // base::FilePath::operator== should probably handle trailing separators.
[email protected]4c219e22012-05-05 19:41:04771 if (white_listed_path == path.StripTrailingSeparators() ||
772 white_listed_path.IsParent(path)) {
773 return true;
774 }
775 }
[email protected]d8e4f132012-09-06 04:28:05776
[email protected]288538482012-09-06 21:09:35777 DVLOG(1) << "File access denied - " << path.value().c_str();
[email protected]4c219e22012-05-05 19:41:04778 return false;
[email protected]d8e4f132012-09-06 04:28:05779#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:04780}
[email protected]a1d4ab072012-06-07 13:21:15781
782bool ChromeNetworkDelegate::OnCanThrottleRequest(
783 const net::URLRequest& request) const {
[email protected]4a2b6232014-06-19 08:44:14784 if (g_never_throttle_requests_)
[email protected]a1d4ab072012-06-07 13:21:15785 return false;
[email protected]c4a7df82012-08-09 22:48:46786 return request.first_party_for_cookies().scheme() ==
[email protected]885c0e92012-11-13 20:27:42787 extensions::kExtensionScheme;
[email protected]a1d4ab072012-06-07 13:21:15788}
[email protected]aa28181e2012-06-13 00:53:58789
[email protected]e6d017652013-05-17 18:01:40790bool ChromeNetworkDelegate::OnCanEnablePrivacyMode(
791 const GURL& url,
792 const GURL& first_party_for_cookies) const {
793 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02794 if (!cookie_settings_.get())
[email protected]e6d017652013-05-17 18:01:40795 return false;
796
797 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed(
798 url, first_party_for_cookies);
799 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed(
800 url, first_party_for_cookies);
801 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed);
802 return privacy_mode;
803}
804
[email protected]aa28181e2012-06-13 00:53:58805int ChromeNetworkDelegate::OnBeforeSocketStreamConnect(
806 net::SocketStream* socket,
807 const net::CompletionCallback& callback) {
808#if defined(ENABLE_CONFIGURATION_POLICY)
809 if (url_blacklist_manager_ &&
810 url_blacklist_manager_->IsURLBlocked(socket->url())) {
811 // URL access blocked by policy.
[email protected]aa28181e2012-06-13 00:53:58812 socket->net_log()->AddEvent(
[email protected]2fa08912012-06-14 20:56:26813 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
814 net::NetLog::StringCallback("url",
815 &socket->url().possibly_invalid_spec()));
[email protected]91468a92013-03-06 17:21:55816 return net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]aa28181e2012-06-13 00:53:58817 }
818#endif
819 return net::OK;
820}
[email protected]5a07c192012-07-30 20:18:22821
[email protected]7a299a92012-10-24 23:54:50822void ChromeNetworkDelegate::AccumulateContentLength(
[email protected]b7796462013-12-12 19:42:34823 int64 received_content_length,
824 int64 original_content_length,
[email protected]a0a06932014-04-14 21:23:42825 data_reduction_proxy::DataReductionProxyRequestType request_type) {
[email protected]7a299a92012-10-24 23:54:50826 DCHECK_GE(received_content_length, 0);
827 DCHECK_GE(original_content_length, 0);
828 StoreAccumulatedContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41829 original_content_length,
[email protected]a0a06932014-04-14 21:23:42830 request_type,
[email protected]b7796462013-12-12 19:42:34831 reinterpret_cast<Profile*>(profile_));
[email protected]7a299a92012-10-24 23:54:50832 received_content_length_ += received_content_length;
833 original_content_length_ += original_content_length;
834}