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 #ifndef CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_THROTTLE_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_THROTTLE_H_ |
6 #define CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_THROTTLE_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_THROTTLE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
14 #include "chrome/browser/safe_browsing/database_manager.h" | 14 #include "chrome/browser/safe_browsing/database_manager.h" |
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
16 #include "chrome/browser/safe_browsing/ui_manager.h" | 16 #include "chrome/browser/safe_browsing/ui_manager.h" |
17 #include "content/public/browser/resource_throttle.h" | 17 #include "content/public/browser/resource_throttle.h" |
18 #include "content/public/common/resource_type.h" | 18 #include "content/public/common/resource_type.h" |
19 #include "net/log/net_log.h" | 19 #include "net/log/net_log.h" |
20 | 20 |
21 using safe_browsing::SafeBrowsingDatabaseManager; | |
Nathan Parker
2015/11/11 21:23:36
shouldn't use "using" in .h's.
vakh (old account. dont use)
2015/11/11 23:22:46
Done.
| |
22 using safe_browsing::SafeBrowsingUIManager; | |
23 | |
21 class ResourceDispatcherHost; | 24 class ResourceDispatcherHost; |
22 | 25 |
23 namespace net { | 26 namespace net { |
24 class URLRequest; | 27 class URLRequest; |
25 } | 28 } |
26 | 29 |
27 // SafeBrowsingResourceThrottle checks that URLs are "safe" before | 30 // SafeBrowsingResourceThrottle checks that URLs are "safe" before |
28 // navigating to them. To be considered "safe", a URL must not appear in the | 31 // navigating to them. To be considered "safe", a URL must not appear in the |
29 // malware/phishing blacklists (see SafeBrowsingService for details). | 32 // malware/phishing blacklists (see SafeBrowsingService for details). |
30 // | 33 // |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 class SafeBrowsingResourceThrottle | 66 class SafeBrowsingResourceThrottle |
64 : public content::ResourceThrottle, | 67 : public content::ResourceThrottle, |
65 public SafeBrowsingDatabaseManager::Client, | 68 public SafeBrowsingDatabaseManager::Client, |
66 public base::SupportsWeakPtr<SafeBrowsingResourceThrottle> { | 69 public base::SupportsWeakPtr<SafeBrowsingResourceThrottle> { |
67 public: | 70 public: |
68 // Will construct a SafeBrowsingResourceThrottle, or return NULL | 71 // Will construct a SafeBrowsingResourceThrottle, or return NULL |
69 // if on Android and not in the field trial. | 72 // if on Android and not in the field trial. |
70 static SafeBrowsingResourceThrottle* MaybeCreate( | 73 static SafeBrowsingResourceThrottle* MaybeCreate( |
71 net::URLRequest* request, | 74 net::URLRequest* request, |
72 content::ResourceType resource_type, | 75 content::ResourceType resource_type, |
73 SafeBrowsingService* sb_service); | 76 safe_browsing::SafeBrowsingService* sb_service); |
74 | 77 |
75 // content::ResourceThrottle implementation (called on IO thread): | 78 // content::ResourceThrottle implementation (called on IO thread): |
76 void WillStartRequest(bool* defer) override; | 79 void WillStartRequest(bool* defer) override; |
77 void WillRedirectRequest(const net::RedirectInfo& redirect_info, | 80 void WillRedirectRequest(const net::RedirectInfo& redirect_info, |
78 bool* defer) override; | 81 bool* defer) override; |
79 void WillProcessResponse(bool* defer) override; | 82 void WillProcessResponse(bool* defer) override; |
80 | 83 |
81 const char* GetNameForLogging() const override; | 84 const char* GetNameForLogging() const override; |
82 | 85 |
83 // SafeBrowsingDabaseManager::Client implementation (called on IO thread): | 86 // SafeBrowsingDabaseManager::Client implementation (called on IO thread): |
84 void OnCheckBrowseUrlResult(const GURL& url, | 87 void OnCheckBrowseUrlResult(const GURL& url, |
85 SBThreatType result, | 88 safe_browsing::SBThreatType result, |
86 const std::string& metadata) override; | 89 const std::string& metadata) override; |
87 | 90 |
88 protected: | 91 protected: |
89 SafeBrowsingResourceThrottle(const net::URLRequest* request, | 92 SafeBrowsingResourceThrottle(const net::URLRequest* request, |
90 content::ResourceType resource_type, | 93 content::ResourceType resource_type, |
91 SafeBrowsingService* sb_service); | 94 safe_browsing::SafeBrowsingService* sb_service); |
92 | 95 |
93 private: | 96 private: |
94 // Describes what phase of the check a throttle is in. | 97 // Describes what phase of the check a throttle is in. |
95 enum State { | 98 enum State { |
96 // Haven't started checking or checking is complete. Not deferred. | 99 // Haven't started checking or checking is complete. Not deferred. |
97 STATE_NONE, | 100 STATE_NONE, |
98 // We have one outstanding URL-check. Could be deferred. | 101 // We have one outstanding URL-check. Could be deferred. |
99 STATE_CHECKING_URL, | 102 STATE_CHECKING_URL, |
100 // We're displaying a blocking page. Could be deferred. | 103 // We're displaying a blocking page. Could be deferred. |
101 STATE_DISPLAYING_BLOCKING_PAGE, | 104 STATE_DISPLAYING_BLOCKING_PAGE, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 const char* value); | 149 const char* value); |
147 void EndNetLogEvent(net::NetLog::EventType type, | 150 void EndNetLogEvent(net::NetLog::EventType type, |
148 const char* name, | 151 const char* name, |
149 const char* value); | 152 const char* value); |
150 | 153 |
151 State state_; | 154 State state_; |
152 DeferState defer_state_; | 155 DeferState defer_state_; |
153 | 156 |
154 // The result of the most recent safe browsing check. Only valid to read this | 157 // The result of the most recent safe browsing check. Only valid to read this |
155 // when state_ != STATE_CHECKING_URL. | 158 // when state_ != STATE_CHECKING_URL. |
156 SBThreatType threat_type_; | 159 safe_browsing::SBThreatType threat_type_; |
157 | 160 |
158 // The time when we started deferring the request. | 161 // The time when we started deferring the request. |
159 base::TimeTicks defer_start_time_; | 162 base::TimeTicks defer_start_time_; |
160 | 163 |
161 // Timer to abort the safe browsing check if it takes too long. | 164 // Timer to abort the safe browsing check if it takes too long. |
162 base::OneShotTimer timer_; | 165 base::OneShotTimer timer_; |
163 | 166 |
164 // The redirect chain for this resource | 167 // The redirect chain for this resource |
165 std::vector<GURL> redirect_urls_; | 168 std::vector<GURL> redirect_urls_; |
166 | 169 |
167 // If in DEFERRED_UNCHECKED_REDIRECT state, this is the | 170 // If in DEFERRED_UNCHECKED_REDIRECT state, this is the |
168 // URL we still need to check before resuming. | 171 // URL we still need to check before resuming. |
169 GURL unchecked_redirect_url_; | 172 GURL unchecked_redirect_url_; |
170 GURL url_being_checked_; | 173 GURL url_being_checked_; |
171 | 174 |
172 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 175 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
173 scoped_refptr<SafeBrowsingUIManager> ui_manager_; | 176 scoped_refptr<SafeBrowsingUIManager> ui_manager_; |
174 const net::URLRequest* request_; | 177 const net::URLRequest* request_; |
175 const content::ResourceType resource_type_; | 178 const content::ResourceType resource_type_; |
176 net::BoundNetLog bound_net_log_; | 179 net::BoundNetLog bound_net_log_; |
177 | 180 |
178 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingResourceThrottle); | 181 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingResourceThrottle); |
179 }; | 182 }; |
180 #endif // CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_THROTTLE_H_ | 183 #endif // CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_THROTTLE_H_ |
OLD | NEW |