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/api/streams_private/streams_private_api.h" | 16 #include "chrome/browser/extensions/api/streams_private/streams_private_api.h" |
17 #include "chrome/browser/extensions/extension_info_map.h" | 17 #include "chrome/browser/extensions/extension_info_map.h" |
18 #include "chrome/browser/extensions/user_script_listener.h" | 18 #include "chrome/browser/extensions/user_script_listener.h" |
19 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 19 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
20 #include "chrome/browser/google/google_util.h" | 20 #include "chrome/browser/google/google_util.h" |
21 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" | 21 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" |
22 #include "chrome/browser/net/load_timing_observer.h" | |
23 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" | 22 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" |
24 #include "chrome/browser/prerender/prerender_manager.h" | 23 #include "chrome/browser/prerender/prerender_manager.h" |
25 #include "chrome/browser/prerender/prerender_tracker.h" | 24 #include "chrome/browser/prerender/prerender_tracker.h" |
26 #include "chrome/browser/prerender/prerender_util.h" | 25 #include "chrome/browser/prerender/prerender_util.h" |
27 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/profiles/profile_io_data.h" | 27 #include "chrome/browser/profiles/profile_io_data.h" |
29 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h" | 28 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h" |
30 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h
" | 29 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h
" |
31 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 30 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
32 #include "chrome/browser/ui/auto_login_prompter.h" | 31 #include "chrome/browser/ui/auto_login_prompter.h" |
33 #include "chrome/browser/ui/login/login_prompt.h" | 32 #include "chrome/browser/ui/login/login_prompt.h" |
34 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 33 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
35 #include "chrome/common/chrome_notification_types.h" | 34 #include "chrome/common/chrome_notification_types.h" |
36 #include "chrome/common/extensions/mime_types_handler.h" | 35 #include "chrome/common/extensions/mime_types_handler.h" |
37 #include "chrome/common/extensions/user_script.h" | 36 #include "chrome/common/extensions/user_script.h" |
38 #include "chrome/common/render_messages.h" | 37 #include "chrome/common/render_messages.h" |
39 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
40 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
41 #include "content/public/browser/render_view_host.h" | 40 #include "content/public/browser/render_view_host.h" |
42 #include "content/public/browser/resource_context.h" | 41 #include "content/public/browser/resource_context.h" |
43 #include "content/public/browser/resource_dispatcher_host.h" | 42 #include "content/public/browser/resource_dispatcher_host.h" |
44 #include "content/public/browser/resource_request_info.h" | 43 #include "content/public/browser/resource_request_info.h" |
45 #include "content/public/browser/stream_handle.h" | 44 #include "content/public/browser/stream_handle.h" |
| 45 #include "content/public/common/resource_response.h" |
46 #include "extensions/common/constants.h" | 46 #include "extensions/common/constants.h" |
47 #include "net/base/load_flags.h" | 47 #include "net/base/load_flags.h" |
| 48 #include "net/base/load_timing_info.h" |
48 #include "net/http/http_response_headers.h" | 49 #include "net/http/http_response_headers.h" |
49 #include "net/ssl/ssl_config_service.h" | 50 #include "net/ssl/ssl_config_service.h" |
50 #include "net/url_request/url_request.h" | 51 #include "net/url_request/url_request.h" |
51 | 52 |
52 #if defined(ENABLE_MANAGED_USERS) | 53 #if defined(ENABLE_MANAGED_USERS) |
53 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" | 54 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" |
54 #endif | 55 #endif |
55 | 56 |
56 #if defined(USE_SYSTEM_PROTOBUF) | 57 #if defined(USE_SYSTEM_PROTOBUF) |
57 #include <google/protobuf/repeated_field.h> | 58 #include <google/protobuf/repeated_field.h> |
(...skipping 24 matching lines...) Expand all Loading... |
82 render_view_id); | 83 render_view_id); |
83 if (!rvh) | 84 if (!rvh) |
84 return; | 85 return; |
85 | 86 |
86 content::NotificationService::current()->Notify( | 87 content::NotificationService::current()->Notify( |
87 chrome::NOTIFICATION_DOWNLOAD_INITIATED, | 88 chrome::NOTIFICATION_DOWNLOAD_INITIATED, |
88 content::Source<RenderViewHost>(rvh), | 89 content::Source<RenderViewHost>(rvh), |
89 content::NotificationService::NoDetails()); | 90 content::NotificationService::NoDetails()); |
90 } | 91 } |
91 | 92 |
| 93 // The network stack returns actual connect times, while the renderer process |
| 94 // expects times that the request was blocked in each phase of setting up |
| 95 // a connection. Due to preconnect and late binding, it is possible for a |
| 96 // connection attempt to start before a request has been started, so this |
| 97 // function is needed to convert times from the network stack to times the |
| 98 // renderer process expects. |
| 99 void FixupLoadTimingInfo(net::LoadTimingInfo* load_timing_info) { |
| 100 // If there are no times, do nothing. |
| 101 if (load_timing_info->request_start.is_null()) |
| 102 return; |
| 103 |
| 104 // Starting the request and resolving the proxy are the only phases of the |
| 105 // request that occur before it blocks on starting a connection. |
| 106 base::TimeTicks block_on_connect_start = load_timing_info->request_start; |
| 107 if (!load_timing_info->proxy_resolve_end.is_null()) |
| 108 block_on_connect_start = load_timing_info->proxy_resolve_end; |
| 109 |
| 110 net::LoadTimingInfo::ConnectTiming* connect_timing = |
| 111 &load_timing_info->connect_timing; |
| 112 if (!connect_timing->dns_start.is_null()) { |
| 113 DCHECK(!connect_timing->dns_end.is_null()); |
| 114 if (connect_timing->dns_start < block_on_connect_start) |
| 115 connect_timing->dns_start = block_on_connect_start; |
| 116 if (connect_timing->dns_end < block_on_connect_start) |
| 117 connect_timing->dns_end = block_on_connect_start; |
| 118 } |
| 119 |
| 120 if (!connect_timing->connect_start.is_null()) { |
| 121 DCHECK(!connect_timing->connect_end.is_null()); |
| 122 if (connect_timing->connect_start < block_on_connect_start) |
| 123 connect_timing->connect_start = block_on_connect_start; |
| 124 if (connect_timing->connect_end < block_on_connect_start) |
| 125 connect_timing->connect_end = block_on_connect_start; |
| 126 } |
| 127 |
| 128 if (!connect_timing->ssl_start.is_null()) { |
| 129 DCHECK(!connect_timing->ssl_end.is_null()); |
| 130 if (connect_timing->ssl_start < block_on_connect_start) |
| 131 connect_timing->ssl_start = block_on_connect_start; |
| 132 if (connect_timing->ssl_end < block_on_connect_start) |
| 133 connect_timing->ssl_end = block_on_connect_start; |
| 134 } |
| 135 } |
| 136 |
92 // Goes through the extension's file browser handlers and checks if there is one | 137 // Goes through the extension's file browser handlers and checks if there is one |
93 // that can handle the |mime_type|. | 138 // that can handle the |mime_type|. |
94 // |extension| must not be NULL. | 139 // |extension| must not be NULL. |
95 bool ExtensionCanHandleMimeType(const Extension* extension, | 140 bool ExtensionCanHandleMimeType(const Extension* extension, |
96 const std::string& mime_type) { | 141 const std::string& mime_type) { |
97 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 142 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
98 if (!handler) | 143 if (!handler) |
99 return false; | 144 return false; |
100 | 145 |
101 return handler->CanHandleMIMEType(mime_type); | 146 return handler->CanHandleMIMEType(mime_type); |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 render_process_id, render_view_id, | 524 render_process_id, render_view_id, |
480 target_id)); | 525 target_id)); |
481 #endif | 526 #endif |
482 } | 527 } |
483 | 528 |
484 void ChromeResourceDispatcherHostDelegate::OnResponseStarted( | 529 void ChromeResourceDispatcherHostDelegate::OnResponseStarted( |
485 net::URLRequest* request, | 530 net::URLRequest* request, |
486 content::ResourceContext* resource_context, | 531 content::ResourceContext* resource_context, |
487 content::ResourceResponse* response, | 532 content::ResourceResponse* response, |
488 IPC::Sender* sender) { | 533 IPC::Sender* sender) { |
489 LoadTimingObserver::PopulateTimingInfo(request, response); | 534 // TODO(mmenke): Figure out if LOAD_ENABLE_LOAD_TIMING is safe to remove. |
| 535 if (request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING) { |
| 536 request->GetLoadTimingInfo(&response->head.load_timing); |
| 537 FixupLoadTimingInfo(&response->head.load_timing); |
| 538 } |
490 | 539 |
491 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 540 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
492 | 541 |
493 if (request->url().SchemeIsSecure()) { | 542 if (request->url().SchemeIsSecure()) { |
494 const net::URLRequestContext* context = request->context(); | 543 const net::URLRequestContext* context = request->context(); |
495 net::TransportSecurityState* state = context->transport_security_state(); | 544 net::TransportSecurityState* state = context->transport_security_state(); |
496 if (state) { | 545 if (state) { |
497 net::TransportSecurityState::DomainState domain_state; | 546 net::TransportSecurityState::DomainState domain_state; |
498 bool has_sni = net::SSLConfigService::IsSNIAvailable( | 547 bool has_sni = net::SSLConfigService::IsSNIAvailable( |
499 context->ssl_config_service()); | 548 context->ssl_config_service()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 io_data->resource_prefetch_predictor_observer()->OnResponseStarted(request); | 587 io_data->resource_prefetch_predictor_observer()->OnResponseStarted(request); |
539 | 588 |
540 prerender::URLRequestResponseStarted(request); | 589 prerender::URLRequestResponseStarted(request); |
541 } | 590 } |
542 | 591 |
543 void ChromeResourceDispatcherHostDelegate::OnRequestRedirected( | 592 void ChromeResourceDispatcherHostDelegate::OnRequestRedirected( |
544 const GURL& redirect_url, | 593 const GURL& redirect_url, |
545 net::URLRequest* request, | 594 net::URLRequest* request, |
546 content::ResourceContext* resource_context, | 595 content::ResourceContext* resource_context, |
547 content::ResourceResponse* response) { | 596 content::ResourceResponse* response) { |
548 LoadTimingObserver::PopulateTimingInfo(request, response); | 597 // TODO(mmenke): Figure out if LOAD_ENABLE_LOAD_TIMING is safe to remove. |
| 598 if (request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING) { |
| 599 request->GetLoadTimingInfo(&response->head.load_timing); |
| 600 FixupLoadTimingInfo(&response->head.load_timing); |
| 601 } |
549 | 602 |
550 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 603 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
551 | 604 |
552 #if defined(ENABLE_ONE_CLICK_SIGNIN) | 605 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
553 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 606 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
554 | 607 |
555 // See if the response contains the Google-Accounts-SignIn header. If so, | 608 // See if the response contains the Google-Accounts-SignIn header. If so, |
556 // then the user has just finished signing in, and the server is allowing the | 609 // then the user has just finished signing in, and the server is allowing the |
557 // browser to suggest connecting the user's profile to the account. | 610 // browser to suggest connecting the user's profile to the account. |
558 OneClickSigninHelper::ShowInfoBarIfPossible(request, io_data, | 611 OneClickSigninHelper::ShowInfoBarIfPossible(request, io_data, |
(...skipping 10 matching lines...) Expand all Loading... |
569 int child_id, route_id; | 622 int child_id, route_id; |
570 if (!prerender::PrerenderManager::DoesURLHaveValidScheme(redirect_url) && | 623 if (!prerender::PrerenderManager::DoesURLHaveValidScheme(redirect_url) && |
571 ResourceRequestInfo::ForRequest(request)->GetAssociatedRenderView( | 624 ResourceRequestInfo::ForRequest(request)->GetAssociatedRenderView( |
572 &child_id, &route_id) && | 625 &child_id, &route_id) && |
573 prerender_tracker_->IsPrerenderingOnIOThread(child_id, route_id)) { | 626 prerender_tracker_->IsPrerenderingOnIOThread(child_id, route_id)) { |
574 prerender_tracker_->TryCancel( | 627 prerender_tracker_->TryCancel( |
575 child_id, route_id, prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); | 628 child_id, route_id, prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); |
576 request->Cancel(); | 629 request->Cancel(); |
577 } | 630 } |
578 } | 631 } |
OLD | NEW |