OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/data_reduction_proxy_resource_throttle_an
droid.h" | 5 #include "chrome/browser/renderer_host/data_reduction_proxy_resource_throttle_an
droid.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/prerender/prerender_contents.h" | 9 #include "chrome/browser/prerender/prerender_contents.h" |
10 #include "chrome/browser/profiles/profile_io_data.h" | 10 #include "chrome/browser/profiles/profile_io_data.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
13 #include "content/public/browser/resource_context.h" | 13 #include "content/public/browser/resource_context.h" |
14 #include "content/public/browser/resource_controller.h" | 14 #include "content/public/browser/resource_controller.h" |
15 #include "content/public/browser/resource_request_info.h" | 15 #include "content/public/browser/resource_request_info.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
18 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
19 #include "net/url_request/redirect_info.h" | 19 #include "net/url_request/redirect_info.h" |
20 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
21 | 21 |
22 using content::BrowserThread; | 22 using content::BrowserThread; |
23 using content::ResourceThrottle; | 23 using content::ResourceThrottle; |
| 24 using safe_browsing::SafeBrowsingService; |
| 25 using safe_browsing::SafeBrowsingUIManager; |
| 26 using safe_browsing::SBThreatType; |
24 | 27 |
25 // TODO(eroman): Downgrade these CHECK()s to DCHECKs once there is more | 28 // TODO(eroman): Downgrade these CHECK()s to DCHECKs once there is more |
26 // unit test coverage. | 29 // unit test coverage. |
27 // TODO(sgurun) following the comment above, also provide tests for | 30 // TODO(sgurun) following the comment above, also provide tests for |
28 // checking whether the headers are injected correctly and the SPDY proxy | 31 // checking whether the headers are injected correctly and the SPDY proxy |
29 // origin is tested properly. | 32 // origin is tested properly. |
30 | 33 |
31 const char* DataReductionProxyResourceThrottle::kUnsafeUrlProceedHeader = | 34 const char* DataReductionProxyResourceThrottle::kUnsafeUrlProceedHeader = |
32 "X-Unsafe-Url-Proceed"; | 35 "X-Unsafe-Url-Proceed"; |
33 | 36 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 void DataReductionProxyResourceThrottle::WillRedirectRequest( | 68 void DataReductionProxyResourceThrottle::WillRedirectRequest( |
66 const net::RedirectInfo& redirect_info, | 69 const net::RedirectInfo& redirect_info, |
67 bool* defer) { | 70 bool* defer) { |
68 CHECK(state_ == STATE_NONE); | 71 CHECK(state_ == STATE_NONE); |
69 | 72 |
70 // Save the redirect urls for possible malware detail reporting later. | 73 // Save the redirect urls for possible malware detail reporting later. |
71 redirect_urls_.push_back(redirect_info.new_url); | 74 redirect_urls_.push_back(redirect_info.new_url); |
72 | 75 |
73 // We need to check the new URL before following the redirect. | 76 // We need to check the new URL before following the redirect. |
74 SBThreatType threat_type = CheckUrl(); | 77 SBThreatType threat_type = CheckUrl(); |
75 if (threat_type == SB_THREAT_TYPE_SAFE) | 78 if (threat_type == safe_browsing::SB_THREAT_TYPE_SAFE) |
76 return; | 79 return; |
77 | 80 |
78 if (request_->load_flags() & net::LOAD_PREFETCH) { | 81 if (request_->load_flags() & net::LOAD_PREFETCH) { |
79 controller()->Cancel(); | 82 controller()->Cancel(); |
80 return; | 83 return; |
81 } | 84 } |
82 const content::ResourceRequestInfo* info = | 85 const content::ResourceRequestInfo* info = |
83 content::ResourceRequestInfo::ForRequest(request_); | 86 content::ResourceRequestInfo::ForRequest(request_); |
84 | 87 |
85 state_ = STATE_DISPLAYING_BLOCKING_PAGE; | 88 state_ = STATE_DISPLAYING_BLOCKING_PAGE; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 CHECK(state_ == STATE_DISPLAYING_BLOCKING_PAGE); | 145 CHECK(state_ == STATE_DISPLAYING_BLOCKING_PAGE); |
143 state_ = STATE_NONE; | 146 state_ = STATE_NONE; |
144 | 147 |
145 if (proceed) | 148 if (proceed) |
146 ResumeRequest(); | 149 ResumeRequest(); |
147 else | 150 else |
148 controller()->Cancel(); | 151 controller()->Cancel(); |
149 } | 152 } |
150 | 153 |
151 SBThreatType DataReductionProxyResourceThrottle::CheckUrl() { | 154 SBThreatType DataReductionProxyResourceThrottle::CheckUrl() { |
152 SBThreatType result = SB_THREAT_TYPE_SAFE; | 155 SBThreatType result = safe_browsing::SB_THREAT_TYPE_SAFE; |
153 | 156 |
154 // TODO(sgurun) Check for spdy proxy origin. | 157 // TODO(sgurun) Check for spdy proxy origin. |
155 if (request_->response_headers() == NULL) | 158 if (request_->response_headers() == NULL) |
156 return result; | 159 return result; |
157 | 160 |
158 if (request_->response_headers()->HasHeader("X-Phishing-Url")) | 161 if (request_->response_headers()->HasHeader("X-Phishing-Url")) |
159 result = SB_THREAT_TYPE_URL_PHISHING; | 162 result = safe_browsing::SB_THREAT_TYPE_URL_PHISHING; |
160 else if (request_->response_headers()->HasHeader("X-Malware-Url")) | 163 else if (request_->response_headers()->HasHeader("X-Malware-Url")) |
161 result = SB_THREAT_TYPE_URL_MALWARE; | 164 result = safe_browsing::SB_THREAT_TYPE_URL_MALWARE; |
162 | 165 |
163 // If safe browsing is disabled and the request is sent to the DRP server, | 166 // If safe browsing is disabled and the request is sent to the DRP server, |
164 // we need to break the redirect loop by setting the extra header. | 167 // we need to break the redirect loop by setting the extra header. |
165 if (result != SB_THREAT_TYPE_SAFE && !safe_browsing_->enabled()) { | 168 if (result != safe_browsing::SB_THREAT_TYPE_SAFE && |
| 169 !safe_browsing_->enabled()) { |
166 request_->SetExtraRequestHeaderByName(kUnsafeUrlProceedHeader, "1", true); | 170 request_->SetExtraRequestHeaderByName(kUnsafeUrlProceedHeader, "1", true); |
167 result = SB_THREAT_TYPE_SAFE; | 171 result = safe_browsing::SB_THREAT_TYPE_SAFE; |
168 } | 172 } |
169 | 173 |
170 return result; | 174 return result; |
171 } | 175 } |
172 | 176 |
173 void DataReductionProxyResourceThrottle::ResumeRequest() { | 177 void DataReductionProxyResourceThrottle::ResumeRequest() { |
174 CHECK(state_ == STATE_NONE); | 178 CHECK(state_ == STATE_NONE); |
175 | 179 |
176 // Inject the header before resuming the request. | 180 // Inject the header before resuming the request. |
177 request_->SetExtraRequestHeaderByName(kUnsafeUrlProceedHeader, "1", true); | 181 request_->SetExtraRequestHeaderByName(kUnsafeUrlProceedHeader, "1", true); |
178 controller()->Resume(); | 182 controller()->Resume(); |
179 } | 183 } |
OLD | NEW |