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/safe_browsing_resource_throttle.h" | 5 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 if (state_ == STATE_CHECKING_URL || | 162 if (state_ == STATE_CHECKING_URL || |
163 state_ == STATE_DISPLAYING_BLOCKING_PAGE) { | 163 state_ == STATE_DISPLAYING_BLOCKING_PAGE) { |
164 defer_state_ = DEFERRED_PROCESSING; | 164 defer_state_ = DEFERRED_PROCESSING; |
165 defer_start_time_ = base::TimeTicks::Now(); | 165 defer_start_time_ = base::TimeTicks::Now(); |
166 *defer = true; | 166 *defer = true; |
167 BeginNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, request_->url(), | 167 BeginNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, request_->url(), |
168 "defer_reason", "at_response"); | 168 "defer_reason", "at_response"); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
| 172 bool SafeBrowsingResourceThrottle::MustProcessResponseBeforeReadingBody() { |
| 173 // On Android, SafeBrowsing may only decide to cancel the request when the |
| 174 // response has been received. Therefore, no part of it should be cached |
| 175 // until this ResourceThrottle has been able to check the response. This |
| 176 // prevents the following scenario: |
| 177 // 1) A request is made for foo.com which has been hacked. |
| 178 // 2) The request is only canceled at WillProcessResponse stage, but part of |
| 179 // it has been cached. |
| 180 // 3) foo.com is no longer hacked and removed from the SafeBrowsing list. |
| 181 // 4) The user requests foo.com, which is not on the SafeBrowsing list. This |
| 182 // is deemed safe. However, the resource is actually served from cache, |
| 183 // using the version that was previously stored. |
| 184 // 5) This results in the user accessing an unsafe resource without being |
| 185 // notified that it's dangerous. |
| 186 // TODO(clamy): Add a browser test that checks this specific scenario. |
| 187 return true; |
| 188 } |
| 189 |
172 void SafeBrowsingResourceThrottle::WillRedirectRequest( | 190 void SafeBrowsingResourceThrottle::WillRedirectRequest( |
173 const net::RedirectInfo& redirect_info, | 191 const net::RedirectInfo& redirect_info, |
174 bool* defer) { | 192 bool* defer) { |
175 CHECK_EQ(defer_state_, DEFERRED_NONE); | 193 CHECK_EQ(defer_state_, DEFERRED_NONE); |
176 | 194 |
177 // Prev check completed and was safe. | 195 // Prev check completed and was safe. |
178 if (state_ == STATE_NONE) { | 196 if (state_ == STATE_NONE) { |
179 // Save the redirect urls for possible malware detail reporting later. | 197 // Save the redirect urls for possible malware detail reporting later. |
180 redirect_urls_.push_back(redirect_info.new_url); | 198 redirect_urls_.push_back(redirect_info.new_url); |
181 | 199 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 unchecked_redirect_url_, "defer_reason", | 406 unchecked_redirect_url_, "defer_reason", |
389 "resumed_redirect"); | 407 "resumed_redirect"); |
390 } | 408 } |
391 } | 409 } |
392 | 410 |
393 if (resume) { | 411 if (resume) { |
394 defer_state_ = DEFERRED_NONE; | 412 defer_state_ = DEFERRED_NONE; |
395 controller()->Resume(); | 413 controller()->Resume(); |
396 } | 414 } |
397 } | 415 } |
OLD | NEW |