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

Side by Side Diff: components/safe_browsing/base_resource_throttle.h

Issue 2623733002: Componentize SafeBrowsingBlockingPage for WebView use (Closed)
Patch Set: address final comments Created 3 years, 11 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
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 #ifndef COMPONENTS_SAFE_BROWSING_BASE_SAFE_BROWSING_RESOURCE_THROTTLE_H_ 5 #ifndef COMPONENTS_SAFE_BROWSING_BASE_RESOURCE_THROTTLE_H_
6 #define COMPONENTS_SAFE_BROWSING_BASE_SAFE_BROWSING_RESOURCE_THROTTLE_H_ 6 #define COMPONENTS_SAFE_BROWSING_BASE_RESOURCE_THROTTLE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
16 #include "components/safe_browsing/base_ui_manager.h" 16 #include "components/safe_browsing/base_ui_manager.h"
17 #include "components/safe_browsing_db/database_manager.h" 17 #include "components/safe_browsing_db/database_manager.h"
18 #include "components/security_interstitials/content/unsafe_resource.h" 18 #include "components/security_interstitials/content/unsafe_resource.h"
19 #include "content/public/browser/resource_throttle.h" 19 #include "content/public/browser/resource_throttle.h"
20 #include "content/public/common/resource_type.h" 20 #include "content/public/common/resource_type.h"
21 #include "net/log/net_log_event_type.h" 21 #include "net/log/net_log_event_type.h"
22 #include "net/log/net_log_with_source.h" 22 #include "net/log/net_log_with_source.h"
23 #include "url/gurl.h" 23 #include "url/gurl.h"
24 24
25 namespace content { 25 namespace content {
26 class ResourceRequestInfo; 26 class ResourceRequestInfo;
27 } 27 }
28 28
29 namespace net { 29 namespace net {
30 class URLRequest; 30 class URLRequest;
31 } 31 }
32 32
33 // BaseSafeBrowsingResourceThrottle checks that URLs are "safe" before 33 namespace safe_browsing {
34
35 // BaseResourceThrottle checks that URLs are "safe" before
34 // navigating to them. To be considered "safe", a URL must not appear in the 36 // navigating to them. To be considered "safe", a URL must not appear in the
35 // malware/phishing blacklists (see SafeBrowsingService for details). 37 // malware/phishing blacklists (see SafeBrowsingService for details).
36 // 38 //
37 // Note that the safe browsing check takes at most kCheckUrlTimeoutMs 39 // Note that the safe browsing check takes at most kCheckUrlTimeoutMs
38 // milliseconds. If it takes longer than this, then the system defaults to 40 // milliseconds. If it takes longer than this, then the system defaults to
39 // treating the URL as safe. 41 // treating the URL as safe.
40 // 42 //
41 // If the URL is classified as dangerous, a warning page is thrown up and 43 // If the URL is classified as dangerous, a warning page is thrown up and
42 // the request remains suspended. If the user clicks "proceed" on warning 44 // the request remains suspended. If the user clicks "proceed" on warning
43 // page, we resume the request. 45 // page, we resume the request.
44 // 46 //
45 // Note: The ResourceThrottle interface is called in this order: 47 // Note: The ResourceThrottle interface is called in this order:
46 // WillStartRequest once, WillRedirectRequest zero or more times, and then 48 // WillStartRequest once, WillRedirectRequest zero or more times, and then
47 // WillProcessReponse once. 49 // WillProcessReponse once.
48 class BaseSafeBrowsingResourceThrottle 50 class BaseResourceThrottle
49 : public content::ResourceThrottle, 51 : public content::ResourceThrottle,
50 public safe_browsing::SafeBrowsingDatabaseManager::Client, 52 public SafeBrowsingDatabaseManager::Client,
51 public base::SupportsWeakPtr<BaseSafeBrowsingResourceThrottle> { 53 public base::SupportsWeakPtr<BaseResourceThrottle> {
52 public: 54 public:
53 // Construct a BaseSafeBrowsingResourceThrottle, or return nullptr if we 55 // Construct a BaseResourceThrottle, or return nullptr if we
54 // cannot access the safe browsing API on Android 56 // cannot access the safe browsing API on Android
55 static BaseSafeBrowsingResourceThrottle* MaybeCreate( 57 static BaseResourceThrottle* MaybeCreate(
56 net::URLRequest* request, 58 net::URLRequest* request,
57 content::ResourceType resource_type, 59 content::ResourceType resource_type,
58 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> 60 scoped_refptr<SafeBrowsingDatabaseManager>
59 database_manager, 61 database_manager,
60 scoped_refptr<safe_browsing::BaseSafeBrowsingUIManager> ui_manager); 62 scoped_refptr<BaseUIManager> ui_manager);
61 63
62 // content::ResourceThrottle implementation (called on IO thread): 64 // content::ResourceThrottle implementation (called on IO thread):
63 void WillStartRequest(bool* defer) override; 65 void WillStartRequest(bool* defer) override;
64 void WillRedirectRequest(const net::RedirectInfo& redirect_info, 66 void WillRedirectRequest(const net::RedirectInfo& redirect_info,
65 bool* defer) override; 67 bool* defer) override;
66 void WillProcessResponse(bool* defer) override; 68 void WillProcessResponse(bool* defer) override;
67 bool MustProcessResponseBeforeReadingBody() override; 69 bool MustProcessResponseBeforeReadingBody() override;
68 70
69 const char* GetNameForLogging() const override; 71 const char* GetNameForLogging() const override;
70 72
71 // SafeBrowsingDatabaseManager::Client implementation (called on IO thread): 73 // SafeBrowsingDatabaseManager::Client implementation (called on IO thread):
72 void OnCheckBrowseUrlResult( 74 void OnCheckBrowseUrlResult(
73 const GURL& url, 75 const GURL& url,
74 safe_browsing::SBThreatType threat_type, 76 SBThreatType threat_type,
75 const safe_browsing::ThreatMetadata& metadata) override; 77 const ThreatMetadata& metadata) override;
76 78
77 protected: 79 protected:
78 BaseSafeBrowsingResourceThrottle( 80 BaseResourceThrottle(
79 const net::URLRequest* request, 81 const net::URLRequest* request,
80 content::ResourceType resource_type, 82 content::ResourceType resource_type,
81 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> 83 scoped_refptr<SafeBrowsingDatabaseManager>
82 database_manager, 84 database_manager,
83 scoped_refptr<safe_browsing::BaseSafeBrowsingUIManager> ui_manager); 85 scoped_refptr<BaseUIManager> ui_manager);
84 86
85 ~BaseSafeBrowsingResourceThrottle() override; 87 ~BaseResourceThrottle() override;
86 88
87 // Does nothing in the base class. Override this to destroy prerender contents 89 // Does nothing in the base class. Override this to destroy prerender contents
88 // in chrome. 90 // in chrome.
89 virtual void MaybeDestroyPrerenderContents( 91 virtual void MaybeDestroyPrerenderContents(
90 const content::ResourceRequestInfo* info); 92 const content::ResourceRequestInfo* info);
91 93
92 // Posts a task for StartDisplayingBlockingPage 94 // Posts a task for StartDisplayingBlockingPage
93 virtual void StartDisplayingBlockingPageHelper( 95 virtual void StartDisplayingBlockingPageHelper(
94 security_interstitials::UnsafeResource resource); 96 security_interstitials::UnsafeResource resource);
95 97
96 scoped_refptr<safe_browsing::BaseSafeBrowsingUIManager> ui_manager_; 98 scoped_refptr<BaseUIManager> ui_manager_;
97 99
98 private: 100 private:
99 // Describes what phase of the check a throttle is in. 101 // Describes what phase of the check a throttle is in.
100 enum State { 102 enum State {
101 // Haven't started checking or checking is complete. Not deferred. 103 // Haven't started checking or checking is complete. Not deferred.
102 STATE_NONE, 104 STATE_NONE,
103 // We have one outstanding URL-check. Could be deferred. 105 // We have one outstanding URL-check. Could be deferred.
104 STATE_CHECKING_URL, 106 STATE_CHECKING_URL,
105 // We're displaying a blocking page. Could be deferred. 107 // We're displaying a blocking page. Could be deferred.
106 STATE_DISPLAYING_BLOCKING_PAGE, 108 STATE_DISPLAYING_BLOCKING_PAGE,
(...skipping 17 matching lines...) Expand all
124 // OnBrowseUrlResult() when the check has completed. 126 // OnBrowseUrlResult() when the check has completed.
125 bool CheckUrl(const GURL& url); 127 bool CheckUrl(const GURL& url);
126 128
127 // Callback for when the safe browsing check (which was initiated by 129 // Callback for when the safe browsing check (which was initiated by
128 // StartCheckingUrl()) has taken longer than kCheckUrlTimeoutMs. 130 // StartCheckingUrl()) has taken longer than kCheckUrlTimeoutMs.
129 void OnCheckUrlTimeout(); 131 void OnCheckUrlTimeout();
130 132
131 // Starts displaying the safe browsing interstitial page. Called on the UI 133 // Starts displaying the safe browsing interstitial page. Called on the UI
132 // thread. 134 // thread.
133 static void StartDisplayingBlockingPage( 135 static void StartDisplayingBlockingPage(
134 const base::WeakPtr<BaseSafeBrowsingResourceThrottle>& throttle, 136 const base::WeakPtr<BaseResourceThrottle>& throttle,
135 scoped_refptr<safe_browsing::BaseSafeBrowsingUIManager> ui_manager, 137 scoped_refptr<BaseUIManager> ui_manager,
136 const security_interstitials::UnsafeResource& resource); 138 const security_interstitials::UnsafeResource& resource);
137 139
138 void ResumeRequest(); 140 void ResumeRequest();
139 141
140 // For marking network events. |name| and |value| can be null. 142 // For marking network events. |name| and |value| can be null.
141 void BeginNetLogEvent(net::NetLogEventType type, 143 void BeginNetLogEvent(net::NetLogEventType type,
142 const GURL& url, 144 const GURL& url,
143 const char* name, 145 const char* name,
144 const char* value); 146 const char* value);
145 void EndNetLogEvent(net::NetLogEventType type, 147 void EndNetLogEvent(net::NetLogEventType type,
(...skipping 11 matching lines...) Expand all
157 base::OneShotTimer timer_; 159 base::OneShotTimer timer_;
158 160
159 // The redirect chain for this resource 161 // The redirect chain for this resource
160 std::vector<GURL> redirect_urls_; 162 std::vector<GURL> redirect_urls_;
161 163
162 // If in DEFERRED_UNCHECKED_REDIRECT state, this is the 164 // If in DEFERRED_UNCHECKED_REDIRECT state, this is the
163 // URL we still need to check before resuming. 165 // URL we still need to check before resuming.
164 GURL unchecked_redirect_url_; 166 GURL unchecked_redirect_url_;
165 GURL url_being_checked_; 167 GURL url_being_checked_;
166 168
167 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_; 169 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
168 const net::URLRequest* request_; 170 const net::URLRequest* request_;
169 171
170 State state_; 172 State state_;
171 DeferState defer_state_; 173 DeferState defer_state_;
172 174
173 const content::ResourceType resource_type_; 175 const content::ResourceType resource_type_;
174 net::NetLogWithSource net_log_with_source_; 176 net::NetLogWithSource net_log_with_source_;
175 177
176 // TODO(vakh): The following set should be removed after fixing 178 // TODO(vakh): The following set should be removed after fixing
177 // http://crbug.com/660293 179 // http://crbug.com/660293
178 // URLs that timed out waiting for a SafeBrowsing reputation check. 180 // URLs that timed out waiting for a SafeBrowsing reputation check.
179 std::set<GURL> timed_out_urls_; 181 std::set<GURL> timed_out_urls_;
180 182
181 DISALLOW_COPY_AND_ASSIGN(BaseSafeBrowsingResourceThrottle); 183 DISALLOW_COPY_AND_ASSIGN(BaseResourceThrottle);
182 }; 184 };
183 185
184 #endif // COMPONENTS_SAFE_BROWSING_BASE_SAFE_BROWSING_RESOURCE_THROTTLE_H_ 186 } // namespace safe_browsing
187
188 #endif // COMPONENTS_SAFE_BROWSING_BASE_RESOURCE_THROTTLE_H_
OLDNEW
« no previous file with comments | « components/safe_browsing/base_blocking_page.cc ('k') | components/safe_browsing/base_resource_throttle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698