OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" | 5 #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/renderer_host/global_request_id.h" | 8 #include "chrome/browser/renderer_host/global_request_id.h" |
9 #include "chrome/browser/renderer_host/render_message_filter.h" | |
10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 9 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
11 #include "chrome/browser/renderer_host/resource_message_filter.h" | 10 #include "chrome/browser/renderer_host/resource_message_filter.h" |
12 #include "chrome/common/notification_service.h" | |
13 #include "chrome/common/resource_response.h" | 11 #include "chrome/common/resource_response.h" |
14 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
15 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
16 | 14 |
17 // Maximum time in milliseconds to wait for the safe browsing service to | 15 // Maximum time in milliseconds to wait for the safe browsing service to |
18 // verify a URL. After this amount of time the outstanding check will be | 16 // verify a URL. After this amount of time the outstanding check will be |
19 // aborted, and the URL will be treated as if it were safe. | 17 // aborted, and the URL will be treated as if it were safe. |
20 static const int kCheckUrlTimeoutMs = 5000; | 18 static const int kCheckUrlTimeoutMs = 5000; |
21 | 19 |
22 // TODO(eroman): Downgrade these CHECK()s to DCHECKs once there is more | 20 // TODO(eroman): Downgrade these CHECK()s to DCHECKs once there is more |
23 // unit test coverage. | 21 // unit test coverage. |
24 | 22 |
25 SafeBrowsingResourceHandler::SafeBrowsingResourceHandler( | 23 SafeBrowsingResourceHandler::SafeBrowsingResourceHandler( |
26 ResourceHandler* handler, | 24 ResourceHandler* handler, |
27 int render_process_host_id, | 25 int render_process_host_id, |
28 int render_view_id, | 26 int render_view_id, |
29 ResourceType::Type resource_type, | 27 ResourceType::Type resource_type, |
30 SafeBrowsingService* safe_browsing, | 28 SafeBrowsingService* safe_browsing, |
31 ResourceDispatcherHost* resource_dispatcher_host) | 29 ResourceDispatcherHost* resource_dispatcher_host) |
32 : state_(STATE_NONE), | 30 : state_(STATE_NONE), |
33 defer_state_(DEFERRED_NONE), | 31 defer_state_(DEFERRED_NONE), |
34 deferred_request_id_(-1), | 32 deferred_request_id_(-1), |
35 next_handler_(handler), | 33 next_handler_(handler), |
36 render_process_host_id_(render_process_host_id), | 34 render_process_host_id_(render_process_host_id), |
37 render_view_id_(render_view_id), | 35 render_view_id_(render_view_id), |
38 safe_browsing_(safe_browsing), | 36 safe_browsing_(safe_browsing), |
39 rdh_(resource_dispatcher_host), | 37 rdh_(resource_dispatcher_host), |
40 resource_type_(resource_type) { | 38 resource_type_(resource_type) { |
41 registrar_.Add(this, NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN, | |
42 NotificationService::AllSources()); | |
43 } | 39 } |
44 | 40 |
45 SafeBrowsingResourceHandler::~SafeBrowsingResourceHandler() { | 41 SafeBrowsingResourceHandler::~SafeBrowsingResourceHandler() { |
46 } | 42 } |
47 | 43 |
48 bool SafeBrowsingResourceHandler::OnUploadProgress(int request_id, | 44 bool SafeBrowsingResourceHandler::OnUploadProgress(int request_id, |
49 uint64 position, | 45 uint64 position, |
50 uint64 size) { | 46 uint64 size) { |
51 return next_handler_->OnUploadProgress(request_id, position, size); | 47 return next_handler_->OnUploadProgress(request_id, position, size); |
52 } | 48 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 if (proceed) { | 193 if (proceed) { |
198 safe_browsing_result_ = SafeBrowsingService::URL_SAFE; | 194 safe_browsing_result_ = SafeBrowsingService::URL_SAFE; |
199 ResumeRequest(); | 195 ResumeRequest(); |
200 } else { | 196 } else { |
201 rdh_->CancelRequest(render_process_host_id_, deferred_request_id_, false); | 197 rdh_->CancelRequest(render_process_host_id_, deferred_request_id_, false); |
202 } | 198 } |
203 | 199 |
204 Release(); // Balances the AddRef() in StartDisplayingBlockingPage(). | 200 Release(); // Balances the AddRef() in StartDisplayingBlockingPage(). |
205 } | 201 } |
206 | 202 |
207 void SafeBrowsingResourceHandler::Observe(NotificationType type, | |
208 const NotificationSource& source, | |
209 const NotificationDetails& details) { | |
210 if (Source<ResourceMessageFilter>(source).ptr()->child_id() == | |
211 render_process_host_id_) { | |
212 Shutdown(); | |
213 } | |
214 } | |
215 | |
216 void SafeBrowsingResourceHandler::Shutdown() { | 203 void SafeBrowsingResourceHandler::Shutdown() { |
217 if (state_ == STATE_CHECKING_URL) { | 204 if (state_ == STATE_CHECKING_URL) { |
218 timer_.Stop(); | 205 timer_.Stop(); |
219 safe_browsing_->CancelCheck(this); | 206 safe_browsing_->CancelCheck(this); |
220 state_ = STATE_NONE; | 207 state_ = STATE_NONE; |
221 // Balance the AddRef() from CheckUrl() which would ordinarily be | 208 // Balance the AddRef() from CheckUrl() which would ordinarily be |
222 // balanced by OnUrlCheckResult(). | 209 // balanced by OnUrlCheckResult(). |
223 Release(); | 210 Release(); |
224 } | 211 } |
225 } | 212 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 rdh_->FollowDeferredRedirect(render_process_host_id_, request_id, | 293 rdh_->FollowDeferredRedirect(render_process_host_id_, request_id, |
307 false, GURL()); | 294 false, GURL()); |
308 } | 295 } |
309 } | 296 } |
310 | 297 |
311 void SafeBrowsingResourceHandler::ClearDeferredRequestInfo() { | 298 void SafeBrowsingResourceHandler::ClearDeferredRequestInfo() { |
312 deferred_request_id_ = -1; | 299 deferred_request_id_ = -1; |
313 deferred_url_ = GURL(); | 300 deferred_url_ = GURL(); |
314 deferred_redirect_response_ = NULL; | 301 deferred_redirect_response_ = NULL; |
315 } | 302 } |
OLD | NEW |