| 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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 std::unique_ptr<base::Value> NetLogStringCallback(const char* name, | 63 std::unique_ptr<base::Value> NetLogStringCallback(const char* name, |
| 64 const char* value, | 64 const char* value, |
| 65 net::NetLogCaptureMode) { | 65 net::NetLogCaptureMode) { |
| 66 std::unique_ptr<base::DictionaryValue> event_params( | 66 std::unique_ptr<base::DictionaryValue> event_params( |
| 67 new base::DictionaryValue()); | 67 new base::DictionaryValue()); |
| 68 if (name && value) | 68 if (name && value) |
| 69 event_params->SetString(name, value); | 69 event_params->SetString(name, value); |
| 70 return std::move(event_params); | 70 return std::move(event_params); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Destroys the prerender contents associated with the web_contents, if any. |
| 74 void DestroyPrerenderContents( |
| 75 const content::ResourceRequestInfo::WebContentsGetter& |
| 76 web_contents_getter) { |
| 77 content::WebContents* web_contents = web_contents_getter.Run(); |
| 78 if (web_contents) { |
| 79 prerender::PrerenderContents* prerender_contents = |
| 80 prerender::PrerenderContents::FromWebContents(web_contents); |
| 81 if (prerender_contents) |
| 82 prerender_contents->Destroy(prerender::FINAL_STATUS_SAFE_BROWSING); |
| 83 } |
| 84 } |
| 85 |
| 73 } // namespace | 86 } // namespace |
| 74 | 87 |
| 75 // TODO(eroman): Downgrade these CHECK()s to DCHECKs once there is more | 88 // TODO(eroman): Downgrade these CHECK()s to DCHECKs once there is more |
| 76 // unit test coverage. | 89 // unit test coverage. |
| 77 | 90 |
| 78 // static | 91 // static |
| 79 SafeBrowsingResourceThrottle* SafeBrowsingResourceThrottle::MaybeCreate( | 92 SafeBrowsingResourceThrottle* SafeBrowsingResourceThrottle::MaybeCreate( |
| 80 net::URLRequest* request, | 93 net::URLRequest* request, |
| 81 content::ResourceType resource_type, | 94 content::ResourceType resource_type, |
| 82 safe_browsing::SafeBrowsingService* sb_service) { | 95 safe_browsing::SafeBrowsingService* sb_service) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 if (defer_state_ != DEFERRED_NONE) { | 273 if (defer_state_ != DEFERRED_NONE) { |
| 261 // Log how much time the safe browsing check cost us. | 274 // Log how much time the safe browsing check cost us. |
| 262 ui_manager_->LogPauseDelay(base::TimeTicks::Now() - defer_start_time_); | 275 ui_manager_->LogPauseDelay(base::TimeTicks::Now() - defer_start_time_); |
| 263 ResumeRequest(); | 276 ResumeRequest(); |
| 264 } else { | 277 } else { |
| 265 ui_manager_->LogPauseDelay(base::TimeDelta()); | 278 ui_manager_->LogPauseDelay(base::TimeDelta()); |
| 266 } | 279 } |
| 267 return; | 280 return; |
| 268 } | 281 } |
| 269 | 282 |
| 283 const content::ResourceRequestInfo* info = |
| 284 content::ResourceRequestInfo::ForRequest(request_); |
| 285 |
| 270 if (request_->load_flags() & net::LOAD_PREFETCH) { | 286 if (request_->load_flags() & net::LOAD_PREFETCH) { |
| 271 // Don't prefetch resources that fail safe browsing, disallow them. | 287 // Don't prefetch resources that fail safe browsing, disallow them. |
| 288 content::BrowserThread::PostTask( |
| 289 content::BrowserThread::UI, FROM_HERE, |
| 290 base::Bind(&DestroyPrerenderContents, |
| 291 info->GetWebContentsGetterForRequest())); |
| 272 Cancel(); | 292 Cancel(); |
| 273 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.UnsafePrefetchCanceled", | 293 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.UnsafePrefetchCanceled", |
| 274 resource_type_, content::RESOURCE_TYPE_LAST_TYPE); | 294 resource_type_, content::RESOURCE_TYPE_LAST_TYPE); |
| 275 return; | 295 return; |
| 276 } | 296 } |
| 277 | 297 |
| 278 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.Unsafe", resource_type_, | 298 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.Unsafe", resource_type_, |
| 279 content::RESOURCE_TYPE_LAST_TYPE); | 299 content::RESOURCE_TYPE_LAST_TYPE); |
| 280 | 300 |
| 281 const content::ResourceRequestInfo* info = | |
| 282 content::ResourceRequestInfo::ForRequest(request_); | |
| 283 | |
| 284 security_interstitials::UnsafeResource resource; | 301 security_interstitials::UnsafeResource resource; |
| 285 resource.url = url; | 302 resource.url = url; |
| 286 resource.original_url = request_->original_url(); | 303 resource.original_url = request_->original_url(); |
| 287 resource.redirect_urls = redirect_urls_; | 304 resource.redirect_urls = redirect_urls_; |
| 288 resource.is_subresource = resource_type_ != content::RESOURCE_TYPE_MAIN_FRAME; | 305 resource.is_subresource = resource_type_ != content::RESOURCE_TYPE_MAIN_FRAME; |
| 289 resource.is_subframe = resource_type_ == content::RESOURCE_TYPE_SUB_FRAME; | 306 resource.is_subframe = resource_type_ == content::RESOURCE_TYPE_SUB_FRAME; |
| 290 resource.threat_type = threat_type; | 307 resource.threat_type = threat_type; |
| 291 resource.threat_metadata = metadata; | 308 resource.threat_metadata = metadata; |
| 292 resource.callback = base::Bind( | 309 resource.callback = base::Bind( |
| 293 &SafeBrowsingResourceThrottle::OnBlockingPageComplete, AsWeakPtr()); | 310 &SafeBrowsingResourceThrottle::OnBlockingPageComplete, AsWeakPtr()); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 unchecked_redirect_url_, "defer_reason", | 450 unchecked_redirect_url_, "defer_reason", |
| 434 "resumed_redirect"); | 451 "resumed_redirect"); |
| 435 } | 452 } |
| 436 } | 453 } |
| 437 | 454 |
| 438 if (resume) { | 455 if (resume) { |
| 439 defer_state_ = DEFERRED_NONE; | 456 defer_state_ = DEFERRED_NONE; |
| 440 Resume(); | 457 Resume(); |
| 441 } | 458 } |
| 442 } | 459 } |
| OLD | NEW |