Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/subresource_filter/content/browser/subresource_filter_activ ation_navigation_throttle.h" | |
| 6 | |
| 7 #include "components/safe_browsing_db/v4_local_database_manager.h" | |
| 8 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/navigation_handle.h" | |
| 11 #include "content/public/browser/web_contents.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 // 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 | |
| 17 // aborted, and the URL will be treated as if it doesn't belong to the | |
| 18 // Subresource Filter only list. | |
| 19 const int kCheckUrlTimeoutMs = 5000; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 namespace subresource_filter { | |
| 24 | |
| 25 SubresourceFilterActivationNavigationThrottle:: | |
| 26 SubresourceFilterActivationNavigationThrottle( | |
| 27 content::NavigationHandle* handle, | |
| 28 const scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>& | |
| 29 database_manager) | |
| 30 : NavigationThrottle(handle), database_manager_(database_manager) {} | |
| 31 | |
| 32 SubresourceFilterActivationNavigationThrottle:: | |
| 33 ~SubresourceFilterActivationNavigationThrottle() {} | |
| 34 | |
| 35 content::NavigationThrottle::ThrottleCheckResult | |
| 36 SubresourceFilterActivationNavigationThrottle::WillProcessResponse() { | |
| 37 content::BrowserThread::PostTask( | |
| 38 content::BrowserThread::IO, FROM_HERE, | |
| 39 base::Bind(&SubresourceFilterActivationNavigationThrottle::CheckUrlOnIO, | |
| 40 base::Unretained(this), navigation_handle()->GetURL())); | |
| 41 return content::NavigationThrottle::ThrottleCheckResult::DEFER; | |
| 42 } | |
| 43 | |
| 44 void SubresourceFilterActivationNavigationThrottle::CheckUrlOnIO( | |
| 45 const GURL& url) { | |
| 46 url_being_checked_ = url; | |
| 47 if (database_manager_->CheckUrlForSubresourceFilter(url, this)) { | |
| 48 content::BrowserThread::PostTask( | |
| 49 content::BrowserThread::UI, FROM_HERE, | |
| 50 base::Bind(&SubresourceFilterActivationNavigationThrottle:: | |
| 51 OnCheckUrlResultOnUI, | |
| 52 AsWeakPtr(), url, safe_browsing::SB_THREAT_TYPE_SAFE, | |
| 53 safe_browsing::ThreatPatternType::NONE)); | |
| 54 } | |
| 55 timer_.Start( | |
| 56 FROM_HERE, base::TimeDelta::FromMilliseconds(kCheckUrlTimeoutMs), this, | |
| 57 &SubresourceFilterActivationNavigationThrottle::OnCheckUrlTimeout); | |
| 58 } | |
| 59 | |
| 60 // SafeBrowsingService::Client implementation, called on the IO thread once | |
|
engedy
2017/02/17 20:50:52
nit: I'd just remove this comment (sign) when we a
melandory
2017/02/28 12:16:05
Done.
| |
| 61 // the URL has been classified. | |
| 62 void SubresourceFilterActivationNavigationThrottle::OnCheckBrowseUrlResult( | |
| 63 const GURL& url, | |
| 64 safe_browsing::SBThreatType threat_type, | |
| 65 const safe_browsing::ThreatMetadata& metadata) { | |
| 66 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 67 timer_.Stop(); // Cancel the timeout timer. | |
| 68 content::BrowserThread::PostTask( | |
| 69 content::BrowserThread::UI, FROM_HERE, | |
| 70 base::Bind( | |
| 71 &SubresourceFilterActivationNavigationThrottle::OnCheckUrlResultOnUI, | |
| 72 AsWeakPtr(), url, threat_type, metadata.threat_pattern_type)); | |
| 73 } | |
| 74 | |
| 75 void SubresourceFilterActivationNavigationThrottle::OnCheckUrlResultOnUI( | |
| 76 const GURL& url, | |
| 77 safe_browsing::SBThreatType threat_type, | |
| 78 safe_browsing::ThreatPatternType pattern_type) { | |
| 79 content::WebContents* web_contents = navigation_handle()->GetWebContents(); | |
| 80 if (web_contents) { | |
| 81 using subresource_filter::ContentSubresourceFilterDriverFactory; | |
| 82 ContentSubresourceFilterDriverFactory* driver_factory = | |
| 83 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents); | |
| 84 DCHECK(driver_factory); | |
| 85 | |
| 86 driver_factory->OnMainResourceMatchedSafeBrowsingBlacklist( | |
| 87 url, std::vector<GURL>(), threat_type, pattern_type); | |
| 88 } | |
| 89 navigation_handle()->Resume(); | |
| 90 } | |
| 91 | |
| 92 void SubresourceFilterActivationNavigationThrottle::OnCheckUrlTimeout() { | |
| 93 database_manager_->CancelCheck(this); | |
| 94 | |
| 95 OnCheckBrowseUrlResult(url_being_checked_, safe_browsing::SB_THREAT_TYPE_SAFE, | |
| 96 safe_browsing::ThreatMetadata()); | |
| 97 } | |
| 98 | |
| 99 } // namespace subresource_filter | |
| OLD | NEW |