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 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // | 55 // |
56 // If the URL is classified as dangerous, a warning page is thrown up and | 56 // If the URL is classified as dangerous, a warning page is thrown up and |
57 // the request remains suspended. If the user clicks "proceed" on warning | 57 // the request remains suspended. If the user clicks "proceed" on warning |
58 // page, we resume the request. | 58 // page, we resume the request. |
59 // | 59 // |
60 // Note: The ResourceThrottle interface is called in this order: | 60 // Note: The ResourceThrottle interface is called in this order: |
61 // WillStartRequest once, WillRedirectRequest zero or more times, and then | 61 // WillStartRequest once, WillRedirectRequest zero or more times, and then |
62 // WillProcessReponse once. | 62 // WillProcessReponse once. |
63 class SafeBrowsingResourceThrottle | 63 class SafeBrowsingResourceThrottle |
64 : public content::ResourceThrottle, | 64 : public content::ResourceThrottle, |
65 public SafeBrowsingDatabaseManager::Client, | 65 public safe_browsing::SafeBrowsingDatabaseManager::Client, |
66 public base::SupportsWeakPtr<SafeBrowsingResourceThrottle> { | 66 public base::SupportsWeakPtr<SafeBrowsingResourceThrottle> { |
67 public: | 67 public: |
68 // Will construct a SafeBrowsingResourceThrottle, or return NULL | 68 // Will construct a SafeBrowsingResourceThrottle, or return NULL |
69 // if on Android and not in the field trial. | 69 // if on Android and not in the field trial. |
70 static SafeBrowsingResourceThrottle* MaybeCreate( | 70 static SafeBrowsingResourceThrottle* MaybeCreate( |
71 net::URLRequest* request, | 71 net::URLRequest* request, |
72 content::ResourceType resource_type, | 72 content::ResourceType resource_type, |
73 SafeBrowsingService* sb_service); | 73 safe_browsing::SafeBrowsingService* sb_service); |
74 | 74 |
75 // content::ResourceThrottle implementation (called on IO thread): | 75 // content::ResourceThrottle implementation (called on IO thread): |
76 void WillStartRequest(bool* defer) override; | 76 void WillStartRequest(bool* defer) override; |
77 void WillRedirectRequest(const net::RedirectInfo& redirect_info, | 77 void WillRedirectRequest(const net::RedirectInfo& redirect_info, |
78 bool* defer) override; | 78 bool* defer) override; |
79 void WillProcessResponse(bool* defer) override; | 79 void WillProcessResponse(bool* defer) override; |
80 | 80 |
81 const char* GetNameForLogging() const override; | 81 const char* GetNameForLogging() const override; |
82 | 82 |
83 // SafeBrowsingDabaseManager::Client implementation (called on IO thread): | 83 // SafeBrowsingDabaseManager::Client implementation (called on IO thread): |
84 void OnCheckBrowseUrlResult(const GURL& url, | 84 void OnCheckBrowseUrlResult(const GURL& url, |
85 SBThreatType result, | 85 safe_browsing::SBThreatType result, |
86 const std::string& metadata) override; | 86 const std::string& metadata) override; |
87 | 87 |
88 protected: | 88 protected: |
89 SafeBrowsingResourceThrottle(const net::URLRequest* request, | 89 SafeBrowsingResourceThrottle(const net::URLRequest* request, |
90 content::ResourceType resource_type, | 90 content::ResourceType resource_type, |
91 SafeBrowsingService* sb_service); | 91 safe_browsing::SafeBrowsingService* sb_service); |
92 | 92 |
93 private: | 93 private: |
94 // Describes what phase of the check a throttle is in. | 94 // Describes what phase of the check a throttle is in. |
95 enum State { | 95 enum State { |
96 // Haven't started checking or checking is complete. Not deferred. | 96 // Haven't started checking or checking is complete. Not deferred. |
97 STATE_NONE, | 97 STATE_NONE, |
98 // We have one outstanding URL-check. Could be deferred. | 98 // We have one outstanding URL-check. Could be deferred. |
99 STATE_CHECKING_URL, | 99 STATE_CHECKING_URL, |
100 // We're displaying a blocking page. Could be deferred. | 100 // We're displaying a blocking page. Could be deferred. |
101 STATE_DISPLAYING_BLOCKING_PAGE, | 101 STATE_DISPLAYING_BLOCKING_PAGE, |
(...skipping 19 matching lines...) Expand all Loading... |
121 bool CheckUrl(const GURL& url); | 121 bool CheckUrl(const GURL& url); |
122 | 122 |
123 // Callback for when the safe browsing check (which was initiated by | 123 // Callback for when the safe browsing check (which was initiated by |
124 // StartCheckingUrl()) has taken longer than kCheckUrlTimeoutMs. | 124 // StartCheckingUrl()) has taken longer than kCheckUrlTimeoutMs. |
125 void OnCheckUrlTimeout(); | 125 void OnCheckUrlTimeout(); |
126 | 126 |
127 // Starts displaying the safe browsing interstitial page if it's not | 127 // Starts displaying the safe browsing interstitial page if it's not |
128 // prerendering. Called on the UI thread. | 128 // prerendering. Called on the UI thread. |
129 static void StartDisplayingBlockingPage( | 129 static void StartDisplayingBlockingPage( |
130 const base::WeakPtr<SafeBrowsingResourceThrottle>& throttle, | 130 const base::WeakPtr<SafeBrowsingResourceThrottle>& throttle, |
131 scoped_refptr<SafeBrowsingUIManager> ui_manager, | 131 scoped_refptr<safe_browsing::SafeBrowsingUIManager> ui_manager, |
132 const SafeBrowsingUIManager::UnsafeResource& resource); | 132 const safe_browsing::SafeBrowsingUIManager::UnsafeResource& resource); |
133 | 133 |
134 // Called on the IO thread if the request turned out to be for a prerendered | 134 // Called on the IO thread if the request turned out to be for a prerendered |
135 // page. | 135 // page. |
136 void Cancel(); | 136 void Cancel(); |
137 | 137 |
138 // Resumes the request, by continuing the deferred action (either starting the | 138 // Resumes the request, by continuing the deferred action (either starting the |
139 // request, or following a redirect). | 139 // request, or following a redirect). |
140 void ResumeRequest(); | 140 void ResumeRequest(); |
141 | 141 |
142 // For marking network events. |name| and |value| can be null. | 142 // For marking network events. |name| and |value| can be null. |
143 void BeginNetLogEvent(net::NetLog::EventType type, | 143 void BeginNetLogEvent(net::NetLog::EventType type, |
144 const GURL& url, | 144 const GURL& url, |
145 const char* name, | 145 const char* name, |
146 const char* value); | 146 const char* value); |
147 void EndNetLogEvent(net::NetLog::EventType type, | 147 void EndNetLogEvent(net::NetLog::EventType type, |
148 const char* name, | 148 const char* name, |
149 const char* value); | 149 const char* value); |
150 | 150 |
151 State state_; | 151 State state_; |
152 DeferState defer_state_; | 152 DeferState defer_state_; |
153 | 153 |
154 // The result of the most recent safe browsing check. Only valid to read this | 154 // The result of the most recent safe browsing check. Only valid to read this |
155 // when state_ != STATE_CHECKING_URL. | 155 // when state_ != STATE_CHECKING_URL. |
156 SBThreatType threat_type_; | 156 safe_browsing::SBThreatType threat_type_; |
157 | 157 |
158 // The time when we started deferring the request. | 158 // The time when we started deferring the request. |
159 base::TimeTicks defer_start_time_; | 159 base::TimeTicks defer_start_time_; |
160 | 160 |
161 // Timer to abort the safe browsing check if it takes too long. | 161 // Timer to abort the safe browsing check if it takes too long. |
162 base::OneShotTimer timer_; | 162 base::OneShotTimer timer_; |
163 | 163 |
164 // The redirect chain for this resource | 164 // The redirect chain for this resource |
165 std::vector<GURL> redirect_urls_; | 165 std::vector<GURL> redirect_urls_; |
166 | 166 |
167 // If in DEFERRED_UNCHECKED_REDIRECT state, this is the | 167 // If in DEFERRED_UNCHECKED_REDIRECT state, this is the |
168 // URL we still need to check before resuming. | 168 // URL we still need to check before resuming. |
169 GURL unchecked_redirect_url_; | 169 GURL unchecked_redirect_url_; |
170 GURL url_being_checked_; | 170 GURL url_being_checked_; |
171 | 171 |
172 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 172 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_; |
173 scoped_refptr<SafeBrowsingUIManager> ui_manager_; | 173 scoped_refptr<safe_browsing::SafeBrowsingUIManager> ui_manager_; |
174 const net::URLRequest* request_; | 174 const net::URLRequest* request_; |
175 const content::ResourceType resource_type_; | 175 const content::ResourceType resource_type_; |
176 net::BoundNetLog bound_net_log_; | 176 net::BoundNetLog bound_net_log_; |
177 | 177 |
178 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingResourceThrottle); | 178 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingResourceThrottle); |
179 }; | 179 }; |
180 #endif // CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_THROTTLE_H_ | 180 #endif // CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_THROTTLE_H_ |
OLD | NEW |