| 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" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/prerender/prerender_contents.h" | 14 #include "chrome/browser/prerender/prerender_contents.h" |
| 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 16 #include "components/safe_browsing_db/util.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/browser/resource_controller.h" | 19 #include "content/public/browser/resource_controller.h" |
| 19 #include "content/public/browser/resource_request_info.h" | 20 #include "content/public/browser/resource_request_info.h" |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 21 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 22 #include "net/log/net_log.h" | 23 #include "net/log/net_log.h" |
| 23 #include "net/url_request/redirect_info.h" | 24 #include "net/url_request/redirect_info.h" |
| 24 #include "net/url_request/url_request.h" | 25 #include "net/url_request/url_request.h" |
| 25 | 26 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 200 |
| 200 const char* SafeBrowsingResourceThrottle::GetNameForLogging() const { | 201 const char* SafeBrowsingResourceThrottle::GetNameForLogging() const { |
| 201 return "SafeBrowsingResourceThrottle"; | 202 return "SafeBrowsingResourceThrottle"; |
| 202 } | 203 } |
| 203 | 204 |
| 204 // SafeBrowsingService::Client implementation, called on the IO thread once | 205 // SafeBrowsingService::Client implementation, called on the IO thread once |
| 205 // the URL has been classified. | 206 // the URL has been classified. |
| 206 void SafeBrowsingResourceThrottle::OnCheckBrowseUrlResult( | 207 void SafeBrowsingResourceThrottle::OnCheckBrowseUrlResult( |
| 207 const GURL& url, | 208 const GURL& url, |
| 208 safe_browsing::SBThreatType threat_type, | 209 safe_browsing::SBThreatType threat_type, |
| 209 const std::string& metadata) { | 210 const safe_browsing::ThreatMetadata& metadata) { |
| 210 CHECK_EQ(state_, STATE_CHECKING_URL); | 211 CHECK_EQ(state_, STATE_CHECKING_URL); |
| 211 CHECK_EQ(url, url_being_checked_); | 212 CHECK_EQ(url, url_being_checked_); |
| 212 | 213 |
| 213 timer_.Stop(); // Cancel the timeout timer. | 214 timer_.Stop(); // Cancel the timeout timer. |
| 214 threat_type_ = threat_type; | 215 threat_type_ = threat_type; |
| 215 state_ = STATE_NONE; | 216 state_ = STATE_NONE; |
| 216 | 217 |
| 217 if (defer_state_ != DEFERRED_NONE) { | 218 if (defer_state_ != DEFERRED_NONE) { |
| 218 EndNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, nullptr, nullptr); | 219 EndNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, nullptr, nullptr); |
| 219 } | 220 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 base::TimeDelta::FromMilliseconds(kCheckUrlTimeoutMs), | 357 base::TimeDelta::FromMilliseconds(kCheckUrlTimeoutMs), |
| 357 this, &SafeBrowsingResourceThrottle::OnCheckUrlTimeout); | 358 this, &SafeBrowsingResourceThrottle::OnCheckUrlTimeout); |
| 358 | 359 |
| 359 return false; | 360 return false; |
| 360 } | 361 } |
| 361 | 362 |
| 362 void SafeBrowsingResourceThrottle::OnCheckUrlTimeout() { | 363 void SafeBrowsingResourceThrottle::OnCheckUrlTimeout() { |
| 363 CHECK_EQ(state_, STATE_CHECKING_URL); | 364 CHECK_EQ(state_, STATE_CHECKING_URL); |
| 364 | 365 |
| 365 database_manager_->CancelCheck(this); | 366 database_manager_->CancelCheck(this); |
| 366 OnCheckBrowseUrlResult( | 367 OnCheckBrowseUrlResult(url_being_checked_, safe_browsing::SB_THREAT_TYPE_SAFE, |
| 367 url_being_checked_, safe_browsing::SB_THREAT_TYPE_SAFE, std::string()); | 368 safe_browsing::ThreatMetadata()); |
| 368 } | 369 } |
| 369 | 370 |
| 370 void SafeBrowsingResourceThrottle::ResumeRequest() { | 371 void SafeBrowsingResourceThrottle::ResumeRequest() { |
| 371 CHECK_EQ(state_, STATE_NONE); | 372 CHECK_EQ(state_, STATE_NONE); |
| 372 CHECK_NE(defer_state_, DEFERRED_NONE); | 373 CHECK_NE(defer_state_, DEFERRED_NONE); |
| 373 | 374 |
| 374 bool resume = true; | 375 bool resume = true; |
| 375 if (defer_state_ == DEFERRED_UNCHECKED_REDIRECT) { | 376 if (defer_state_ == DEFERRED_UNCHECKED_REDIRECT) { |
| 376 // Save the redirect urls for possible malware detail reporting later. | 377 // Save the redirect urls for possible malware detail reporting later. |
| 377 redirect_urls_.push_back(unchecked_redirect_url_); | 378 redirect_urls_.push_back(unchecked_redirect_url_); |
| 378 if (!CheckUrl(unchecked_redirect_url_)) { | 379 if (!CheckUrl(unchecked_redirect_url_)) { |
| 379 // We're now waiting for the unchecked_redirect_url_. | 380 // We're now waiting for the unchecked_redirect_url_. |
| 380 defer_state_ = DEFERRED_REDIRECT; | 381 defer_state_ = DEFERRED_REDIRECT; |
| 381 resume = false; | 382 resume = false; |
| 382 BeginNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, | 383 BeginNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, |
| 383 unchecked_redirect_url_, "defer_reason", | 384 unchecked_redirect_url_, "defer_reason", |
| 384 "resumed_redirect"); | 385 "resumed_redirect"); |
| 385 } | 386 } |
| 386 } | 387 } |
| 387 | 388 |
| 388 if (resume) { | 389 if (resume) { |
| 389 defer_state_ = DEFERRED_NONE; | 390 defer_state_ = DEFERRED_NONE; |
| 390 controller()->Resume(); | 391 controller()->Resume(); |
| 391 } | 392 } |
| 392 } | 393 } |
| OLD | NEW |