| 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/renderer_host/chrome_resource_dispatcher_host_delegate.
h" | 5 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/content_settings/host_content_settings_map.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 13 #include "chrome/browser/download/download_request_limiter.h" | 13 #include "chrome/browser/download/download_request_limiter.h" |
| 14 #include "chrome/browser/download/download_resource_throttle.h" | 14 #include "chrome/browser/download/download_resource_throttle.h" |
| 15 #include "chrome/browser/download/download_util.h" | 15 #include "chrome/browser/download/download_util.h" |
| 16 #include "chrome/browser/extensions/user_script_listener.h" | 16 #include "chrome/browser/extensions/user_script_listener.h" |
| 17 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 17 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 18 #include "chrome/browser/google/google_util.h" | 18 #include "chrome/browser/google/google_util.h" |
| 19 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" | 19 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" |
| 20 #include "chrome/browser/net/load_timing_observer.h" | |
| 21 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" | 20 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" |
| 22 #include "chrome/browser/prerender/prerender_manager.h" | 21 #include "chrome/browser/prerender/prerender_manager.h" |
| 23 #include "chrome/browser/prerender/prerender_tracker.h" | 22 #include "chrome/browser/prerender/prerender_tracker.h" |
| 24 #include "chrome/browser/prerender/prerender_util.h" | 23 #include "chrome/browser/prerender/prerender_util.h" |
| 25 #include "chrome/browser/profiles/profile_io_data.h" | 24 #include "chrome/browser/profiles/profile_io_data.h" |
| 26 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h" | 25 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h" |
| 27 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h
" | 26 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h
" |
| 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 27 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 29 #include "chrome/browser/ui/auto_login_prompter.h" | 28 #include "chrome/browser/ui/auto_login_prompter.h" |
| 30 #include "chrome/browser/ui/login/login_prompt.h" | 29 #include "chrome/browser/ui/login/login_prompt.h" |
| 31 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 30 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
| 32 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
| 33 #include "chrome/common/extensions/extension_constants.h" | 32 #include "chrome/common/extensions/extension_constants.h" |
| 34 #include "chrome/common/extensions/user_script.h" | 33 #include "chrome/common/extensions/user_script.h" |
| 35 #include "chrome/common/render_messages.h" | 34 #include "chrome/common/render_messages.h" |
| 36 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
| 38 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
| 39 #include "content/public/browser/resource_context.h" | 38 #include "content/public/browser/resource_context.h" |
| 40 #include "content/public/browser/resource_dispatcher_host.h" | 39 #include "content/public/browser/resource_dispatcher_host.h" |
| 41 #include "content/public/browser/resource_request_info.h" | 40 #include "content/public/browser/resource_request_info.h" |
| 41 #include "content/public/common/resource_response.h" |
| 42 #include "net/base/load_flags.h" | 42 #include "net/base/load_flags.h" |
| 43 #include "net/base/load_timing_info.h" |
| 43 #include "net/base/ssl_config_service.h" | 44 #include "net/base/ssl_config_service.h" |
| 44 #include "net/http/http_response_headers.h" | 45 #include "net/http/http_response_headers.h" |
| 45 #include "net/url_request/url_request.h" | 46 #include "net/url_request/url_request.h" |
| 46 | 47 |
| 47 #if defined(ENABLE_MANAGED_USERS) | 48 #if defined(ENABLE_MANAGED_USERS) |
| 48 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" | 49 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" |
| 49 #endif | 50 #endif |
| 50 | 51 |
| 51 #if defined(USE_SYSTEM_PROTOBUF) | 52 #if defined(USE_SYSTEM_PROTOBUF) |
| 52 #include <google/protobuf/repeated_field.h> | 53 #include <google/protobuf/repeated_field.h> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 77 render_view_id); | 78 render_view_id); |
| 78 if (!rvh) | 79 if (!rvh) |
| 79 return; | 80 return; |
| 80 | 81 |
| 81 content::NotificationService::current()->Notify( | 82 content::NotificationService::current()->Notify( |
| 82 chrome::NOTIFICATION_DOWNLOAD_INITIATED, | 83 chrome::NOTIFICATION_DOWNLOAD_INITIATED, |
| 83 content::Source<RenderViewHost>(rvh), | 84 content::Source<RenderViewHost>(rvh), |
| 84 content::NotificationService::NoDetails()); | 85 content::NotificationService::NoDetails()); |
| 85 } | 86 } |
| 86 | 87 |
| 88 // The network stack returns actual connect times, while the renderer process |
| 89 // expects times that the request was blocked in each phase of setting up |
| 90 // a connection. Due to preconnect and late binding, it is possible for a |
| 91 // connection attempt to start before a request has been started, so this |
| 92 // function is needed to convert times from the network stack to times the |
| 93 // renderer process expects. |
| 94 void FixupLoadTimingInfo(net::LoadTimingInfo* load_timing_info) { |
| 95 // If there are no times, do nothing. |
| 96 if (load_timing_info->request_start.is_null()) |
| 97 return; |
| 98 |
| 99 // Starting the request and resolving the proxy are the only phases of the |
| 100 // request that occur before it blocks on starting a connection. |
| 101 base::TimeTicks block_on_connect_start = load_timing_info->request_start; |
| 102 if (!load_timing_info->proxy_resolve_end.is_null()) |
| 103 block_on_connect_start = load_timing_info->proxy_resolve_end; |
| 104 |
| 105 net::LoadTimingInfo::ConnectTiming* connect_timing = |
| 106 &load_timing_info->connect_timing; |
| 107 if (!connect_timing->dns_start.is_null()) { |
| 108 DCHECK(!connect_timing->dns_end.is_null()); |
| 109 if (connect_timing->dns_start < block_on_connect_start) |
| 110 connect_timing->dns_start = block_on_connect_start; |
| 111 if (connect_timing->dns_end < block_on_connect_start) |
| 112 connect_timing->dns_end = block_on_connect_start; |
| 113 } |
| 114 |
| 115 if (!connect_timing->connect_start.is_null()) { |
| 116 DCHECK(!connect_timing->connect_end.is_null()); |
| 117 if (connect_timing->connect_start < block_on_connect_start) |
| 118 connect_timing->connect_start = block_on_connect_start; |
| 119 if (connect_timing->connect_end < block_on_connect_start) |
| 120 connect_timing->connect_end = block_on_connect_start; |
| 121 } |
| 122 |
| 123 if (!connect_timing->ssl_start.is_null()) { |
| 124 DCHECK(!connect_timing->ssl_end.is_null()); |
| 125 if (connect_timing->ssl_start < block_on_connect_start) |
| 126 connect_timing->ssl_start = block_on_connect_start; |
| 127 if (connect_timing->ssl_end < block_on_connect_start) |
| 128 connect_timing->ssl_end = block_on_connect_start; |
| 129 } |
| 130 } |
| 131 |
| 87 } // end namespace | 132 } // end namespace |
| 88 | 133 |
| 89 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate( | 134 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate( |
| 90 prerender::PrerenderTracker* prerender_tracker) | 135 prerender::PrerenderTracker* prerender_tracker) |
| 91 : download_request_limiter_(g_browser_process->download_request_limiter()), | 136 : download_request_limiter_(g_browser_process->download_request_limiter()), |
| 92 safe_browsing_(g_browser_process->safe_browsing_service()), | 137 safe_browsing_(g_browser_process->safe_browsing_service()), |
| 93 user_script_listener_(new extensions::UserScriptListener()), | 138 user_script_listener_(new extensions::UserScriptListener()), |
| 94 prerender_tracker_(prerender_tracker) { | 139 prerender_tracker_(prerender_tracker) { |
| 95 } | 140 } |
| 96 | 141 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 const GURL& url, const std::string& mime_type) { | 417 const GURL& url, const std::string& mime_type) { |
| 373 // Special-case user scripts to get downloaded instead of viewed. | 418 // Special-case user scripts to get downloaded instead of viewed. |
| 374 return extensions::UserScript::IsURLUserScript(url, mime_type); | 419 return extensions::UserScript::IsURLUserScript(url, mime_type); |
| 375 } | 420 } |
| 376 | 421 |
| 377 void ChromeResourceDispatcherHostDelegate::OnResponseStarted( | 422 void ChromeResourceDispatcherHostDelegate::OnResponseStarted( |
| 378 net::URLRequest* request, | 423 net::URLRequest* request, |
| 379 content::ResourceContext* resource_context, | 424 content::ResourceContext* resource_context, |
| 380 content::ResourceResponse* response, | 425 content::ResourceResponse* response, |
| 381 IPC::Sender* sender) { | 426 IPC::Sender* sender) { |
| 382 LoadTimingObserver::PopulateTimingInfo(request, response); | 427 // TODO(mmenke): Figure out if LOAD_ENABLE_LOAD_TIMING is safe to remove. |
| 428 if (request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING) { |
| 429 request->GetLoadTimingInfo(&response->head.load_timing); |
| 430 FixupLoadTimingInfo(&response->head.load_timing); |
| 431 } |
| 383 | 432 |
| 384 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 433 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 385 | 434 |
| 386 if (request->url().SchemeIsSecure()) { | 435 if (request->url().SchemeIsSecure()) { |
| 387 const net::URLRequestContext* context = request->context(); | 436 const net::URLRequestContext* context = request->context(); |
| 388 net::TransportSecurityState* state = context->transport_security_state(); | 437 net::TransportSecurityState* state = context->transport_security_state(); |
| 389 if (state) { | 438 if (state) { |
| 390 net::TransportSecurityState::DomainState domain_state; | 439 net::TransportSecurityState::DomainState domain_state; |
| 391 bool has_sni = net::SSLConfigService::IsSNIAvailable( | 440 bool has_sni = net::SSLConfigService::IsSNIAvailable( |
| 392 context->ssl_config_service()); | 441 context->ssl_config_service()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 io_data->resource_prefetch_predictor_observer()->OnResponseStarted(request); | 480 io_data->resource_prefetch_predictor_observer()->OnResponseStarted(request); |
| 432 | 481 |
| 433 prerender::URLRequestResponseStarted(request); | 482 prerender::URLRequestResponseStarted(request); |
| 434 } | 483 } |
| 435 | 484 |
| 436 void ChromeResourceDispatcherHostDelegate::OnRequestRedirected( | 485 void ChromeResourceDispatcherHostDelegate::OnRequestRedirected( |
| 437 const GURL& redirect_url, | 486 const GURL& redirect_url, |
| 438 net::URLRequest* request, | 487 net::URLRequest* request, |
| 439 content::ResourceContext* resource_context, | 488 content::ResourceContext* resource_context, |
| 440 content::ResourceResponse* response) { | 489 content::ResourceResponse* response) { |
| 441 LoadTimingObserver::PopulateTimingInfo(request, response); | 490 // TODO(mmenke): Figure out if LOAD_ENABLE_LOAD_TIMING is safe to remove. |
| 491 if (request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING) { |
| 492 request->GetLoadTimingInfo(&response->head.load_timing); |
| 493 FixupLoadTimingInfo(&response->head.load_timing); |
| 494 } |
| 442 | 495 |
| 443 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 496 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 444 | 497 |
| 445 #if defined(ENABLE_ONE_CLICK_SIGNIN) | 498 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 446 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 499 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 447 | 500 |
| 448 // See if the response contains the Google-Accounts-SignIn header. If so, | 501 // See if the response contains the Google-Accounts-SignIn header. If so, |
| 449 // then the user has just finished signing in, and the server is allowing the | 502 // then the user has just finished signing in, and the server is allowing the |
| 450 // browser to suggest connecting the user's profile to the account. | 503 // browser to suggest connecting the user's profile to the account. |
| 451 OneClickSigninHelper::ShowInfoBarIfPossible(request, io_data, | 504 OneClickSigninHelper::ShowInfoBarIfPossible(request, io_data, |
| 452 info->GetChildID(), | 505 info->GetChildID(), |
| 453 info->GetRouteID()); | 506 info->GetRouteID()); |
| 454 AppendChromeSyncGaiaHeader(request, resource_context); | 507 AppendChromeSyncGaiaHeader(request, resource_context); |
| 455 #endif | 508 #endif |
| 456 | 509 |
| 457 if (io_data->resource_prefetch_predictor_observer()) { | 510 if (io_data->resource_prefetch_predictor_observer()) { |
| 458 io_data->resource_prefetch_predictor_observer()->OnRequestRedirected( | 511 io_data->resource_prefetch_predictor_observer()->OnRequestRedirected( |
| 459 redirect_url, request); | 512 redirect_url, request); |
| 460 } | 513 } |
| 461 } | 514 } |
| OLD | NEW |