Index: chrome/browser/renderer_host/data_reduction_proxy_resource_throttle_android.cc |
diff --git a/chrome/browser/renderer_host/data_reduction_proxy_resource_throttle_android.cc b/chrome/browser/renderer_host/data_reduction_proxy_resource_throttle_android.cc |
index 524f504b896cc44a0124edf4e6d89e2ac9afcba8..2982730b213af831ad199e1ede3323d39968efe4 100644 |
--- a/chrome/browser/renderer_host/data_reduction_proxy_resource_throttle_android.cc |
+++ b/chrome/browser/renderer_host/data_reduction_proxy_resource_throttle_android.cc |
@@ -8,6 +8,7 @@ |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/prerender/prerender_contents.h" |
#include "chrome/browser/profiles/profile_io_data.h" |
+#include "chrome/browser/renderer_host/data_reduction_proxy_throttling_utils_android.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/render_view_host.h" |
#include "content/public/browser/resource_context.h" |
@@ -31,37 +32,27 @@ using safe_browsing::SBThreatType; |
// checking whether the headers are injected correctly and the SPDY proxy |
// origin is tested properly. |
-const char* DataReductionProxyResourceThrottle::kUnsafeUrlProceedHeader = |
- "X-Unsafe-Url-Proceed"; |
- |
// static |
DataReductionProxyResourceThrottle* |
DataReductionProxyResourceThrottle::MaybeCreate( |
net::URLRequest* request, |
content::ResourceContext* resource_context, |
- content::ResourceType resource_type, |
SafeBrowsingService* sb_service) { |
ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
// Don't create the throttle if we can't handle the request. |
- if (io_data->IsOffTheRecord() || !io_data->IsDataReductionProxyEnabled() || |
- request->url().SchemeIsCryptographic()) { |
+ if (!data_reduction_proxy_throttling_utils::CanCreateThrottle( |
+ io_data->IsOffTheRecord(), io_data->IsDataReductionProxyEnabled(), |
+ request->url())) { |
return NULL; |
} |
- return new DataReductionProxyResourceThrottle(request, resource_type, |
- sb_service); |
+ return new DataReductionProxyResourceThrottle(request, sb_service); |
} |
DataReductionProxyResourceThrottle::DataReductionProxyResourceThrottle( |
net::URLRequest* request, |
- content::ResourceType resource_type, |
SafeBrowsingService* safe_browsing) |
- : state_(STATE_NONE), |
- safe_browsing_(safe_browsing), |
- request_(request), |
- is_subresource_(resource_type != content::RESOURCE_TYPE_MAIN_FRAME), |
- is_subframe_(resource_type == content::RESOURCE_TYPE_SUB_FRAME) { |
-} |
+ : state_(STATE_NONE), safe_browsing_(safe_browsing), request_(request) {} |
DataReductionProxyResourceThrottle::~DataReductionProxyResourceThrottle() { } |
@@ -74,10 +65,21 @@ void DataReductionProxyResourceThrottle::WillRedirectRequest( |
redirect_urls_.push_back(redirect_info.new_url); |
// We need to check the new URL before following the redirect. |
- SBThreatType threat_type = CheckUrl(); |
+ SBThreatType threat_type = |
+ data_reduction_proxy_throttling_utils::CheckHeaders( |
+ request_->response_headers()); |
if (threat_type == safe_browsing::SB_THREAT_TYPE_SAFE) |
return; |
+ // If safe browsing is disabled and the request is sent to the DRP server, |
+ // we need to break the redirect loop by setting the extra header. |
+ if (!safe_browsing_->enabled()) { |
+ request_->SetExtraRequestHeaderByName( |
+ data_reduction_proxy_throttling_utils::kUnsafeUrlProceedHeader, "1", |
+ true); |
+ return; |
+ } |
+ |
if (request_->load_flags() & net::LOAD_PREFETCH) { |
controller()->Cancel(); |
return; |
@@ -90,8 +92,8 @@ void DataReductionProxyResourceThrottle::WillRedirectRequest( |
unsafe_resource.url = redirect_info.new_url; |
unsafe_resource.original_url = request_->original_url(); |
unsafe_resource.redirect_urls = redirect_urls_; |
- unsafe_resource.is_subresource = is_subresource_; |
- unsafe_resource.is_subframe = is_subframe_; |
+ unsafe_resource.is_subresource = true; |
+ unsafe_resource.is_subframe = false; |
unsafe_resource.threat_type = threat_type; |
unsafe_resource.callback = base::Bind( |
&DataReductionProxyResourceThrottle::OnBlockingPageComplete, AsWeakPtr()); |
@@ -154,33 +156,12 @@ void DataReductionProxyResourceThrottle::OnBlockingPageComplete(bool proceed) { |
controller()->Cancel(); |
} |
-SBThreatType DataReductionProxyResourceThrottle::CheckUrl() { |
- SBThreatType result = safe_browsing::SB_THREAT_TYPE_SAFE; |
- |
- // TODO(sgurun) Check for spdy proxy origin. |
- if (request_->response_headers() == NULL) |
- return result; |
- |
- if (request_->response_headers()->HasHeader("X-Phishing-Url")) |
- result = safe_browsing::SB_THREAT_TYPE_URL_PHISHING; |
- else if (request_->response_headers()->HasHeader("X-Malware-Url")) |
- result = safe_browsing::SB_THREAT_TYPE_URL_MALWARE; |
- |
- // If safe browsing is disabled and the request is sent to the DRP server, |
- // we need to break the redirect loop by setting the extra header. |
- if (result != safe_browsing::SB_THREAT_TYPE_SAFE && |
- !safe_browsing_->enabled()) { |
- request_->SetExtraRequestHeaderByName(kUnsafeUrlProceedHeader, "1", true); |
- result = safe_browsing::SB_THREAT_TYPE_SAFE; |
- } |
- |
- return result; |
-} |
- |
void DataReductionProxyResourceThrottle::ResumeRequest() { |
CHECK(state_ == STATE_NONE); |
// Inject the header before resuming the request. |
- request_->SetExtraRequestHeaderByName(kUnsafeUrlProceedHeader, "1", true); |
+ request_->SetExtraRequestHeaderByName( |
+ data_reduction_proxy_throttling_utils::kUnsafeUrlProceedHeader, "1", |
+ true); |
controller()->Resume(); |
} |