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/ssl/ssl_manager.h" | 5 #include "chrome/browser/ssl/ssl_manager.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
10 #include "chrome/browser/load_from_memory_cache_details.h" | 10 #include "chrome/browser/load_from_memory_cache_details.h" |
11 #include "chrome/browser/net/url_request_tracking.h" | 11 #include "chrome/browser/net/url_request_tracking.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/renderer_host/render_view_host.h" |
13 #include "chrome/browser/renderer_host/resource_request_details.h" | 14 #include "chrome/browser/renderer_host/resource_request_details.h" |
| 15 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 16 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" |
14 #include "chrome/browser/ssl/ssl_cert_error_handler.h" | 17 #include "chrome/browser/ssl/ssl_cert_error_handler.h" |
15 #include "chrome/browser/ssl/ssl_policy.h" | 18 #include "chrome/browser/ssl/ssl_policy.h" |
16 #include "chrome/browser/ssl/ssl_request_info.h" | 19 #include "chrome/browser/ssl/ssl_request_info.h" |
17 #include "chrome/browser/tab_contents/navigation_controller.h" | 20 #include "chrome/browser/tab_contents/navigation_controller.h" |
18 #include "chrome/browser/tab_contents/navigation_entry.h" | 21 #include "chrome/browser/tab_contents/navigation_entry.h" |
19 #include "chrome/browser/tab_contents/provisional_load_details.h" | 22 #include "chrome/browser/tab_contents/provisional_load_details.h" |
| 23 #include "chrome/browser/tab_contents/tab_contents.h" |
20 #include "chrome/common/notification_service.h" | 24 #include "chrome/common/notification_service.h" |
21 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
22 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
23 #include "net/base/cert_status_flags.h" | 27 #include "net/base/cert_status_flags.h" |
24 | 28 |
25 // static | 29 // static |
26 void SSLManager::OnSSLCertificateError(ResourceDispatcherHost* rdh, | 30 void SSLManager::OnSSLCertificateError(ResourceDispatcherHost* rdh, |
27 net::URLRequest* request, | 31 net::URLRequest* request, |
28 int cert_error, | 32 int cert_error, |
29 net::X509Certificate* cert) { | 33 net::X509Certificate* cert) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 SSLManager::SSLManager(NavigationController* controller) | 115 SSLManager::SSLManager(NavigationController* controller) |
112 : backend_(controller), | 116 : backend_(controller), |
113 policy_(new SSLPolicy(&backend_)), | 117 policy_(new SSLPolicy(&backend_)), |
114 controller_(controller) { | 118 controller_(controller) { |
115 DCHECK(controller_); | 119 DCHECK(controller_); |
116 | 120 |
117 // Subscribe to various notifications. | 121 // Subscribe to various notifications. |
118 registrar_.Add(this, NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, | 122 registrar_.Add(this, NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
119 Source<NavigationController>(controller_)); | 123 Source<NavigationController>(controller_)); |
120 registrar_.Add(this, NotificationType::RESOURCE_RESPONSE_STARTED, | 124 registrar_.Add(this, NotificationType::RESOURCE_RESPONSE_STARTED, |
121 Source<NavigationController>(controller_)); | 125 NotificationService::AllSources()); |
122 registrar_.Add(this, NotificationType::RESOURCE_RECEIVED_REDIRECT, | 126 registrar_.Add(this, NotificationType::RESOURCE_RECEIVED_REDIRECT, |
123 Source<NavigationController>(controller_)); | 127 NotificationService::AllSources()); |
124 registrar_.Add(this, NotificationType::LOAD_FROM_MEMORY_CACHE, | 128 registrar_.Add(this, NotificationType::LOAD_FROM_MEMORY_CACHE, |
125 Source<NavigationController>(controller_)); | 129 Source<NavigationController>(controller_)); |
126 registrar_.Add(this, NotificationType::SSL_INTERNAL_STATE_CHANGED, | 130 registrar_.Add(this, NotificationType::SSL_INTERNAL_STATE_CHANGED, |
127 NotificationService::AllSources()); | 131 NotificationService::AllSources()); |
128 } | 132 } |
129 | 133 |
130 SSLManager::~SSLManager() { | 134 SSLManager::~SSLManager() { |
131 } | 135 } |
132 | 136 |
133 void SSLManager::DidCommitProvisionalLoad( | 137 void SSLManager::DidCommitProvisionalLoad( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 break; | 201 break; |
198 case NotificationType::SSL_INTERNAL_STATE_CHANGED: | 202 case NotificationType::SSL_INTERNAL_STATE_CHANGED: |
199 DidChangeSSLInternalState(); | 203 DidChangeSSLInternalState(); |
200 break; | 204 break; |
201 default: | 205 default: |
202 NOTREACHED() << "The SSLManager received an unexpected notification."; | 206 NOTREACHED() << "The SSLManager received an unexpected notification."; |
203 } | 207 } |
204 } | 208 } |
205 | 209 |
206 void SSLManager::DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details) { | 210 void SSLManager::DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details) { |
207 DCHECK(details); | |
208 | |
209 // Simulate loading this resource through the usual path. | 211 // Simulate loading this resource through the usual path. |
210 // Note that we specify SUB_RESOURCE as the resource type as WebCore only | 212 // Note that we specify SUB_RESOURCE as the resource type as WebCore only |
211 // caches sub-resources. | 213 // caches sub-resources. |
212 // This resource must have been loaded with no filtering because filtered | 214 // This resource must have been loaded with no filtering because filtered |
213 // resouces aren't cachable. | 215 // resouces aren't cachable. |
214 scoped_refptr<SSLRequestInfo> info(new SSLRequestInfo( | 216 scoped_refptr<SSLRequestInfo> info(new SSLRequestInfo( |
215 details->url(), | 217 details->url(), |
216 ResourceType::SUB_RESOURCE, | 218 ResourceType::SUB_RESOURCE, |
217 details->frame_origin(), | 219 details->frame_origin(), |
218 details->main_frame_origin(), | 220 details->main_frame_origin(), |
219 details->pid(), | 221 details->pid(), |
220 details->ssl_cert_id(), | 222 details->ssl_cert_id(), |
221 details->ssl_cert_status())); | 223 details->ssl_cert_status())); |
222 | 224 |
223 // Simulate loading this resource through the usual path. | 225 // Simulate loading this resource through the usual path. |
224 policy()->OnRequestStarted(info.get()); | 226 policy()->OnRequestStarted(info.get()); |
225 } | 227 } |
226 | 228 |
227 void SSLManager::DidStartResourceResponse(ResourceRequestDetails* details) { | 229 void SSLManager::DidStartResourceResponse(ResourceRequestDetails* details) { |
228 DCHECK(details); | 230 RenderViewHost* rvh = RenderViewHost::FromID( |
| 231 details->render_process_id(), details->render_view_id()); |
| 232 if (rvh != controller_->tab_contents()->render_view_host()) |
| 233 return; |
229 | 234 |
230 scoped_refptr<SSLRequestInfo> info(new SSLRequestInfo( | 235 scoped_refptr<SSLRequestInfo> info(new SSLRequestInfo( |
231 details->url(), | 236 details->url(), |
232 details->resource_type(), | 237 details->resource_type(), |
233 details->frame_origin(), | 238 details->frame_origin(), |
234 details->main_frame_origin(), | 239 details->main_frame_origin(), |
235 details->origin_child_id(), | 240 details->origin_child_id(), |
236 details->ssl_cert_id(), | 241 details->ssl_cert_id(), |
237 details->ssl_cert_status())); | 242 details->ssl_cert_status())); |
238 | 243 |
239 // Notify our policy that we started a resource request. Ideally, the | 244 // Notify our policy that we started a resource request. Ideally, the |
240 // policy should have the ability to cancel the request, but we can't do | 245 // policy should have the ability to cancel the request, but we can't do |
241 // that yet. | 246 // that yet. |
242 policy()->OnRequestStarted(info.get()); | 247 policy()->OnRequestStarted(info.get()); |
243 } | 248 } |
244 | 249 |
245 void SSLManager::DidReceiveResourceRedirect(ResourceRedirectDetails* details) { | 250 void SSLManager::DidReceiveResourceRedirect(ResourceRedirectDetails* details) { |
| 251 RenderViewHost* rvh = RenderViewHost::FromID( |
| 252 details->render_process_id(), details->render_view_id()); |
| 253 if (rvh != controller_->tab_contents()->render_view_host()) |
| 254 return; |
| 255 |
246 // TODO(abarth): Make sure our redirect behavior is correct. If we ever see a | 256 // TODO(abarth): Make sure our redirect behavior is correct. If we ever see a |
247 // non-HTTPS resource in the redirect chain, we want to trigger | 257 // non-HTTPS resource in the redirect chain, we want to trigger |
248 // insecure content, even if the redirect chain goes back to | 258 // insecure content, even if the redirect chain goes back to |
249 // HTTPS. This is because the network attacker can redirect the | 259 // HTTPS. This is because the network attacker can redirect the |
250 // HTTP request to https://attacker.com/payload.js. | 260 // HTTP request to https://attacker.com/payload.js. |
251 } | 261 } |
252 | 262 |
253 void SSLManager::DidChangeSSLInternalState() { | 263 void SSLManager::DidChangeSSLInternalState() { |
254 UpdateEntry(controller_->GetActiveEntry()); | 264 UpdateEntry(controller_->GetActiveEntry()); |
255 } | 265 } |
256 | 266 |
257 void SSLManager::UpdateEntry(NavigationEntry* entry) { | 267 void SSLManager::UpdateEntry(NavigationEntry* entry) { |
258 // We don't always have a navigation entry to update, for example in the | 268 // We don't always have a navigation entry to update, for example in the |
259 // case of the Web Inspector. | 269 // case of the Web Inspector. |
260 if (!entry) | 270 if (!entry) |
261 return; | 271 return; |
262 | 272 |
263 NavigationEntry::SSLStatus original_ssl_status = entry->ssl(); // Copy! | 273 NavigationEntry::SSLStatus original_ssl_status = entry->ssl(); // Copy! |
264 | 274 |
265 policy()->UpdateEntry(entry, controller_->tab_contents()); | 275 policy()->UpdateEntry(entry, controller_->tab_contents()); |
266 | 276 |
267 if (!entry->ssl().Equals(original_ssl_status)) { | 277 if (!entry->ssl().Equals(original_ssl_status)) { |
268 NotificationService::current()->Notify( | 278 NotificationService::current()->Notify( |
269 NotificationType::SSL_VISIBLE_STATE_CHANGED, | 279 NotificationType::SSL_VISIBLE_STATE_CHANGED, |
270 Source<NavigationController>(controller_), | 280 Source<NavigationController>(controller_), |
271 NotificationService::NoDetails()); | 281 NotificationService::NoDetails()); |
272 } | 282 } |
273 } | 283 } |
OLD | NEW |