| 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/loader/safe_browsing_resource_throttle.h" | 5 #include "chrome/browser/loader/safe_browsing_resource_throttle.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/prerender/prerender_contents.h" | 16 #include "chrome/browser/prerender/prerender_contents.h" |
| 17 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 17 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 18 #include "components/safe_browsing_db/util.h" | 18 #include "components/safe_browsing_db/util.h" |
| 19 #include "components/safe_browsing_db/v4_feature_list.h" | 19 #include "components/safe_browsing_db/v4_feature_list.h" |
| 20 #include "components/safe_browsing_db/v4_local_database_manager.h" | 20 #include "components/safe_browsing_db/v4_local_database_manager.h" |
| 21 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" | 21 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 24 #include "content/public/browser/resource_controller.h" | |
| 25 #include "content/public/browser/resource_request_info.h" | 24 #include "content/public/browser/resource_request_info.h" |
| 26 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 27 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
| 28 #include "net/log/net_log_capture_mode.h" | 27 #include "net/log/net_log_capture_mode.h" |
| 29 #include "net/log/net_log_source.h" | 28 #include "net/log/net_log_source.h" |
| 30 #include "net/log/net_log_source_type.h" | 29 #include "net/log/net_log_source_type.h" |
| 31 #include "net/url_request/redirect_info.h" | 30 #include "net/url_request/redirect_info.h" |
| 32 #include "net/url_request/url_request.h" | 31 #include "net/url_request/url_request.h" |
| 33 | 32 |
| 34 using net::NetLogEventType; | 33 using net::NetLogEventType; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 ui_manager_->LogPauseDelay(base::TimeTicks::Now() - defer_start_time_); | 262 ui_manager_->LogPauseDelay(base::TimeTicks::Now() - defer_start_time_); |
| 264 ResumeRequest(); | 263 ResumeRequest(); |
| 265 } else { | 264 } else { |
| 266 ui_manager_->LogPauseDelay(base::TimeDelta()); | 265 ui_manager_->LogPauseDelay(base::TimeDelta()); |
| 267 } | 266 } |
| 268 return; | 267 return; |
| 269 } | 268 } |
| 270 | 269 |
| 271 if (request_->load_flags() & net::LOAD_PREFETCH) { | 270 if (request_->load_flags() & net::LOAD_PREFETCH) { |
| 272 // Don't prefetch resources that fail safe browsing, disallow them. | 271 // Don't prefetch resources that fail safe browsing, disallow them. |
| 273 controller()->Cancel(); | 272 Cancel(); |
| 274 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.UnsafePrefetchCanceled", | 273 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.UnsafePrefetchCanceled", |
| 275 resource_type_, content::RESOURCE_TYPE_LAST_TYPE); | 274 resource_type_, content::RESOURCE_TYPE_LAST_TYPE); |
| 276 return; | 275 return; |
| 277 } | 276 } |
| 278 | 277 |
| 279 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.Unsafe", resource_type_, | 278 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.Unsafe", resource_type_, |
| 280 content::RESOURCE_TYPE_LAST_TYPE); | 279 content::RESOURCE_TYPE_LAST_TYPE); |
| 281 | 280 |
| 282 const content::ResourceRequestInfo* info = | 281 const content::ResourceRequestInfo* info = |
| 283 content::ResourceRequestInfo::ForRequest(request_); | 282 content::ResourceRequestInfo::ForRequest(request_); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 } | 344 } |
| 346 } | 345 } |
| 347 | 346 |
| 348 // Tab is gone or it's being prerendered. | 347 // Tab is gone or it's being prerendered. |
| 349 content::BrowserThread::PostTask( | 348 content::BrowserThread::PostTask( |
| 350 content::BrowserThread::IO, | 349 content::BrowserThread::IO, |
| 351 FROM_HERE, | 350 FROM_HERE, |
| 352 base::Bind(&SafeBrowsingResourceThrottle::Cancel, throttle)); | 351 base::Bind(&SafeBrowsingResourceThrottle::Cancel, throttle)); |
| 353 } | 352 } |
| 354 | 353 |
| 355 void SafeBrowsingResourceThrottle::Cancel() { | |
| 356 controller()->Cancel(); | |
| 357 } | |
| 358 | |
| 359 // SafeBrowsingService::UrlCheckCallback implementation, called on the IO | 354 // SafeBrowsingService::UrlCheckCallback implementation, called on the IO |
| 360 // thread when the user has decided to proceed with the current request, or | 355 // thread when the user has decided to proceed with the current request, or |
| 361 // go back. | 356 // go back. |
| 362 void SafeBrowsingResourceThrottle::OnBlockingPageComplete(bool proceed) { | 357 void SafeBrowsingResourceThrottle::OnBlockingPageComplete(bool proceed) { |
| 363 CHECK_EQ(state_, STATE_DISPLAYING_BLOCKING_PAGE); | 358 CHECK_EQ(state_, STATE_DISPLAYING_BLOCKING_PAGE); |
| 364 state_ = STATE_NONE; | 359 state_ = STATE_NONE; |
| 365 | 360 |
| 366 if (proceed) { | 361 if (proceed) { |
| 367 threat_type_ = safe_browsing::SB_THREAT_TYPE_SAFE; | 362 threat_type_ = safe_browsing::SB_THREAT_TYPE_SAFE; |
| 368 if (defer_state_ != DEFERRED_NONE) { | 363 if (defer_state_ != DEFERRED_NONE) { |
| 369 ResumeRequest(); | 364 ResumeRequest(); |
| 370 } | 365 } |
| 371 } else { | 366 } else { |
| 372 controller()->Cancel(); | 367 Cancel(); |
| 373 } | 368 } |
| 374 } | 369 } |
| 375 | 370 |
| 376 bool SafeBrowsingResourceThrottle::CheckUrl(const GURL& url) { | 371 bool SafeBrowsingResourceThrottle::CheckUrl(const GURL& url) { |
| 377 TRACE_EVENT1("loader", "SafeBrowsingResourceThrottle::CheckUrl", "url", | 372 TRACE_EVENT1("loader", "SafeBrowsingResourceThrottle::CheckUrl", "url", |
| 378 url.spec()); | 373 url.spec()); |
| 379 CHECK_EQ(state_, STATE_NONE); | 374 CHECK_EQ(state_, STATE_NONE); |
| 380 // To reduce aggregate latency on mobile, check only the most dangerous | 375 // To reduce aggregate latency on mobile, check only the most dangerous |
| 381 // resource types. | 376 // resource types. |
| 382 if (!database_manager_->CanCheckResourceType(resource_type_)) { | 377 if (!database_manager_->CanCheckResourceType(resource_type_)) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 defer_state_ = DEFERRED_REDIRECT; | 430 defer_state_ = DEFERRED_REDIRECT; |
| 436 resume = false; | 431 resume = false; |
| 437 BeginNetLogEvent(NetLogEventType::SAFE_BROWSING_DEFERRED, | 432 BeginNetLogEvent(NetLogEventType::SAFE_BROWSING_DEFERRED, |
| 438 unchecked_redirect_url_, "defer_reason", | 433 unchecked_redirect_url_, "defer_reason", |
| 439 "resumed_redirect"); | 434 "resumed_redirect"); |
| 440 } | 435 } |
| 441 } | 436 } |
| 442 | 437 |
| 443 if (resume) { | 438 if (resume) { |
| 444 defer_state_ = DEFERRED_NONE; | 439 defer_state_ = DEFERRED_NONE; |
| 445 controller()->Resume(); | 440 Resume(); |
| 446 } | 441 } |
| 447 } | 442 } |
| OLD | NEW |