[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 2 | // 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] | eac11e1 | 2013-03-19 22:04:32 | [diff] [blame] | 7 | #include <stdlib.h> |
| 8 | |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 11 | #include "base/base_paths.h" |
jochen | b93dba3c | 2014-11-11 05:28:41 | [diff] [blame^] | 12 | #include "base/debug/alias.h" |
jochen | b5680e6 | 2014-10-13 08:43:41 | [diff] [blame] | 13 | #include "base/debug/dump_without_crashing.h" |
jochen | b93dba3c | 2014-11-11 05:28:41 | [diff] [blame^] | 14 | #include "base/debug/stack_trace.h" |
[email protected] | 4aca5db | 2013-08-17 00:51:56 | [diff] [blame] | 15 | #include "base/debug/trace_event.h" |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 16 | #include "base/logging.h" |
| 17 | #include "base/metrics/histogram.h" |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 18 | #include "base/metrics/user_metrics.h" |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 19 | #include "base/path_service.h" |
[email protected] | 1ab137b | 2013-03-21 03:33:18 | [diff] [blame] | 20 | #include "base/prefs/pref_member.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 21 | #include "base/prefs/pref_service.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 22 | #include "base/strings/string_number_conversions.h" |
[email protected] | 069c4916 | 2013-09-11 20:46:35 | [diff] [blame] | 23 | #include "base/time/time.h" |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 24 | #include "chrome/browser/browser_process.h" |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 25 | #include "chrome/browser/content_settings/cookie_settings.h" |
| 26 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | 8523ba5 | 2011-05-22 19:00:58 | [diff] [blame] | 27 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 28 | #include "chrome/browser/net/chrome_extensions_network_delegate.h" |
[email protected] | 3620bbc | 2013-10-05 05:07:23 | [diff] [blame] | 29 | #include "chrome/browser/net/client_hints.h" |
[email protected] | f53b480 | 2012-12-20 17:04:23 | [diff] [blame] | 30 | #include "chrome/browser/net/connect_interceptor.h" |
[email protected] | 184799df | 2014-07-22 16:03:24 | [diff] [blame] | 31 | #include "chrome/browser/net/safe_search_util.h" |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 32 | #include "chrome/browser/prerender/prerender_tracker.h" |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 33 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 8523ba5 | 2011-05-22 19:00:58 | [diff] [blame] | 34 | #include "chrome/browser/task_manager/task_manager.h" |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 35 | #include "chrome/common/pref_names.h" |
megjablon | 3476e04 | 2014-10-14 19:21:59 | [diff] [blame] | 36 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h" |
| 37 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h" |
megjablon | 3476e04 | 2014-10-14 19:21:59 | [diff] [blame] | 38 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h" |
| 39 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h" |
jeremyim | db2599e | 2014-10-29 02:13:09 | [diff] [blame] | 40 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 41 | #include "components/domain_reliability/monitor.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 42 | #include "content/public/browser/browser_thread.h" |
[email protected] | 9dfed87 | 2013-12-30 23:08:56 | [diff] [blame] | 43 | #include "content/public/browser/render_frame_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 44 | #include "content/public/browser/render_view_host.h" |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 45 | #include "content/public/browser/resource_request_info.h" |
[email protected] | 82b4230 | 2011-04-20 16:28:16 | [diff] [blame] | 46 | #include "net/base/host_port_pair.h" |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 47 | #include "net/base/net_errors.h" |
[email protected] | 6a5f77c3 | 2011-09-04 19:19:59 | [diff] [blame] | 48 | #include "net/base/net_log.h" |
[email protected] | 5b9bc35 | 2012-07-18 13:13:34 | [diff] [blame] | 49 | #include "net/cookies/canonical_cookie.h" |
| 50 | #include "net/cookies/cookie_options.h" |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 51 | #include "net/http/http_request_headers.h" |
[email protected] | 4894438 | 2011-04-23 13:28:16 | [diff] [blame] | 52 | #include "net/http/http_response_headers.h" |
[email protected] | 1273179 | 2014-08-14 11:45:54 | [diff] [blame] | 53 | #include "net/proxy/proxy_config.h" |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 54 | #include "net/proxy/proxy_info.h" |
[email protected] | 1273179 | 2014-08-14 11:45:54 | [diff] [blame] | 55 | #include "net/proxy/proxy_retry_info.h" |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 56 | #include "net/proxy/proxy_server.h" |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 57 | #include "net/url_request/url_request.h" |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 58 | #include "net/url_request/url_request_context.h" |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 59 | |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 60 | #if defined(OS_ANDROID) |
| 61 | #include "chrome/browser/io_thread.h" |
| 62 | #include "components/precache/content/precache_manager.h" |
| 63 | #include "components/precache/content/precache_manager_factory.h" |
| 64 | #endif |
| 65 | |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 66 | #if defined(OS_CHROMEOS) |
[email protected] | 28853848 | 2012-09-06 21:09:35 | [diff] [blame] | 67 | #include "base/command_line.h" |
[email protected] | 49c4cf85 | 2013-09-27 19:28:24 | [diff] [blame] | 68 | #include "base/sys_info.h" |
[email protected] | 28853848 | 2012-09-06 21:09:35 | [diff] [blame] | 69 | #include "chrome/common/chrome_switches.h" |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 70 | #endif |
| 71 | |
[email protected] | 3e598ff1 | 2011-09-06 11:22:34 | [diff] [blame] | 72 | #if defined(ENABLE_CONFIGURATION_POLICY) |
[email protected] | f522afa | 2014-01-08 15:36:36 | [diff] [blame] | 73 | #include "components/policy/core/browser/url_blacklist_manager.h" |
[email protected] | 3e598ff1 | 2011-09-06 11:22:34 | [diff] [blame] | 74 | #endif |
| 75 | |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 76 | #if defined(ENABLE_EXTENSIONS) |
| 77 | #include "extensions/common/constants.h" |
| 78 | #endif |
| 79 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 80 | using content::BrowserThread; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 81 | using content::RenderViewHost; |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 82 | using content::ResourceRequestInfo; |
[email protected] | 7491ad0 | 2014-07-05 19:10:07 | [diff] [blame] | 83 | using content::ResourceType; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 84 | |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 85 | // By default we don't allow access to all file:// urls on ChromeOS and |
| 86 | // Android. |
| 87 | #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 88 | bool ChromeNetworkDelegate::g_allow_file_access_ = false; |
| 89 | #else |
| 90 | bool ChromeNetworkDelegate::g_allow_file_access_ = true; |
| 91 | #endif |
| 92 | |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 93 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | c4a7df8 | 2012-08-09 22:48:46 | [diff] [blame] | 94 | // This remains false unless the --disable-extensions-http-throttling |
| 95 | // flag is passed to the browser. |
| 96 | bool ChromeNetworkDelegate::g_never_throttle_requests_ = false; |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 97 | #endif |
[email protected] | c4a7df8 | 2012-08-09 22:48:46 | [diff] [blame] | 98 | |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 99 | namespace { |
| 100 | |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 101 | const char kDNTHeader[] = "DNT"; |
| 102 | |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 103 | // Gets called when the extensions finish work on the URL. If the extensions |
| 104 | // did not do a redirect (so |new_url| is empty) then we enforce the |
| 105 | // SafeSearch parameters. Otherwise we will get called again after the |
| 106 | // redirect and we enforce SafeSearch then. |
| 107 | void ForceGoogleSafeSearchCallbackWrapper( |
| 108 | const net::CompletionCallback& callback, |
| 109 | net::URLRequest* request, |
| 110 | GURL* new_url, |
| 111 | int rv) { |
| 112 | if (rv == net::OK && new_url->is_empty()) |
[email protected] | 184799df | 2014-07-22 16:03:24 | [diff] [blame] | 113 | safe_search_util::ForceGoogleSafeSearch(request, new_url); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 114 | callback.Run(rv); |
| 115 | } |
| 116 | |
[email protected] | 828eab2 | 2013-12-10 22:42:38 | [diff] [blame] | 117 | void UpdateContentLengthPrefs( |
| 118 | int received_content_length, |
| 119 | int original_content_length, |
[email protected] | a0a0693 | 2014-04-14 21:23:42 | [diff] [blame] | 120 | data_reduction_proxy::DataReductionProxyRequestType request_type, |
megjablon | 53f608b | 2014-09-18 19:24:55 | [diff] [blame] | 121 | Profile* profile, |
| 122 | data_reduction_proxy::DataReductionProxyStatisticsPrefs* statistics_prefs) { |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 123 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 124 | DCHECK_GE(received_content_length, 0); |
| 125 | DCHECK_GE(original_content_length, 0); |
| 126 | |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 127 | // Can be NULL in a unit test. |
| 128 | if (!g_browser_process) |
| 129 | return; |
| 130 | |
[email protected] | b779646 | 2013-12-12 19:42:34 | [diff] [blame] | 131 | // Ignore off-the-record data. |
| 132 | if (!g_browser_process->profile_manager()->IsValidProfile(profile) || |
| 133 | profile->IsOffTheRecord()) { |
| 134 | return; |
| 135 | } |
megjablon | 53f608b | 2014-09-18 19:24:55 | [diff] [blame] | 136 | data_reduction_proxy::UpdateContentLengthPrefs( |
| 137 | received_content_length, |
| 138 | original_content_length, |
kundaji | 88ca411 | 2014-09-23 01:35:21 | [diff] [blame] | 139 | profile->GetPrefs(), |
| 140 | request_type, statistics_prefs); |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 141 | } |
| 142 | |
[email protected] | 828eab2 | 2013-12-10 22:42:38 | [diff] [blame] | 143 | void StoreAccumulatedContentLength( |
| 144 | int received_content_length, |
| 145 | int original_content_length, |
[email protected] | a0a0693 | 2014-04-14 21:23:42 | [diff] [blame] | 146 | data_reduction_proxy::DataReductionProxyRequestType request_type, |
megjablon | 53f608b | 2014-09-18 19:24:55 | [diff] [blame] | 147 | Profile* profile, |
| 148 | data_reduction_proxy::DataReductionProxyStatisticsPrefs* statistics_prefs) { |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 149 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 150 | base::Bind(&UpdateContentLengthPrefs, |
megjablon | 53f608b | 2014-09-18 19:24:55 | [diff] [blame] | 151 | received_content_length, |
| 152 | original_content_length, |
| 153 | request_type, |
| 154 | profile, |
| 155 | statistics_prefs)); |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | void RecordContentLengthHistograms( |
[email protected] | f81a5ee | 2013-06-20 21:08:49 | [diff] [blame] | 159 | int64 received_content_length, |
| 160 | int64 original_content_length, |
| 161 | const base::TimeDelta& freshness_lifetime) { |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 162 | // Add the current resource to these histograms only when a valid |
| 163 | // X-Original-Content-Length header is present. |
| 164 | if (original_content_length >= 0) { |
| 165 | UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL", |
| 166 | received_content_length); |
| 167 | UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL", |
| 168 | original_content_length); |
| 169 | UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL", |
| 170 | original_content_length - received_content_length); |
| 171 | } else { |
| 172 | // Presume the original content length is the same as the received content |
| 173 | // length if the X-Original-Content-Header is not present. |
| 174 | original_content_length = received_content_length; |
| 175 | } |
| 176 | UMA_HISTOGRAM_COUNTS("Net.HttpContentLength", received_content_length); |
| 177 | UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLength", |
| 178 | original_content_length); |
| 179 | UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifference", |
| 180 | original_content_length - received_content_length); |
[email protected] | f81a5ee | 2013-06-20 21:08:49 | [diff] [blame] | 181 | UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpContentFreshnessLifetime", |
| 182 | freshness_lifetime.InSeconds(), |
| 183 | base::TimeDelta::FromHours(1).InSeconds(), |
| 184 | base::TimeDelta::FromDays(30).InSeconds(), |
| 185 | 100); |
| 186 | if (freshness_lifetime.InSeconds() <= 0) |
| 187 | return; |
| 188 | UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable", |
| 189 | received_content_length); |
| 190 | if (freshness_lifetime.InHours() < 4) |
| 191 | return; |
| 192 | UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours", |
| 193 | received_content_length); |
| 194 | |
| 195 | if (freshness_lifetime.InHours() < 24) |
| 196 | return; |
| 197 | UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours", |
| 198 | received_content_length); |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 199 | } |
| 200 | |
[email protected] | 3555881 | 2013-12-18 21:58:36 | [diff] [blame] | 201 | #if defined(OS_ANDROID) |
| 202 | void RecordPrecacheStatsOnUIThread(const GURL& url, |
| 203 | const base::Time& fetch_time, int64 size, |
| 204 | bool was_cached, void* profile_id) { |
| 205 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 206 | |
| 207 | Profile* profile = reinterpret_cast<Profile*>(profile_id); |
| 208 | if (!g_browser_process->profile_manager()->IsValidProfile(profile)) { |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | precache::PrecacheManager* precache_manager = |
| 213 | precache::PrecacheManagerFactory::GetForBrowserContext(profile); |
tanviraumi | 387f633 | 2014-08-29 19:04:36 | [diff] [blame] | 214 | if (!precache_manager || !precache_manager->IsPrecachingAllowed()) { |
| 215 | // |precache_manager| could be NULL if the profile is off the record. |
[email protected] | 3555881 | 2013-12-18 21:58:36 | [diff] [blame] | 216 | return; |
| 217 | } |
| 218 | |
| 219 | precache_manager->RecordStatsForFetch(url, fetch_time, size, was_cached); |
| 220 | } |
[email protected] | d827e11 | 2014-03-31 17:45:05 | [diff] [blame] | 221 | |
| 222 | void RecordIOThreadToRequestStartOnUIThread( |
| 223 | const base::TimeTicks& request_start) { |
| 224 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 225 | base::TimeDelta request_lag = request_start - |
| 226 | g_browser_process->io_thread()->creation_time(); |
| 227 | UMA_HISTOGRAM_TIMES("Net.IOThreadCreationToHTTPRequestStart", request_lag); |
| 228 | } |
[email protected] | 3555881 | 2013-12-18 21:58:36 | [diff] [blame] | 229 | #endif // defined(OS_ANDROID) |
| 230 | |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 231 | void ReportInvalidReferrerSend(const GURL& target_url, |
jochen | b93dba3c | 2014-11-11 05:28:41 | [diff] [blame^] | 232 | const GURL& referrer_url, |
| 233 | const base::debug::StackTrace& callstack) { |
| 234 | // Record information to help debug http://crbug.com/422871 |
| 235 | base::debug::StackTrace trace = callstack; |
| 236 | base::debug::Alias(&trace); |
| 237 | enum { INVALID_URL, FILE_URL, DATA_URL, HTTP_URL, OTHER } reason = OTHER; |
| 238 | if (!target_url.is_valid()) |
| 239 | reason = INVALID_URL; |
| 240 | else if (target_url.SchemeIsFile()) |
| 241 | reason = FILE_URL; |
| 242 | else if (target_url.SchemeIs(url::kDataScheme)) |
| 243 | reason = DATA_URL; |
| 244 | else if (target_url.SchemeIs(url::kHttpScheme)) |
| 245 | reason = HTTP_URL; |
| 246 | base::debug::Alias(&reason); |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 247 | base::RecordAction( |
| 248 | base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer")); |
jochen | b5680e6 | 2014-10-13 08:43:41 | [diff] [blame] | 249 | base::debug::DumpWithoutCrashing(); |
| 250 | NOTREACHED(); |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 251 | } |
| 252 | |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 253 | } // namespace |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 254 | |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 255 | ChromeNetworkDelegate::ChromeNetworkDelegate( |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 256 | extensions::EventRouterForwarder* event_router, |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 257 | BooleanPrefMember* enable_referrers) |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 258 | : profile_(NULL), |
[email protected] | 6a5f77c3 | 2011-09-04 19:19:59 | [diff] [blame] | 259 | enable_referrers_(enable_referrers), |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 260 | enable_do_not_track_(NULL), |
| 261 | force_google_safe_search_(NULL), |
[email protected] | a948dad | 2014-07-25 00:39:38 | [diff] [blame] | 262 | data_reduction_proxy_enabled_(NULL), |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 263 | #if defined(ENABLE_CONFIGURATION_POLICY) |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 264 | url_blacklist_manager_(NULL), |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 265 | #endif |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 266 | domain_reliability_monitor_(NULL), |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 267 | received_content_length_(0), |
[email protected] | d827e11 | 2014-03-31 17:45:05 | [diff] [blame] | 268 | original_content_length_(0), |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 269 | first_request_(true), |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 270 | prerender_tracker_(NULL), |
[email protected] | bceab7f | 2014-06-25 04:36:20 | [diff] [blame] | 271 | data_reduction_proxy_params_(NULL), |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 272 | data_reduction_proxy_usage_stats_(NULL), |
megjablon | 53f608b | 2014-09-18 19:24:55 | [diff] [blame] | 273 | data_reduction_proxy_auth_request_handler_(NULL), |
| 274 | data_reduction_proxy_statistics_prefs_(NULL) { |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 275 | DCHECK(enable_referrers); |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 276 | extensions_delegate_.reset( |
| 277 | ChromeExtensionsNetworkDelegate::Create(event_router)); |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 278 | } |
| 279 | |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 280 | ChromeNetworkDelegate::~ChromeNetworkDelegate() {} |
| 281 | |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 282 | void ChromeNetworkDelegate::set_extension_info_map( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 283 | extensions::InfoMap* extension_info_map) { |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 284 | extensions_delegate_->set_extension_info_map(extension_info_map); |
| 285 | } |
| 286 | |
| 287 | void ChromeNetworkDelegate::set_profile(void* profile) { |
| 288 | profile_ = profile; |
| 289 | extensions_delegate_->set_profile(profile); |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | void ChromeNetworkDelegate::set_cookie_settings( |
| 293 | CookieSettings* cookie_settings) { |
| 294 | cookie_settings_ = cookie_settings; |
| 295 | } |
| 296 | |
[email protected] | f53b480 | 2012-12-20 17:04:23 | [diff] [blame] | 297 | void ChromeNetworkDelegate::set_predictor( |
| 298 | chrome_browser_net::Predictor* predictor) { |
| 299 | connect_interceptor_.reset( |
| 300 | new chrome_browser_net::ConnectInterceptor(predictor)); |
| 301 | } |
| 302 | |
[email protected] | 3620bbc | 2013-10-05 05:07:23 | [diff] [blame] | 303 | void ChromeNetworkDelegate::SetEnableClientHints() { |
| 304 | client_hints_.reset(new ClientHints()); |
| 305 | client_hints_->Init(); |
| 306 | } |
| 307 | |
[email protected] | c4a7df8 | 2012-08-09 22:48:46 | [diff] [blame] | 308 | // static |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 309 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 310 | void ChromeNetworkDelegate::NeverThrottleRequests() { |
[email protected] | c4a7df8 | 2012-08-09 22:48:46 | [diff] [blame] | 311 | g_never_throttle_requests_ = true; |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 312 | } |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 313 | #endif |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 314 | |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 315 | // static |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 316 | void ChromeNetworkDelegate::InitializePrefsOnUIThread( |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 317 | BooleanPrefMember* enable_referrers, |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 318 | BooleanPrefMember* enable_do_not_track, |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 319 | BooleanPrefMember* force_google_safe_search, |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 320 | PrefService* pref_service) { |
| 321 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 96a5c34 | 2012-12-04 18:14:02 | [diff] [blame] | 322 | enable_referrers->Init(prefs::kEnableReferrers, pref_service); |
[email protected] | 6a1c98e0 | 2012-10-24 21:49:43 | [diff] [blame] | 323 | enable_referrers->MoveToThread( |
| 324 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 325 | if (enable_do_not_track) { |
[email protected] | 96a5c34 | 2012-12-04 18:14:02 | [diff] [blame] | 326 | enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service); |
[email protected] | 6a1c98e0 | 2012-10-24 21:49:43 | [diff] [blame] | 327 | enable_do_not_track->MoveToThread( |
| 328 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 329 | } |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 330 | if (force_google_safe_search) { |
[email protected] | 96a5c34 | 2012-12-04 18:14:02 | [diff] [blame] | 331 | force_google_safe_search->Init(prefs::kForceSafeSearch, pref_service); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 332 | force_google_safe_search->MoveToThread( |
| 333 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 334 | } |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 335 | } |
| 336 | |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 337 | // static |
| 338 | void ChromeNetworkDelegate::AllowAccessToAllFiles() { |
| 339 | g_allow_file_access_ = true; |
| 340 | } |
| 341 | |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 342 | // static |
megjablon | 53f608b | 2014-09-18 19:24:55 | [diff] [blame] | 343 | // TODO(megjablon): Use data_reduction_proxy_delayed_pref_service to read prefs. |
| 344 | // Until updated the pref values may be up to an hour behind on desktop. |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 345 | base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() { |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 346 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 347 | PrefService* prefs = g_browser_process->local_state(); |
[email protected] | a0a0693 | 2014-04-14 21:23:42 | [diff] [blame] | 348 | int64 total_received = prefs->GetInt64( |
| 349 | data_reduction_proxy::prefs::kHttpReceivedContentLength); |
| 350 | int64 total_original = prefs->GetInt64( |
| 351 | data_reduction_proxy::prefs::kHttpOriginalContentLength); |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 352 | |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 353 | base::DictionaryValue* dict = new base::DictionaryValue(); |
[email protected] | ae638fbe2 | 2012-12-07 02:57:42 | [diff] [blame] | 354 | // Use strings to avoid overflow. base::Value only supports 32-bit integers. |
| 355 | dict->SetString("historic_received_content_length", |
| 356 | base::Int64ToString(total_received)); |
| 357 | dict->SetString("historic_original_content_length", |
| 358 | base::Int64ToString(total_original)); |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 359 | return dict; |
| 360 | } |
| 361 | |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 362 | base::Value* ChromeNetworkDelegate::SessionNetworkStatsInfoToValue() const { |
| 363 | base::DictionaryValue* dict = new base::DictionaryValue(); |
[email protected] | ae638fbe2 | 2012-12-07 02:57:42 | [diff] [blame] | 364 | // Use strings to avoid overflow. base::Value only supports 32-bit integers. |
| 365 | dict->SetString("session_received_content_length", |
| 366 | base::Int64ToString(received_content_length_)); |
| 367 | dict->SetString("session_original_content_length", |
| 368 | base::Int64ToString(original_content_length_)); |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 369 | return dict; |
| 370 | } |
| 371 | |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 372 | int ChromeNetworkDelegate::OnBeforeURLRequest( |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 373 | net::URLRequest* request, |
[email protected] | 084262c | 2011-12-01 21:12:47 | [diff] [blame] | 374 | const net::CompletionCallback& callback, |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 375 | GURL* new_url) { |
[email protected] | d827e11 | 2014-03-31 17:45:05 | [diff] [blame] | 376 | #if defined(OS_ANDROID) |
| 377 | // This UMA tracks the time to the first user-initiated request start, so |
| 378 | // only non-null profiles are considered. |
| 379 | if (first_request_ && profile_) { |
| 380 | bool record_timing = true; |
[email protected] | bec6a99 | 2014-06-19 01:03:21 | [diff] [blame] | 381 | if (data_reduction_proxy_params_) { |
| 382 | record_timing = |
| 383 | (request->url() != data_reduction_proxy_params_->probe_url()) && |
| 384 | (request->url() != data_reduction_proxy_params_->warmup_url()); |
| 385 | } |
[email protected] | d827e11 | 2014-03-31 17:45:05 | [diff] [blame] | 386 | if (record_timing) { |
| 387 | first_request_ = false; |
| 388 | net::LoadTimingInfo timing_info; |
| 389 | request->GetLoadTimingInfo(&timing_info); |
| 390 | BrowserThread::PostTask( |
| 391 | BrowserThread::UI, FROM_HERE, |
| 392 | base::Bind(&RecordIOThreadToRequestStartOnUIThread, |
| 393 | timing_info.request_start)); |
| 394 | } |
| 395 | } |
| 396 | #endif // defined(OS_ANDROID) |
| 397 | |
[email protected] | 3e598ff1 | 2011-09-06 11:22:34 | [diff] [blame] | 398 | #if defined(ENABLE_CONFIGURATION_POLICY) |
[email protected] | 6a5f77c3 | 2011-09-04 19:19:59 | [diff] [blame] | 399 | // TODO(joaodasilva): This prevents extensions from seeing URLs that are |
| 400 | // blocked. However, an extension might redirect the request to another URL, |
| 401 | // which is not blocked. |
[email protected] | cb85f8e5 | 2014-04-08 11:44:40 | [diff] [blame] | 402 | int error = net::ERR_BLOCKED_BY_ADMINISTRATOR; |
[email protected] | 6a5f77c3 | 2011-09-04 19:19:59 | [diff] [blame] | 403 | if (url_blacklist_manager_ && |
[email protected] | cb85f8e5 | 2014-04-08 11:44:40 | [diff] [blame] | 404 | url_blacklist_manager_->IsRequestBlocked(*request, &error)) { |
[email protected] | 6a5f77c3 | 2011-09-04 19:19:59 | [diff] [blame] | 405 | // URL access blocked by policy. |
[email protected] | 6a5f77c3 | 2011-09-04 19:19:59 | [diff] [blame] | 406 | request->net_log().AddEvent( |
[email protected] | 2fa0891 | 2012-06-14 20:56:26 | [diff] [blame] | 407 | net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST, |
| 408 | net::NetLog::StringCallback("url", |
| 409 | &request->url().possibly_invalid_spec())); |
[email protected] | cb85f8e5 | 2014-04-08 11:44:40 | [diff] [blame] | 410 | return error; |
[email protected] | 6a5f77c3 | 2011-09-04 19:19:59 | [diff] [blame] | 411 | } |
[email protected] | 3e598ff1 | 2011-09-06 11:22:34 | [diff] [blame] | 412 | #endif |
[email protected] | 6a5f77c3 | 2011-09-04 19:19:59 | [diff] [blame] | 413 | |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 414 | extensions_delegate_->ForwardStartRequestStatus(request); |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 415 | |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 416 | if (!enable_referrers_->GetValue()) |
[email protected] | 99ecf6e | 2013-04-10 22:46:13 | [diff] [blame] | 417 | request->SetReferrer(std::string()); |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 418 | if (enable_do_not_track_ && enable_do_not_track_->GetValue()) |
| 419 | request->SetExtraRequestHeaderByName(kDNTHeader, "1", true /* override */); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 420 | |
[email protected] | 3620bbc | 2013-10-05 05:07:23 | [diff] [blame] | 421 | if (client_hints_) { |
| 422 | request->SetExtraRequestHeaderByName( |
| 423 | ClientHints::kDevicePixelRatioHeader, |
| 424 | client_hints_->GetDevicePixelRatioHeader(), true); |
| 425 | } |
| 426 | |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 427 | bool force_safe_search = force_google_safe_search_ && |
| 428 | force_google_safe_search_->GetValue(); |
| 429 | |
| 430 | net::CompletionCallback wrapped_callback = callback; |
| 431 | if (force_safe_search) { |
| 432 | wrapped_callback = base::Bind(&ForceGoogleSafeSearchCallbackWrapper, |
| 433 | callback, |
| 434 | base::Unretained(request), |
| 435 | base::Unretained(new_url)); |
| 436 | } |
| 437 | |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 438 | int rv = extensions_delegate_->OnBeforeURLRequest( |
| 439 | request, wrapped_callback, new_url); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 440 | |
| 441 | if (force_safe_search && rv == net::OK && new_url->is_empty()) |
[email protected] | 184799df | 2014-07-22 16:03:24 | [diff] [blame] | 442 | safe_search_util::ForceGoogleSafeSearch(request, new_url); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 443 | |
[email protected] | f53b480 | 2012-12-20 17:04:23 | [diff] [blame] | 444 | if (connect_interceptor_) |
| 445 | connect_interceptor_->WitnessURLRequest(request); |
| 446 | |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 447 | return rv; |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 448 | } |
| 449 | |
[email protected] | a702da7 | 2014-07-09 05:23:54 | [diff] [blame] | 450 | void ChromeNetworkDelegate::OnResolveProxy( |
[email protected] | 1273179 | 2014-08-14 11:45:54 | [diff] [blame] | 451 | const GURL& url, |
| 452 | int load_flags, |
| 453 | const net::ProxyService& proxy_service, |
| 454 | net::ProxyInfo* result) { |
| 455 | if (!on_resolve_proxy_handler_.is_null() && |
| 456 | !proxy_config_getter_.is_null()) { |
[email protected] | a702da7 | 2014-07-09 05:23:54 | [diff] [blame] | 457 | on_resolve_proxy_handler_.Run(url, load_flags, |
[email protected] | 1273179 | 2014-08-14 11:45:54 | [diff] [blame] | 458 | proxy_config_getter_.Run(), |
bengr | f5c403d | 2014-11-04 03:02:57 | [diff] [blame] | 459 | proxy_service.config(), |
[email protected] | 1273179 | 2014-08-14 11:45:54 | [diff] [blame] | 460 | proxy_service.proxy_retry_info(), |
[email protected] | a702da7 | 2014-07-09 05:23:54 | [diff] [blame] | 461 | data_reduction_proxy_params_, result); |
| 462 | } |
| 463 | } |
| 464 | |
[email protected] | f09f968 | 2014-08-10 01:21:39 | [diff] [blame] | 465 | void ChromeNetworkDelegate::OnProxyFallback(const net::ProxyServer& bad_proxy, |
[email protected] | d0483b19 | 2014-08-15 23:50:17 | [diff] [blame] | 466 | int net_error) { |
[email protected] | f09f968 | 2014-08-10 01:21:39 | [diff] [blame] | 467 | if (data_reduction_proxy_usage_stats_) { |
kundaji | a9a4b7da | 2014-09-23 21:10:56 | [diff] [blame] | 468 | data_reduction_proxy_usage_stats_->OnProxyFallback( |
[email protected] | d0483b19 | 2014-08-15 23:50:17 | [diff] [blame] | 469 | bad_proxy, net_error); |
[email protected] | f09f968 | 2014-08-10 01:21:39 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 473 | int ChromeNetworkDelegate::OnBeforeSendHeaders( |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 474 | net::URLRequest* request, |
[email protected] | 084262c | 2011-12-01 21:12:47 | [diff] [blame] | 475 | const net::CompletionCallback& callback, |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 476 | net::HttpRequestHeaders* headers) { |
[email protected] | 184799df | 2014-07-22 16:03:24 | [diff] [blame] | 477 | bool force_safe_search = force_google_safe_search_ && |
| 478 | force_google_safe_search_->GetValue(); |
| 479 | if (force_safe_search) |
| 480 | safe_search_util::ForceYouTubeSafetyMode(request, headers); |
| 481 | |
[email protected] | 186468f | 2013-10-24 02:44:11 | [diff] [blame] | 482 | TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest"); |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 483 | return extensions_delegate_->OnBeforeSendHeaders(request, callback, headers); |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 484 | } |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 485 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 486 | void 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] | 5796dc94 | 2011-07-14 19:26:10 | [diff] [blame] | 496 | void ChromeNetworkDelegate::OnSendHeaders( |
| 497 | net::URLRequest* request, |
[email protected] | 783573b | 2011-05-13 11:05:15 | [diff] [blame] | 498 | const net::HttpRequestHeaders& headers) { |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 499 | extensions_delegate_->OnSendHeaders(request, headers); |
[email protected] | 82b4230 | 2011-04-20 16:28:16 | [diff] [blame] | 500 | } |
| 501 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 502 | int ChromeNetworkDelegate::OnHeadersReceived( |
| 503 | net::URLRequest* request, |
[email protected] | 084262c | 2011-12-01 21:12:47 | [diff] [blame] | 504 | const net::CompletionCallback& callback, |
[email protected] | 507af8f | 2012-10-20 00:42:32 | [diff] [blame] | 505 | const net::HttpResponseHeaders* original_response_headers, |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 506 | scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
| 507 | GURL* allowed_unsafe_redirect_url) { |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 508 | return extensions_delegate_->OnHeadersReceived( |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 509 | request, |
| 510 | callback, |
| 511 | original_response_headers, |
| 512 | override_response_headers, |
| 513 | allowed_unsafe_redirect_url); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 514 | } |
| 515 | |
[email protected] | 31b2e5f | 2011-04-20 16:58:32 | [diff] [blame] | 516 | void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request, |
| 517 | const GURL& new_location) { |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 518 | if (domain_reliability_monitor_) |
| 519 | domain_reliability_monitor_->OnBeforeRedirect(request); |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 520 | extensions_delegate_->OnBeforeRedirect(request, new_location); |
[email protected] | 31b2e5f | 2011-04-20 16:58:32 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 524 | void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) { |
[email protected] | 186468f | 2013-10-24 02:44:11 | [diff] [blame] | 525 | TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "ResponseStarted"); |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 526 | extensions_delegate_->OnResponseStarted(request); |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 527 | } |
| 528 | |
[email protected] | 8523ba5 | 2011-05-22 19:00:58 | [diff] [blame] | 529 | void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request, |
| 530 | int bytes_read) { |
[email protected] | 186468f | 2013-10-24 02:44:11 | [diff] [blame] | 531 | TRACE_EVENT_ASYNC_STEP_PAST1("net", "URLRequest", &request, "DidRead", |
| 532 | "bytes_read", bytes_read); |
[email protected] | 44879ed | 2012-04-06 01:11:02 | [diff] [blame] | 533 | #if defined(ENABLE_TASK_MANAGER) |
[email protected] | 17df9e7c | 2014-02-13 03:49:29 | [diff] [blame] | 534 | // This is not completely accurate, but as a first approximation ignore |
| 535 | // requests that are served from the cache. See bug 330931 for more info. |
| 536 | if (!request.was_cached()) |
| 537 | TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read); |
[email protected] | 44879ed | 2012-04-06 01:11:02 | [diff] [blame] | 538 | #endif // defined(ENABLE_TASK_MANAGER) |
[email protected] | 8523ba5 | 2011-05-22 19:00:58 | [diff] [blame] | 539 | } |
| 540 | |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 541 | void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, |
| 542 | bool started) { |
[email protected] | bceab7f | 2014-06-25 04:36:20 | [diff] [blame] | 543 | if (data_reduction_proxy_usage_stats_) |
| 544 | data_reduction_proxy_usage_stats_->OnUrlRequestCompleted(request, started); |
| 545 | |
[email protected] | 4aca5db | 2013-08-17 00:51:56 | [diff] [blame] | 546 | TRACE_EVENT_ASYNC_END0("net", "URLRequest", request); |
[email protected] | 2756a8e | 2012-09-07 18:24:29 | [diff] [blame] | 547 | if (request->status().status() == net::URLRequestStatus::SUCCESS) { |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 548 | // For better accuracy, we use the actual bytes read instead of the length |
| 549 | // specified with the Content-Length header, which may be inaccurate, |
| 550 | // or missing, as is the case with chunked encoding. |
| 551 | int64 received_content_length = request->received_response_content_length(); |
| 552 | |
[email protected] | 3555881 | 2013-12-18 21:58:36 | [diff] [blame] | 553 | #if defined(OS_ANDROID) |
| 554 | if (precache::PrecacheManager::IsPrecachingEnabled()) { |
| 555 | // Record precache metrics when a fetch is completed successfully, if |
| 556 | // precaching is enabled. |
| 557 | BrowserThread::PostTask( |
| 558 | BrowserThread::UI, FROM_HERE, |
| 559 | base::Bind(&RecordPrecacheStatsOnUIThread, request->url(), |
| 560 | base::Time::Now(), received_content_length, |
| 561 | request->was_cached(), profile_)); |
| 562 | } |
| 563 | #endif // defined(OS_ANDROID) |
| 564 | |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 565 | // Only record for http or https urls. |
| 566 | bool is_http = request->url().SchemeIs("http"); |
| 567 | bool is_https = request->url().SchemeIs("https"); |
| 568 | |
| 569 | if (!request->was_cached() && // Don't record cached content |
| 570 | received_content_length && // Zero-byte responses aren't useful. |
| 571 | (is_http || is_https)) { // Only record for HTTP or HTTPS urls. |
| 572 | int64 original_content_length = |
| 573 | request->response_info().headers->GetInt64HeaderValue( |
| 574 | "x-original-content-length"); |
[email protected] | a0a0693 | 2014-04-14 21:23:42 | [diff] [blame] | 575 | data_reduction_proxy::DataReductionProxyRequestType request_type = |
| 576 | data_reduction_proxy::GetDataReductionProxyRequestType(request); |
[email protected] | 2db93e4 | 2013-08-07 17:40:41 | [diff] [blame] | 577 | |
[email protected] | f81a5ee | 2013-06-20 21:08:49 | [diff] [blame] | 578 | base::TimeDelta freshness_lifetime = |
ricea | 4373698 | 2014-10-30 09:15:48 | [diff] [blame] | 579 | request->response_info().headers->GetFreshnessLifetimes( |
| 580 | request->response_info().response_time).freshness; |
[email protected] | 828eab2 | 2013-12-10 22:42:38 | [diff] [blame] | 581 | int64 adjusted_original_content_length = |
[email protected] | a0a0693 | 2014-04-14 21:23:42 | [diff] [blame] | 582 | data_reduction_proxy::GetAdjustedOriginalContentLength( |
| 583 | request_type, original_content_length, |
[email protected] | 828eab2 | 2013-12-10 22:42:38 | [diff] [blame] | 584 | received_content_length); |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 585 | AccumulateContentLength(received_content_length, |
[email protected] | 2db93e4 | 2013-08-07 17:40:41 | [diff] [blame] | 586 | adjusted_original_content_length, |
[email protected] | a0a0693 | 2014-04-14 21:23:42 | [diff] [blame] | 587 | request_type); |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 588 | RecordContentLengthHistograms(received_content_length, |
[email protected] | f81a5ee | 2013-06-20 21:08:49 | [diff] [blame] | 589 | original_content_length, |
| 590 | freshness_lifetime); |
sclittle | f72ee64 | 2014-09-24 20:04:28 | [diff] [blame] | 591 | |
megjablon | 25ff71d3 | 2014-09-05 03:21:44 | [diff] [blame] | 592 | if (data_reduction_proxy_enabled_ && |
| 593 | data_reduction_proxy_usage_stats_ && |
| 594 | !proxy_config_getter_.is_null()) { |
sclittle | f72ee64 | 2014-09-24 20:04:28 | [diff] [blame] | 595 | data_reduction_proxy_usage_stats_->RecordBytesHistograms( |
| 596 | request, |
megjablon | 25ff71d3 | 2014-09-05 03:21:44 | [diff] [blame] | 597 | *data_reduction_proxy_enabled_, |
| 598 | proxy_config_getter_.Run()); |
[email protected] | a948dad | 2014-07-25 00:39:38 | [diff] [blame] | 599 | } |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 600 | DVLOG(2) << __FUNCTION__ |
| 601 | << " received content length: " << received_content_length |
| 602 | << " original content length: " << original_content_length |
| 603 | << " url: " << request->url(); |
| 604 | } |
| 605 | |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 606 | extensions_delegate_->OnCompleted(request, started); |
[email protected] | a83dd33 | 2011-07-13 10:41:01 | [diff] [blame] | 607 | } else if (request->status().status() == net::URLRequestStatus::FAILED || |
| 608 | request->status().status() == net::URLRequestStatus::CANCELED) { |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 609 | extensions_delegate_->OnCompleted(request, started); |
[email protected] | a83dd33 | 2011-07-13 10:41:01 | [diff] [blame] | 610 | } else { |
| 611 | NOTREACHED(); |
[email protected] | 4894438 | 2011-04-23 13:28:16 | [diff] [blame] | 612 | } |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 613 | if (domain_reliability_monitor_) |
| 614 | domain_reliability_monitor_->OnCompleted(request, started); |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 615 | extensions_delegate_->ForwardProxyErrors(request); |
| 616 | extensions_delegate_->ForwardDoneRequestStatus(request); |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 617 | } |
[email protected] | 4b50cb5 | 2011-03-10 00:29:37 | [diff] [blame] | 618 | |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 619 | void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 620 | extensions_delegate_->OnURLRequestDestroyed(request); |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 621 | } |
| 622 | |
[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 623 | void ChromeNetworkDelegate::OnPACScriptError(int line_number, |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 624 | const base::string16& error) { |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 625 | extensions_delegate_->OnPACScriptError(line_number, error); |
[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 626 | } |
[email protected] | 7efc582d | 2011-08-03 20:46:35 | [diff] [blame] | 627 | |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 628 | net::NetworkDelegate::AuthRequiredResponse |
| 629 | ChromeNetworkDelegate::OnAuthRequired( |
[email protected] | 7efc582d | 2011-08-03 20:46:35 | [diff] [blame] | 630 | net::URLRequest* request, |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 631 | const net::AuthChallengeInfo& auth_info, |
| 632 | const AuthCallback& callback, |
| 633 | net::AuthCredentials* credentials) { |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 634 | return extensions_delegate_->OnAuthRequired( |
| 635 | request, auth_info, callback, credentials); |
[email protected] | 7efc582d | 2011-08-03 20:46:35 | [diff] [blame] | 636 | } |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 637 | |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 638 | bool ChromeNetworkDelegate::OnCanGetCookies( |
| 639 | const net::URLRequest& request, |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 640 | const net::CookieList& cookie_list) { |
| 641 | // NULL during tests, or when we're running in the system context. |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 642 | if (!cookie_settings_.get()) |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 643 | return true; |
| 644 | |
| 645 | bool allow = cookie_settings_->IsReadingCookieAllowed( |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 646 | request.url(), request.first_party_for_cookies()); |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 647 | |
| 648 | int render_process_id = -1; |
[email protected] | f3add92 | 2013-12-20 23:17:16 | [diff] [blame] | 649 | int render_frame_id = -1; |
[email protected] | f7fa5b6 | 2014-03-19 15:20:06 | [diff] [blame] | 650 | |
| 651 | // |is_for_blocking_resource| indicates whether the cookies read were for a |
| 652 | // blocking resource (eg script, css). It is only temporarily added for |
| 653 | // diagnostic purposes, per bug 353678. Will be removed again once data |
| 654 | // collection is finished. |
| 655 | bool is_for_blocking_resource = false; |
| 656 | const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); |
| 657 | if (info && ((!info->IsAsync()) || |
[email protected] | 6c1e0521 | 2014-07-31 00:59:40 | [diff] [blame] | 658 | info->GetResourceType() == content::RESOURCE_TYPE_STYLESHEET || |
| 659 | info->GetResourceType() == content::RESOURCE_TYPE_SCRIPT)) { |
[email protected] | f7fa5b6 | 2014-03-19 15:20:06 | [diff] [blame] | 660 | is_for_blocking_resource = true; |
| 661 | } |
| 662 | |
[email protected] | f3add92 | 2013-12-20 23:17:16 | [diff] [blame] | 663 | if (content::ResourceRequestInfo::GetRenderFrameForRequest( |
| 664 | &request, &render_process_id, &render_frame_id)) { |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 665 | BrowserThread::PostTask( |
| 666 | BrowserThread::UI, FROM_HERE, |
| 667 | base::Bind(&TabSpecificContentSettings::CookiesRead, |
[email protected] | f3add92 | 2013-12-20 23:17:16 | [diff] [blame] | 668 | render_process_id, render_frame_id, |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 669 | request.url(), request.first_party_for_cookies(), |
[email protected] | f7fa5b6 | 2014-03-19 15:20:06 | [diff] [blame] | 670 | cookie_list, !allow, is_for_blocking_resource)); |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | return allow; |
| 674 | } |
| 675 | |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 676 | bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, |
| 677 | const std::string& cookie_line, |
| 678 | net::CookieOptions* options) { |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 679 | // NULL during tests, or when we're running in the system context. |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 680 | if (!cookie_settings_.get()) |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 681 | return true; |
| 682 | |
| 683 | bool allow = cookie_settings_->IsSettingCookieAllowed( |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 684 | request.url(), request.first_party_for_cookies()); |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 685 | |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 686 | int render_process_id = -1; |
[email protected] | f3add92 | 2013-12-20 23:17:16 | [diff] [blame] | 687 | int render_frame_id = -1; |
| 688 | if (content::ResourceRequestInfo::GetRenderFrameForRequest( |
| 689 | &request, &render_process_id, &render_frame_id)) { |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 690 | BrowserThread::PostTask( |
| 691 | BrowserThread::UI, FROM_HERE, |
| 692 | base::Bind(&TabSpecificContentSettings::CookieChanged, |
[email protected] | f3add92 | 2013-12-20 23:17:16 | [diff] [blame] | 693 | render_process_id, render_frame_id, |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 694 | request.url(), request.first_party_for_cookies(), |
[email protected] | fd473d1 | 2012-04-05 11:38:43 | [diff] [blame] | 695 | cookie_line, *options, !allow)); |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 696 | } |
| 697 | |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 698 | if (prerender_tracker_) { |
| 699 | prerender_tracker_->OnCookieChangedForURL( |
| 700 | render_process_id, |
| 701 | request.context()->cookie_store()->GetCookieMonster(), |
| 702 | request.url()); |
| 703 | } |
| 704 | |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 705 | return allow; |
| 706 | } |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 707 | |
| 708 | bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 709 | const base::FilePath& path) const { |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 710 | if (g_allow_file_access_) |
| 711 | return true; |
| 712 | |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 713 | #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 714 | return true; |
| 715 | #else |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 716 | #if defined(OS_CHROMEOS) |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 717 | // If we're running Chrome for ChromeOS on Linux, we want to allow file |
| 718 | // access. |
[email protected] | 49c4cf85 | 2013-09-27 19:28:24 | [diff] [blame] | 719 | if (!base::SysInfo::IsRunningOnChromeOS() || |
[email protected] | 28853848 | 2012-09-06 21:09:35 | [diff] [blame] | 720 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 721 | return true; |
[email protected] | 28853848 | 2012-09-06 21:09:35 | [diff] [blame] | 722 | } |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 723 | |
| 724 | // Use a whitelist to only allow access to files residing in the list of |
| 725 | // directories below. |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 726 | static const char* const kLocalAccessWhiteList[] = { |
| 727 | "/home/chronos/user/Downloads", |
| 728 | "/home/chronos/user/log", |
[email protected] | 4791af43d | 2014-05-05 13:19:42 | [diff] [blame] | 729 | "/home/chronos/user/WebRTC Logs", |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 730 | "/media", |
| 731 | "/opt/oem", |
| 732 | "/usr/share/chromeos-assets", |
| 733 | "/tmp", |
| 734 | "/var/log", |
| 735 | }; |
[email protected] | ae015e1 | 2013-11-04 19:11:33 | [diff] [blame] | 736 | |
[email protected] | 9e73328 | 2014-06-18 16:56:55 | [diff] [blame] | 737 | // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under |
| 738 | // the profile path ("/home/chronos/user' is a hard link to current primary |
| 739 | // logged in profile.) For the support of multi-profile sessions, we are |
| 740 | // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such |
| 741 | // access. |
[email protected] | ae015e1 | 2013-11-04 19:11:33 | [diff] [blame] | 742 | if (!profile_path_.empty()) { |
| 743 | const base::FilePath downloads = profile_path_.AppendASCII("Downloads"); |
| 744 | if (downloads == path.StripTrailingSeparators() || downloads.IsParent(path)) |
| 745 | return true; |
[email protected] | 9e73328 | 2014-06-18 16:56:55 | [diff] [blame] | 746 | const base::FilePath webrtc_logs = profile_path_.AppendASCII("WebRTC Logs"); |
| 747 | if (webrtc_logs == path.StripTrailingSeparators() || |
| 748 | webrtc_logs.IsParent(path)) { |
| 749 | return true; |
| 750 | } |
[email protected] | ae015e1 | 2013-11-04 19:11:33 | [diff] [blame] | 751 | } |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 752 | #elif defined(OS_ANDROID) |
| 753 | // Access to files in external storage is allowed. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 754 | base::FilePath external_storage_path; |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 755 | PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path); |
| 756 | if (external_storage_path.IsParent(path)) |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 757 | return true; |
| 758 | |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 759 | // Whitelist of other allowed directories. |
| 760 | static const char* const kLocalAccessWhiteList[] = { |
| 761 | "/sdcard", |
| 762 | "/mnt/sdcard", |
| 763 | }; |
| 764 | #endif |
| 765 | |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 766 | for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 767 | const base::FilePath white_listed_path(kLocalAccessWhiteList[i]); |
| 768 | // base::FilePath::operator== should probably handle trailing separators. |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 769 | if (white_listed_path == path.StripTrailingSeparators() || |
| 770 | white_listed_path.IsParent(path)) { |
| 771 | return true; |
| 772 | } |
| 773 | } |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 774 | |
[email protected] | 28853848 | 2012-09-06 21:09:35 | [diff] [blame] | 775 | DVLOG(1) << "File access denied - " << path.value().c_str(); |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 776 | return false; |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 777 | #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 778 | } |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 779 | |
| 780 | bool ChromeNetworkDelegate::OnCanThrottleRequest( |
| 781 | const net::URLRequest& request) const { |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 782 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 783 | if (g_never_throttle_requests_) |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 784 | return false; |
[email protected] | c4a7df8 | 2012-08-09 22:48:46 | [diff] [blame] | 785 | return request.first_party_for_cookies().scheme() == |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 786 | extensions::kExtensionScheme; |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 787 | #else |
| 788 | return false; |
| 789 | #endif |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 790 | } |
[email protected] | aa28181e | 2012-06-13 00:53:58 | [diff] [blame] | 791 | |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 792 | bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( |
| 793 | const GURL& url, |
| 794 | const GURL& first_party_for_cookies) const { |
| 795 | // NULL during tests, or when we're running in the system context. |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 796 | if (!cookie_settings_.get()) |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 797 | return false; |
| 798 | |
| 799 | bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed( |
| 800 | url, first_party_for_cookies); |
| 801 | bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed( |
| 802 | url, first_party_for_cookies); |
| 803 | bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed); |
| 804 | return privacy_mode; |
| 805 | } |
| 806 | |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 807 | bool ChromeNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader( |
| 808 | const net::URLRequest& request, |
| 809 | const GURL& target_url, |
| 810 | const GURL& referrer_url) const { |
jochen | b93dba3c | 2014-11-11 05:28:41 | [diff] [blame^] | 811 | base::debug::StackTrace callstack; |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 812 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
jochen | b93dba3c | 2014-11-11 05:28:41 | [diff] [blame^] | 813 | base::Bind(&ReportInvalidReferrerSend, target_url, |
| 814 | referrer_url, callstack)); |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 815 | return true; |
| 816 | } |
| 817 | |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 818 | void ChromeNetworkDelegate::AccumulateContentLength( |
[email protected] | b779646 | 2013-12-12 19:42:34 | [diff] [blame] | 819 | int64 received_content_length, |
| 820 | int64 original_content_length, |
[email protected] | a0a0693 | 2014-04-14 21:23:42 | [diff] [blame] | 821 | data_reduction_proxy::DataReductionProxyRequestType request_type) { |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 822 | DCHECK_GE(received_content_length, 0); |
| 823 | DCHECK_GE(original_content_length, 0); |
megjablon | 53f608b | 2014-09-18 19:24:55 | [diff] [blame] | 824 | if (data_reduction_proxy_statistics_prefs_) { |
| 825 | StoreAccumulatedContentLength(received_content_length, |
| 826 | original_content_length, |
| 827 | request_type, |
| 828 | reinterpret_cast<Profile*>(profile_), |
| 829 | data_reduction_proxy_statistics_prefs_); |
| 830 | } |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 831 | received_content_length_ += received_content_length; |
| 832 | original_content_length_ += original_content_length; |
| 833 | } |