OLD | NEW |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 "components/safe_browsing/base_resource_throttle.h" | 5 #include "components/safe_browsing/base_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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 309 |
310 void BaseResourceThrottle::StartDisplayingBlockingPageHelper( | 310 void BaseResourceThrottle::StartDisplayingBlockingPageHelper( |
311 security_interstitials::UnsafeResource resource) { | 311 security_interstitials::UnsafeResource resource) { |
312 content::BrowserThread::PostTask( | 312 content::BrowserThread::PostTask( |
313 content::BrowserThread::UI, FROM_HERE, | 313 content::BrowserThread::UI, FROM_HERE, |
314 base::Bind(&BaseResourceThrottle::StartDisplayingBlockingPage, | 314 base::Bind(&BaseResourceThrottle::StartDisplayingBlockingPage, |
315 AsWeakPtr(), ui_manager_, resource)); | 315 AsWeakPtr(), ui_manager_, resource)); |
316 } | 316 } |
317 | 317 |
318 // Static | 318 // Static |
| 319 void BaseResourceThrottle::NotifySubresourceFilterOfBlockedResource( |
| 320 const security_interstitials::UnsafeResource& resource) { |
| 321 content::WebContents* web_contents = resource.web_contents_getter.Run(); |
| 322 DCHECK(web_contents); |
| 323 // Once activated, the subresource filter will filter subresources, but is |
| 324 // triggered when the main frame document matches Safe Browsing blacklists. |
| 325 if (!resource.is_subresource) { |
| 326 using subresource_filter::ContentSubresourceFilterDriverFactory; |
| 327 ContentSubresourceFilterDriverFactory* driver_factory = |
| 328 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents); |
| 329 |
| 330 // Content embedders (such as Android Webview) do not have a driver_factory. |
| 331 if (driver_factory) { |
| 332 // For a redirect chain of A -> B -> C, the subresource filter expects C |
| 333 // as the resource URL and [A, B] as redirect URLs. |
| 334 std::vector<GURL> redirect_parent_urls; |
| 335 if (!resource.redirect_urls.empty()) { |
| 336 redirect_parent_urls.push_back(resource.original_url); |
| 337 redirect_parent_urls.insert(redirect_parent_urls.end(), |
| 338 resource.redirect_urls.begin(), |
| 339 std::prev(resource.redirect_urls.end())); |
| 340 } |
| 341 driver_factory->OnMainResourceMatchedSafeBrowsingBlacklist( |
| 342 resource.url, redirect_parent_urls, resource.threat_type, |
| 343 resource.threat_metadata.threat_pattern_type); |
| 344 } |
| 345 } |
| 346 } |
| 347 |
| 348 // Static |
319 void BaseResourceThrottle::StartDisplayingBlockingPage( | 349 void BaseResourceThrottle::StartDisplayingBlockingPage( |
320 const base::WeakPtr<BaseResourceThrottle>& throttle, | 350 const base::WeakPtr<BaseResourceThrottle>& throttle, |
321 scoped_refptr<BaseUIManager> ui_manager, | 351 scoped_refptr<BaseUIManager> ui_manager, |
322 const security_interstitials::UnsafeResource& resource) { | 352 const security_interstitials::UnsafeResource& resource) { |
323 content::WebContents* web_contents = resource.web_contents_getter.Run(); | 353 content::WebContents* web_contents = resource.web_contents_getter.Run(); |
324 if (web_contents) { | 354 if (web_contents) { |
325 // Once activated, the subresource filter will filter subresources, but is | 355 NotifySubresourceFilterOfBlockedResource(resource); |
326 // triggered when the main frame document matches Safe Browsing blacklists. | |
327 if (!resource.is_subresource) { | |
328 using subresource_filter::ContentSubresourceFilterDriverFactory; | |
329 ContentSubresourceFilterDriverFactory* driver_factory = | |
330 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents); | |
331 // Content embedders (such as Android Webview) does not have a | |
332 // driver_factory. | |
333 if (driver_factory) { | |
334 // For a redirect chain of A -> B -> C, the subresource filter expects C | |
335 // as the resource URL and [A, B] as redirect URLs. | |
336 std::vector<GURL> redirect_parent_urls; | |
337 if (!resource.redirect_urls.empty()) { | |
338 redirect_parent_urls.push_back(resource.original_url); | |
339 redirect_parent_urls.insert(redirect_parent_urls.end(), | |
340 resource.redirect_urls.begin(), | |
341 std::prev(resource.redirect_urls.end())); | |
342 } | |
343 driver_factory->OnMainResourceMatchedSafeBrowsingBlacklist( | |
344 resource.url, redirect_parent_urls, resource.threat_type, | |
345 resource.threat_metadata.threat_pattern_type); | |
346 } | |
347 } | |
348 | |
349 ui_manager->DisplayBlockingPage(resource); | 356 ui_manager->DisplayBlockingPage(resource); |
350 return; | 357 return; |
351 } | 358 } |
352 | 359 |
353 // Tab is gone or it's being prerendered. | 360 // Tab is gone or it's being prerendered. |
354 content::BrowserThread::PostTask( | 361 content::BrowserThread::PostTask( |
355 content::BrowserThread::IO, FROM_HERE, | 362 content::BrowserThread::IO, FROM_HERE, |
356 base::Bind(&BaseResourceThrottle::Cancel, throttle)); | 363 base::Bind(&BaseResourceThrottle::Cancel, throttle)); |
357 } | 364 } |
358 | 365 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 } | 453 } |
447 } | 454 } |
448 | 455 |
449 if (resume) { | 456 if (resume) { |
450 defer_state_ = DEFERRED_NONE; | 457 defer_state_ = DEFERRED_NONE; |
451 Resume(); | 458 Resume(); |
452 } | 459 } |
453 } | 460 } |
454 | 461 |
455 } // namespace safe_browsing | 462 } // namespace safe_browsing |
OLD | NEW |