| 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_client_certificate_selector.h" | 5 #include "chrome/browser/ssl_client_certificate_selector.h" |
| 6 | 6 |
| 7 #import <SecurityInterface/SFChooseIdentityPanel.h> | 7 #import <SecurityInterface/SFChooseIdentityPanel.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #import "app/l10n_util_mac.h" | 11 #import "app/l10n_util_mac.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 14 #include "base/scoped_cftyperef.h" | 14 #include "base/scoped_cftyperef.h" |
| 15 #import "base/scoped_nsobject.h" | 15 #import "base/scoped_nsobject.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/sys_string_conversions.h" | 17 #include "base/sys_string_conversions.h" |
| 18 #import "chrome/browser/cocoa/constrained_window_mac.h" | 18 #import "chrome/browser/cocoa/constrained_window_mac.h" |
| 19 #include "chrome/browser/chrome_thread.h" | 19 #include "chrome/browser/chrome_thread.h" |
| 20 #include "chrome/browser/ssl/ssl_client_auth_handler.h" | 20 #include "chrome/browser/ssl/ssl_client_auth_handler.h" |
| 21 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
| 22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 23 #include "net/base/net_util.h" |
| 23 #include "net/base/x509_certificate.h" | 24 #include "net/base/x509_certificate.h" |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 class ConstrainedSFChooseIdentityPanel | 28 class ConstrainedSFChooseIdentityPanel |
| 28 : public ConstrainedWindowMacDelegateSystemSheet { | 29 : public ConstrainedWindowMacDelegateSystemSheet { |
| 29 public: | 30 public: |
| 30 ConstrainedSFChooseIdentityPanel(SFChooseIdentityPanel* panel, | 31 ConstrainedSFChooseIdentityPanel(SFChooseIdentityPanel* panel, |
| 31 id delegate, SEL didEndSelector, | 32 id delegate, SEL didEndSelector, |
| 32 NSArray* identities, NSString* message) | 33 NSArray* identities, NSString* message) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 167 } |
| 167 | 168 |
| 168 // Get the message to display: | 169 // Get the message to display: |
| 169 NSString* title = l10n_util::GetNSString(IDS_CLIENT_CERT_DIALOG_TITLE); | 170 NSString* title = l10n_util::GetNSString(IDS_CLIENT_CERT_DIALOG_TITLE); |
| 170 NSString* message = l10n_util::GetNSStringF( | 171 NSString* message = l10n_util::GetNSStringF( |
| 171 IDS_CLIENT_CERT_DIALOG_TEXT, | 172 IDS_CLIENT_CERT_DIALOG_TEXT, |
| 172 ASCIIToUTF16(certRequestInfo_->host_and_port)); | 173 ASCIIToUTF16(certRequestInfo_->host_and_port)); |
| 173 | 174 |
| 174 // Create and set up a system choose-identity panel. | 175 // Create and set up a system choose-identity panel. |
| 175 SFChooseIdentityPanel* panel = [[SFChooseIdentityPanel alloc] init]; | 176 SFChooseIdentityPanel* panel = [[SFChooseIdentityPanel alloc] init]; |
| 176 NSString* domain = base::SysUTF8ToNSString( | 177 std::string host; |
| 177 "https://" + certRequestInfo_->host_and_port); | 178 int port; |
| 178 // Setting the domain causes the dialog to record the preferred | 179 if (net::ParseHostAndPort(certRequestInfo_->host_and_port, &host, &port)) { |
| 179 // identity in the system keychain. | 180 // Safari does not include the port number in its identity preferences, so |
| 180 [panel setDomain:domain]; | 181 // similarly strip it off. |
| 182 NSString* domain = base::SysUTF8ToNSString("https://" + host); |
| 183 // Setting the domain causes the dialog to record the preferred |
| 184 // identity in the system keychain. |
| 185 [panel setDomain:domain]; |
| 186 } else { |
| 187 NOTREACHED(); |
| 188 } |
| 181 [panel setInformativeText:message]; | 189 [panel setInformativeText:message]; |
| 182 [panel setDefaultButtonTitle:l10n_util::GetNSString(IDS_OK)]; | 190 [panel setDefaultButtonTitle:l10n_util::GetNSString(IDS_OK)]; |
| 183 [panel setAlternateButtonTitle:l10n_util::GetNSString(IDS_CANCEL)]; | 191 [panel setAlternateButtonTitle:l10n_util::GetNSString(IDS_CANCEL)]; |
| 184 SecPolicyRef sslPolicy; | 192 SecPolicyRef sslPolicy; |
| 185 if (net::X509Certificate::CreateSSLClientPolicy(&sslPolicy) == noErr) { | 193 if (net::X509Certificate::CreateSSLClientPolicy(&sslPolicy) == noErr) { |
| 186 [panel setPolicies:(id)sslPolicy]; | 194 [panel setPolicies:(id)sslPolicy]; |
| 187 CFRelease(sslPolicy); | 195 CFRelease(sslPolicy); |
| 188 } | 196 } |
| 189 | 197 |
| 190 window_ = | 198 window_ = |
| 191 parent->CreateConstrainedDialog(new ConstrainedSFChooseIdentityPanel( | 199 parent->CreateConstrainedDialog(new ConstrainedSFChooseIdentityPanel( |
| 192 panel, self, | 200 panel, self, |
| 193 @selector(sheetDidEnd:returnCode:context:), | 201 @selector(sheetDidEnd:returnCode:context:), |
| 194 identities_, title)); | 202 identities_, title)); |
| 195 // Note: SFChooseIdentityPanel does not take a reference to itself while the | 203 // Note: SFChooseIdentityPanel does not take a reference to itself while the |
| 196 // sheet is open. Don't release the ownership claim until the sheet has ended | 204 // sheet is open. Don't release the ownership claim until the sheet has ended |
| 197 // in |-sheetDidEnd:returnCode:context:|. | 205 // in |-sheetDidEnd:returnCode:context:|. |
| 198 } | 206 } |
| 199 | 207 |
| 200 @end | 208 @end |
| OLD | NEW |