Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: components/subresource_filter/content/browser/subresource_filter_activation_navigation_throttle.cc

Issue 2645283007: Add the client for accessing Subresource Filter only list. (Closed)
Patch Set: fix unittest Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 if (database_manager_->CheckUrlForSubresourceFilter(url, this)) {
47 content::BrowserThread::PostTask(
48 content::BrowserThread::UI, FROM_HERE,
49 base::Bind(&SubresourceFilterActivationNavigationThrottle::
50 OnCheckUrlResultOnUI,
51 AsWeakPtr(), url, safe_browsing::SB_THREAT_TYPE_SAFE,
52 safe_browsing::ThreatPatternType::NONE));
53 }
54 defer_start_time_ = base::TimeTicks::Now();
55 }
56
57 // SafeBrowsingService::Client implementation, called on the IO thread once
58 // the URL has been classified.
59 void SubresourceFilterActivationNavigationThrottle::OnCheckBrowseUrlResult(
60 const GURL& url,
61 safe_browsing::SBThreatType threat_type,
62 const safe_browsing::ThreatMetadata& metadata) {
63 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
64 timer_.Stop(); // Cancel the timeout timer.
65 content::BrowserThread::PostTask(
66 content::BrowserThread::UI, FROM_HERE,
67 base::Bind(
68 &SubresourceFilterActivationNavigationThrottle::OnCheckUrlResultOnUI,
69 AsWeakPtr(), url, threat_type, metadata.threat_pattern_type));
70 }
71
72 void SubresourceFilterActivationNavigationThrottle::OnCheckUrlResultOnUI(
73 const GURL& url,
74 safe_browsing::SBThreatType threat_type,
75 safe_browsing::ThreatPatternType pattern_type) {
76 content::WebContents* web_contents = navigation_handle()->GetWebContents();
77 if (web_contents) {
78 using subresource_filter::ContentSubresourceFilterDriverFactory;
79 ContentSubresourceFilterDriverFactory* driver_factory =
80 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents);
81 DCHECK(driver_factory);
82
83 driver_factory->OnMainResourceMatchedSafeBrowsingBlacklist(
84 url, std::vector<GURL>(), threat_type, pattern_type);
85 }
86 navigation_handle()->Resume();
87 }
88
89 bool SubresourceFilterActivationNavigationThrottle::CheckUrl(const GURL& url) {
90 if (database_manager_->CheckUrlForSubresourceFilter(url, this))
91 return true;
92
93 timer_.Start(
94 FROM_HERE, base::TimeDelta::FromMilliseconds(kCheckUrlTimeoutMs), this,
95 &SubresourceFilterActivationNavigationThrottle::OnCheckUrlTimeout);
96 return false;
97 }
98
99 void SubresourceFilterActivationNavigationThrottle::OnCheckUrlTimeout() {
100 database_manager_->CancelCheck(this);
101
102 OnCheckBrowseUrlResult(GURL::EmptyGURL(), safe_browsing::SB_THREAT_TYPE_SAFE,
vakh (use Gerrit instead) 2017/02/10 03:00:12 This should be the url for which the request timed
melandory 2017/02/14 17:40:34 Done.
103 safe_browsing::ThreatMetadata());
104 }
105
106 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698