| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/net/chrome_network_delegate.h" | 5 #include "chrome/browser/net/chrome_network_delegate.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/prefs/pref_member.h" | 16 #include "base/prefs/pref_member.h" |
| 17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/content_settings/cookie_settings.h" | 22 #include "chrome/browser/content_settings/cookie_settings.h" |
| 23 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 23 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 24 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 24 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 25 #include "chrome/browser/extensions/api/proxy/proxy_api.h" | |
| 26 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | |
| 27 #include "chrome/browser/extensions/event_router_forwarder.h" | |
| 28 #include "chrome/browser/google/google_util.h" | 25 #include "chrome/browser/google/google_util.h" |
| 26 #include "chrome/browser/net/chrome_extensions_network_delegate.h" |
| 29 #include "chrome/browser/net/client_hints.h" | 27 #include "chrome/browser/net/client_hints.h" |
| 30 #include "chrome/browser/net/connect_interceptor.h" | 28 #include "chrome/browser/net/connect_interceptor.h" |
| 31 #include "chrome/browser/performance_monitor/performance_monitor.h" | 29 #include "chrome/browser/performance_monitor/performance_monitor.h" |
| 32 #include "chrome/browser/prerender/prerender_tracker.h" | 30 #include "chrome/browser/prerender/prerender_tracker.h" |
| 33 #include "chrome/browser/profiles/profile_manager.h" | 31 #include "chrome/browser/profiles/profile_manager.h" |
| 34 #include "chrome/browser/task_manager/task_manager.h" | 32 #include "chrome/browser/task_manager/task_manager.h" |
| 35 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 36 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
| 37 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h
" | 35 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h
" |
| 38 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 36 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
| 39 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" | 37 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" |
| 40 #include "components/domain_reliability/monitor.h" | 38 #include "components/domain_reliability/monitor.h" |
| 41 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
| 42 #include "content/public/browser/render_frame_host.h" | 40 #include "content/public/browser/render_frame_host.h" |
| 43 #include "content/public/browser/render_view_host.h" | 41 #include "content/public/browser/render_view_host.h" |
| 44 #include "content/public/browser/resource_request_info.h" | 42 #include "content/public/browser/resource_request_info.h" |
| 45 #include "extensions/browser/extension_system.h" | |
| 46 #include "extensions/browser/info_map.h" | |
| 47 #include "extensions/browser/process_manager.h" | |
| 48 #include "extensions/common/constants.h" | 43 #include "extensions/common/constants.h" |
| 49 #include "net/base/host_port_pair.h" | 44 #include "net/base/host_port_pair.h" |
| 50 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
| 51 #include "net/base/net_log.h" | 46 #include "net/base/net_log.h" |
| 52 #include "net/cookies/canonical_cookie.h" | 47 #include "net/cookies/canonical_cookie.h" |
| 53 #include "net/cookies/cookie_options.h" | 48 #include "net/cookies/cookie_options.h" |
| 54 #include "net/http/http_request_headers.h" | 49 #include "net/http/http_request_headers.h" |
| 55 #include "net/http/http_response_headers.h" | 50 #include "net/http/http_response_headers.h" |
| 56 #include "net/socket_stream/socket_stream.h" | 51 #include "net/socket_stream/socket_stream.h" |
| 57 #include "net/url_request/url_request.h" | 52 #include "net/url_request/url_request.h" |
| 58 #include "net/url_request/url_request_context.h" | 53 #include "net/url_request/url_request_context.h" |
| 59 | 54 |
| 55 #if defined(OS_ANDROID) |
| 56 #include "chrome/browser/io_thread.h" |
| 57 #include "components/precache/content/precache_manager.h" |
| 58 #include "components/precache/content/precache_manager_factory.h" |
| 59 #endif |
| 60 |
| 60 #if defined(OS_CHROMEOS) | 61 #if defined(OS_CHROMEOS) |
| 61 #include "base/command_line.h" | 62 #include "base/command_line.h" |
| 62 #include "base/sys_info.h" | 63 #include "base/sys_info.h" |
| 63 #include "chrome/common/chrome_switches.h" | 64 #include "chrome/common/chrome_switches.h" |
| 64 #endif | 65 #endif |
| 65 | 66 |
| 66 #if defined(ENABLE_CONFIGURATION_POLICY) | 67 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 67 #include "components/policy/core/browser/url_blacklist_manager.h" | 68 #include "components/policy/core/browser/url_blacklist_manager.h" |
| 68 #endif | 69 #endif |
| 69 | 70 |
| 70 #if defined(OS_ANDROID) | |
| 71 #include "chrome/browser/io_thread.h" | |
| 72 #include "components/precache/content/precache_manager.h" | |
| 73 #include "components/precache/content/precache_manager_factory.h" | |
| 74 #endif | |
| 75 | |
| 76 using content::BrowserThread; | 71 using content::BrowserThread; |
| 77 using content::RenderViewHost; | 72 using content::RenderViewHost; |
| 78 using content::ResourceRequestInfo; | 73 using content::ResourceRequestInfo; |
| 79 | 74 |
| 80 // By default we don't allow access to all file:// urls on ChromeOS and | 75 // By default we don't allow access to all file:// urls on ChromeOS and |
| 81 // Android. | 76 // Android. |
| 82 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 77 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 83 bool ChromeNetworkDelegate::g_allow_file_access_ = false; | 78 bool ChromeNetworkDelegate::g_allow_file_access_ = false; |
| 84 #else | 79 #else |
| 85 bool ChromeNetworkDelegate::g_allow_file_access_ = true; | 80 bool ChromeNetworkDelegate::g_allow_file_access_ = true; |
| 86 #endif | 81 #endif |
| 87 | 82 |
| 88 // This remains false unless the --disable-extensions-http-throttling | 83 // This remains false unless the --disable-extensions-http-throttling |
| 89 // flag is passed to the browser. | 84 // flag is passed to the browser. |
| 90 bool ChromeNetworkDelegate::g_never_throttle_requests_ = false; | 85 bool ChromeNetworkDelegate::g_never_throttle_requests_ = false; |
| 91 | 86 |
| 92 namespace { | 87 namespace { |
| 93 | 88 |
| 94 const char kDNTHeader[] = "DNT"; | 89 const char kDNTHeader[] = "DNT"; |
| 95 | 90 |
| 96 // If the |request| failed due to problems with a proxy, forward the error to | |
| 97 // the proxy extension API. | |
| 98 void ForwardProxyErrors(net::URLRequest* request, | |
| 99 extensions::EventRouterForwarder* event_router, | |
| 100 void* profile) { | |
| 101 if (request->status().status() == net::URLRequestStatus::FAILED) { | |
| 102 switch (request->status().error()) { | |
| 103 case net::ERR_PROXY_AUTH_UNSUPPORTED: | |
| 104 case net::ERR_PROXY_CONNECTION_FAILED: | |
| 105 case net::ERR_TUNNEL_CONNECTION_FAILED: | |
| 106 extensions::ProxyEventRouter::GetInstance()->OnProxyError( | |
| 107 event_router, profile, request->status().error()); | |
| 108 } | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 // Returns whether a URL parameter, |first_parameter| (e.g. foo=bar), has the | 91 // Returns whether a URL parameter, |first_parameter| (e.g. foo=bar), has the |
| 113 // same key as the the |second_parameter| (e.g. foo=baz). Both parameters | 92 // same key as the the |second_parameter| (e.g. foo=baz). Both parameters |
| 114 // must be in key=value form. | 93 // must be in key=value form. |
| 115 bool HasSameParameterKey(const std::string& first_parameter, | 94 bool HasSameParameterKey(const std::string& first_parameter, |
| 116 const std::string& second_parameter) { | 95 const std::string& second_parameter) { |
| 117 DCHECK(second_parameter.find("=") != std::string::npos); | 96 DCHECK(second_parameter.find("=") != std::string::npos); |
| 118 // Prefix for "foo=bar" is "foo=". | 97 // Prefix for "foo=bar" is "foo=". |
| 119 std::string parameter_prefix = second_parameter.substr( | 98 std::string parameter_prefix = second_parameter.substr( |
| 120 0, second_parameter.find("=") + 1); | 99 0, second_parameter.find("=") + 1); |
| 121 return StartsWithASCII(first_parameter, parameter_prefix, false); | 100 return StartsWithASCII(first_parameter, parameter_prefix, false); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 void ForceGoogleSafeSearchCallbackWrapper( | 150 void ForceGoogleSafeSearchCallbackWrapper( |
| 172 const net::CompletionCallback& callback, | 151 const net::CompletionCallback& callback, |
| 173 net::URLRequest* request, | 152 net::URLRequest* request, |
| 174 GURL* new_url, | 153 GURL* new_url, |
| 175 int rv) { | 154 int rv) { |
| 176 if (rv == net::OK && new_url->is_empty()) | 155 if (rv == net::OK && new_url->is_empty()) |
| 177 ForceGoogleSafeSearch(request, new_url); | 156 ForceGoogleSafeSearch(request, new_url); |
| 178 callback.Run(rv); | 157 callback.Run(rv); |
| 179 } | 158 } |
| 180 | 159 |
| 181 enum RequestStatus { REQUEST_STARTED, REQUEST_DONE }; | |
| 182 | |
| 183 // Notifies the extensions::ProcessManager that a request has started or stopped | |
| 184 // for a particular RenderFrame. | |
| 185 void NotifyEPMRequestStatus(RequestStatus status, | |
| 186 void* profile_id, | |
| 187 int process_id, | |
| 188 int render_frame_id) { | |
| 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 190 Profile* profile = reinterpret_cast<Profile*>(profile_id); | |
| 191 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | |
| 192 return; | |
| 193 | |
| 194 extensions::ProcessManager* process_manager = | |
| 195 extensions::ExtensionSystem::Get(profile)->process_manager(); | |
| 196 // This may be NULL in unit tests. | |
| 197 if (!process_manager) | |
| 198 return; | |
| 199 | |
| 200 // Will be NULL if the request was not issued on behalf of a renderer (e.g. a | |
| 201 // system-level request). | |
| 202 content::RenderFrameHost* render_frame_host = | |
| 203 content::RenderFrameHost::FromID(process_id, render_frame_id); | |
| 204 if (render_frame_host) { | |
| 205 if (status == REQUEST_STARTED) { | |
| 206 process_manager->OnNetworkRequestStarted(render_frame_host); | |
| 207 } else if (status == REQUEST_DONE) { | |
| 208 process_manager->OnNetworkRequestDone(render_frame_host); | |
| 209 } else { | |
| 210 NOTREACHED(); | |
| 211 } | |
| 212 } | |
| 213 } | |
| 214 | |
| 215 void ForwardRequestStatus( | |
| 216 RequestStatus status, net::URLRequest* request, void* profile_id) { | |
| 217 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | |
| 218 if (!info) | |
| 219 return; | |
| 220 | |
| 221 int process_id, render_frame_id; | |
| 222 if (info->GetAssociatedRenderFrame(&process_id, &render_frame_id)) { | |
| 223 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 224 base::Bind(&NotifyEPMRequestStatus, | |
| 225 status, profile_id, process_id, render_frame_id)); | |
| 226 } | |
| 227 } | |
| 228 | |
| 229 void UpdateContentLengthPrefs( | 160 void UpdateContentLengthPrefs( |
| 230 int received_content_length, | 161 int received_content_length, |
| 231 int original_content_length, | 162 int original_content_length, |
| 232 data_reduction_proxy::DataReductionProxyRequestType request_type, | 163 data_reduction_proxy::DataReductionProxyRequestType request_type, |
| 233 Profile* profile) { | 164 Profile* profile) { |
| 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 235 DCHECK_GE(received_content_length, 0); | 166 DCHECK_GE(received_content_length, 0); |
| 236 DCHECK_GE(original_content_length, 0); | 167 DCHECK_GE(original_content_length, 0); |
| 237 | 168 |
| 238 // Can be NULL in a unit test. | 169 // Can be NULL in a unit test. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 g_browser_process->io_thread()->creation_time(); | 277 g_browser_process->io_thread()->creation_time(); |
| 347 UMA_HISTOGRAM_TIMES("Net.IOThreadCreationToHTTPRequestStart", request_lag); | 278 UMA_HISTOGRAM_TIMES("Net.IOThreadCreationToHTTPRequestStart", request_lag); |
| 348 } | 279 } |
| 349 #endif // defined(OS_ANDROID) | 280 #endif // defined(OS_ANDROID) |
| 350 | 281 |
| 351 } // namespace | 282 } // namespace |
| 352 | 283 |
| 353 ChromeNetworkDelegate::ChromeNetworkDelegate( | 284 ChromeNetworkDelegate::ChromeNetworkDelegate( |
| 354 extensions::EventRouterForwarder* event_router, | 285 extensions::EventRouterForwarder* event_router, |
| 355 BooleanPrefMember* enable_referrers) | 286 BooleanPrefMember* enable_referrers) |
| 356 : event_router_(event_router), | 287 : profile_(NULL), |
| 357 profile_(NULL), | |
| 358 enable_referrers_(enable_referrers), | 288 enable_referrers_(enable_referrers), |
| 359 enable_do_not_track_(NULL), | 289 enable_do_not_track_(NULL), |
| 360 force_google_safe_search_(NULL), | 290 force_google_safe_search_(NULL), |
| 291 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 361 url_blacklist_manager_(NULL), | 292 url_blacklist_manager_(NULL), |
| 293 #endif |
| 362 domain_reliability_monitor_(NULL), | 294 domain_reliability_monitor_(NULL), |
| 363 received_content_length_(0), | 295 received_content_length_(0), |
| 364 original_content_length_(0), | 296 original_content_length_(0), |
| 365 first_request_(true), | 297 first_request_(true), |
| 366 prerender_tracker_(NULL), | 298 prerender_tracker_(NULL), |
| 367 data_reduction_proxy_params_(NULL) { | 299 data_reduction_proxy_params_(NULL) { |
| 368 DCHECK(event_router); | |
| 369 DCHECK(enable_referrers); | 300 DCHECK(enable_referrers); |
| 301 extensions_delegate_.reset( |
| 302 ChromeExtensionsNetworkDelegate::Create(event_router)); |
| 370 } | 303 } |
| 371 | 304 |
| 372 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} | 305 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} |
| 373 | 306 |
| 374 void ChromeNetworkDelegate::set_extension_info_map( | 307 void ChromeNetworkDelegate::set_extension_info_map( |
| 375 extensions::InfoMap* extension_info_map) { | 308 extensions::InfoMap* extension_info_map) { |
| 376 extension_info_map_ = extension_info_map; | 309 extensions_delegate_->set_extension_info_map(extension_info_map); |
| 310 } |
| 311 |
| 312 void ChromeNetworkDelegate::set_profile(void* profile) { |
| 313 profile_ = profile; |
| 314 extensions_delegate_->set_profile(profile); |
| 377 } | 315 } |
| 378 | 316 |
| 379 void ChromeNetworkDelegate::set_cookie_settings( | 317 void ChromeNetworkDelegate::set_cookie_settings( |
| 380 CookieSettings* cookie_settings) { | 318 CookieSettings* cookie_settings) { |
| 381 cookie_settings_ = cookie_settings; | 319 cookie_settings_ = cookie_settings; |
| 382 } | 320 } |
| 383 | 321 |
| 384 void ChromeNetworkDelegate::set_predictor( | 322 void ChromeNetworkDelegate::set_predictor( |
| 385 chrome_browser_net::Predictor* predictor) { | 323 chrome_browser_net::Predictor* predictor) { |
| 386 connect_interceptor_.reset( | 324 connect_interceptor_.reset( |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 url_blacklist_manager_->IsRequestBlocked(*request, &error)) { | 423 url_blacklist_manager_->IsRequestBlocked(*request, &error)) { |
| 486 // URL access blocked by policy. | 424 // URL access blocked by policy. |
| 487 request->net_log().AddEvent( | 425 request->net_log().AddEvent( |
| 488 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST, | 426 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST, |
| 489 net::NetLog::StringCallback("url", | 427 net::NetLog::StringCallback("url", |
| 490 &request->url().possibly_invalid_spec())); | 428 &request->url().possibly_invalid_spec())); |
| 491 return error; | 429 return error; |
| 492 } | 430 } |
| 493 #endif | 431 #endif |
| 494 | 432 |
| 495 ForwardRequestStatus(REQUEST_STARTED, request, profile_); | 433 extensions_delegate_->ForwardStartRequestStatus(request); |
| 496 | 434 |
| 497 if (!enable_referrers_->GetValue()) | 435 if (!enable_referrers_->GetValue()) |
| 498 request->SetReferrer(std::string()); | 436 request->SetReferrer(std::string()); |
| 499 if (enable_do_not_track_ && enable_do_not_track_->GetValue()) | 437 if (enable_do_not_track_ && enable_do_not_track_->GetValue()) |
| 500 request->SetExtraRequestHeaderByName(kDNTHeader, "1", true /* override */); | 438 request->SetExtraRequestHeaderByName(kDNTHeader, "1", true /* override */); |
| 501 | 439 |
| 502 if (client_hints_) { | 440 if (client_hints_) { |
| 503 request->SetExtraRequestHeaderByName( | 441 request->SetExtraRequestHeaderByName( |
| 504 ClientHints::kDevicePixelRatioHeader, | 442 ClientHints::kDevicePixelRatioHeader, |
| 505 client_hints_->GetDevicePixelRatioHeader(), true); | 443 client_hints_->GetDevicePixelRatioHeader(), true); |
| 506 } | 444 } |
| 507 | 445 |
| 508 bool force_safe_search = force_google_safe_search_ && | 446 bool force_safe_search = force_google_safe_search_ && |
| 509 force_google_safe_search_->GetValue(); | 447 force_google_safe_search_->GetValue(); |
| 510 | 448 |
| 511 net::CompletionCallback wrapped_callback = callback; | 449 net::CompletionCallback wrapped_callback = callback; |
| 512 if (force_safe_search) { | 450 if (force_safe_search) { |
| 513 wrapped_callback = base::Bind(&ForceGoogleSafeSearchCallbackWrapper, | 451 wrapped_callback = base::Bind(&ForceGoogleSafeSearchCallbackWrapper, |
| 514 callback, | 452 callback, |
| 515 base::Unretained(request), | 453 base::Unretained(request), |
| 516 base::Unretained(new_url)); | 454 base::Unretained(new_url)); |
| 517 } | 455 } |
| 518 | 456 |
| 519 int rv = ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest( | 457 int rv = extensions_delegate_->OnBeforeURLRequest( |
| 520 profile_, extension_info_map_.get(), request, wrapped_callback, | 458 request, wrapped_callback, new_url); |
| 521 new_url); | |
| 522 | 459 |
| 523 if (force_safe_search && rv == net::OK && new_url->is_empty()) | 460 if (force_safe_search && rv == net::OK && new_url->is_empty()) |
| 524 ForceGoogleSafeSearch(request, new_url); | 461 ForceGoogleSafeSearch(request, new_url); |
| 525 | 462 |
| 526 if (connect_interceptor_) | 463 if (connect_interceptor_) |
| 527 connect_interceptor_->WitnessURLRequest(request); | 464 connect_interceptor_->WitnessURLRequest(request); |
| 528 | 465 |
| 529 return rv; | 466 return rv; |
| 530 } | 467 } |
| 531 | 468 |
| 532 int ChromeNetworkDelegate::OnBeforeSendHeaders( | 469 int ChromeNetworkDelegate::OnBeforeSendHeaders( |
| 533 net::URLRequest* request, | 470 net::URLRequest* request, |
| 534 const net::CompletionCallback& callback, | 471 const net::CompletionCallback& callback, |
| 535 net::HttpRequestHeaders* headers) { | 472 net::HttpRequestHeaders* headers) { |
| 536 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest"); | 473 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest"); |
| 537 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders( | 474 return extensions_delegate_->OnBeforeSendHeaders(request, callback, headers); |
| 538 profile_, extension_info_map_.get(), request, callback, headers); | |
| 539 } | 475 } |
| 540 | 476 |
| 541 void ChromeNetworkDelegate::OnSendHeaders( | 477 void ChromeNetworkDelegate::OnSendHeaders( |
| 542 net::URLRequest* request, | 478 net::URLRequest* request, |
| 543 const net::HttpRequestHeaders& headers) { | 479 const net::HttpRequestHeaders& headers) { |
| 544 ExtensionWebRequestEventRouter::GetInstance()->OnSendHeaders( | 480 extensions_delegate_->OnSendHeaders(request, headers); |
| 545 profile_, extension_info_map_.get(), request, headers); | |
| 546 } | 481 } |
| 547 | 482 |
| 548 int ChromeNetworkDelegate::OnHeadersReceived( | 483 int ChromeNetworkDelegate::OnHeadersReceived( |
| 549 net::URLRequest* request, | 484 net::URLRequest* request, |
| 550 const net::CompletionCallback& callback, | 485 const net::CompletionCallback& callback, |
| 551 const net::HttpResponseHeaders* original_response_headers, | 486 const net::HttpResponseHeaders* original_response_headers, |
| 552 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 487 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
| 553 GURL* allowed_unsafe_redirect_url) { | 488 GURL* allowed_unsafe_redirect_url) { |
| 554 | |
| 555 if (data_reduction_proxy::MaybeBypassProxyAndPrepareToRetry( | 489 if (data_reduction_proxy::MaybeBypassProxyAndPrepareToRetry( |
| 556 data_reduction_proxy_params_, | 490 data_reduction_proxy_params_, |
| 557 request, | 491 request, |
| 558 original_response_headers, | 492 original_response_headers, |
| 559 override_response_headers)) { | 493 override_response_headers)) { |
| 560 return net::OK; | 494 return net::OK; |
| 561 } | 495 } |
| 562 | 496 |
| 563 return ExtensionWebRequestEventRouter::GetInstance()->OnHeadersReceived( | 497 return extensions_delegate_->OnHeadersReceived( |
| 564 profile_, | |
| 565 extension_info_map_.get(), | |
| 566 request, | 498 request, |
| 567 callback, | 499 callback, |
| 568 original_response_headers, | 500 original_response_headers, |
| 569 override_response_headers, | 501 override_response_headers, |
| 570 allowed_unsafe_redirect_url); | 502 allowed_unsafe_redirect_url); |
| 571 } | 503 } |
| 572 | 504 |
| 573 void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request, | 505 void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request, |
| 574 const GURL& new_location) { | 506 const GURL& new_location) { |
| 575 if (domain_reliability_monitor_) | 507 if (domain_reliability_monitor_) |
| 576 domain_reliability_monitor_->OnBeforeRedirect(request); | 508 domain_reliability_monitor_->OnBeforeRedirect(request); |
| 577 ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRedirect( | 509 extensions_delegate_->OnBeforeRedirect(request, new_location); |
| 578 profile_, extension_info_map_.get(), request, new_location); | |
| 579 } | 510 } |
| 580 | 511 |
| 581 | 512 |
| 582 void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) { | 513 void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) { |
| 583 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "ResponseStarted"); | 514 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "ResponseStarted"); |
| 584 ExtensionWebRequestEventRouter::GetInstance()->OnResponseStarted( | 515 extensions_delegate_->OnResponseStarted(request); |
| 585 profile_, extension_info_map_.get(), request); | |
| 586 ForwardProxyErrors(request, event_router_.get(), profile_); | |
| 587 } | 516 } |
| 588 | 517 |
| 589 void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request, | 518 void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request, |
| 590 int bytes_read) { | 519 int bytes_read) { |
| 591 TRACE_EVENT_ASYNC_STEP_PAST1("net", "URLRequest", &request, "DidRead", | 520 TRACE_EVENT_ASYNC_STEP_PAST1("net", "URLRequest", &request, "DidRead", |
| 592 "bytes_read", bytes_read); | 521 "bytes_read", bytes_read); |
| 593 performance_monitor::PerformanceMonitor::GetInstance()->BytesReadOnIOThread( | 522 performance_monitor::PerformanceMonitor::GetInstance()->BytesReadOnIOThread( |
| 594 request, bytes_read); | 523 request, bytes_read); |
| 595 | 524 |
| 596 #if defined(ENABLE_TASK_MANAGER) | 525 #if defined(ENABLE_TASK_MANAGER) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 request_type); | 576 request_type); |
| 648 RecordContentLengthHistograms(received_content_length, | 577 RecordContentLengthHistograms(received_content_length, |
| 649 original_content_length, | 578 original_content_length, |
| 650 freshness_lifetime); | 579 freshness_lifetime); |
| 651 DVLOG(2) << __FUNCTION__ | 580 DVLOG(2) << __FUNCTION__ |
| 652 << " received content length: " << received_content_length | 581 << " received content length: " << received_content_length |
| 653 << " original content length: " << original_content_length | 582 << " original content length: " << original_content_length |
| 654 << " url: " << request->url(); | 583 << " url: " << request->url(); |
| 655 } | 584 } |
| 656 | 585 |
| 657 bool is_redirect = request->response_headers() && | 586 extensions_delegate_->OnCompleted(request, started); |
| 658 net::HttpResponseHeaders::IsRedirectResponseCode( | |
| 659 request->response_headers()->response_code()); | |
| 660 if (!is_redirect) { | |
| 661 ExtensionWebRequestEventRouter::GetInstance()->OnCompleted( | |
| 662 profile_, extension_info_map_.get(), request); | |
| 663 } | |
| 664 } else if (request->status().status() == net::URLRequestStatus::FAILED || | 587 } else if (request->status().status() == net::URLRequestStatus::FAILED || |
| 665 request->status().status() == net::URLRequestStatus::CANCELED) { | 588 request->status().status() == net::URLRequestStatus::CANCELED) { |
| 666 ExtensionWebRequestEventRouter::GetInstance()->OnErrorOccurred( | 589 extensions_delegate_->OnCompleted(request, started); |
| 667 profile_, extension_info_map_.get(), request, started); | |
| 668 } else { | 590 } else { |
| 669 NOTREACHED(); | 591 NOTREACHED(); |
| 670 } | 592 } |
| 671 if (domain_reliability_monitor_) | 593 if (domain_reliability_monitor_) |
| 672 domain_reliability_monitor_->OnCompleted(request, started); | 594 domain_reliability_monitor_->OnCompleted(request, started); |
| 673 ForwardProxyErrors(request, event_router_.get(), profile_); | 595 extensions_delegate_->ForwardProxyErrors(request); |
| 674 | 596 extensions_delegate_->ForwardDoneRequestStatus(request); |
| 675 ForwardRequestStatus(REQUEST_DONE, request, profile_); | |
| 676 } | 597 } |
| 677 | 598 |
| 678 void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { | 599 void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { |
| 679 ExtensionWebRequestEventRouter::GetInstance()->OnURLRequestDestroyed( | 600 extensions_delegate_->OnURLRequestDestroyed(request); |
| 680 profile_, request); | |
| 681 } | 601 } |
| 682 | 602 |
| 683 void ChromeNetworkDelegate::OnPACScriptError(int line_number, | 603 void ChromeNetworkDelegate::OnPACScriptError(int line_number, |
| 684 const base::string16& error) { | 604 const base::string16& error) { |
| 685 extensions::ProxyEventRouter::GetInstance()->OnPACScriptError( | 605 extensions_delegate_->OnPACScriptError(line_number, error); |
| 686 event_router_.get(), profile_, line_number, error); | |
| 687 } | 606 } |
| 688 | 607 |
| 689 net::NetworkDelegate::AuthRequiredResponse | 608 net::NetworkDelegate::AuthRequiredResponse |
| 690 ChromeNetworkDelegate::OnAuthRequired( | 609 ChromeNetworkDelegate::OnAuthRequired( |
| 691 net::URLRequest* request, | 610 net::URLRequest* request, |
| 692 const net::AuthChallengeInfo& auth_info, | 611 const net::AuthChallengeInfo& auth_info, |
| 693 const AuthCallback& callback, | 612 const AuthCallback& callback, |
| 694 net::AuthCredentials* credentials) { | 613 net::AuthCredentials* credentials) { |
| 695 return ExtensionWebRequestEventRouter::GetInstance()->OnAuthRequired( | 614 return extensions_delegate_->OnAuthRequired( |
| 696 profile_, extension_info_map_.get(), request, auth_info, | 615 request, auth_info, callback, credentials); |
| 697 callback, credentials); | |
| 698 } | 616 } |
| 699 | 617 |
| 700 bool ChromeNetworkDelegate::OnCanGetCookies( | 618 bool ChromeNetworkDelegate::OnCanGetCookies( |
| 701 const net::URLRequest& request, | 619 const net::URLRequest& request, |
| 702 const net::CookieList& cookie_list) { | 620 const net::CookieList& cookie_list) { |
| 703 // NULL during tests, or when we're running in the system context. | 621 // NULL during tests, or when we're running in the system context. |
| 704 if (!cookie_settings_.get()) | 622 if (!cookie_settings_.get()) |
| 705 return true; | 623 return true; |
| 706 | 624 |
| 707 bool allow = cookie_settings_->IsReadingCookieAllowed( | 625 bool allow = cookie_settings_->IsReadingCookieAllowed( |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 } | 747 } |
| 830 } | 748 } |
| 831 | 749 |
| 832 DVLOG(1) << "File access denied - " << path.value().c_str(); | 750 DVLOG(1) << "File access denied - " << path.value().c_str(); |
| 833 return false; | 751 return false; |
| 834 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 752 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 835 } | 753 } |
| 836 | 754 |
| 837 bool ChromeNetworkDelegate::OnCanThrottleRequest( | 755 bool ChromeNetworkDelegate::OnCanThrottleRequest( |
| 838 const net::URLRequest& request) const { | 756 const net::URLRequest& request) const { |
| 839 if (g_never_throttle_requests_) { | 757 if (g_never_throttle_requests_) |
| 840 return false; | 758 return false; |
| 841 } | |
| 842 | |
| 843 return request.first_party_for_cookies().scheme() == | 759 return request.first_party_for_cookies().scheme() == |
| 844 extensions::kExtensionScheme; | 760 extensions::kExtensionScheme; |
| 845 } | 761 } |
| 846 | 762 |
| 847 bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( | 763 bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( |
| 848 const GURL& url, | 764 const GURL& url, |
| 849 const GURL& first_party_for_cookies) const { | 765 const GURL& first_party_for_cookies) const { |
| 850 // NULL during tests, or when we're running in the system context. | 766 // NULL during tests, or when we're running in the system context. |
| 851 if (!cookie_settings_.get()) | 767 if (!cookie_settings_.get()) |
| 852 return false; | 768 return false; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 882 data_reduction_proxy::DataReductionProxyRequestType request_type) { | 798 data_reduction_proxy::DataReductionProxyRequestType request_type) { |
| 883 DCHECK_GE(received_content_length, 0); | 799 DCHECK_GE(received_content_length, 0); |
| 884 DCHECK_GE(original_content_length, 0); | 800 DCHECK_GE(original_content_length, 0); |
| 885 StoreAccumulatedContentLength(received_content_length, | 801 StoreAccumulatedContentLength(received_content_length, |
| 886 original_content_length, | 802 original_content_length, |
| 887 request_type, | 803 request_type, |
| 888 reinterpret_cast<Profile*>(profile_)); | 804 reinterpret_cast<Profile*>(profile_)); |
| 889 received_content_length_ += received_content_length; | 805 received_content_length_ += received_content_length; |
| 890 original_content_length_ += original_content_length; | 806 original_content_length_ += original_content_length; |
| 891 } | 807 } |
| OLD | NEW |