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