blob: 747f670bfc10b753149a2e07a67728e818375ee4 [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]aa84a7e2012-03-15 21:29:0625#include "chrome/browser/extensions/api/proxy/proxy_api.h"
[email protected]2b33dcd02012-03-18 01:34:1626#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]5a38dfd2012-07-23 23:22:1027#include "chrome/browser/extensions/event_router_forwarder.h"
[email protected]d1208ba32012-11-08 11:10:3328#include "chrome/browser/google/google_util.h"
[email protected]3620bbc2013-10-05 05:07:2329#include "chrome/browser/net/client_hints.h"
[email protected]f53b4802012-12-20 17:04:2330#include "chrome/browser/net/connect_interceptor.h"
[email protected]9a0d6002013-12-19 02:04:2831#include "chrome/browser/net/spdyproxy/data_saving_metrics.h"
[email protected]6f4b4b42012-08-27 21:59:0732#include "chrome/browser/performance_monitor/performance_monitor.h"
[email protected]6baff0b52012-03-06 01:30:1833#include "chrome/browser/profiles/profile_manager.h"
[email protected]8523ba52011-05-22 19:00:5834#include "chrome/browser/task_manager/task_manager.h"
[email protected]0a8db0d2011-04-13 15:15:4035#include "chrome/common/pref_names.h"
[email protected]a1d4ab072012-06-07 13:21:1536#include "chrome/common/url_constants.h"
[email protected]c38831a12011-10-28 12:44:4937#include "content/public/browser/browser_thread.h"
[email protected]9dfed872013-12-30 23:08:5638#include "content/public/browser/render_frame_host.h"
[email protected]9c1662b2012-03-06 15:44:3339#include "content/public/browser/render_view_host.h"
[email protected]9c8ae8c2012-03-09 13:13:3540#include "content/public/browser/resource_request_info.h"
[email protected]59b0e602014-01-30 00:41:2441#include "extensions/browser/extension_system.h"
[email protected]38427a12013-11-09 17:34:2042#include "extensions/browser/info_map.h"
[email protected]98b6d942013-11-10 00:34:0743#include "extensions/browser/process_manager.h"
[email protected]885c0e92012-11-13 20:27:4244#include "extensions/common/constants.h"
[email protected]82b42302011-04-20 16:28:1645#include "net/base/host_port_pair.h"
[email protected]8202d0c2011-02-23 08:31:1446#include "net/base/net_errors.h"
[email protected]6a5f77c32011-09-04 19:19:5947#include "net/base/net_log.h"
[email protected]5b9bc352012-07-18 13:13:3448#include "net/cookies/canonical_cookie.h"
49#include "net/cookies/cookie_options.h"
[email protected]ac039522010-06-15 16:39:4450#include "net/http/http_request_headers.h"
[email protected]48944382011-04-23 13:28:1651#include "net/http/http_response_headers.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"
54
[email protected]4c219e22012-05-05 19:41:0455#if defined(OS_CHROMEOS)
[email protected]288538482012-09-06 21:09:3556#include "base/command_line.h"
[email protected]49c4cf852013-09-27 19:28:2457#include "base/sys_info.h"
[email protected]288538482012-09-06 21:09:3558#include "chrome/common/chrome_switches.h"
[email protected]4c219e22012-05-05 19:41:0459#endif
60
[email protected]3e598ff12011-09-06 11:22:3461#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]f522afa2014-01-08 15:36:3662#include "components/policy/core/browser/url_blacklist_manager.h"
[email protected]3e598ff12011-09-06 11:22:3463#endif
64
[email protected]35558812013-12-18 21:58:3665#if defined(OS_ANDROID)
66#include "components/precache/content/precache_manager.h"
67#include "components/precache/content/precache_manager_factory.h"
68#endif
69
[email protected]631bb742011-11-02 11:29:3970using content::BrowserThread;
[email protected]eaabba22012-03-07 15:02:1171using content::RenderViewHost;
[email protected]ea114722012-03-12 01:11:2572using content::ResourceRequestInfo;
[email protected]631bb742011-11-02 11:29:3973
[email protected]d8e4f132012-09-06 04:28:0574// By default we don't allow access to all file:// urls on ChromeOS and
75// Android.
76#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:0477bool ChromeNetworkDelegate::g_allow_file_access_ = false;
78#else
79bool ChromeNetworkDelegate::g_allow_file_access_ = true;
80#endif
81
[email protected]c4a7df82012-08-09 22:48:4682// This remains false unless the --disable-extensions-http-throttling
83// flag is passed to the browser.
84bool ChromeNetworkDelegate::g_never_throttle_requests_ = false;
85
[email protected]d05ef99c2011-02-01 21:38:1686namespace {
87
[email protected]9d8cfb682012-09-13 16:48:0488const char kDNTHeader[] = "DNT";
89
[email protected]8202d0c2011-02-23 08:31:1490// If the |request| failed due to problems with a proxy, forward the error to
91// the proxy extension API.
[email protected]0651b812011-02-24 00:22:5092void ForwardProxyErrors(net::URLRequest* request,
[email protected]5a38dfd2012-07-23 23:22:1093 extensions::EventRouterForwarder* event_router,
[email protected]673514522011-07-13 18:17:1894 void* profile) {
[email protected]8202d0c2011-02-23 08:31:1495 if (request->status().status() == net::URLRequestStatus::FAILED) {
[email protected]d0cc35b2011-09-08 12:02:0596 switch (request->status().error()) {
[email protected]8202d0c2011-02-23 08:31:1497 case net::ERR_PROXY_AUTH_UNSUPPORTED:
98 case net::ERR_PROXY_CONNECTION_FAILED:
99 case net::ERR_TUNNEL_CONNECTION_FAILED:
[email protected]c454fe672012-03-12 21:18:01100 extensions::ProxyEventRouter::GetInstance()->OnProxyError(
[email protected]d0cc35b2011-09-08 12:02:05101 event_router, profile, request->status().error());
[email protected]8202d0c2011-02-23 08:31:14102 }
103 }
104}
105
[email protected]d1208ba32012-11-08 11:10:33106// Returns whether a URL parameter, |first_parameter| (e.g. foo=bar), has the
107// same key as the the |second_parameter| (e.g. foo=baz). Both parameters
108// must be in key=value form.
109bool HasSameParameterKey(const std::string& first_parameter,
110 const std::string& second_parameter) {
111 DCHECK(second_parameter.find("=") != std::string::npos);
112 // Prefix for "foo=bar" is "foo=".
113 std::string parameter_prefix = second_parameter.substr(
114 0, second_parameter.find("=") + 1);
115 return StartsWithASCII(first_parameter, parameter_prefix, false);
116}
117
118// Examines the query string containing parameters and adds the necessary ones
119// so that SafeSearch is active. |query| is the string to examine and the
120// return value is the |query| string modified such that SafeSearch is active.
121std::string AddSafeSearchParameters(const std::string& query) {
122 std::vector<std::string> new_parameters;
123 std::string safe_parameter = chrome::kSafeSearchSafeParameter;
124 std::string ssui_parameter = chrome::kSafeSearchSsuiParameter;
125
126 std::vector<std::string> parameters;
127 base::SplitString(query, '&', &parameters);
128
129 std::vector<std::string>::iterator it;
130 for (it = parameters.begin(); it < parameters.end(); ++it) {
131 if (!HasSameParameterKey(*it, safe_parameter) &&
132 !HasSameParameterKey(*it, ssui_parameter)) {
133 new_parameters.push_back(*it);
134 }
135 }
136
137 new_parameters.push_back(safe_parameter);
138 new_parameters.push_back(ssui_parameter);
139 return JoinString(new_parameters, '&');
140}
141
142// If |request| is a request to Google Web Search the function
143// enforces that the SafeSearch query parameters are set to active.
144// Sets the query part of |new_url| with the new value of the parameters.
145void ForceGoogleSafeSearch(net::URLRequest* request,
146 GURL* new_url) {
[email protected]c02f79d2013-06-27 21:46:47147 if (!google_util::IsGoogleSearchUrl(request->url()) &&
148 !google_util::IsGoogleHomePageUrl(request->url()))
[email protected]d1208ba32012-11-08 11:10:33149 return;
150
151 std::string query = request->url().query();
152 std::string new_query = AddSafeSearchParameters(query);
153 if (query == new_query)
154 return;
155
156 GURL::Replacements replacements;
157 replacements.SetQueryStr(new_query);
158 *new_url = request->url().ReplaceComponents(replacements);
159}
160
161// Gets called when the extensions finish work on the URL. If the extensions
162// did not do a redirect (so |new_url| is empty) then we enforce the
163// SafeSearch parameters. Otherwise we will get called again after the
164// redirect and we enforce SafeSearch then.
165void ForceGoogleSafeSearchCallbackWrapper(
166 const net::CompletionCallback& callback,
167 net::URLRequest* request,
168 GURL* new_url,
169 int rv) {
170 if (rv == net::OK && new_url->is_empty())
171 ForceGoogleSafeSearch(request, new_url);
172 callback.Run(rv);
173}
174
[email protected]6baff0b52012-03-06 01:30:18175enum RequestStatus { REQUEST_STARTED, REQUEST_DONE };
176
[email protected]98b6d942013-11-10 00:34:07177// Notifies the extensions::ProcessManager that a request has started or stopped
[email protected]9dfed872013-12-30 23:08:56178// for a particular RenderFrame.
[email protected]6baff0b52012-03-06 01:30:18179void NotifyEPMRequestStatus(RequestStatus status,
180 void* profile_id,
181 int process_id,
[email protected]9dfed872013-12-30 23:08:56182 int render_frame_id) {
[email protected]6baff0b52012-03-06 01:30:18183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
184 Profile* profile = reinterpret_cast<Profile*>(profile_id);
185 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
186 return;
187
[email protected]98b6d942013-11-10 00:34:07188 extensions::ProcessManager* process_manager =
[email protected]be93bba02012-10-24 16:44:03189 extensions::ExtensionSystem::Get(profile)->process_manager();
[email protected]e5775a52012-03-17 04:59:57190 // This may be NULL in unit tests.
[email protected]98b6d942013-11-10 00:34:07191 if (!process_manager)
[email protected]e5775a52012-03-17 04:59:57192 return;
193
[email protected]6baff0b52012-03-06 01:30:18194 // Will be NULL if the request was not issued on behalf of a renderer (e.g. a
195 // system-level request).
[email protected]9dfed872013-12-30 23:08:56196 content::RenderFrameHost* render_frame_host =
197 content::RenderFrameHost::FromID(process_id, render_frame_id);
198 if (render_frame_host) {
[email protected]6baff0b52012-03-06 01:30:18199 if (status == REQUEST_STARTED) {
[email protected]9dfed872013-12-30 23:08:56200 process_manager->OnNetworkRequestStarted(render_frame_host);
[email protected]6baff0b52012-03-06 01:30:18201 } else if (status == REQUEST_DONE) {
[email protected]9dfed872013-12-30 23:08:56202 process_manager->OnNetworkRequestDone(render_frame_host);
[email protected]6baff0b52012-03-06 01:30:18203 } else {
204 NOTREACHED();
205 }
206 }
207}
208
209void ForwardRequestStatus(
210 RequestStatus status, net::URLRequest* request, void* profile_id) {
[email protected]ea114722012-03-12 01:11:25211 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
212 if (!info)
213 return;
214
[email protected]9dfed872013-12-30 23:08:56215 int process_id, render_frame_id;
216 if (info->GetAssociatedRenderFrame(&process_id, &render_frame_id)) {
[email protected]6baff0b52012-03-06 01:30:18217 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
218 base::Bind(&NotifyEPMRequestStatus,
[email protected]9dfed872013-12-30 23:08:56219 status, profile_id, process_id, render_frame_id));
[email protected]6baff0b52012-03-06 01:30:18220 }
221}
222
[email protected]828eab22013-12-10 22:42:38223void UpdateContentLengthPrefs(
224 int received_content_length,
225 int original_content_length,
[email protected]9a0d6002013-12-19 02:04:28226 spdyproxy::DataReductionRequestType data_reduction_type,
[email protected]b7796462013-12-12 19:42:34227 Profile* profile) {
[email protected]7a299a92012-10-24 23:54:50228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
229 DCHECK_GE(received_content_length, 0);
230 DCHECK_GE(original_content_length, 0);
231
[email protected]a09159a2012-11-29 12:51:48232 // Can be NULL in a unit test.
233 if (!g_browser_process)
234 return;
235
[email protected]7a299a92012-10-24 23:54:50236 PrefService* prefs = g_browser_process->local_state();
[email protected]a09159a2012-11-29 12:51:48237 if (!prefs)
238 return;
[email protected]7a299a92012-10-24 23:54:50239
[email protected]b7796462013-12-12 19:42:34240 // Ignore off-the-record data.
241 if (!g_browser_process->profile_manager()->IsValidProfile(profile) ||
242 profile->IsOffTheRecord()) {
243 return;
244 }
[email protected]0d36d1e2013-09-24 04:25:28245#if defined(OS_ANDROID)
[email protected]b1d5ed52013-12-18 02:34:56246 // If Android ever goes multi profile, the profile should be passed so that
247 // the browser preference will be taken.
[email protected]0d36d1e2013-09-24 04:25:28248 bool with_data_reduction_proxy_enabled =
[email protected]b1d5ed52013-12-18 02:34:56249 ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean(
250 prefs::kSpdyProxyAuthEnabled);
[email protected]0d36d1e2013-09-24 04:25:28251#else
252 bool with_data_reduction_proxy_enabled = false;
[email protected]eac11e12013-03-19 22:04:32253#endif
[email protected]0d36d1e2013-09-24 04:25:28254
[email protected]9a0d6002013-12-19 02:04:28255 spdyproxy::UpdateContentLengthPrefs(received_content_length,
256 original_content_length,
257 with_data_reduction_proxy_enabled,
258 data_reduction_type, prefs);
[email protected]7a299a92012-10-24 23:54:50259}
260
[email protected]828eab22013-12-10 22:42:38261void StoreAccumulatedContentLength(
262 int received_content_length,
263 int original_content_length,
[email protected]9a0d6002013-12-19 02:04:28264 spdyproxy::DataReductionRequestType data_reduction_type,
[email protected]b7796462013-12-12 19:42:34265 Profile* profile) {
[email protected]7a299a92012-10-24 23:54:50266 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
267 base::Bind(&UpdateContentLengthPrefs,
[email protected]2db93e42013-08-07 17:40:41268 received_content_length, original_content_length,
[email protected]b7796462013-12-12 19:42:34269 data_reduction_type, profile));
[email protected]7a299a92012-10-24 23:54:50270}
271
272void RecordContentLengthHistograms(
[email protected]f81a5ee2013-06-20 21:08:49273 int64 received_content_length,
274 int64 original_content_length,
275 const base::TimeDelta& freshness_lifetime) {
[email protected]0d36d1e2013-09-24 04:25:28276#if defined(OS_ANDROID)
[email protected]7a299a92012-10-24 23:54:50277 // Add the current resource to these histograms only when a valid
278 // X-Original-Content-Length header is present.
279 if (original_content_length >= 0) {
280 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL",
281 received_content_length);
282 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL",
283 original_content_length);
284 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL",
285 original_content_length - received_content_length);
286 } else {
287 // Presume the original content length is the same as the received content
288 // length if the X-Original-Content-Header is not present.
289 original_content_length = received_content_length;
290 }
291 UMA_HISTOGRAM_COUNTS("Net.HttpContentLength", received_content_length);
292 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLength",
293 original_content_length);
294 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifference",
295 original_content_length - received_content_length);
[email protected]f81a5ee2013-06-20 21:08:49296 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpContentFreshnessLifetime",
297 freshness_lifetime.InSeconds(),
298 base::TimeDelta::FromHours(1).InSeconds(),
299 base::TimeDelta::FromDays(30).InSeconds(),
300 100);
301 if (freshness_lifetime.InSeconds() <= 0)
302 return;
303 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable",
304 received_content_length);
305 if (freshness_lifetime.InHours() < 4)
306 return;
307 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours",
308 received_content_length);
309
310 if (freshness_lifetime.InHours() < 24)
311 return;
312 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours",
313 received_content_length);
[email protected]0d36d1e2013-09-24 04:25:28314#endif // defined(OS_ANDROID)
[email protected]7a299a92012-10-24 23:54:50315}
316
[email protected]35558812013-12-18 21:58:36317#if defined(OS_ANDROID)
318void RecordPrecacheStatsOnUIThread(const GURL& url,
319 const base::Time& fetch_time, int64 size,
320 bool was_cached, void* profile_id) {
321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
322
323 Profile* profile = reinterpret_cast<Profile*>(profile_id);
324 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) {
325 return;
326 }
327
328 precache::PrecacheManager* precache_manager =
329 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
330 if (!precache_manager) {
331 // This could be NULL if the profile is off the record.
332 return;
333 }
334
335 precache_manager->RecordStatsForFetch(url, fetch_time, size, was_cached);
336}
337#endif // defined(OS_ANDROID)
338
[email protected]d05ef99c2011-02-01 21:38:16339} // namespace
[email protected]ac039522010-06-15 16:39:44340
[email protected]0651b812011-02-24 00:22:50341ChromeNetworkDelegate::ChromeNetworkDelegate(
[email protected]5a38dfd2012-07-23 23:22:10342 extensions::EventRouterForwarder* event_router,
[email protected]a09159a2012-11-29 12:51:48343 BooleanPrefMember* enable_referrers)
[email protected]3ce02412011-03-01 12:01:15344 : event_router_(event_router),
[email protected]a09159a2012-11-29 12:51:48345 profile_(NULL),
[email protected]6a5f77c32011-09-04 19:19:59346 enable_referrers_(enable_referrers),
[email protected]a09159a2012-11-29 12:51:48347 enable_do_not_track_(NULL),
348 force_google_safe_search_(NULL),
349 url_blacklist_manager_(NULL),
[email protected]7a299a92012-10-24 23:54:50350 received_content_length_(0),
351 original_content_length_(0) {
[email protected]4b50cb52011-03-10 00:29:37352 DCHECK(event_router);
[email protected]0a8db0d2011-04-13 15:15:40353 DCHECK(enable_referrers);
[email protected]0651b812011-02-24 00:22:50354}
355
[email protected]ac039522010-06-15 16:39:44356ChromeNetworkDelegate::~ChromeNetworkDelegate() {}
357
[email protected]a09159a2012-11-29 12:51:48358void ChromeNetworkDelegate::set_extension_info_map(
[email protected]38427a12013-11-09 17:34:20359 extensions::InfoMap* extension_info_map) {
[email protected]a09159a2012-11-29 12:51:48360 extension_info_map_ = extension_info_map;
361}
362
363void ChromeNetworkDelegate::set_cookie_settings(
364 CookieSettings* cookie_settings) {
365 cookie_settings_ = cookie_settings;
366}
367
[email protected]f53b4802012-12-20 17:04:23368void ChromeNetworkDelegate::set_predictor(
369 chrome_browser_net::Predictor* predictor) {
370 connect_interceptor_.reset(
371 new chrome_browser_net::ConnectInterceptor(predictor));
372}
373
[email protected]3620bbc2013-10-05 05:07:23374void ChromeNetworkDelegate::SetEnableClientHints() {
375 client_hints_.reset(new ClientHints());
376 client_hints_->Init();
377}
378
[email protected]c4a7df82012-08-09 22:48:46379// static
[email protected]a1d4ab072012-06-07 13:21:15380void ChromeNetworkDelegate::NeverThrottleRequests() {
[email protected]c4a7df82012-08-09 22:48:46381 g_never_throttle_requests_ = true;
[email protected]a1d4ab072012-06-07 13:21:15382}
383
[email protected]0a8db0d2011-04-13 15:15:40384// static
[email protected]9d8cfb682012-09-13 16:48:04385void ChromeNetworkDelegate::InitializePrefsOnUIThread(
[email protected]0a8db0d2011-04-13 15:15:40386 BooleanPrefMember* enable_referrers,
[email protected]9d8cfb682012-09-13 16:48:04387 BooleanPrefMember* enable_do_not_track,
[email protected]d1208ba32012-11-08 11:10:33388 BooleanPrefMember* force_google_safe_search,
[email protected]0a8db0d2011-04-13 15:15:40389 PrefService* pref_service) {
390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]96a5c342012-12-04 18:14:02391 enable_referrers->Init(prefs::kEnableReferrers, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43392 enable_referrers->MoveToThread(
393 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04394 if (enable_do_not_track) {
[email protected]96a5c342012-12-04 18:14:02395 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43396 enable_do_not_track->MoveToThread(
397 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04398 }
[email protected]d1208ba32012-11-08 11:10:33399 if (force_google_safe_search) {
[email protected]96a5c342012-12-04 18:14:02400 force_google_safe_search->Init(prefs::kForceSafeSearch, pref_service);
[email protected]d1208ba32012-11-08 11:10:33401 force_google_safe_search->MoveToThread(
402 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
403 }
[email protected]0a8db0d2011-04-13 15:15:40404}
405
[email protected]4c219e22012-05-05 19:41:04406// static
407void ChromeNetworkDelegate::AllowAccessToAllFiles() {
408 g_allow_file_access_ = true;
409}
410
[email protected]7a299a92012-10-24 23:54:50411// static
[email protected]cb1078de2013-12-23 20:04:22412base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() {
[email protected]7a299a92012-10-24 23:54:50413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
414 PrefService* prefs = g_browser_process->local_state();
415 int64 total_received = prefs->GetInt64(prefs::kHttpReceivedContentLength);
416 int64 total_original = prefs->GetInt64(prefs::kHttpOriginalContentLength);
417
[email protected]cb1078de2013-12-23 20:04:22418 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42419 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
420 dict->SetString("historic_received_content_length",
421 base::Int64ToString(total_received));
422 dict->SetString("historic_original_content_length",
423 base::Int64ToString(total_original));
[email protected]7a299a92012-10-24 23:54:50424 return dict;
425}
426
[email protected]cb1078de2013-12-23 20:04:22427base::Value* ChromeNetworkDelegate::SessionNetworkStatsInfoToValue() const {
428 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42429 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
430 dict->SetString("session_received_content_length",
431 base::Int64ToString(received_content_length_));
432 dict->SetString("session_original_content_length",
433 base::Int64ToString(original_content_length_));
[email protected]7a299a92012-10-24 23:54:50434 return dict;
435}
436
[email protected]4875ba12011-03-30 22:31:51437int ChromeNetworkDelegate::OnBeforeURLRequest(
[email protected]4c76d7c2011-04-15 19:14:12438 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47439 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12440 GURL* new_url) {
[email protected]3e598ff12011-09-06 11:22:34441#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]6a5f77c32011-09-04 19:19:59442 // TODO(joaodasilva): This prevents extensions from seeing URLs that are
443 // blocked. However, an extension might redirect the request to another URL,
444 // which is not blocked.
445 if (url_blacklist_manager_ &&
[email protected]74575252013-03-12 19:58:21446 url_blacklist_manager_->IsRequestBlocked(*request)) {
[email protected]6a5f77c32011-09-04 19:19:59447 // URL access blocked by policy.
[email protected]6a5f77c32011-09-04 19:19:59448 request->net_log().AddEvent(
[email protected]2fa08912012-06-14 20:56:26449 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
450 net::NetLog::StringCallback("url",
451 &request->url().possibly_invalid_spec()));
[email protected]91468a92013-03-06 17:21:55452 return net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]6a5f77c32011-09-04 19:19:59453 }
[email protected]3e598ff12011-09-06 11:22:34454#endif
[email protected]6a5f77c32011-09-04 19:19:59455
[email protected]6baff0b52012-03-06 01:30:18456 ForwardRequestStatus(REQUEST_STARTED, request, profile_);
457
[email protected]0a8db0d2011-04-13 15:15:40458 if (!enable_referrers_->GetValue())
[email protected]99ecf6e2013-04-10 22:46:13459 request->SetReferrer(std::string());
[email protected]9d8cfb682012-09-13 16:48:04460 if (enable_do_not_track_ && enable_do_not_track_->GetValue())
461 request->SetExtraRequestHeaderByName(kDNTHeader, "1", true /* override */);
[email protected]d1208ba32012-11-08 11:10:33462
[email protected]3620bbc2013-10-05 05:07:23463 if (client_hints_) {
464 request->SetExtraRequestHeaderByName(
465 ClientHints::kDevicePixelRatioHeader,
466 client_hints_->GetDevicePixelRatioHeader(), true);
467 }
468
[email protected]d1208ba32012-11-08 11:10:33469 bool force_safe_search = force_google_safe_search_ &&
470 force_google_safe_search_->GetValue();
471
472 net::CompletionCallback wrapped_callback = callback;
473 if (force_safe_search) {
474 wrapped_callback = base::Bind(&ForceGoogleSafeSearchCallbackWrapper,
475 callback,
476 base::Unretained(request),
477 base::Unretained(new_url));
478 }
479
480 int rv = ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest(
481 profile_, extension_info_map_.get(), request, wrapped_callback,
482 new_url);
483
484 if (force_safe_search && rv == net::OK && new_url->is_empty())
485 ForceGoogleSafeSearch(request, new_url);
486
[email protected]f53b4802012-12-20 17:04:23487 if (connect_interceptor_)
488 connect_interceptor_->WitnessURLRequest(request);
489
[email protected]d1208ba32012-11-08 11:10:33490 return rv;
[email protected]d05ef99c2011-02-01 21:38:16491}
492
[email protected]4875ba12011-03-30 22:31:51493int ChromeNetworkDelegate::OnBeforeSendHeaders(
[email protected]636eccd2011-06-28 12:28:01494 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47495 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12496 net::HttpRequestHeaders* headers) {
[email protected]186468f2013-10-24 02:44:11497 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest");
[email protected]4875ba12011-03-30 22:31:51498 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders(
[email protected]673514522011-07-13 18:17:18499 profile_, extension_info_map_.get(), request, callback, headers);
[email protected]ac039522010-06-15 16:39:44500}
[email protected]8202d0c2011-02-23 08:31:14501
[email protected]5796dc942011-07-14 19:26:10502void ChromeNetworkDelegate::OnSendHeaders(
503 net::URLRequest* request,
[email protected]783573b2011-05-13 11:05:15504 const net::HttpRequestHeaders& headers) {
[email protected]5796dc942011-07-14 19:26:10505 ExtensionWebRequestEventRouter::GetInstance()->OnSendHeaders(
506 profile_, extension_info_map_.get(), request, headers);
[email protected]82b42302011-04-20 16:28:16507}
508
[email protected]ea8141e2011-10-05 13:12:51509int ChromeNetworkDelegate::OnHeadersReceived(
510 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47511 const net::CompletionCallback& callback,
[email protected]507af8f2012-10-20 00:42:32512 const net::HttpResponseHeaders* original_response_headers,
[email protected]ea8141e2011-10-05 13:12:51513 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) {
514 return ExtensionWebRequestEventRouter::GetInstance()->OnHeadersReceived(
515 profile_, extension_info_map_.get(), request, callback,
516 original_response_headers, override_response_headers);
517}
518
[email protected]31b2e5f2011-04-20 16:58:32519void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
520 const GURL& new_location) {
521 ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRedirect(
[email protected]673514522011-07-13 18:17:18522 profile_, extension_info_map_.get(), request, new_location);
[email protected]31b2e5f2011-04-20 16:58:32523}
524
525
[email protected]8202d0c2011-02-23 08:31:14526void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
[email protected]186468f2013-10-24 02:44:11527 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "ResponseStarted");
[email protected]62fecae2011-04-21 11:08:24528 ExtensionWebRequestEventRouter::GetInstance()->OnResponseStarted(
[email protected]673514522011-07-13 18:17:18529 profile_, extension_info_map_.get(), request);
530 ForwardProxyErrors(request, event_router_.get(), profile_);
[email protected]8202d0c2011-02-23 08:31:14531}
532
[email protected]8523ba52011-05-22 19:00:58533void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
534 int bytes_read) {
[email protected]186468f2013-10-24 02:44:11535 TRACE_EVENT_ASYNC_STEP_PAST1("net", "URLRequest", &request, "DidRead",
536 "bytes_read", bytes_read);
[email protected]6f4b4b42012-08-27 21:59:07537 performance_monitor::PerformanceMonitor::GetInstance()->BytesReadOnIOThread(
538 request, bytes_read);
539
[email protected]44879ed2012-04-06 01:11:02540#if defined(ENABLE_TASK_MANAGER)
[email protected]8523ba52011-05-22 19:00:58541 TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read);
[email protected]44879ed2012-04-06 01:11:02542#endif // defined(ENABLE_TASK_MANAGER)
[email protected]8523ba52011-05-22 19:00:58543}
544
[email protected]9045b8822012-01-13 20:35:35545void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
546 bool started) {
[email protected]4aca5db2013-08-17 00:51:56547 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request);
[email protected]2756a8e2012-09-07 18:24:29548 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
[email protected]7a299a92012-10-24 23:54:50549 // For better accuracy, we use the actual bytes read instead of the length
550 // specified with the Content-Length header, which may be inaccurate,
551 // or missing, as is the case with chunked encoding.
552 int64 received_content_length = request->received_response_content_length();
553
[email protected]35558812013-12-18 21:58:36554#if defined(OS_ANDROID)
555 if (precache::PrecacheManager::IsPrecachingEnabled()) {
556 // Record precache metrics when a fetch is completed successfully, if
557 // precaching is enabled.
558 BrowserThread::PostTask(
559 BrowserThread::UI, FROM_HERE,
560 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(),
561 base::Time::Now(), received_content_length,
562 request->was_cached(), profile_));
563 }
564#endif // defined(OS_ANDROID)
565
[email protected]7a299a92012-10-24 23:54:50566 // Only record for http or https urls.
567 bool is_http = request->url().SchemeIs("http");
568 bool is_https = request->url().SchemeIs("https");
569
570 if (!request->was_cached() && // Don't record cached content
571 received_content_length && // Zero-byte responses aren't useful.
572 (is_http || is_https)) { // Only record for HTTP or HTTPS urls.
573 int64 original_content_length =
574 request->response_info().headers->GetInt64HeaderValue(
575 "x-original-content-length");
[email protected]9a0d6002013-12-19 02:04:28576 spdyproxy::DataReductionRequestType data_reduction_type =
577 spdyproxy::GetDataReductionRequestType(request);
[email protected]2db93e42013-08-07 17:40:41578
[email protected]f81a5ee2013-06-20 21:08:49579 base::TimeDelta freshness_lifetime =
580 request->response_info().headers->GetFreshnessLifetime(
581 request->response_info().response_time);
[email protected]828eab22013-12-10 22:42:38582 int64 adjusted_original_content_length =
[email protected]9a0d6002013-12-19 02:04:28583 spdyproxy::GetAdjustedOriginalContentLength(
[email protected]828eab22013-12-10 22:42:38584 data_reduction_type, original_content_length,
585 received_content_length);
[email protected]7a299a92012-10-24 23:54:50586 AccumulateContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41587 adjusted_original_content_length,
[email protected]9a0d6002013-12-19 02:04:28588 data_reduction_type);
[email protected]7a299a92012-10-24 23:54:50589 RecordContentLengthHistograms(received_content_length,
[email protected]f81a5ee2013-06-20 21:08:49590 original_content_length,
591 freshness_lifetime);
[email protected]7a299a92012-10-24 23:54:50592 DVLOG(2) << __FUNCTION__
593 << " received content length: " << received_content_length
594 << " original content length: " << original_content_length
595 << " url: " << request->url();
596 }
597
[email protected]48944382011-04-23 13:28:16598 bool is_redirect = request->response_headers() &&
599 net::HttpResponseHeaders::IsRedirectResponseCode(
600 request->response_headers()->response_code());
601 if (!is_redirect) {
602 ExtensionWebRequestEventRouter::GetInstance()->OnCompleted(
[email protected]673514522011-07-13 18:17:18603 profile_, extension_info_map_.get(), request);
[email protected]48944382011-04-23 13:28:16604 }
[email protected]a83dd332011-07-13 10:41:01605 } else if (request->status().status() == net::URLRequestStatus::FAILED ||
606 request->status().status() == net::URLRequestStatus::CANCELED) {
[email protected]05b6ab42011-04-23 13:46:04607 ExtensionWebRequestEventRouter::GetInstance()->OnErrorOccurred(
[email protected]9045b8822012-01-13 20:35:35608 profile_, extension_info_map_.get(), request, started);
[email protected]a83dd332011-07-13 10:41:01609 } else {
610 NOTREACHED();
[email protected]48944382011-04-23 13:28:16611 }
[email protected]673514522011-07-13 18:17:18612 ForwardProxyErrors(request, event_router_.get(), profile_);
[email protected]6baff0b52012-03-06 01:30:18613
614 ForwardRequestStatus(REQUEST_DONE, request, profile_);
[email protected]8202d0c2011-02-23 08:31:14615}
[email protected]4b50cb52011-03-10 00:29:37616
[email protected]4875ba12011-03-30 22:31:51617void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
618 ExtensionWebRequestEventRouter::GetInstance()->OnURLRequestDestroyed(
[email protected]673514522011-07-13 18:17:18619 profile_, request);
[email protected]4875ba12011-03-30 22:31:51620}
621
[email protected]82a37672011-05-03 12:02:41622void ChromeNetworkDelegate::OnPACScriptError(int line_number,
[email protected]439f1e32013-12-09 20:09:09623 const base::string16& error) {
[email protected]c454fe672012-03-12 21:18:01624 extensions::ProxyEventRouter::GetInstance()->OnPACScriptError(
[email protected]673514522011-07-13 18:17:18625 event_router_.get(), profile_, line_number, error);
[email protected]82a37672011-05-03 12:02:41626}
[email protected]7efc582d2011-08-03 20:46:35627
[email protected]c2911d72011-10-03 22:16:36628net::NetworkDelegate::AuthRequiredResponse
629ChromeNetworkDelegate::OnAuthRequired(
[email protected]7efc582d2011-08-03 20:46:35630 net::URLRequest* request,
[email protected]c2911d72011-10-03 22:16:36631 const net::AuthChallengeInfo& auth_info,
632 const AuthCallback& callback,
633 net::AuthCredentials* credentials) {
[email protected]90449ab2011-10-11 15:36:45634 return ExtensionWebRequestEventRouter::GetInstance()->OnAuthRequired(
635 profile_, extension_info_map_.get(), request, auth_info,
636 callback, credentials);
[email protected]7efc582d2011-08-03 20:46:35637}
[email protected]9c8ae8c2012-03-09 13:13:35638
[email protected]4c219e22012-05-05 19:41:04639bool ChromeNetworkDelegate::OnCanGetCookies(
640 const net::URLRequest& request,
[email protected]9c8ae8c2012-03-09 13:13:35641 const net::CookieList& cookie_list) {
642 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02643 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35644 return true;
645
646 bool allow = cookie_settings_->IsReadingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04647 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35648
649 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16650 int render_frame_id = -1;
651 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
652 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35653 BrowserThread::PostTask(
654 BrowserThread::UI, FROM_HERE,
655 base::Bind(&TabSpecificContentSettings::CookiesRead,
[email protected]f3add922013-12-20 23:17:16656 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04657 request.url(), request.first_party_for_cookies(),
[email protected]fd473d12012-04-05 11:38:43658 cookie_list, !allow));
[email protected]9c8ae8c2012-03-09 13:13:35659 }
660
661 return allow;
662}
663
[email protected]4c219e22012-05-05 19:41:04664bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
665 const std::string& cookie_line,
666 net::CookieOptions* options) {
[email protected]9c8ae8c2012-03-09 13:13:35667 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02668 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35669 return true;
670
671 bool allow = cookie_settings_->IsSettingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04672 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35673
[email protected]9c8ae8c2012-03-09 13:13:35674 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16675 int render_frame_id = -1;
676 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
677 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35678 BrowserThread::PostTask(
679 BrowserThread::UI, FROM_HERE,
680 base::Bind(&TabSpecificContentSettings::CookieChanged,
[email protected]f3add922013-12-20 23:17:16681 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04682 request.url(), request.first_party_for_cookies(),
[email protected]fd473d12012-04-05 11:38:43683 cookie_line, *options, !allow));
[email protected]9c8ae8c2012-03-09 13:13:35684 }
685
686 return allow;
687}
[email protected]4c219e22012-05-05 19:41:04688
689bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
[email protected]650b2d52013-02-10 03:41:45690 const base::FilePath& path) const {
[email protected]4c219e22012-05-05 19:41:04691 if (g_allow_file_access_)
692 return true;
693
[email protected]d8e4f132012-09-06 04:28:05694#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
695 return true;
696#else
[email protected]4c219e22012-05-05 19:41:04697#if defined(OS_CHROMEOS)
[email protected]d8e4f132012-09-06 04:28:05698 // If we're running Chrome for ChromeOS on Linux, we want to allow file
699 // access.
[email protected]49c4cf852013-09-27 19:28:24700 if (!base::SysInfo::IsRunningOnChromeOS() ||
[email protected]288538482012-09-06 21:09:35701 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
[email protected]d8e4f132012-09-06 04:28:05702 return true;
[email protected]288538482012-09-06 21:09:35703 }
[email protected]d8e4f132012-09-06 04:28:05704
705 // Use a whitelist to only allow access to files residing in the list of
706 // directories below.
[email protected]4c219e22012-05-05 19:41:04707 static const char* const kLocalAccessWhiteList[] = {
708 "/home/chronos/user/Downloads",
709 "/home/chronos/user/log",
710 "/media",
711 "/opt/oem",
712 "/usr/share/chromeos-assets",
713 "/tmp",
714 "/var/log",
715 };
[email protected]ae015e12013-11-04 19:11:33716
717 // The actual location of "/home/chronos/user/Downloads" is the Downloads
718 // directory under the profile path ("/home/chronos/user' is a hard link to
719 // current primary logged in profile.) For the support of multi-profile
720 // sessions, we are switching to use explicit "$PROFILE_PATH/Downloads" path
721 // and here whitelist such access.
722 if (!profile_path_.empty()) {
723 const base::FilePath downloads = profile_path_.AppendASCII("Downloads");
724 if (downloads == path.StripTrailingSeparators() || downloads.IsParent(path))
725 return true;
726 }
[email protected]d8e4f132012-09-06 04:28:05727#elif defined(OS_ANDROID)
728 // Access to files in external storage is allowed.
[email protected]650b2d52013-02-10 03:41:45729 base::FilePath external_storage_path;
[email protected]d8e4f132012-09-06 04:28:05730 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path);
731 if (external_storage_path.IsParent(path))
[email protected]4c219e22012-05-05 19:41:04732 return true;
733
[email protected]d8e4f132012-09-06 04:28:05734 // Whitelist of other allowed directories.
735 static const char* const kLocalAccessWhiteList[] = {
736 "/sdcard",
737 "/mnt/sdcard",
738 };
739#endif
740
[email protected]4c219e22012-05-05 19:41:04741 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
[email protected]650b2d52013-02-10 03:41:45742 const base::FilePath white_listed_path(kLocalAccessWhiteList[i]);
743 // base::FilePath::operator== should probably handle trailing separators.
[email protected]4c219e22012-05-05 19:41:04744 if (white_listed_path == path.StripTrailingSeparators() ||
745 white_listed_path.IsParent(path)) {
746 return true;
747 }
748 }
[email protected]d8e4f132012-09-06 04:28:05749
[email protected]288538482012-09-06 21:09:35750 DVLOG(1) << "File access denied - " << path.value().c_str();
[email protected]4c219e22012-05-05 19:41:04751 return false;
[email protected]d8e4f132012-09-06 04:28:05752#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:04753}
[email protected]a1d4ab072012-06-07 13:21:15754
755bool ChromeNetworkDelegate::OnCanThrottleRequest(
756 const net::URLRequest& request) const {
[email protected]c4a7df82012-08-09 22:48:46757 if (g_never_throttle_requests_) {
[email protected]a1d4ab072012-06-07 13:21:15758 return false;
759 }
760
[email protected]c4a7df82012-08-09 22:48:46761 return request.first_party_for_cookies().scheme() ==
[email protected]885c0e92012-11-13 20:27:42762 extensions::kExtensionScheme;
[email protected]a1d4ab072012-06-07 13:21:15763}
[email protected]aa28181e2012-06-13 00:53:58764
[email protected]e6d017652013-05-17 18:01:40765bool ChromeNetworkDelegate::OnCanEnablePrivacyMode(
766 const GURL& url,
767 const GURL& first_party_for_cookies) const {
768 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02769 if (!cookie_settings_.get())
[email protected]e6d017652013-05-17 18:01:40770 return false;
771
772 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed(
773 url, first_party_for_cookies);
774 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed(
775 url, first_party_for_cookies);
776 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed);
777 return privacy_mode;
778}
779
[email protected]aa28181e2012-06-13 00:53:58780int ChromeNetworkDelegate::OnBeforeSocketStreamConnect(
781 net::SocketStream* socket,
782 const net::CompletionCallback& callback) {
783#if defined(ENABLE_CONFIGURATION_POLICY)
784 if (url_blacklist_manager_ &&
785 url_blacklist_manager_->IsURLBlocked(socket->url())) {
786 // URL access blocked by policy.
[email protected]aa28181e2012-06-13 00:53:58787 socket->net_log()->AddEvent(
[email protected]2fa08912012-06-14 20:56:26788 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
789 net::NetLog::StringCallback("url",
790 &socket->url().possibly_invalid_spec()));
[email protected]91468a92013-03-06 17:21:55791 return net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]aa28181e2012-06-13 00:53:58792 }
793#endif
794 return net::OK;
795}
[email protected]5a07c192012-07-30 20:18:22796
[email protected]7a299a92012-10-24 23:54:50797void ChromeNetworkDelegate::AccumulateContentLength(
[email protected]b7796462013-12-12 19:42:34798 int64 received_content_length,
799 int64 original_content_length,
[email protected]9a0d6002013-12-19 02:04:28800 spdyproxy::DataReductionRequestType data_reduction_type) {
[email protected]7a299a92012-10-24 23:54:50801 DCHECK_GE(received_content_length, 0);
802 DCHECK_GE(original_content_length, 0);
803 StoreAccumulatedContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41804 original_content_length,
[email protected]b7796462013-12-12 19:42:34805 data_reduction_type,
806 reinterpret_cast<Profile*>(profile_));
[email protected]7a299a92012-10-24 23:54:50807 received_content_length_ += received_content_length;
808 original_content_length_ += original_content_length;
809}