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://" |
| 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_SELECT_CERTIFICATE, |
| 201 std::string()); |
| 202 DCHECK_NE(setting, CONTENT_SETTING_DEFAULT); |
| 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 { |
| 214 ShowClientCertificateRequestDialog(handler); |
| 215 } |
| 216 } |
| 217 |
181 void TabContentsSSLHelper::ShowClientCertificateRequestDialog( | 218 void TabContentsSSLHelper::ShowClientCertificateRequestDialog( |
182 scoped_refptr<SSLClientAuthHandler> handler) { | 219 scoped_refptr<SSLClientAuthHandler> handler) { |
183 browser::ShowSSLClientCertificateSelector( | 220 browser::ShowSSLClientCertificateSelector( |
184 tab_contents_->tab_contents(), handler->cert_request_info(), handler); | 221 tab_contents_->tab_contents(), handler->cert_request_info(), handler); |
185 } | 222 } |
186 | 223 |
187 void TabContentsSSLHelper::OnVerifyClientCertificateError( | 224 void TabContentsSSLHelper::OnVerifyClientCertificateError( |
188 scoped_refptr<SSLAddCertHandler> handler, int error_code) { | 225 scoped_refptr<SSLAddCertHandler> handler, int error_code) { |
189 SSLAddCertData* add_cert_data = GetAddCertData(handler); | 226 SSLAddCertData* add_cert_data = GetAddCertData(handler); |
190 // Display an infobar with the error message. | 227 // 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( | 265 TabContentsSSLHelper::SSLAddCertData* TabContentsSSLHelper::GetAddCertData( |
229 SSLAddCertHandler* handler) { | 266 SSLAddCertHandler* handler) { |
230 // Find/create the slot. | 267 // Find/create the slot. |
231 linked_ptr<SSLAddCertData>& ptr_ref = | 268 linked_ptr<SSLAddCertData>& ptr_ref = |
232 request_id_to_add_cert_data_[handler->network_request_id()]; | 269 request_id_to_add_cert_data_[handler->network_request_id()]; |
233 // Fill it if necessary. | 270 // Fill it if necessary. |
234 if (!ptr_ref.get()) | 271 if (!ptr_ref.get()) |
235 ptr_ref.reset(new SSLAddCertData(tab_contents_)); | 272 ptr_ref.reset(new SSLAddCertData(tab_contents_)); |
236 return ptr_ref.get(); | 273 return ptr_ref.get(); |
237 } | 274 } |
OLD | NEW |