| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_handler.h" | 5 #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/browser/renderer_host/global_request_id.h" | 8 #include "content/browser/renderer_host/global_request_id.h" |
| 9 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 9 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 10 #include "content/browser/renderer_host/resource_message_filter.h" | 10 #include "content/browser/renderer_host/resource_message_filter.h" |
| 11 #include "content/common/resource_response.h" | 11 #include "content/common/resource_response.h" |
| 12 #include "net/base/io_buffer.h" |
| 13 #include "net/base/load_flags.h" |
| 12 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 13 #include "net/base/io_buffer.h" | 15 #include "net/url_request/url_request.h" |
| 14 | 16 |
| 15 // Maximum time in milliseconds to wait for the safe browsing service to | 17 // Maximum time in milliseconds to wait for the safe browsing service to |
| 16 // verify a URL. After this amount of time the outstanding check will be | 18 // verify a URL. After this amount of time the outstanding check will be |
| 17 // aborted, and the URL will be treated as if it were safe. | 19 // aborted, and the URL will be treated as if it were safe. |
| 18 static const int kCheckUrlTimeoutMs = 5000; | 20 static const int kCheckUrlTimeoutMs = 5000; |
| 19 | 21 |
| 20 // TODO(eroman): Downgrade these CHECK()s to DCHECKs once there is more | 22 // TODO(eroman): Downgrade these CHECK()s to DCHECKs once there is more |
| 21 // unit test coverage. | 23 // unit test coverage. |
| 22 | 24 |
| 23 SafeBrowsingResourceHandler::SafeBrowsingResourceHandler( | 25 SafeBrowsingResourceHandler::SafeBrowsingResourceHandler( |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 153 |
| 152 if (result == SafeBrowsingService::SAFE) { | 154 if (result == SafeBrowsingService::SAFE) { |
| 153 // Log how much time the safe browsing check cost us. | 155 // Log how much time the safe browsing check cost us. |
| 154 base::TimeDelta pause_delta; | 156 base::TimeDelta pause_delta; |
| 155 pause_delta = base::TimeTicks::Now() - url_check_start_time_; | 157 pause_delta = base::TimeTicks::Now() - url_check_start_time_; |
| 156 safe_browsing_->LogPauseDelay(pause_delta); | 158 safe_browsing_->LogPauseDelay(pause_delta); |
| 157 | 159 |
| 158 // Continue the request. | 160 // Continue the request. |
| 159 ResumeRequest(); | 161 ResumeRequest(); |
| 160 } else { | 162 } else { |
| 161 StartDisplayingBlockingPage(url, result); | 163 const net::URLRequest* request = rdh_->GetURLRequest( |
| 164 GlobalRequestID(render_process_host_id_, deferred_request_id_)); |
| 165 if (request->load_flags() & net::LOAD_PREFETCH) { |
| 166 // Don't prefetch resources that fail safe browsing, disallow |
| 167 // them. |
| 168 rdh_->CancelRequest(render_process_host_id_, deferred_request_id_, false); |
| 169 } else { |
| 170 StartDisplayingBlockingPage(url, result); |
| 171 } |
| 162 } | 172 } |
| 163 | 173 |
| 164 Release(); // Balances the AddRef() in CheckingUrl(). | 174 Release(); // Balances the AddRef() in CheckingUrl(). |
| 165 } | 175 } |
| 166 | 176 |
| 167 void SafeBrowsingResourceHandler::StartDisplayingBlockingPage( | 177 void SafeBrowsingResourceHandler::StartDisplayingBlockingPage( |
| 168 const GURL& url, | 178 const GURL& url, |
| 169 SafeBrowsingService::UrlCheckResult result) { | 179 SafeBrowsingService::UrlCheckResult result) { |
| 170 CHECK(state_ == STATE_NONE); | 180 CHECK(state_ == STATE_NONE); |
| 171 CHECK(defer_state_ != DEFERRED_NONE); | 181 CHECK(defer_state_ != DEFERRED_NONE); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 rdh_->FollowDeferredRedirect(render_process_host_id_, request_id, | 307 rdh_->FollowDeferredRedirect(render_process_host_id_, request_id, |
| 298 false, GURL()); | 308 false, GURL()); |
| 299 } | 309 } |
| 300 } | 310 } |
| 301 | 311 |
| 302 void SafeBrowsingResourceHandler::ClearDeferredRequestInfo() { | 312 void SafeBrowsingResourceHandler::ClearDeferredRequestInfo() { |
| 303 deferred_request_id_ = -1; | 313 deferred_request_id_ = -1; |
| 304 deferred_url_ = GURL(); | 314 deferred_url_ = GURL(); |
| 305 deferred_redirect_response_ = NULL; | 315 deferred_redirect_response_ = NULL; |
| 306 } | 316 } |
| OLD | NEW |