OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/tab_contents_ssl_helper.h" | 5 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" |
6 | 6 |
7 #include <string> | |
8 | |
7 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | |
8 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/certificate_viewer.h" | 13 #include "chrome/browser/certificate_viewer.h" |
14 #include "chrome/browser/content_settings/host_content_settings_map.h" | |
15 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/browser/ssl/ssl_add_cert_handler.h" | 16 #include "chrome/browser/ssl/ssl_add_cert_handler.h" |
12 #include "chrome/browser/ssl_client_certificate_selector.h" | 17 #include "chrome/browser/ssl_client_certificate_selector.h" |
13 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 18 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
14 #include "chrome/browser/tab_contents/infobar.h" | 19 #include "chrome/browser/tab_contents/infobar.h" |
15 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | 20 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
17 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/chrome_switches.h" | |
24 #include "chrome/common/content_settings.h" | |
18 #include "content/browser/ssl/ssl_client_auth_handler.h" | 25 #include "content/browser/ssl/ssl_client_auth_handler.h" |
19 #include "content/common/notification_details.h" | 26 #include "content/common/notification_details.h" |
20 #include "content/common/notification_source.h" | 27 #include "content/common/notification_source.h" |
21 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
22 #include "grit/theme_resources_standard.h" | 29 #include "grit/theme_resources_standard.h" |
23 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
24 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
26 | 33 |
27 namespace { | 34 namespace { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 | 178 |
172 // TabContentsSSLHelper ------------------------------------------------------- | 179 // TabContentsSSLHelper ------------------------------------------------------- |
173 | 180 |
174 TabContentsSSLHelper::TabContentsSSLHelper(TabContentsWrapper* tab_contents) | 181 TabContentsSSLHelper::TabContentsSSLHelper(TabContentsWrapper* tab_contents) |
175 : tab_contents_(tab_contents) { | 182 : tab_contents_(tab_contents) { |
176 } | 183 } |
177 | 184 |
178 TabContentsSSLHelper::~TabContentsSSLHelper() { | 185 TabContentsSSLHelper::~TabContentsSSLHelper() { |
179 } | 186 } |
180 | 187 |
188 void TabContentsSSLHelper::SelectClientCertificate( | |
189 scoped_refptr<SSLClientAuthHandler> handler) { | |
190 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info(); | |
191 GURL requesting_url("https://" + cert_request_info->host_and_port); | |
192 DCHECK(requesting_url.is_valid()) << " Invalid URL string: https://" | |
wtc
2011/08/18 22:03:38
Nit: does the error message string need to start w
markusheintz_
2011/08/19 15:17:58
Not at all. Removed the leading space.
| |
193 << cert_request_info->host_and_port; | |
194 | |
195 HostContentSettingsMap* map = | |
196 tab_contents_->profile()->GetHostContentSettingsMap(); | |
197 ContentSetting setting = map->GetContentSetting( | |
198 requesting_url, | |
199 requesting_url, | |
200 CONTENT_SETTINGS_TYPE_AUTO_SUBMIT_CERTIFICATE, | |
201 std::string()); | |
202 DCHECK(setting != CONTENT_SETTING_DEFAULT); | |
wtc
2011/08/18 22:03:38
Nit: use DCHECK_NE, which prints the value of 'set
markusheintz_
2011/08/19 15:17:58
Done.
| |
203 | |
204 // TODO(markusheintz): Implement filter for matching specific certificate | |
205 // criteria. | |
206 bool cert_matches_filter = true; | |
207 | |
208 if (setting == CONTENT_SETTING_ALLOW && | |
209 cert_request_info->client_certs.size() == 1 && | |
210 cert_matches_filter) { | |
211 net::X509Certificate* cert = cert_request_info->client_certs[0].get(); | |
212 handler->CertificateSelected(cert); | |
213 } else if (setting == CONTENT_SETTING_ASK) { | |
214 ShowClientCertificateRequestDialog(handler); | |
215 } else { | |
216 handler->CertificateSelected(NULL); | |
217 } | |
218 } | |
219 | |
181 void TabContentsSSLHelper::ShowClientCertificateRequestDialog( | 220 void TabContentsSSLHelper::ShowClientCertificateRequestDialog( |
182 scoped_refptr<SSLClientAuthHandler> handler) { | 221 scoped_refptr<SSLClientAuthHandler> handler) { |
183 browser::ShowSSLClientCertificateSelector( | 222 browser::ShowSSLClientCertificateSelector( |
184 tab_contents_->tab_contents(), handler->cert_request_info(), handler); | 223 tab_contents_->tab_contents(), handler->cert_request_info(), handler); |
185 } | 224 } |
186 | 225 |
187 void TabContentsSSLHelper::OnVerifyClientCertificateError( | 226 void TabContentsSSLHelper::OnVerifyClientCertificateError( |
188 scoped_refptr<SSLAddCertHandler> handler, int error_code) { | 227 scoped_refptr<SSLAddCertHandler> handler, int error_code) { |
189 SSLAddCertData* add_cert_data = GetAddCertData(handler); | 228 SSLAddCertData* add_cert_data = GetAddCertData(handler); |
190 // Display an infobar with the error message. | 229 // Display an infobar with the error message. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 TabContentsSSLHelper::SSLAddCertData* TabContentsSSLHelper::GetAddCertData( | 267 TabContentsSSLHelper::SSLAddCertData* TabContentsSSLHelper::GetAddCertData( |
229 SSLAddCertHandler* handler) { | 268 SSLAddCertHandler* handler) { |
230 // Find/create the slot. | 269 // Find/create the slot. |
231 linked_ptr<SSLAddCertData>& ptr_ref = | 270 linked_ptr<SSLAddCertData>& ptr_ref = |
232 request_id_to_add_cert_data_[handler->network_request_id()]; | 271 request_id_to_add_cert_data_[handler->network_request_id()]; |
233 // Fill it if necessary. | 272 // Fill it if necessary. |
234 if (!ptr_ref.get()) | 273 if (!ptr_ref.get()) |
235 ptr_ref.reset(new SSLAddCertData(tab_contents_)); | 274 ptr_ref.reset(new SSLAddCertData(tab_contents_)); |
236 return ptr_ref.get(); | 275 return ptr_ref.get(); |
237 } | 276 } |
OLD | NEW |