| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/renderer_host/resource_dispatcher_host.h" | 7 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 8 #include "chrome/browser/renderer_host/resource_message_filter.h" |
| 9 #include "chrome/common/notification_service.h" |
| 8 | 10 |
| 9 // Maximum time to wait for a gethash response from the Safe Browsing servers. | 11 // Maximum time to wait for a gethash response from the Safe Browsing servers. |
| 10 static const int kMaxGetHashMs = 1000; | 12 static const int kMaxGetHashMs = 1000; |
| 11 | 13 |
| 12 SafeBrowsingResourceHandler::SafeBrowsingResourceHandler( | 14 SafeBrowsingResourceHandler::SafeBrowsingResourceHandler( |
| 13 ResourceHandler* handler, | 15 ResourceHandler* handler, |
| 14 int render_process_host_id, | 16 int render_process_host_id, |
| 15 int render_view_id, | 17 int render_view_id, |
| 16 const GURL& url, | 18 const GURL& url, |
| 17 ResourceType::Type resource_type, | 19 ResourceType::Type resource_type, |
| 18 SafeBrowsingService* safe_browsing, | 20 SafeBrowsingService* safe_browsing, |
| 19 ResourceDispatcherHost* resource_dispatcher_host) | 21 ResourceDispatcherHost* resource_dispatcher_host, |
| 22 ResourceDispatcherHost::Receiver* receiver) |
| 20 : next_handler_(handler), | 23 : next_handler_(handler), |
| 21 render_process_host_id_(render_process_host_id), | 24 render_process_host_id_(render_process_host_id), |
| 22 render_view_id_(render_view_id), | 25 render_view_id_(render_view_id), |
| 23 paused_request_id_(-1), | 26 paused_request_id_(-1), |
| 24 in_safe_browsing_check_(false), | 27 in_safe_browsing_check_(false), |
| 25 displaying_blocking_page_(false), | 28 displaying_blocking_page_(false), |
| 26 safe_browsing_(safe_browsing), | 29 safe_browsing_(safe_browsing), |
| 27 queued_error_request_id_(-1), | 30 queued_error_request_id_(-1), |
| 28 rdh_(resource_dispatcher_host), | 31 rdh_(resource_dispatcher_host), |
| 29 resource_type_(resource_type) { | 32 resource_type_(resource_type), |
| 33 receiver_(receiver) { |
| 30 if (safe_browsing_->CheckUrl(url, this)) { | 34 if (safe_browsing_->CheckUrl(url, this)) { |
| 31 safe_browsing_result_ = SafeBrowsingService::URL_SAFE; | 35 safe_browsing_result_ = SafeBrowsingService::URL_SAFE; |
| 32 safe_browsing_->LogPauseDelay(base::TimeDelta()); // No delay. | 36 safe_browsing_->LogPauseDelay(base::TimeDelta()); // No delay. |
| 33 } else { | 37 } else { |
| 34 AddRef(); | 38 AddRef(); |
| 35 in_safe_browsing_check_ = true; | 39 in_safe_browsing_check_ = true; |
| 36 // Can't pause now because it's too early, so we'll do it in OnWillRead. | 40 // Can't pause now because it's too early, so we'll do it in OnWillRead. |
| 37 } | 41 } |
| 42 |
| 43 NotificationService::current()->AddObserver( |
| 44 this, |
| 45 NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN, |
| 46 Source<ResourceMessageFilter>( |
| 47 static_cast<ResourceMessageFilter*>(receiver_))); |
| 38 } | 48 } |
| 39 | 49 |
| 40 SafeBrowsingResourceHandler::~SafeBrowsingResourceHandler() { | 50 SafeBrowsingResourceHandler::~SafeBrowsingResourceHandler() { |
| 41 // If we're being deleted before the SafeBrowsing check has completed, cancel | 51 NotificationService::current()->RemoveObserver( |
| 42 // the check. | 52 this, |
| 43 if (in_safe_browsing_check_) | 53 NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN, |
| 44 safe_browsing_->CancelCheck(this); | 54 Source<ResourceMessageFilter>( |
| 55 static_cast<ResourceMessageFilter*>(receiver_))); |
| 45 } | 56 } |
| 46 | 57 |
| 47 bool SafeBrowsingResourceHandler::OnUploadProgress(int request_id, | 58 bool SafeBrowsingResourceHandler::OnUploadProgress(int request_id, |
| 48 uint64 position, | 59 uint64 position, |
| 49 uint64 size) { | 60 uint64 size) { |
| 50 return next_handler_->OnUploadProgress(request_id, position, size); | 61 return next_handler_->OnUploadProgress(request_id, position, size); |
| 51 } | 62 } |
| 52 | 63 |
| 53 bool SafeBrowsingResourceHandler::OnRequestRedirected(int request_id, | 64 bool SafeBrowsingResourceHandler::OnRequestRedirected(int request_id, |
| 54 const GURL& new_url) { | 65 const GURL& new_url) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 queued_security_info_); | 194 queued_security_info_); |
| 184 queued_error_.reset(); | 195 queued_error_.reset(); |
| 185 queued_security_info_.clear(); | 196 queued_security_info_.clear(); |
| 186 } | 197 } |
| 187 } else { | 198 } else { |
| 188 rdh_->CancelRequest(render_process_host_id_, paused_request_id_, false); | 199 rdh_->CancelRequest(render_process_host_id_, paused_request_id_, false); |
| 189 } | 200 } |
| 190 | 201 |
| 191 Release(); | 202 Release(); |
| 192 } | 203 } |
| 204 |
| 205 void SafeBrowsingResourceHandler::Observe(NotificationType type, |
| 206 const NotificationSource& source, |
| 207 const NotificationDetails& details) { |
| 208 DCHECK(type.value == NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN); |
| 209 if (in_safe_browsing_check_) { |
| 210 safe_browsing_->CancelCheck(this); |
| 211 in_safe_browsing_check_ = false; |
| 212 Release(); |
| 213 } |
| 214 } |
| 215 |
| OLD | NEW |