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/loader/chrome_resource_dispatcher_host_delegate.h" | 5 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 | 390 |
391 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate() | 391 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate() |
392 : download_request_limiter_(g_browser_process->download_request_limiter()), | 392 : download_request_limiter_(g_browser_process->download_request_limiter()), |
393 safe_browsing_(g_browser_process->safe_browsing_service()) | 393 safe_browsing_(g_browser_process->safe_browsing_service()) |
394 #if BUILDFLAG(ENABLE_EXTENSIONS) | 394 #if BUILDFLAG(ENABLE_EXTENSIONS) |
395 , user_script_listener_(new extensions::UserScriptListener()) | 395 , user_script_listener_(new extensions::UserScriptListener()) |
396 #endif | 396 #endif |
397 { | 397 { |
398 BrowserThread::PostTask( | 398 BrowserThread::PostTask( |
399 BrowserThread::IO, FROM_HERE, | 399 BrowserThread::IO, FROM_HERE, |
400 base::Bind(content::ServiceWorkerContext::AddExcludedHeadersForFetchEvent, | 400 base::BindOnce( |
401 variations::GetVariationHeaderNames())); | 401 content::ServiceWorkerContext::AddExcludedHeadersForFetchEvent, |
| 402 variations::GetVariationHeaderNames())); |
402 } | 403 } |
403 | 404 |
404 ChromeResourceDispatcherHostDelegate::~ChromeResourceDispatcherHostDelegate() { | 405 ChromeResourceDispatcherHostDelegate::~ChromeResourceDispatcherHostDelegate() { |
405 #if BUILDFLAG(ENABLE_EXTENSIONS) | 406 #if BUILDFLAG(ENABLE_EXTENSIONS) |
406 CHECK(stream_target_info_.empty()); | 407 CHECK(stream_target_info_.empty()); |
407 #endif | 408 #endif |
408 } | 409 } |
409 | 410 |
410 bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest( | 411 bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest( |
411 const std::string& method, | 412 const std::string& method, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 net::URLRequest* request, | 510 net::URLRequest* request, |
510 content::ResourceContext* resource_context, | 511 content::ResourceContext* resource_context, |
511 bool is_content_initiated, | 512 bool is_content_initiated, |
512 bool must_download, | 513 bool must_download, |
513 bool is_new_request, | 514 bool is_new_request, |
514 std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) { | 515 std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) { |
515 const content::ResourceRequestInfo* info = | 516 const content::ResourceRequestInfo* info = |
516 content::ResourceRequestInfo::ForRequest(request); | 517 content::ResourceRequestInfo::ForRequest(request); |
517 BrowserThread::PostTask( | 518 BrowserThread::PostTask( |
518 BrowserThread::UI, FROM_HERE, | 519 BrowserThread::UI, FROM_HERE, |
519 base::Bind(&NotifyDownloadInitiatedOnUI, | 520 base::BindOnce(&NotifyDownloadInitiatedOnUI, |
520 info->GetWebContentsGetterForRequest())); | 521 info->GetWebContentsGetterForRequest())); |
521 | 522 |
522 // If it's from the web, we don't trust it, so we push the throttle on. | 523 // If it's from the web, we don't trust it, so we push the throttle on. |
523 if (is_content_initiated) { | 524 if (is_content_initiated) { |
524 throttles->push_back(base::MakeUnique<DownloadResourceThrottle>( | 525 throttles->push_back(base::MakeUnique<DownloadResourceThrottle>( |
525 download_request_limiter_, info->GetWebContentsGetterForRequest(), | 526 download_request_limiter_, info->GetWebContentsGetterForRequest(), |
526 request->url(), request->method())); | 527 request->url(), request->method())); |
527 } | 528 } |
528 | 529 |
529 // If this isn't a new request, the standard resource throttles have already | 530 // If this isn't a new request, the standard resource throttles have already |
530 // been added, so no need to add them again. | 531 // been added, so no need to add them again. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 // Main frame external protocols are handled by | 593 // Main frame external protocols are handled by |
593 // InterceptNavigationResourceThrottle. | 594 // InterceptNavigationResourceThrottle. |
594 if (info->IsMainFrame()) | 595 if (info->IsMainFrame()) |
595 return false; | 596 return false; |
596 #endif // defined(ANDROID) | 597 #endif // defined(ANDROID) |
597 | 598 |
598 const bool is_whitelisted = | 599 const bool is_whitelisted = |
599 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST; | 600 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST; |
600 BrowserThread::PostTask( | 601 BrowserThread::PostTask( |
601 BrowserThread::UI, FROM_HERE, | 602 BrowserThread::UI, FROM_HERE, |
602 base::Bind(&LaunchURL, url, info->GetWebContentsGetterForRequest(), | 603 base::BindOnce(&LaunchURL, url, info->GetWebContentsGetterForRequest(), |
603 info->GetPageTransition(), info->HasUserGesture(), | 604 info->GetPageTransition(), info->HasUserGesture(), |
604 is_whitelisted)); | 605 is_whitelisted)); |
605 return true; | 606 return true; |
606 } | 607 } |
607 | 608 |
608 void ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles( | 609 void ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles( |
609 net::URLRequest* request, | 610 net::URLRequest* request, |
610 content::ResourceContext* resource_context, | 611 content::ResourceContext* resource_context, |
611 ResourceType resource_type, | 612 ResourceType resource_type, |
612 std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) { | 613 std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) { |
613 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 614 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
614 | 615 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 net::URLRequest* request, | 731 net::URLRequest* request, |
731 std::unique_ptr<content::StreamInfo> stream) { | 732 std::unique_ptr<content::StreamInfo> stream) { |
732 #if BUILDFLAG(ENABLE_EXTENSIONS) | 733 #if BUILDFLAG(ENABLE_EXTENSIONS) |
733 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 734 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
734 std::map<net::URLRequest*, StreamTargetInfo>::iterator ix = | 735 std::map<net::URLRequest*, StreamTargetInfo>::iterator ix = |
735 stream_target_info_.find(request); | 736 stream_target_info_.find(request); |
736 CHECK(ix != stream_target_info_.end()); | 737 CHECK(ix != stream_target_info_.end()); |
737 bool embedded = info->GetResourceType() != content::RESOURCE_TYPE_MAIN_FRAME; | 738 bool embedded = info->GetResourceType() != content::RESOURCE_TYPE_MAIN_FRAME; |
738 content::BrowserThread::PostTask( | 739 content::BrowserThread::PostTask( |
739 content::BrowserThread::UI, FROM_HERE, | 740 content::BrowserThread::UI, FROM_HERE, |
740 base::Bind(&SendExecuteMimeTypeHandlerEvent, base::Passed(&stream), | 741 base::BindOnce(&SendExecuteMimeTypeHandlerEvent, base::Passed(&stream), |
741 request->GetExpectedContentSize(), ix->second.extension_id, | 742 request->GetExpectedContentSize(), ix->second.extension_id, |
742 ix->second.view_id, embedded, info->GetFrameTreeNodeId(), | 743 ix->second.view_id, embedded, info->GetFrameTreeNodeId(), |
743 info->GetChildID(), info->GetRenderFrameID())); | 744 info->GetChildID(), info->GetRenderFrameID())); |
744 stream_target_info_.erase(request); | 745 stream_target_info_.erase(request); |
745 #endif | 746 #endif |
746 } | 747 } |
747 | 748 |
748 void ChromeResourceDispatcherHostDelegate::OnResponseStarted( | 749 void ChromeResourceDispatcherHostDelegate::OnResponseStarted( |
749 net::URLRequest* request, | 750 net::URLRequest* request, |
750 content::ResourceContext* resource_context, | 751 content::ResourceContext* resource_context, |
751 content::ResourceResponse* response) { | 752 content::ResourceResponse* response) { |
752 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 753 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
753 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 754 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 data_reduction_proxy::DataReductionProxyData* data = | 824 data_reduction_proxy::DataReductionProxyData* data = |
824 data_reduction_proxy::DataReductionProxyData::GetData(*url_request); | 825 data_reduction_proxy::DataReductionProxyData::GetData(*url_request); |
825 bool used_data_reduction_proxy = data && data->used_data_reduction_proxy(); | 826 bool used_data_reduction_proxy = data && data->used_data_reduction_proxy(); |
826 int64_t original_content_length = | 827 int64_t original_content_length = |
827 used_data_reduction_proxy | 828 used_data_reduction_proxy |
828 ? data_reduction_proxy::util::CalculateEffectiveOCL(*url_request) | 829 ? data_reduction_proxy::util::CalculateEffectiveOCL(*url_request) |
829 : url_request->GetRawBodyBytes(); | 830 : url_request->GetRawBodyBytes(); |
830 | 831 |
831 BrowserThread::PostTask( | 832 BrowserThread::PostTask( |
832 BrowserThread::UI, FROM_HERE, | 833 BrowserThread::UI, FROM_HERE, |
833 base::Bind(&NotifyUIThreadOfRequestComplete, | 834 base::BindOnce(&NotifyUIThreadOfRequestComplete, |
834 info->GetWebContentsGetterForRequest(), url_request->url(), | 835 info->GetWebContentsGetterForRequest(), url_request->url(), |
835 info->GetGlobalRequestID(), info->GetResourceType(), | 836 info->GetGlobalRequestID(), info->GetResourceType(), |
836 url_request->was_cached(), used_data_reduction_proxy, | 837 url_request->was_cached(), used_data_reduction_proxy, |
837 net_error, url_request->GetTotalReceivedBytes(), | 838 net_error, url_request->GetTotalReceivedBytes(), |
838 url_request->GetRawBodyBytes(), original_content_length, | 839 url_request->GetRawBodyBytes(), original_content_length, |
839 url_request->creation_time(), | 840 url_request->creation_time(), |
840 base::TimeTicks::Now() - url_request->creation_time())); | 841 base::TimeTicks::Now() - url_request->creation_time())); |
841 } | 842 } |
842 | 843 |
843 content::PreviewsState ChromeResourceDispatcherHostDelegate::GetPreviewsState( | 844 content::PreviewsState ChromeResourceDispatcherHostDelegate::GetPreviewsState( |
844 const net::URLRequest& url_request, | 845 const net::URLRequest& url_request, |
845 content::ResourceContext* resource_context) { | 846 content::ResourceContext* resource_context) { |
846 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 847 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
847 data_reduction_proxy::DataReductionProxyIOData* data_reduction_proxy_io_data = | 848 data_reduction_proxy::DataReductionProxyIOData* data_reduction_proxy_io_data = |
848 io_data->data_reduction_proxy_io_data(); | 849 io_data->data_reduction_proxy_io_data(); |
849 | 850 |
850 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED; | 851 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 return ProfileIOData::FromResourceContext(resource_context)-> | 901 return ProfileIOData::FromResourceContext(resource_context)-> |
901 CreateClientCertStore(); | 902 CreateClientCertStore(); |
902 } | 903 } |
903 | 904 |
904 // Record RAPPOR for aborted main frame loads. Separate into a fast and | 905 // Record RAPPOR for aborted main frame loads. Separate into a fast and |
905 // slow bucket because a shocking number of aborts happen under 100ms. | 906 // slow bucket because a shocking number of aborts happen under 100ms. |
906 void ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad( | 907 void ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad( |
907 const GURL& url, | 908 const GURL& url, |
908 base::TimeDelta request_loading_time) { | 909 base::TimeDelta request_loading_time) { |
909 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 910 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
910 BrowserThread::PostTask( | 911 BrowserThread::PostTask( |
911 BrowserThread::UI, FROM_HERE, | 912 BrowserThread::UI, FROM_HERE, |
912 base::Bind(&ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad, | 913 base::BindOnce( |
913 base::Unretained(this), url, request_loading_time)); | 914 &ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad, |
914 return; | 915 base::Unretained(this), url, request_loading_time)); |
| 916 return; |
915 } | 917 } |
916 | 918 |
917 std::string metric_name = (request_loading_time.InMilliseconds() < 100 ? | 919 std::string metric_name = (request_loading_time.InMilliseconds() < 100 ? |
918 "Net.ErrAborted.Fast" : "Net.ErrAborted.Slow"); | 920 "Net.ErrAborted.Fast" : "Net.ErrAborted.Slow"); |
919 rappor::SampleDomainAndRegistryFromGURL( | 921 rappor::SampleDomainAndRegistryFromGURL( |
920 g_browser_process->rappor_service(), metric_name, url); | 922 g_browser_process->rappor_service(), metric_name, url); |
921 } | 923 } |
OLD | NEW |