OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/ssl/ssl_manager.h" | 5 #include "content/browser/ssl/ssl_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 9 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
10 #include "content/browser/loader/resource_request_info_impl.h" | 10 #include "content/browser/loader/resource_request_info_impl.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 new SSLCertErrorHandler(delegate, | 53 new SSLCertErrorHandler(delegate, |
54 id, | 54 id, |
55 resource_type, | 55 resource_type, |
56 url, | 56 url, |
57 render_process_id, | 57 render_process_id, |
58 render_view_id, | 58 render_view_id, |
59 ssl_info, | 59 ssl_info, |
60 fatal))); | 60 fatal))); |
61 } | 61 } |
62 | 62 |
63 // static | |
64 void SSLManager::NotifySSLInternalStateChanged( | |
65 NavigationControllerImpl* controller) { | |
66 NotificationService::current()->Notify( | |
67 NOTIFICATION_SSL_INTERNAL_STATE_CHANGED, | |
68 Source<BrowserContext>(controller->GetBrowserContext()), | |
69 NotificationService::NoDetails()); | |
70 } | |
71 | |
72 SSLManager::SSLManager(NavigationControllerImpl* controller) | 63 SSLManager::SSLManager(NavigationControllerImpl* controller) |
73 : backend_(controller), | 64 : backend_(controller), |
74 policy_(new SSLPolicy(&backend_)), | 65 policy_(new SSLPolicy(&backend_)), |
75 controller_(controller) { | 66 controller_(controller) { |
76 DCHECK(controller_); | 67 DCHECK(controller_); |
77 | 68 |
78 // Subscribe to various notifications. | 69 // Subscribe to various notifications. |
79 registrar_.Add( | 70 registrar_.Add( |
80 this, NOTIFICATION_RESOURCE_RESPONSE_STARTED, | 71 this, NOTIFICATION_RESOURCE_RESPONSE_STARTED, |
81 Source<WebContents>(controller_->web_contents())); | 72 Source<WebContents>(controller_->web_contents())); |
82 registrar_.Add( | 73 registrar_.Add( |
83 this, NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 74 this, NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
84 Source<WebContents>(controller_->web_contents())); | 75 Source<WebContents>(controller_->web_contents())); |
85 registrar_.Add( | 76 registrar_.Add( |
86 this, NOTIFICATION_LOAD_FROM_MEMORY_CACHE, | 77 this, NOTIFICATION_LOAD_FROM_MEMORY_CACHE, |
87 Source<NavigationController>(controller_)); | 78 Source<NavigationController>(controller_)); |
88 registrar_.Add( | |
89 this, NOTIFICATION_SSL_INTERNAL_STATE_CHANGED, | |
90 Source<BrowserContext>( | |
91 controller_->GetBrowserContext())); | |
92 } | 79 } |
93 | 80 |
94 SSLManager::~SSLManager() { | 81 SSLManager::~SSLManager() { |
95 } | 82 } |
96 | 83 |
97 void SSLManager::DidCommitProvisionalLoad( | 84 void SSLManager::DidCommitProvisionalLoad( |
98 const NotificationDetails& in_details) { | 85 const NotificationDetails& in_details) { |
99 LoadCommittedDetails* details = | 86 LoadCommittedDetails* details = |
100 Details<LoadCommittedDetails>(in_details).ptr(); | 87 Details<LoadCommittedDetails>(in_details).ptr(); |
101 | 88 |
(...skipping 19 matching lines...) Expand all Loading... | |
121 entry->GetSSL().cert_id = ssl_cert_id; | 108 entry->GetSSL().cert_id = ssl_cert_id; |
122 entry->GetSSL().cert_status = ssl_cert_status; | 109 entry->GetSSL().cert_status = ssl_cert_status; |
123 entry->GetSSL().security_bits = ssl_security_bits; | 110 entry->GetSSL().security_bits = ssl_security_bits; |
124 entry->GetSSL().connection_status = ssl_connection_status; | 111 entry->GetSSL().connection_status = ssl_connection_status; |
125 } | 112 } |
126 } | 113 } |
127 | 114 |
128 UpdateEntry(entry); | 115 UpdateEntry(entry); |
129 } | 116 } |
130 | 117 |
118 void SSLManager::DidDisplayInsecureContent() { | |
119 UpdateEntry( | |
120 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry())); | |
121 } | |
122 | |
131 void SSLManager::DidRunInsecureContent(const std::string& security_origin) { | 123 void SSLManager::DidRunInsecureContent(const std::string& security_origin) { |
132 policy()->DidRunInsecureContent( | 124 NavigationEntryImpl* navigation_entry = |
133 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry()), | 125 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry()); |
134 security_origin); | 126 policy()->DidRunInsecureContent(navigation_entry, security_origin); |
127 UpdateEntry(navigation_entry); | |
128 } | |
129 | |
130 void SSLManager::DidChangeInternalSSLState() { | |
131 UpdateEntry( | |
Paweł Hajdan Jr.
2013/01/24 18:53:43
Question: I'd need to broadcast the notification t
jam
2013/01/30 01:17:51
there isn't a way to do this now. one suggestion:
| |
132 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry())); | |
135 } | 133 } |
136 | 134 |
137 void SSLManager::Observe(int type, | 135 void SSLManager::Observe(int type, |
138 const NotificationSource& source, | 136 const NotificationSource& source, |
139 const NotificationDetails& details) { | 137 const NotificationDetails& details) { |
140 // Dispatch by type. | 138 // Dispatch by type. |
141 switch (type) { | 139 switch (type) { |
142 case NOTIFICATION_RESOURCE_RESPONSE_STARTED: | 140 case NOTIFICATION_RESOURCE_RESPONSE_STARTED: |
143 DidStartResourceResponse( | 141 DidStartResourceResponse( |
144 Details<ResourceRequestDetails>(details).ptr()); | 142 Details<ResourceRequestDetails>(details).ptr()); |
145 break; | 143 break; |
146 case NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: | 144 case NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: |
147 DidReceiveResourceRedirect( | 145 DidReceiveResourceRedirect( |
148 Details<ResourceRedirectDetails>(details).ptr()); | 146 Details<ResourceRedirectDetails>(details).ptr()); |
149 break; | 147 break; |
150 case NOTIFICATION_LOAD_FROM_MEMORY_CACHE: | 148 case NOTIFICATION_LOAD_FROM_MEMORY_CACHE: |
151 DidLoadFromMemoryCache( | 149 DidLoadFromMemoryCache( |
152 Details<LoadFromMemoryCacheDetails>(details).ptr()); | 150 Details<LoadFromMemoryCacheDetails>(details).ptr()); |
153 break; | 151 break; |
154 case NOTIFICATION_SSL_INTERNAL_STATE_CHANGED: | |
155 DidChangeSSLInternalState(); | |
156 break; | |
157 default: | 152 default: |
158 NOTREACHED() << "The SSLManager received an unexpected notification."; | 153 NOTREACHED() << "The SSLManager received an unexpected notification."; |
159 } | 154 } |
160 } | 155 } |
161 | 156 |
162 void SSLManager::DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details) { | 157 void SSLManager::DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details) { |
163 // Simulate loading this resource through the usual path. | 158 // Simulate loading this resource through the usual path. |
164 // Note that we specify SUB_RESOURCE as the resource type as WebCore only | 159 // Note that we specify SUB_RESOURCE as the resource type as WebCore only |
165 // caches sub-resources. | 160 // caches sub-resources. |
166 // This resource must have been loaded with no filtering because filtered | 161 // This resource must have been loaded with no filtering because filtered |
(...skipping 24 matching lines...) Expand all Loading... | |
191 } | 186 } |
192 | 187 |
193 void SSLManager::DidReceiveResourceRedirect(ResourceRedirectDetails* details) { | 188 void SSLManager::DidReceiveResourceRedirect(ResourceRedirectDetails* details) { |
194 // TODO(abarth): Make sure our redirect behavior is correct. If we ever see a | 189 // TODO(abarth): Make sure our redirect behavior is correct. If we ever see a |
195 // non-HTTPS resource in the redirect chain, we want to trigger | 190 // non-HTTPS resource in the redirect chain, we want to trigger |
196 // insecure content, even if the redirect chain goes back to | 191 // insecure content, even if the redirect chain goes back to |
197 // HTTPS. This is because the network attacker can redirect the | 192 // HTTPS. This is because the network attacker can redirect the |
198 // HTTP request to https://attacker.com/payload.js. | 193 // HTTP request to https://attacker.com/payload.js. |
199 } | 194 } |
200 | 195 |
201 void SSLManager::DidChangeSSLInternalState() { | |
202 UpdateEntry( | |
203 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry())); | |
204 } | |
205 | |
206 void SSLManager::UpdateEntry(NavigationEntryImpl* entry) { | 196 void SSLManager::UpdateEntry(NavigationEntryImpl* entry) { |
207 // We don't always have a navigation entry to update, for example in the | 197 // We don't always have a navigation entry to update, for example in the |
208 // case of the Web Inspector. | 198 // case of the Web Inspector. |
209 if (!entry) | 199 if (!entry) |
210 return; | 200 return; |
211 | 201 |
212 SSLStatus original_ssl_status = entry->GetSSL(); // Copy! | 202 SSLStatus original_ssl_status = entry->GetSSL(); // Copy! |
213 | 203 |
214 policy()->UpdateEntry(entry, controller_->web_contents()); | 204 policy()->UpdateEntry(entry, controller_->web_contents()); |
215 | 205 |
216 if (!entry->GetSSL().Equals(original_ssl_status)) { | 206 if (!entry->GetSSL().Equals(original_ssl_status)) |
217 NotificationService::current()->Notify( | 207 controller_->web_contents()->DidChangeVisibleSSLState(); |
218 NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, | |
219 Source<NavigationController>(controller_), | |
220 NotificationService::NoDetails()); | |
221 } | |
222 } | 208 } |
223 | 209 |
224 } // namespace content | 210 } // namespace content |
OLD | NEW |