| 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 | 8 |
| 9 // Maximum time to wait for a gethash response from the Safe Browsing servers. | 9 // Maximum time to wait for a gethash response from the Safe Browsing servers. |
| 10 static const int kMaxGetHashMs = 1000; | 10 static const int kMaxGetHashMs = 1000; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 return next_handler_->OnWillRead(request_id, buf, buf_size, min_size); | 95 return next_handler_->OnWillRead(request_id, buf, buf_size, min_size); |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool SafeBrowsingResourceHandler::OnReadCompleted(int request_id, | 98 bool SafeBrowsingResourceHandler::OnReadCompleted(int request_id, |
| 99 int* bytes_read) { | 99 int* bytes_read) { |
| 100 return next_handler_->OnReadCompleted(request_id, bytes_read); | 100 return next_handler_->OnReadCompleted(request_id, bytes_read); |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool SafeBrowsingResourceHandler::OnResponseCompleted( | 103 bool SafeBrowsingResourceHandler::OnResponseCompleted( |
| 104 int request_id, const URLRequestStatus& status) { | 104 int request_id, const URLRequestStatus& status, |
| 105 const std::string& security_info) { |
| 105 if ((in_safe_browsing_check_ || | 106 if ((in_safe_browsing_check_ || |
| 106 safe_browsing_result_ != SafeBrowsingService::URL_SAFE) && | 107 safe_browsing_result_ != SafeBrowsingService::URL_SAFE) && |
| 107 status.status() == URLRequestStatus::FAILED && | 108 status.status() == URLRequestStatus::FAILED && |
| 108 status.os_error() == net::ERR_NAME_NOT_RESOLVED) { | 109 status.os_error() == net::ERR_NAME_NOT_RESOLVED) { |
| 109 // Got a DNS error while the safebrowsing check is in progress or we | 110 // Got a DNS error while the safebrowsing check is in progress or we |
| 110 // already know that the site is unsafe. Don't show the the dns error | 111 // already know that the site is unsafe. Don't show the the dns error |
| 111 // page. | 112 // page. |
| 112 queued_error_.reset(new URLRequestStatus(status)); | 113 queued_error_.reset(new URLRequestStatus(status)); |
| 113 queued_error_request_id_ = request_id; | 114 queued_error_request_id_ = request_id; |
| 115 queued_security_info_ = security_info; |
| 114 return true; | 116 return true; |
| 115 } | 117 } |
| 116 | 118 |
| 117 return next_handler_->OnResponseCompleted(request_id, status); | 119 return next_handler_->OnResponseCompleted(request_id, status, security_info); |
| 118 } | 120 } |
| 119 | 121 |
| 120 // SafeBrowsingService::Client implementation, called on the IO thread once | 122 // SafeBrowsingService::Client implementation, called on the IO thread once |
| 121 // the URL has been classified. | 123 // the URL has been classified. |
| 122 void SafeBrowsingResourceHandler::OnUrlCheckResult( | 124 void SafeBrowsingResourceHandler::OnUrlCheckResult( |
| 123 const GURL& url, SafeBrowsingService::UrlCheckResult result) { | 125 const GURL& url, SafeBrowsingService::UrlCheckResult result) { |
| 124 DCHECK(in_safe_browsing_check_); | 126 DCHECK(in_safe_browsing_check_); |
| 125 DCHECK(!displaying_blocking_page_); | 127 DCHECK(!displaying_blocking_page_); |
| 126 | 128 |
| 127 safe_browsing_result_ = result; | 129 safe_browsing_result_ = result; |
| 128 in_safe_browsing_check_ = false; | 130 in_safe_browsing_check_ = false; |
| 129 | 131 |
| 130 if (result == SafeBrowsingService::URL_SAFE) { | 132 if (result == SafeBrowsingService::URL_SAFE) { |
| 131 if (paused_request_id_ != -1) { | 133 if (paused_request_id_ != -1) { |
| 132 rdh_->PauseRequest(render_process_host_id_, paused_request_id_, false); | 134 rdh_->PauseRequest(render_process_host_id_, paused_request_id_, false); |
| 133 paused_request_id_ = -1; | 135 paused_request_id_ = -1; |
| 134 } | 136 } |
| 135 | 137 |
| 136 base::TimeDelta pause_delta; | 138 base::TimeDelta pause_delta; |
| 137 if (!pause_time_.is_null()) | 139 if (!pause_time_.is_null()) |
| 138 pause_delta = base::Time::Now() - pause_time_; | 140 pause_delta = base::Time::Now() - pause_time_; |
| 139 safe_browsing_->LogPauseDelay(pause_delta); | 141 safe_browsing_->LogPauseDelay(pause_delta); |
| 140 | 142 |
| 141 if (queued_error_.get()) { | 143 if (queued_error_.get()) { |
| 142 next_handler_->OnResponseCompleted( | 144 next_handler_->OnResponseCompleted( |
| 143 queued_error_request_id_, *queued_error_.get()); | 145 queued_error_request_id_, *queued_error_.get(), |
| 146 queued_security_info_); |
| 144 queued_error_.reset(); | 147 queued_error_.reset(); |
| 148 queued_security_info_.clear(); |
| 145 } | 149 } |
| 146 | 150 |
| 147 Release(); | 151 Release(); |
| 148 } else { | 152 } else { |
| 149 displaying_blocking_page_ = true; | 153 displaying_blocking_page_ = true; |
| 150 safe_browsing_->DisplayBlockingPage( | 154 safe_browsing_->DisplayBlockingPage( |
| 151 url, resource_type_, result, this, rdh_->ui_loop(), | 155 url, resource_type_, result, this, rdh_->ui_loop(), |
| 152 render_process_host_id_, render_view_id_); | 156 render_process_host_id_, render_view_id_); |
| 153 } | 157 } |
| 154 } | 158 } |
| 155 | 159 |
| 156 // SafeBrowsingService::Client implementation, called on the IO thread when | 160 // SafeBrowsingService::Client implementation, called on the IO thread when |
| 157 // the user has decided to proceed with the current request, or go back. | 161 // the user has decided to proceed with the current request, or go back. |
| 158 void SafeBrowsingResourceHandler::OnBlockingPageComplete(bool proceed) { | 162 void SafeBrowsingResourceHandler::OnBlockingPageComplete(bool proceed) { |
| 159 DCHECK(displaying_blocking_page_); | 163 DCHECK(displaying_blocking_page_); |
| 160 displaying_blocking_page_ = false; | 164 displaying_blocking_page_ = false; |
| 161 | 165 |
| 162 if (proceed) { | 166 if (proceed) { |
| 163 safe_browsing_result_ = SafeBrowsingService::URL_SAFE; | 167 safe_browsing_result_ = SafeBrowsingService::URL_SAFE; |
| 164 if (paused_request_id_ != -1) { | 168 if (paused_request_id_ != -1) { |
| 165 rdh_->PauseRequest(render_process_host_id_, paused_request_id_, false); | 169 rdh_->PauseRequest(render_process_host_id_, paused_request_id_, false); |
| 166 paused_request_id_ = -1; | 170 paused_request_id_ = -1; |
| 167 } | 171 } |
| 168 | 172 |
| 169 if (queued_error_.get()) { | 173 if (queued_error_.get()) { |
| 170 next_handler_->OnResponseCompleted( | 174 next_handler_->OnResponseCompleted( |
| 171 queued_error_request_id_, *queued_error_.get()); | 175 queued_error_request_id_, *queued_error_.get(), |
| 176 queued_security_info_); |
| 172 queued_error_.reset(); | 177 queued_error_.reset(); |
| 178 queued_security_info_.clear(); |
| 173 } | 179 } |
| 174 } else { | 180 } else { |
| 175 rdh_->CancelRequest(render_process_host_id_, paused_request_id_, false); | 181 rdh_->CancelRequest(render_process_host_id_, paused_request_id_, false); |
| 176 } | 182 } |
| 177 | 183 |
| 178 Release(); | 184 Release(); |
| 179 } | 185 } |
| OLD | NEW |